PDA按单移位修改

This commit is contained in:
秦鸿展
2026-03-16 16:16:28 +08:00
parent 17103690aa
commit aaf44fe929
2 changed files with 34 additions and 14 deletions
@@ -1,4 +1,4 @@
package com.mhd.wms.domain.shiftManage.service; package com.mhd.wms.domain.shiftManage.service;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
@@ -674,7 +674,14 @@ public class ShiftManageDomainService {
shiftManage.setShiftQuantity(shiftManageDO.getShiftQuantity()); shiftManage.setShiftQuantity(shiftManageDO.getShiftQuantity());
shiftManage.setShiftMaterialQuantity(shiftManageDO.getShiftMaterialQuantity()); shiftManage.setShiftMaterialQuantity(shiftManageDO.getShiftMaterialQuantity());
int shiftStatus = 3; int shiftStatus = 3;
if(shiftManageDO.getShiftQuantity().compareTo(shiftManagePO.getQuantity()) >= 0){ // 多条物料时,需要查询所有明细,判断是否全部已完成移位(shiftQuantity >= quantity),才能置为已完成
ShiftMaterialDetailDO queryDetailDO = new ShiftMaterialDetailDO();
queryDetailDO.setShiftNumber(shiftManagePO.getShiftNumber());
List<ShiftMaterialDetailPO> allDetails = shiftMaterialDetailService.queryList(queryDetailDO);
boolean allDone = !allDetails.isEmpty() && allDetails.stream().allMatch(d ->
d.getShiftQuantity() != null && d.getQuantity() != null
&& d.getShiftQuantity().compareTo(d.getQuantity()) >= 0);
if (allDone) {
shiftStatus = 4; shiftStatus = 4;
} }
shiftManage.setShiftStatus(shiftStatus); shiftManage.setShiftStatus(shiftStatus);
@@ -705,32 +712,44 @@ public class ShiftManageDomainService {
ShiftMaterialDetailDO shiftMaterialDetailDO = new ShiftMaterialDetailDO(); ShiftMaterialDetailDO shiftMaterialDetailDO = new ShiftMaterialDetailDO();
shiftMaterialDetailDO.setShiftNumber(shiftNumber); shiftMaterialDetailDO.setShiftNumber(shiftNumber);
List<ShiftMaterialDetailPO> shiftMaterialDetailPOList = shiftMaterialDetailService.queryListChildren(shiftMaterialDetailDO); List<ShiftMaterialDetailPO> shiftMaterialDetailPOList = shiftMaterialDetailService.queryListChildren(shiftMaterialDetailDO);
// 避免 NPEgetMaterialMoreDetailList 可能为 null;同一 shift 下 shiftNumber 重复需合并 // key by uniqueId so each detail maps to its own materialMoreDetailList
Map<String, List<MaterialMoreDetailPO>> MaterialMoreDetailMap = shiftMaterialDetailList.stream() Map<Long, List<MaterialMoreDetailPO>> materialMoreDetailMap = new java.util.HashMap<>();
.filter(d -> d.getShiftNumber() != null) for (ShiftMaterialDetailDO d : shiftMaterialDetailList) {
.collect(Collectors.toMap( if (d.getUniqueId() != null) {
ShiftMaterialDetailDO::getShiftNumber, materialMoreDetailMap.put(d.getUniqueId(),
d -> d.getMaterialMoreDetailList() != null ? d.getMaterialMoreDetailList() : new ArrayList<>(), d.getMaterialMoreDetailList() != null ? d.getMaterialMoreDetailList() : new ArrayList<>());
(a, b) -> a }
)); if (!CollectionUtils.isEmpty(d.getChildren())) {
for (ShiftMaterialDetailDO child : d.getChildren()) {
if (child.getUniqueId() != null) {
materialMoreDetailMap.put(child.getUniqueId(),
child.getMaterialMoreDetailList() != null ? child.getMaterialMoreDetailList()
: (d.getMaterialMoreDetailList() != null ? d.getMaterialMoreDetailList() : new ArrayList<>()));
}
}
}
}
for (ShiftMaterialDetailPO shiftMaterialDetailPO : shiftMaterialDetailPOList){ for (ShiftMaterialDetailPO shiftMaterialDetailPO : shiftMaterialDetailPOList){
MaterialInventory materialInventoryOldDb = materialInventoryService.getById(shiftMaterialDetailPO.getMaterialInventoryId()); MaterialInventory materialInventoryOldDb = materialInventoryService.getById(shiftMaterialDetailPO.getMaterialInventoryId());
List<ShiftMaterialDetailPO> shiftMaterialDetailPOChildrenList = shiftMaterialDetailPO.getChildren(); List<ShiftMaterialDetailPO> shiftMaterialDetailPOChildrenList = shiftMaterialDetailPO.getChildren();
boolean hasChildren = !CollectionUtils.isEmpty(shiftMaterialDetailPOChildrenList); boolean hasChildren = !CollectionUtils.isEmpty(shiftMaterialDetailPOChildrenList);
// 有子项时仅用子项参与库存计算,避免父项+子项重复累加(容器移位已改为扁平结构无子项,此处主要防护按单移位的父子同目标场景)
BigDecimal shiftQuantity; BigDecimal shiftQuantity;
if (hasChildren) { if (hasChildren) {
shiftQuantity = shiftMaterialDetailPOChildrenList.stream() shiftQuantity = shiftMaterialDetailPOChildrenList.stream()
.map(c -> c.getShiftQuantity() != null ? c.getShiftQuantity() : BigDecimal.ZERO) .map(c -> c.getShiftQuantity() != null ? c.getShiftQuantity() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add); .reduce(BigDecimal.ZERO, BigDecimal::add);
shiftMaterialDetailPO.setMaterialMoreDetailList(MaterialMoreDetailMap.get(shiftMaterialDetailPO.getShiftNumber())); shiftMaterialDetailPO.setMaterialMoreDetailList(materialMoreDetailMap.get(shiftMaterialDetailPO.getUniqueId()));
for (ShiftMaterialDetailPO shiftMaterialDetailPOChildren : shiftMaterialDetailPOChildrenList) { for (ShiftMaterialDetailPO shiftMaterialDetailPOChildren : shiftMaterialDetailPOChildrenList) {
shiftMaterialDetailPOChildren.setMaterialMoreDetailList(MaterialMoreDetailMap.get(shiftMaterialDetailPO.getShiftNumber())); List<MaterialMoreDetailPO> childMoreDetail = materialMoreDetailMap.get(shiftMaterialDetailPOChildren.getUniqueId());
if (childMoreDetail == null) {
childMoreDetail = materialMoreDetailMap.get(shiftMaterialDetailPO.getUniqueId());
}
shiftMaterialDetailPOChildren.setMaterialMoreDetailList(childMoreDetail);
materialInventoryNowList.add(genMaterialInventory(shiftMaterialDetailPOChildren)); materialInventoryNowList.add(genMaterialInventory(shiftMaterialDetailPOChildren));
} }
} else { } else {
shiftQuantity = shiftMaterialDetailPO.getShiftQuantity() != null ? shiftMaterialDetailPO.getShiftQuantity() : BigDecimal.ZERO; shiftQuantity = shiftMaterialDetailPO.getShiftQuantity() != null ? shiftMaterialDetailPO.getShiftQuantity() : BigDecimal.ZERO;
shiftMaterialDetailPO.setMaterialMoreDetailList(MaterialMoreDetailMap.get(shiftMaterialDetailPO.getShiftNumber())); shiftMaterialDetailPO.setMaterialMoreDetailList(materialMoreDetailMap.get(shiftMaterialDetailPO.getUniqueId()));
materialInventoryNowList.add(genMaterialInventory(shiftMaterialDetailPO)); materialInventoryNowList.add(genMaterialInventory(shiftMaterialDetailPO));
} }
if (materialInventoryOldDb.getInventoryQuantity().compareTo(shiftQuantity) < 0){ if (materialInventoryOldDb.getInventoryQuantity().compareTo(shiftQuantity) < 0){
@@ -6,6 +6,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="com.mhd.wms.domain.shiftMaterialDetail.repository.po.ShiftMaterialDetailPO" id="ShiftMaterialDetailResult"> <resultMap type="com.mhd.wms.domain.shiftMaterialDetail.repository.po.ShiftMaterialDetailPO" id="ShiftMaterialDetailResult">
<result property="shiftIoDetailId" column="shift_io_detail_id" /> <result property="shiftIoDetailId" column="shift_io_detail_id" />
<result property="materialInventoryId" column="material_inventory_id" />
<result property="organizationId" column="organization_id" /> <result property="organizationId" column="organization_id" />
<result property="organizationName" column="organization_name" /> <result property="organizationName" column="organization_name" />
<result property="topOrganizationId" column="top_organization_id" /> <result property="topOrganizationId" column="top_organization_id" />