上架数量显示异常1

This commit is contained in:
秦鸿展
2026-04-15 10:56:04 +08:00
parent fdb70db6f6
commit 1fbdaaaf51
3 changed files with 52 additions and 17 deletions
@@ -872,12 +872,32 @@ public class StockOutOrderApplicationService {
*/
public Boolean cancelAssign(StockOutOrderDO stockOutOrderDO){
StockOutOrderPO infoChildren = getInfoChildren(stockOutOrderDO.getOutOrderId());
BigDecimal alreadyAllocationQuantityAll = infoChildren.getMaterialDetailList().stream().map(OutMaterialDetailPO::getAlreadyAllocationQuantity)
.filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal alreadyAllocationQuantityAll = BigDecimal.ZERO;
if (infoChildren != null && !CollectionUtils.isEmpty(infoChildren.getMaterialDetailList())) {
for (OutMaterialDetailPO line : infoChildren.getMaterialDetailList()) {
alreadyAllocationQuantityAll = alreadyAllocationQuantityAll.add(sumAlreadyAllocationInclusive(line));
}
}
stockOutOrderDO.setAlreadyAllocationQuantityAll(alreadyAllocationQuantityAll);
return stockOutOrderDomainService.cancelAssign(stockOutOrderDO);
}
/** 计划行(含子行)已分配数量之和,用于单头汇总、取消分配等 */
private static BigDecimal sumAlreadyAllocationInclusive(OutMaterialDetailPO node) {
if (node == null) {
return BigDecimal.ZERO;
}
BigDecimal s = node.getAlreadyAllocationQuantity() != null ? node.getAlreadyAllocationQuantity() : BigDecimal.ZERO;
List<OutMaterialDetailPO> ch = node.getChildren();
if (CollectionUtils.isEmpty(ch)) {
return s;
}
for (OutMaterialDetailPO c : ch) {
s = s.add(sumAlreadyAllocationInclusive(c));
}
return s;
}
/**
* @description 手动取消分配(点击确认后直接取消分配)
* @author ZhouGY
@@ -1061,16 +1081,15 @@ public class StockOutOrderApplicationService {
outMaterialDetailDO.setAllowModify(2);
//未分配过货 统计到当前分配单作业分配数
}
totalAllocationQuantity = outMaterialDetailDO.getAllocationQuantity();
// 主行「已分配数量」仅记主行本行分配量;子行各自带自己的已分配,不累加到主行(避免双库位时主项显示成主+子)
BigDecimal parentAllocationQuantity = outMaterialDetailDO.getAllocationQuantity();
//判断是否存在子项
List<OutMaterialDetailDO> returnOutMaterialDetailDOChildList = new ArrayList<>();
List<OutMaterialDetailDO> outMaterialDetailDOChildList = outMaterialDetailDO.getChildren();
if (!CollectionUtils.isEmpty(outMaterialDetailDOChildList)){
BigDecimal totalNowAllocationQuantity = BigDecimal.ZERO;//当前作业分配数量
for (OutMaterialDetailDO outMaterialDetailDOChild : outMaterialDetailDOChildList){
OutMaterialDetailPO outMaterialDetailPOChildDb = outMaterialDetailDbMap.get(outMaterialDetailDOChild.getMaterialDetailId());
if (outMaterialDetailPOChildDb != null){
totalAllocationQuantity = totalAllocationQuantity.add(outMaterialDetailDOChild.getAllocationQuantity());
returnOutMaterialDetailDOChildList.add(outMaterialDetailDOChild);
continue;
}
@@ -1092,11 +1111,9 @@ public class StockOutOrderApplicationService {
returnOutMaterialDetailDOChild.setLevel(2);
returnOutMaterialDetailDOChild.setParentUniqueId(outMaterialDetailPO.getUniqueId());
returnOutMaterialDetailDOChildList.add(returnOutMaterialDetailDOChild);
totalAllocationQuantity = totalAllocationQuantity.add(returnOutMaterialDetailDOChild.getAllocationQuantity());
}
}
//主单当分配作业数量和
outMaterialDetailDO.setAlreadyAllocationQuantity(totalAllocationQuantity);
outMaterialDetailDO.setAlreadyAllocationQuantity(parentAllocationQuantity);
OutMaterialDetailDO returnOutMaterialDetailDO = new OutMaterialDetailDO();
BeanUtils.copyProperties(outMaterialDetailPO, returnOutMaterialDetailDO);
BeanUtils.copyProperties(outMaterialDetailDO, returnOutMaterialDetailDO, IgnoreNullUtil.getNullPropertyNames(outMaterialDetailDO));
@@ -1295,7 +1312,11 @@ public class StockOutOrderApplicationService {
outMaterialDetailPOList.forEach(outMaterialDetailPO -> {
BigDecimal quantity = outMaterialDetailPO.getQuantity(); // 计划数量
BigDecimal alreadyAllocationQuantity = outMaterialDetailPO.getAlreadyAllocationQuantity(); // 已分配数量
List<OutMaterialDetailPO> ch = outMaterialDetailPO.getChildren();
if (!CollectionUtils.isEmpty(ch)) {
alreadyAllocationQuantity = sumAlreadyAllocationInclusive(outMaterialDetailPO);
}
// 判断按钮显示类型
// 已分配数量 = 0:显示"库存分配"按钮(类型1
// 已分配数量 = 计划数量:显示"取消分配"按钮(类型2
@@ -1311,9 +1332,8 @@ public class StockOutOrderApplicationService {
}
// 递归处理子级
List<OutMaterialDetailPO> children = outMaterialDetailPO.getChildren();
if (!CollectionUtils.isEmpty(children)) {
setAllocationButtonTypeRecursively(children);
if (!CollectionUtils.isEmpty(ch)) {
setAllocationButtonTypeRecursively(ch);
}
});
}
@@ -311,7 +311,7 @@ public class StockShelfOrderApplicationService {
// 第一次上架:主项无子项时,上架数量默认等于收货数量(quantity 由上架单生成时取自收货数量),供 PDA 表单默认展示
fillFirstShelvesQuantityDefault(shelfMaterialDetailPOList);
// PC 端(addParentCopyWhenNoChildren==false):与收货单 getInfo 相同流水线——先按行递归汇总部净重/毛重/体面积,再扁平化主行、清空子行计划数量、待上架数量,最后按「计划−已上架」覆盖 total* 展示(对齐收货详情计算口径)
// PC 端(addParentCopyWhenNoChildren==false):单头 total* 仍按明细树递归汇总;明细行净重/毛重/体积/面积<strong>不</strong>做「计划−已上架」覆盖,保持 shelf_material_detail 库表值
if (!addParentCopyWhenNoChildren) {
BigDecimal totalNetWeight = BigDecimal.ZERO;
BigDecimal totalGrossWeight = BigDecimal.ZERO;
@@ -333,8 +333,6 @@ public class StockShelfOrderApplicationService {
flattenShelfMaterialDetailList(shelfMaterialDetailPOList, shelfOrderCompleted);
clearChildQuantityShelfRecursively(shelfMaterialDetailPOList);
fillPendingShelvesQuantityRecursively(shelfMaterialDetailPOList);
Map<Long, WeightMetrics> planWeightMetrics = loadReceiptPlanWeightMetrics(stockShelfOrderPO.getReceiptOrderNumber());
overwriteTotalWithPendingForPdaWeightDisplayRecursively(shelfMaterialDetailPOList, planWeightMetrics);
syncMaterialMoreDetailWeightValuesRecursively(shelfMaterialDetailPOList);
}
@@ -1094,6 +1092,14 @@ public class StockShelfOrderApplicationService {
BigDecimal alreadyVol = d.getAlreadyShelvesVolume() != null ? d.getAlreadyShelvesVolume() : BigDecimal.ZERO;
BigDecimal alreadyArea = d.getAlreadyShelvesArea() != null ? d.getAlreadyShelvesArea() : BigDecimal.ZERO;
// level=1 有子行:待上架 = 计划 − (主行+子行)已上架;flatten 不再把主行重量汇总后,此处必须用整卡累计参与扣减,否则会只减主行
if (d.getLevel() != null && d.getLevel() == 1 && !CollectionUtils.isEmpty(d.getChildren())) {
alreadyNet = sumShelfPlanRowAggregatedAlreadyMetric(d, ShelfMaterialDetailPO::getAlreadyShelvesNetWeight);
alreadyGross = sumShelfPlanRowAggregatedAlreadyMetric(d, ShelfMaterialDetailPO::getAlreadyShelvesGrossWeight);
alreadyVol = sumShelfPlanRowAggregatedAlreadyMetric(d, ShelfMaterialDetailPO::getAlreadyShelvesVolume);
alreadyArea = sumShelfPlanRowAggregatedAlreadyMetric(d, ShelfMaterialDetailPO::getAlreadyShelvesArea);
}
// level=2 子行:计划为整张卡;已上架量用主行+子行 DB 累计之和(主行自身字段不再汇总时仍按整卡扣计划)
if (planParent != null && d.getLevel() != null && d.getLevel() == 2) {
alreadyNet = sumShelfPlanRowAggregatedAlreadyMetric(planParent, ShelfMaterialDetailPO::getAlreadyShelvesNetWeight);
@@ -317,8 +317,17 @@ public class OutMaterialDetailImpl extends ServiceImpl<OutMaterialDetailMapper,
// 有子项时父项不参与库存扣减避免父项+子项重复扣减导致数量翻倍子项已代表实际分配
outMaterialDetail.setNowAllocationQuantity(BigDecimal.ZERO);
}
//记录收货单收货总数
totalAllocationQuantity = totalAllocationQuantity.add(outMaterialDetail.getAlreadyAllocationQuantity());
// 单头分配数量= 本计划行主行已分配 + 各子行已分配主行字段不再存主+子合计
BigDecimal lineAllocatedSum = outMaterialDetail.getAlreadyAllocationQuantity() != null
? outMaterialDetail.getAlreadyAllocationQuantity() : BigDecimal.ZERO;
if (!CollectionUtils.isEmpty(materialDetailDOChildList)) {
for (OutMaterialDetailDO childDo : materialDetailDOChildList) {
BigDecimal childAlloc = childDo.getAlreadyAllocationQuantity() != null
? childDo.getAlreadyAllocationQuantity() : BigDecimal.ZERO;
lineAllocatedSum = lineAllocatedSum.add(childAlloc);
}
}
totalAllocationQuantity = totalAllocationQuantity.add(lineAllocatedSum);
}
stockOutOrderPO.setAllocationQuantity(totalAllocationQuantity);
//分配(修改库存)