# WarehouseServiceImpl.java

    package com.mycim.server.asm.service;

    import com.alipay.sofa.runtime.api.annotation.SofaService;
    import com.alipay.sofa.runtime.api.annotation.SofaServiceBinding;
    import com.fa.sesa.exception.Assert;
    import com.fa.sesa.exception.Errors;
    import com.fa.sesa.i18n.I18nUtils;
    import com.mycim.framework.jdbc.Page;
    import com.mycim.framework.utils.lang.StringUtils;
    import com.mycim.framework.utils.lang.collections.MapUtils;
    import com.mycim.framework.utils.lang.math.NumberUtils;
    import com.mycim.framework.utils.lang.time.DateUtils;
    import com.mycim.server.asm.manager.LotInventoryManager;
    import com.mycim.server.asm.manager.MaterialManager;
    import com.mycim.server.asm.manager.WarehouseManager;
    import com.mycim.server.base.manager.NamedObjectManager;
    import com.mycim.server.prp.manager.OperationManager;
    import com.mycim.server.system.manager.ReferenceFileManager;
    import com.mycim.valueobject.MessageIdList;
    import com.mycim.valueobject.ObjectList;
    import com.mycim.valueobject.consts.AsmConst;
    import com.mycim.valueobject.consts.ReferenceDetailNames;
    import com.mycim.valueobject.consts.ReferenceFileConst;
    import com.mycim.valueobject.inv.LotInventoryDO;
    import com.mycim.valueobject.inv.MaterialDO;
    import com.mycim.valueobject.inv.WarehouseInventoryDO;
    import com.mycim.valueobject.inv.WarehouseTransBO;
    import com.mycim.valueobject.inv.value.WarehouseNames;
    import com.mycim.valueobject.prp.Operation;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;

    import java.sql.Timestamp;
    import java.text.SimpleDateFormat;
    import java.util.*;

    /**
     * @author shijie.deng
     * @date 2019/8/27
     **/
    @Service
    @SofaService(interfaceType = WarehouseService.class, bindings = {@SofaServiceBinding(bindingType = "bolt")})
    public class WarehouseServiceImpl implements WarehouseService {

        @Autowired
        private WarehouseManager warehouseManager;

        @Autowired
        private OperationManager operationManager;

        @Autowired
        private ReferenceFileManager referenceFileManager;

        @Autowired
        private MaterialManager materialManager;

        @Autowired
        private NamedObjectManager namedObjectManager;

        @Autowired
        private LotInventoryManager lotInventoryManager;

        @Override
        public Operation getWarehouse(Long facilityRrn, String warehouseId) {
            Assert.isFalse(StringUtils.isEmpty(warehouseId),
                           Errors.create().content("Warehouse Id can not be empty!").build());

            Operation warehouse = operationManager.getOperation(warehouseId, facilityRrn);
            Assert.isFalse(warehouse == null || warehouse.getInstanceRrn() < 1,
                           Errors.create().content("Warehouse Id not exist!").build());

            Assert.isFalse(warehouse.getStoreFlag() == null || !"on".equalsIgnoreCase(warehouse.getStoreFlag()),
                           Errors.create().content("This Warehouse Id is not a Warehouse! Please check it!").build());
            return warehouse;
        }

        @Override
        public List<Map<String, String>> getWarehouseInventoryList(Long warehouseRrn) {
            List<MaterialDO> getWarehouseInventoryList = warehouseManager.getWarehouseInventoryList(warehouseRrn, null);

            return buildWarehouseInfoShowList(getWarehouseInventoryList);
        }

        @Override
        public List<Map<String, String>> getWarehouseInventoryList(Long warehouseRrn, Map<String, String> condition) {
            List<MaterialDO> getWarehouseInventoryList = warehouseManager
                    .getWarehouseInventoryList(warehouseRrn, condition);
            return buildWarehouseInfoShowList(getWarehouseInventoryList);
        }

        @Override
        public List<Map<String, String>> getWarehouseInventoryListForMaterialWithExt(Long warehouseRrn,
                                                                                     Map<String, String> condition) {
            List<MaterialDO> getWarehouseInventoryList = warehouseManager
                    .getWarehouseInventoryListForMaterialWithExt(warehouseRrn, condition);
            return buildWarehouseInfoShowList(getWarehouseInventoryList);
        }

        @Override
        public void checkWarehouseReceiveType(String warehouseId, String materialObjectSubType) {
            String key;
            try {
                // 如果不存在，该底层方法会返回传入参数key_1_value的值
                key = referenceFileManager
                        .getReferenceDetailExchange(ReferenceDetailNames.WAREHOUSE_ACCEPTABLE_TYPE, warehouseId,
                                                    materialObjectSubType, ReferenceFileConst.KEY_2_VALUE);
            } catch (Exception e) {
                key = warehouseId;
            }

            Assert.isFalse(key == warehouseId, Errors.create().key(MessageIdList.ASM_CANT_RECEIVE_MATERIAL_TYPE)
                                                     .content("库房未允许接收该类型{},请到类表{}进行设置!").args(materialObjectSubType,
                                                                                               ReferenceDetailNames.WAREHOUSE_ACCEPTABLE_TYPE)
                                                     .build());
        }

        @Override
        public void receiveMaterialToWarehouse(Long facilityRrn, String userId, String warehouseId,
                                               List<Map<String, Object>> receiptList) throws Exception {
            Operation warehouse = getWarehouse(facilityRrn, warehouseId);

            List<WarehouseTransBO> receiveTrans = new ArrayList<>();
            WarehouseTransBO warehouseTrans;

            for (Map<String, Object> map : receiptList) {
                MaterialDO material = new MaterialDO(MapUtils.getString(map, AsmConst.MATERIAL_ID),
                                                     namedObjectManager.getNamedSpace(facilityRrn, ObjectList.ITEM_KEY),
                                                     ObjectList.ITEM_KEY);
                material = materialManager.getMaterial(material);
                warehouseTrans = new WarehouseTransBO();
                buildWarehouseTrans(warehouseTrans, warehouse, material, map);

                receiveTrans.add(warehouseTrans);
            }

            warehouseManager.saveReceivedMaterialToWarehouse(facilityRrn, userId, receiveTrans);
        }

        @Override
        public List<Map<String, String>> getLotInventoryListInWarehouseByMaterialRrn(Long itemRrn, Long warehouseRrn) {
            return getLotInventoryListForShowInfo(null, itemRrn, warehouseRrn, null, true);
        }

        @Override
        public List<Map<String, String>> getLotInventoryListInWarehouseByMaterialRrn(String lotNumber, Long itemRrn, Long warehouseRrn, boolean isAll) {
            return getLotInventoryListForShowInfo(lotNumber, itemRrn, warehouseRrn, null, isAll);
        }

        @Override
        public List<Map<String, Object>> getMaterialInfoByLot(Long LotRrn) {
            return lotInventoryManager.getMaterialInfoByLot(LotRrn);
        }

        @Override
        public Map<String, Object> getMaterialInfoByUnit(long unitRrn) {
            return lotInventoryManager.getMaterialInfoByUnit(unitRrn);
        }

        @Override
        public LotInventoryDO getLotInventory(String lotNumber, Long itemRrn, Long warehouseRrn) {
            return lotInventoryManager.getLotInventory(lotNumber, itemRrn, warehouseRrn);
        }

        @Override
        public void deleteLotInventory(String lotNumber, Long itemRrn, Long warehouseRrn) {
            lotInventoryManager.deleteLotInventory(lotNumber, itemRrn, warehouseRrn);
        }

        @Override
        public void updateLotInventory(LotInventoryDO lotInventory) {
            lotInventoryManager.updateLotInventory(lotInventory);
        }

        @Override
        public void consumeMaterialFromWarehouse(Long facilityRrn, String userId, String warehouseId, String materialId,
                                                 List<Map<String, Object>> cunsumptionList) throws Exception {
            Operation warehouse = getWarehouse(facilityRrn, warehouseId);
            MaterialDO material = materialManager.getMaterial(
                    new MaterialDO(materialId, namedObjectManager.getNamedSpace(facilityRrn, ObjectList.ITEM_KEY),
                                   ObjectList.ITEM_KEY));

            WarehouseTransBO warehouseTrans;
            LotInventoryDO lotInventory;
            List<WarehouseTransBO> consumptionTrans = new ArrayList<>();

            for (Map<String, Object> map : cunsumptionList) {
                lotInventory = lotInventoryManager
                        .getLotInventory(MapUtils.getString(map, AsmConst.LOT_NUMBER), material.getInstanceRrn(),
                                         warehouse.getInstanceRrn());
                warehouseTrans = new WarehouseTransBO(lotInventory);
                buildWarehouseTrans(warehouseTrans, warehouse, material, map);

                double totalQty = lotInventory.getTotalQuantity();

                lotInventory.setStatus(lotInventoryManager.getLotInventoryStatus(lotInventory.getLotNumber(), totalQty,
                                                                                 warehouseTrans.getTransQty()));

                consumptionTrans.add(warehouseTrans);
            }
            warehouseManager.saveConsumeMaterialFromWarehouse(facilityRrn, userId, consumptionTrans);
        }

        @Override
        public List<Map<String, String>> getLotInventoryListForConsumption(String lotNumber, Long itemRrn,
                                                                           Long warehouseRrn) {
            return getLotInventoryListForShowInfo(lotNumber, itemRrn, warehouseRrn, null, false);
        }

        @Override
        public Page pageLotInventoryListInWarehouse(Page page, Long itemRrn, Long warehouseRrn, String lotNumber) {
            return pageLotInventoryListForShowInfo(page, itemRrn, warehouseRrn, lotNumber);
        }

        @Override
        public void checkWarehouseInventoryQuantityOfWarning(Long warehouseRrn, Long materialRrn, Double quantityOfWarning,
                                                             Double totalConsumeQty) {
            WarehouseInventoryDO warehouseInventory = warehouseManager.getWarehouseInventory(warehouseRrn, materialRrn);
            double totalInWarehouse = warehouseInventory.getTotalQuantity();
            double afterConsumeTotal = totalInWarehouse - totalConsumeQty;
            Assert.isFalse(quantityOfWarning != 0 && afterConsumeTotal < quantityOfWarning,
                           Errors.create().content("消耗物料后，库存数量将低于安全库存数量({}),{}, 请及时补充物料！")
                                 .args(String.format("%.2f", quantityOfWarning),
                                       String.format("%.2f", quantityOfWarning - afterConsumeTotal)).build());
        }

        @Override
        public WarehouseInventoryDO checkWarehouseInventoryQuantityOfWarningForCode(Long warehouseRrn, Long materialRrn) {
            return warehouseManager.getWarehouseInventory(warehouseRrn, materialRrn);
        }

        @Override
        public void convertMaterialFromWarehouse(Long facilityRrn, String userId, String warehouseId, String materialId,
                                                 String sourceType,
                                                 List<Map<String, Object>> convertList) throws Exception {
            Operation warehouse = getWarehouse(facilityRrn, warehouseId);
            MaterialDO materialDO = new MaterialDO(materialId,
                                                   namedObjectManager.getNamedSpace(facilityRrn, ObjectList.ITEM_KEY),
                                                   ObjectList.ITEM_KEY);
            MaterialDO material = materialManager.getMaterial(materialDO);

            WarehouseTransBO warehouseTrans;
            LotInventoryDO lotInventory;
            List<WarehouseTransBO> convertTrans = new ArrayList<>();
            for (Map<String, Object> map : convertList) {
                lotInventory = lotInventoryManager
                        .getLotInventory(MapUtils.getString(map, AsmConst.LOT_NUMBER), material.getInstanceRrn(),
                                         warehouse.getInstanceRrn());
                warehouseTrans = new WarehouseTransBO(lotInventory);
                buildWarehouseTrans(warehouseTrans, warehouse, material, map);

                lotInventory.setStatus(lotInventoryManager.getLotInventoryStatus(lotInventory.getLotNumber(),
                                                                                 lotInventory.getTotalQuantity(),
                                                                                 warehouseTrans.getTransQty()));

                warehouseTrans.setTargetType(MapUtils.getString(map, AsmConst.CONVERSION_TYPE));
                warehouseTrans.setTransType(buildConversionTargetType(sourceType, warehouseTrans.getTargetType()));
                warehouseTrans.setTargetLotNumber(StringUtils.substringBeforeLast(lotInventory.getLotNumber(), sourceType) +
                                                          warehouseTrans.getTargetType());

                convertTrans.add(warehouseTrans);
            }

            warehouseManager.saveConvertMaterialFromWarehouse(facilityRrn, userId, convertTrans);
        }

        @Override
        public List<Map<String, String>> getLotInventoryListForConversion(String lotNumber, Long itemRrn, Long warehouseRrn,
                                                                          String transType) {
            return getLotInventoryListForShowInfo(lotNumber, itemRrn, warehouseRrn, transType, false);
        }

        @Override
        public void stocktakeMaterialFromWarehouse(Long facilityRrn, String userId, String warehouseId, String materialId,
                                                   List<Map<String, Object>> stocktakeList) throws Exception {
            Operation warehouse = getWarehouse(facilityRrn, warehouseId);
            MaterialDO materialDO = new MaterialDO(materialId,
                                                   namedObjectManager.getNamedSpace(facilityRrn, ObjectList.ITEM_KEY),
                                                   ObjectList.ITEM_KEY);
            MaterialDO material = materialManager.getMaterial(materialDO);

            WarehouseTransBO warehouseTrans;
            LotInventoryDO lotInventory;
            List<WarehouseTransBO> stocktakeTrans = new ArrayList<>();
            for (Map<String, Object> map : stocktakeList) {
                lotInventory = lotInventoryManager
                        .getLotInventory(MapUtils.getString(map, AsmConst.LOT_NUMBER), material.getInstanceRrn(),
                                         warehouse.getInstanceRrn());
                warehouseTrans = new WarehouseTransBO(lotInventory);
                buildWarehouseTrans(warehouseTrans, warehouse, material, map);

                double totalQty = lotInventory.getTotalQuantity();

                if (warehouseTrans.getTransQty() == 0) {
                    lotInventory.setStatus(WarehouseNames.CLOSE_STATUS);
                }

                warehouseTrans.setTransQty(warehouseTrans.getTransQty() - totalQty);

                stocktakeTrans.add(warehouseTrans);
            }
            warehouseManager.saveStocktakeMaterialFromWarehouse(facilityRrn, userId, stocktakeTrans);
        }

        @Override
        public List<Map<String, String>> getLotInventoryListForStocktake(String lotNumber, Long itemRrn, Long warehouseRrn,
                                                                         String transType) {
            return getLotInventoryListForShowInfo(lotNumber, itemRrn, warehouseRrn, transType, true);
        }

        @Override
        public void transferMaterialFromWarehouse(Long facilityRrn, String userId, String fromWarehouseId,
                                                  String toWarehouseId, String materialId,
                                                  List<Map<String, Object>> transferList) throws Exception {
            Operation fromWarehouse = getWarehouse(facilityRrn, fromWarehouseId);
            Operation toWarehouse = getWarehouse(facilityRrn, toWarehouseId);

            MaterialDO materialDO = new MaterialDO(materialId,
                                                   namedObjectManager.getNamedSpace(facilityRrn, ObjectList.ITEM_KEY),
                                                   ObjectList.ITEM_KEY);
            // 获取物料信息
            MaterialDO material = materialManager.getMaterial(materialDO);

            checkWarehouseReceiveType(toWarehouse.getInstanceId(), material.getObjectSubtype());

            WarehouseTransBO warehouseTrans;
            LotInventoryDO lotInventory;
            List<WarehouseTransBO> transferTrans = new ArrayList<>();
            for (Map<String, Object> map : transferList) {
                lotInventory = lotInventoryManager
                        .getLotInventory(MapUtils.getString(map, AsmConst.LOT_NUMBER), material.getInstanceRrn(),
                                         fromWarehouse.getInstanceRrn());
                warehouseTrans = new WarehouseTransBO(lotInventory);
                buildWarehouseTrans(warehouseTrans, fromWarehouse, material, map);

                lotInventory.setStatus(lotInventoryManager.getLotInventoryStatus(lotInventory.getLotNumber(),
                                                                                 lotInventory.getTotalQuantity(),
                                                                                 warehouseTrans.getTransQty()));

                warehouseTrans.setToWarehouseRrn(toWarehouse.getInstanceRrn());
                warehouseTrans.setToWarehouseId(toWarehouse.getInstanceId());
                warehouseTrans.setTransQty(-warehouseTrans.getTransQty());

                transferTrans.add(warehouseTrans);
            }

            warehouseManager.saveTransferMaterialFromWarehouse(facilityRrn, userId, transferTrans);
        }

        @Override
        public Page getInventoryTransHistoryForPage(Page page, Long warehouseRrn, Long materialRrn, String lotNumber,
                                                    String transId, Timestamp startDateTime, Timestamp endDateTime) {
            Page resultPage = warehouseManager
                    .getInventoryTransHistoryForPage(page, warehouseRrn, materialRrn, lotNumber, transId, startDateTime,
                                                     endDateTime);
            List<Map<String, String>> resultList = (List<Map<String, String>>) resultPage.getResults();
            for (Map<String, String> map : resultList) {
                map.put(AsmConst.MATERIAL_DESC, StringUtils.defaultString(map.get(AsmConst.MATERIAL_DESC)));
                map.put(AsmConst.TRANS_TYPE, StringUtils.defaultString(referenceFileManager.getReferenceDetailExchange(
                        ReferenceDetailNames.INV_TRANS_ID, map.get(AsmConst.TRANS_TYPE), ReferenceFileConst.DATA_1_VALUE),
                                                                       map.get(AsmConst.TRANS_TYPE)));
                map.put(AsmConst.COMMENTS, StringUtils.defaultString(map.get(AsmConst.COMMENTS)));
            }
            return resultPage;
        }

        @Override
        public long consumeItemQty(List<Map<String, Object>> consumedItems, String userId, long facilityRrn,
                                   Long checklistJobRrn) {
            return warehouseManager.consumeItemQty(consumedItems, userId, facilityRrn, checklistJobRrn);
        }

        @Override
        public Page getLotConsumesMaterialHistoryForPage(Page page, Map<String, Object> conditions) {
            return warehouseManager.getLotConsumesMaterialHistoryForPage(page, conditions);
        }

        @Override
        public Page getReceiveHistoryForPage(Page page, Long warehouseRrn, Long materialRrn, String lotNumber,
                                             Timestamp startDateTime, Timestamp endDateTime) {
            return warehouseManager
                    .getReceiveHistoryForPage(page, warehouseRrn, materialRrn, lotNumber, startDateTime, endDateTime);
        }

        @Override
        public List<Map<String, String>> getLotInventoryListForConversion4Erp(String lotNumber, Long itemRrn,
                                                                              Long warehouseRrn) {
            List<LotInventoryDO> lotInventoryList = lotInventoryManager
                    .getLotInventoryList4Erp(itemRrn, warehouseRrn, lotNumber);
            List<Map<String, String>> result = new ArrayList<>();
            for (LotInventoryDO lotInventoryDO : lotInventoryList) {
                if (lotInventoryDO.getTotalQuantity() > 0) {
                    result.add(buildLotInventoryShowInfo(lotInventoryDO, lotInventoryDO.getTotalQuantity()));
                }
            }
            return result;
        }

        @Override
        public List<Map<String, String>> getLotInventoryListForConversionForBom(String lotNumber, Long itemRrn,
                                                                                Long warehouseRrn) {
            List<LotInventoryDO> lotInventoryList = lotInventoryManager
                    .getLotInventoryList4Erp(itemRrn, warehouseRrn, lotNumber);
            List<Map<String, String>> result = new ArrayList<>();
            for (LotInventoryDO lotInventoryDO : lotInventoryList) {
                if (lotInventoryDO.getTotalQuantity() > 0) {
                    result.add(buildLotInventoryShowInfoForBom(lotInventoryDO, lotInventoryDO.getTotalQuantity()));
                }
            }
            return result;
        }

        private String buildTargetLotNumber(String sourceLotNumber, String sourceType, String targetType) {
            return StringUtils.substringBeforeLast(sourceLotNumber, sourceType) + targetType;
        }

        /**
         * 构建库存物料显示列表
         */
        private List<Map<String, String>> buildWarehouseInfoShowList(List<MaterialDO> getWarehouseInventoryList) {
            List<Map<String, String>> results = new ArrayList<>();
            Map<String, String> map;
            for (Iterator<MaterialDO> iterator = getWarehouseInventoryList.iterator(); iterator.hasNext(); ) {
                MaterialDO materialDO = iterator.next();
                if (materialDO.getTotalQuantity() <= 0) {
                    //数量为0的，过滤掉不显示
                    continue;
                }
                map = new HashMap<>();
                map.put(AsmConst.MATERIAL_ID, materialDO.getInstanceId());
                map.put(AsmConst.MATERIAL_DESC, materialDO.getInstanceDesc());
                map.put(AsmConst.MATERIAL_TYPE_DESC, referenceFileManager
                        .getReferenceDetailExchange(ReferenceDetailNames.MATERIAL_TYPE, materialDO.getObjectSubtype(),
                                                    ReferenceFileConst.DATA_1_VALUE));
                map.put(AsmConst.MATERIAL_SUB_TYPE_DESC, referenceFileManager
                        .getReferenceDetailExchange(ReferenceDetailNames.MATERIAL_SUB_TYPE, materialDO.getItemClass(),
                                                    ReferenceFileConst.DATA_1_VALUE));
                map.put(AsmConst.QUANTITY, StringUtils.toString(materialDO.getTotalQuantity()));
                map.put(AsmConst.STORE_UOM_DESC, referenceFileManager
                        .getReferenceDetailExchange(ReferenceDetailNames.UNIT_OF_MEASURE_FOR_BANK, materialDO.getStoreUom(),
                                                    ReferenceFileConst.DATA_1_VALUE));
                results.add(map);
            }
            return results;
        }

        private void buildWarehouseTrans(WarehouseTransBO warehouseTrans, Operation warehouse, MaterialDO material,
                                         Map<String, Object> map) throws Exception {
            warehouseTrans.setTransQty(NumberUtils.toDouble(MapUtils.getString(map, AsmConst.QTY)));
            String equipment = MapUtils.getString(map, "equipmentId");
            String language = I18nUtils.getCurrentLanguage().name();
            if (StringUtils.isNotEmpty(equipment)) {
                if ("CN".equalsIgnoreCase(language)) {
                    equipment = " 消耗机台号:" + equipment;
                } else {
                    equipment = " Consumed Equipment ID:" + equipment;
                }
            } else {
                equipment = StringUtils.EMPTY;
            }
            warehouseTrans.setTransComments(MapUtils.getString(map, AsmConst.COMMENTS) + equipment);

            LotInventoryDO lotInventory = warehouseTrans.getLotInventoryDO();

            lotInventory.setLotNumber(StringUtils.trim(MapUtils.getString(map, AsmConst.LOT_NUMBER)));
            lotInventory.setItemRrn(material.getInstanceRrn());
            lotInventory.setWarehouseRrn(warehouse.getInstanceRrn());
            lotInventory.setWarehouseId(warehouse.getInstanceId());
            lotInventory.setMaterialType(material.getObjectSubtype());

            lotInventory.setReceiptDate(new Timestamp(System.currentTimeMillis()));
            lotInventory.setExpirationDate(DateUtils.stringToTimestamp(MapUtils.getString(map, AsmConst.EXPIRATION_DATE)));
            lotInventory.setProductionDate(DateUtils.stringToTimestamp(MapUtils.getString(map, AsmConst.PRODUCTION_DATE)));
            lotInventory.setIncomingDate(DateUtils.stringToTimestamp(MapUtils.getString(map, AsmConst.INCOMING_DATE)));
            lotInventory.setCheckDate(DateUtils.stringToTimestamp(MapUtils.getString(map, AsmConst.CHECK_DATE)));
            lotInventory.setCheckUser(MapUtils.getString(map, AsmConst.CHECK_USER));
            lotInventory.setCheckResult(MapUtils.getString(map, AsmConst.CHECK_RESULT));

            warehouseManager.setExpirationDateForReceive(material.getExpirationLength(), lotInventory);

            lotInventory.setAttributeData1(MapUtils.getString(map, AsmConst.SUPPLIER_ID));
            lotInventory.setAttributeData2(MapUtils.getString(map, AsmConst.MANUFACTURER_ID));

            lotInventory.setStatus(WarehouseNames.ACTIVE_STATUS);
        }

        private List<Map<String, String>> getLotInventoryListForShowInfo(String lotNumber, Long itemRrn, Long warehouseRrn,
                                                                         String transType, Boolean isAll) {
            List<LotInventoryDO> lotInventoryList = lotInventoryManager
                    .getLotInventoryList(itemRrn, warehouseRrn, lotNumber, transType);
            List<Map<String, String>> result = new ArrayList<>();
            for (LotInventoryDO lotInventoryDO : lotInventoryList) {
                if (isAll || lotInventoryDO.getTotalQuantity() > 0) {
                    result.add(buildLotInventoryShowInfo(lotInventoryDO, lotInventoryDO.getTotalQuantity()));
                }
            }
            return result;
        }

        private Map<String, String> buildLotInventoryShowInfo(LotInventoryDO lotInventoryDO, double totalQty) {
            Map<String, String> map = new HashMap<>();

            map.put(AsmConst.LOT_NUMBER, lotInventoryDO.getLotNumber());
            map.put(AsmConst.QUANTITY, StringUtils.toString(totalQty));
            map.put(AsmConst.ISSUE_QTY, StringUtils.toString(lotInventoryDO.getIssueQty()));
            map.put(AsmConst.STATUS, lotInventoryDO.getStatus());
            SimpleDateFormat formatter = new SimpleDateFormat(DateUtils.DATE_FORMAT4DAY);
            String expirationDate = "";
            if (lotInventoryDO.getExpirationDate() != null) {
                expirationDate = formatter.format(lotInventoryDO.getExpirationDate());
            }
            map.put(AsmConst.EXPIRATION_DATE, expirationDate);
            String productionDate = "";
            if (lotInventoryDO.getProductionDate() != null) {
                productionDate = formatter.format(lotInventoryDO.getProductionDate());
            }
            map.put(AsmConst.PRODUCTION_DATE, productionDate);
            String incomingDate = "";
            if (lotInventoryDO.getIncomingDate() != null) {
                incomingDate = formatter.format(lotInventoryDO.getIncomingDate());
            }
            map.put(AsmConst.INCOMING_DATE, incomingDate);
            String checkDate = "";
            if (lotInventoryDO.getCheckDate() != null) {
                checkDate = formatter.format(lotInventoryDO.getCheckDate());
            }
            map.put(AsmConst.CHECK_DATE, checkDate);
            map.put(AsmConst.CHECK_USER, StringUtils.defaultString(lotInventoryDO.getCheckUser()));
            map.put(AsmConst.CHECK_RESULT, StringUtils.defaultString(lotInventoryDO.getCheckResult()));
            map.put(AsmConst.SUPPLIER_ID, StringUtils.defaultString(referenceFileManager.getReferenceDetailExchange(
                    ReferenceDetailNames.RAW_WAFER_SUPPLIER, lotInventoryDO.getAttributeData1(),
                    ReferenceFileConst.DATA_1_VALUE)));
            map.put(AsmConst.MANUFACTURER_ID, StringUtils.defaultString(lotInventoryDO.getAttributeData2()));
            map.put("workOrderId", StringUtils.defaultString(lotInventoryDO.getAttributeData3()));
            map.put("sapMaterialId", StringUtils.defaultString(lotInventoryDO.getAttributeData4()));

            return map;
        }

        private Map<String, String> buildLotInventoryShowInfoForBom(LotInventoryDO lotInventoryDO, double totalQty) {
            Map<String, String> map = new HashMap<>();

            map.put(AsmConst.LOT_NUMBER, lotInventoryDO.getLotNumber());
            map.put(AsmConst.QUANTITY, StringUtils.toString(totalQty));
            map.put(AsmConst.ISSUE_QTY, StringUtils.toString(lotInventoryDO.getIssueQty()));
            map.put(AsmConst.STATUS, lotInventoryDO.getStatus());
            SimpleDateFormat formatter = new SimpleDateFormat(DateUtils.DATE_FORMAT4DAY);
            String expirationDate = "";
            if (lotInventoryDO.getExpirationDate() != null) {
                expirationDate = formatter.format(lotInventoryDO.getExpirationDate());
            }
            map.put(AsmConst.EXPIRATION_DATE, expirationDate);
            String productionDate = "";
            if (lotInventoryDO.getProductionDate() != null) {
                productionDate = formatter.format(lotInventoryDO.getProductionDate());
            }
            map.put(AsmConst.PRODUCTION_DATE, productionDate);
            String incomingDate = "";
            if (lotInventoryDO.getIncomingDate() != null) {
                incomingDate = formatter.format(lotInventoryDO.getIncomingDate());
            }
            map.put(AsmConst.INCOMING_DATE, incomingDate);
            String checkDate = "";
            if (lotInventoryDO.getCheckDate() != null) {
                checkDate = formatter.format(lotInventoryDO.getCheckDate());
            }
            map.put(AsmConst.CHECK_DATE, checkDate);
            map.put(AsmConst.CHECK_USER, StringUtils.defaultString(lotInventoryDO.getCheckUser()));
            map.put(AsmConst.CHECK_RESULT, StringUtils.defaultString(lotInventoryDO.getCheckResult()));
            map.put(AsmConst.SUPPLIER_ID, StringUtils.defaultString(referenceFileManager.getReferenceDetailExchange(
                    ReferenceDetailNames.RAW_WAFER_SUPPLIER, lotInventoryDO.getAttributeData1(),
                    ReferenceFileConst.DATA_1_VALUE)));
            map.put(AsmConst.MANUFACTURER_ID, StringUtils.defaultString(lotInventoryDO.getAttributeData2()));

            map.put("sapClintId", StringUtils.defaultString(lotInventoryDO.getAttributeData3())); //sap client号
            map.put("materialType", StringUtils.defaultString(lotInventoryDO.getAttributeData4()));//主辅料
            map.put("materialCertificateId", StringUtils.defaultString(lotInventoryDO.getAttributeData1()));//物料凭证号

            return map;
        }

        private Page pageLotInventoryListForShowInfo(Page page, Long itemRrn, Long warehouseRrn, String lotNumber) {
            Page pageResult = lotInventoryManager.pageLotInventoryList(page, itemRrn, warehouseRrn, lotNumber);
            List<LotInventoryDO> lotInventoryList = (List<LotInventoryDO>) pageResult.getResults();
            List<Map<String, String>> result = new ArrayList<>();
            for (LotInventoryDO lotInventoryDO : lotInventoryList) {
                result.add(buildLotInventoryShowInfo(lotInventoryDO, lotInventoryDO.getTotalQuantity()));
            }
            pageResult.setResults(result);
            return pageResult;
        }

        private String buildConversionTargetType(String sourceType, String targetType) {
            String transId = referenceFileManager
                    .getReferenceDetailExchange(ReferenceDetailNames.TRANS_MATERIAL_TYPE, sourceType, targetType,
                                                ReferenceFileConst.DATA_3_VALUE);
            if (StringUtils.isNotBlank(transId)) {
                return transId;
            } else {
                return sourceType + "->" + targetType;
            }
        }

    }