WarehouseTransactionHistoryAction.java
package com.mycim.webapp.actions.warehouse;
import com.fa.sesa.exception.Assert;
import com.fa.sesa.exception.Errors;
import com.fa.sesa.exception.SystemIllegalArgumentException;
import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.framework.jdbc.Page;
import com.mycim.framework.utils.lang.StringUtils;
import com.mycim.framework.utils.lang.math.NumberUtils;
import com.mycim.framework.utils.lang.time.DateUtils;
import com.mycim.valueobject.MessageIdList;
import com.mycim.valueobject.prp.Operation;
import com.mycim.webapp.actions.AsmSetupAction;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Map;
/**
* 库房事务历史
*
* @author yanbing.chen
* @date 2019/9/3
* @since 1.8
**/
public class WarehouseTransactionHistoryAction extends AsmSetupAction {
/**
* 查询库房历史
*/
public Map queryInventoryTransHistory(Map map) {
long facilityRrn = LocalContext.getFacilityRrn();
String warehouseId = map.get("warehouseId").toString();
Assert.isFalse(StringUtils.isEmpty(warehouseId),
Errors.create().key(MessageIdList.ASM_MISSING_WAREHOUSE_ID).content("库房号不能为空!").build());
Operation warehouse = warehouseService.getWarehouse(facilityRrn, warehouseId);
Assert.isFalse(warehouse == null || warehouse.getInstanceRrn() <= 0,
Errors.create().key(MessageIdList.ASM_MISSING_WAREHOUSE).content("库房号不存在!").build());
String materialId = StringUtils.trimToUpperCase(map.get("materialId").toString());
long materialRrn = 0;
if (materialId != null) {
materialRrn = asmService.getAndCheckMaterial(facilityRrn, materialId).getInstanceRrn();
}
String lotNumber = map.get("lotNumber").toString();
String transType = map.get("transType").toString();
String effectiveDateFrom = map.get("effectiveDateFrom").toString();
String effectiveDateTo = map.get("effectiveDateTo").toString();
int effectiveHourFrom = NumberUtils.toInt(map.get("effectiveHourFrom").toString());
int effectiveHourTo = NumberUtils.toInt(map.get("effectiveHourTo").toString());
Timestamp startDateTime = null;
Timestamp endDateTime = null;
try {
startDateTime = DateUtils.parseDateAndHourStringToTimestamp(effectiveDateFrom, effectiveHourFrom);
endDateTime = DateUtils.parseDateAndHourStringToTimestamp(effectiveDateTo, effectiveHourTo);
} catch (Exception e) {
throw new SystemIllegalArgumentException(
Errors.create().key(MessageIdList.ASM_DATEFORMAT_CHECK).content("日期格式不正确,请检查!").build());
}
int pageNo = NumberUtils.toInt(map.get("currentPage").toString());
if (pageNo <= 0) {
pageNo = 1;
}
int pageSize = 10;
Page page = new Page();
page.setPageSize(pageSize);
page.setPageNo(pageNo);
page = warehouseService
.getInventoryTransHistoryForPage(page, warehouse.getInstanceRrn(), materialRrn, lotNumber, transType,
startDateTime, endDateTime);
Map<String, Object> result = new HashMap<>();
result.put("pageSize", page.getNextPage());
result.put("pageNum", page.getPageNo());
result.put("maxPage", page.getTotalPages());
result.put("startRowNum", page.getStartRow());
result.put("isFirstPage", page.isFirstPage());
result.put("hasPreviousPage", page.isHasPrePage());
result.put("isLastPage", page.isLastPage());
result.put("hasNextPage", page.isHasNextPage());
result.put("list", page.getResults());
return result;
}
}