ReceiveMaterialHistoryAction.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 chaoyu.song
 * @date 2020/7/16
 * @since 1.8
 **/
public class ReceiveMaterialHistoryAction 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 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
                .getReceiveHistoryForPage(page, warehouse.getInstanceRrn(), materialRrn, lotNumber, 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;
    }

}