完善同步代码

This commit is contained in:
刘名喜 2024-12-13 15:57:59 +08:00
parent e19e5f36be
commit c0fc567b10

View File

@ -6,6 +6,7 @@ import com.ktg.common.utils.StringUtils;
import com.ktg.mes.md.domain.*;
import com.ktg.mes.md.mapper.*;
import com.ktg.mes.md.service.IWmsOutPlanService;
import com.ktg.mes.stl.domain.InventoryAdjustment;
import com.ktg.mes.stl.mapper.InventoryAdjustmentMapper;
import com.ktg.mes.wm.domain.WmStorageArea;
import com.ktg.mes.wm.mapper.WmStorageAreaMapper;
@ -295,12 +296,19 @@ public class WmsOutPlanServiceImpl implements IWmsOutPlanService {
public int synchronizationMiniBox(String username) {
// 获得全部未记录的小货柜出库数据
HashMap<String, List<AP0AE>> ap0aeDateMap = new HashMap<>();
HashMap<String, List<InventoryAdjustment>> inventoryAdjustmentDateMap = new HashMap<>();
List<AP0AE> ap0AEList = ap0AEMapper.selectOutNewData();
List<InventoryAdjustment> inventoryAdjustmentList = this.inventoryAdjustmentMapper.selectOutNewData();
ap0AEList.forEach(ap0AE -> {
String dateKey = new SimpleDateFormat("yyyy-MM-dd").format(ap0AE.getDATE01());
ap0aeDateMap.computeIfAbsent(dateKey, k -> new ArrayList<>());
ap0aeDateMap.get(dateKey).add(ap0AE);
});
inventoryAdjustmentList.forEach(inventoryAdjustment -> {
String dateKey = new SimpleDateFormat("yyyy-MM-dd").format(inventoryAdjustment.getInTime());
inventoryAdjustmentDateMap.computeIfAbsent(dateKey, k -> new ArrayList<>());
inventoryAdjustmentDateMap.get(dateKey).add(inventoryAdjustment);
});
// 根据日期进行分组遍历
ap0aeDateMap.keySet().forEach(dateKey -> {
@ -419,6 +427,122 @@ public class WmsOutPlanServiceImpl implements IWmsOutPlanService {
this.ap0AEMapper.updateOutDataToOld(ap0AE);
});
});
inventoryAdjustmentDateMap.keySet().forEach(dateKey -> {
Date itemDate = new Date();
try {
itemDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateKey + " 00:00:00");
} catch (ParseException ignored) {
}
// 构建出库计划
WmsOutPlan wmsOutPlan = new WmsOutPlan();
wmsOutPlan.setPlanCode(Long.toString(System.currentTimeMillis(), 32).toUpperCase(Locale.ROOT));
wmsOutPlan.setWmsBusinessTypeId(this.wmsBusinessTypeMapper.selectWmsBusinessTypeByCode("DPCK").getTypeId() != null ? Long.parseLong(this.wmsBusinessTypeMapper.selectWmsBusinessTypeByCode("DPCK").getTypeId()) : 11L);
wmsOutPlan.setPlanState("1");
wmsOutPlan.setPlanType("XTTB");
wmsOutPlan.setRemark("同步小型刀具库数据");
wmsOutPlan.setCreateBy(username);
wmsOutPlan.setCreateTime(itemDate);
wmsOutPlanMapper.insertWmsOutPlan(wmsOutPlan);
// 构建出库计划明细
inventoryAdjustmentDateMap.get(dateKey).forEach(inventoryAdjustment -> {
// 获得物料对象
MdItem mdItem = mdItemMapper.selectMdItemByCode(inventoryAdjustment.getProductNumber());
if (mdItem == null) return;
// 获得库位对象
WmStorageArea wmStorageArea = wmStorageAreaMapper.selectWmStorageAreaByAreaCode(inventoryAdjustment.getOutWarehouse());
if (wmStorageArea == null) return;
// 构建出库计划明细
WmsOutPlanDetail wmsOutPlanDetail = new WmsOutPlanDetail();
wmsOutPlanDetail.setWmsOutPlanId(wmsOutPlan.getWmsOutPlanId());
wmsOutPlanDetail.setMdItemId(mdItem.getItemId());
wmsOutPlanDetail.setMdItemCode(mdItem.getItemCode());
wmsOutPlanDetail.setMdItemName(mdItem.getItemName());
wmsOutPlanDetail.setMdItemUnit(mdItem.getUnitName());
wmsOutPlanDetail.setPlannedQuantity((int) inventoryAdjustment.getQuantity().doubleValue());
wmsOutPlanDetail.setRealQuantity((int) inventoryAdjustment.getQuantity().doubleValue());
wmsOutPlanDetail.setDetailBatchNum("1");
wmsOutPlanDetail.setWmStorageAreaId(wmStorageArea.getAreaId());
wmsOutPlanDetail.setWmStorageAreaCode(wmStorageArea.getAreaCode());
wmsOutPlanDetail.setWmStorageAreaName(wmStorageArea.getAreaName());
wmsOutPlanDetail.setDetailState("1");
wmsOutPlanDetail.setRemark("同步小型刀具库数据");
wmsOutPlanDetail.setCreateBy(username);
wmsOutPlanDetail.setCreateTime(inventoryAdjustment.getInTime());
wmsOutPlanMapper.insertWmsOutPlanDetail(wmsOutPlanDetail);
// 获得该出库计划子项对应的工具台账实体
List<BaseKnife> baseKnifeList = this.baseKnifeMapper.selectBaseKnifeListByMbbBdMrlIdAndAreaCodeAndKnifeFineStateAndIsLocked(
wmsOutPlanDetail.getMdItemId(),
wmsOutPlanDetail.getWmStorageAreaCode(),
0
);
// 校验库中数量是否足够
if (baseKnifeList.size() < wmsOutPlanDetail.getPlannedQuantity()) {
throw new RuntimeException("库存数量不足以支持本次出库物料:" + inventoryAdjustment.getProductName());
}
// 开始遍历出库计划子项
baseKnifeList.subList(0, wmsOutPlanDetail.getPlannedQuantity()).forEach(baseKnife -> {
// 构建出库计划明细实体
WmsOutPlanDetailEntity wmsOutPlanDetailEntity = new WmsOutPlanDetailEntity();
wmsOutPlanDetailEntity.setWmsOutPlanDetailId(wmsOutPlanDetail.getWmsOutPlanDetailId());
wmsOutPlanDetailEntity.setBaseKnifeId(baseKnife.getBaseKnifeId());
wmsOutPlanDetailEntity.setAreaCode(baseKnife.getAreaCode());
wmsOutPlanDetailEntity.setItemOrProduct(baseKnife.getItemOrProduct());
wmsOutPlanDetailEntity.setKnifeCode(baseKnife.getKnifeCode());
wmsOutPlanDetailEntity.setKnifeName(baseKnife.getKnifeName());
wmsOutPlanDetailEntity.setPlanSheet(baseKnife.getPlanSheet());
wmsOutPlanDetailEntity.setKnifeLife(baseKnife.getKnifeLife());
wmsOutPlanDetailEntity.setResetCount(baseKnife.getResetCount());
wmsOutPlanDetailEntity.setKnifeUnit(baseKnife.getKnifeUnit());
wmsOutPlanDetailEntity.setSafeStock(baseKnife.getKnifeType());
wmsOutPlanDetailEntity.setStandardQuantity(baseKnife.getStandardQuantity());
// 插入出库计划明细实体
this.wmsOutPlanDetailEntityMapper.insertWmsOutPlanDetailEntity(wmsOutPlanDetailEntity);
// 锁定工具台账中的物料实体
this.baseKnifeMapper.updateBaseKnifeIsLockedByBaseKnifeId(baseKnife.getBaseKnifeId(), 1);
// 锁定并出库台账明细实体
this.baseKnifeMapper.updateBaseKnifeKnifeFineStateAndIsLockedByBaseKnifeId(
wmsOutPlanDetailEntity.getBaseKnifeId(),
2,
1
);
});
// 构建出库任务
WmsOutTask wmsOutTask = new WmsOutTask();
wmsOutTask.setWmsOutPlanId(wmsOutPlan.getWmsOutPlanId());
wmsOutTask.setWmsOutPlanCode(wmsOutPlan.getPlanCode());
wmsOutTask.setWmsOutPlanDetailId(wmsOutPlanDetail.getWmsOutPlanDetailId());
wmsOutTask.setWmsBusinessTypeId(wmsOutPlan.getWmsBusinessTypeId());
wmsOutTask.setTaskCode(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()));
wmsOutTask.setTaskNumber(wmsOutPlanDetail.getPlannedQuantity());
wmsOutTask.setOutNumber(wmsOutPlanDetail.getPlannedQuantity());
wmsOutTask.setWmStorageAreaId(wmsOutPlanDetail.getWmStorageAreaId());
wmsOutTask.setBatchNum(wmsOutPlanDetail.getDetailBatchNum());
wmsOutTask.setMdItemId(wmsOutPlanDetail.getMdItemId());
wmsOutTask.setMdItemCode(wmsOutPlanDetail.getMdItemCode());
wmsOutTask.setMdItemName(wmsOutPlanDetail.getMdItemName());
wmsOutTask.setMdItemUnit(wmsOutPlanDetail.getMdItemUnit());
wmsOutTask.setTaskState("1");
wmsOutTask.setRecipientUsername(wmsOutPlan.getRecipientUsername());
wmsOutTask.setCreateTime(new Date());
// 插入出库任务
this.wmsOutTaskMapper.insertWmsOutTask(wmsOutTask);
// 设置小型货柜数据为已读
this.inventoryAdjustmentMapper.updateOutDataToOld(inventoryAdjustment);
});
});
return 1;
}