Merge remote-tracking branch 'origin/dev_WMS20260401' into dev_WMS20260401
This commit is contained in:
+76
-38
@@ -562,16 +562,22 @@ public class MaterialInventoryImpl extends ServiceImpl<MaterialInventoryMapper,
|
||||
@Override
|
||||
public synchronized void kctzjl(MaterialInventoryParamDO materialInventoryParamDO,
|
||||
String adjustAction,LoginUser loginUser) {
|
||||
//库存调整记录
|
||||
//库存调整记录(在 xgkc 更新库存前调用,materialInventory 为调整前快照)
|
||||
Long materialInventoryId = materialInventoryParamDO.getMaterialInventoryId();
|
||||
MaterialInventory materialInventory = materialInventoryMapper.selectOne(new QueryWrapper<MaterialInventory>().lambda()
|
||||
.eq(MaterialInventory::getMaterialInventoryId, materialInventoryId));
|
||||
if (materialInventory == null) {
|
||||
throw new ServiceException("物料库存不存在,无法生成库存调整记录");
|
||||
}
|
||||
Long materialBaseInfoId = materialInventory.getMaterialBaseInfoId();
|
||||
MaterialBaseInfo materialBaseInfo = materialBaseInfoService.getOne(new QueryWrapper<MaterialBaseInfo>().lambda()
|
||||
.eq(MaterialBaseInfo::getMaterialBaseInfoId, materialBaseInfoId).eq(BaseVOEntity::getDelFlag,1));
|
||||
InventoryAdjustmentRecord inventoryAdjustmentRecord = new InventoryAdjustmentRecord();
|
||||
inventoryAdjustmentRecord.setAdjustAction(adjustAction);
|
||||
inventoryAdjustmentRecord.setRelateNo(materialInventoryParamDO.getInOrderNumber());
|
||||
String relateNo = StringUtils.hasText(materialInventoryParamDO.getRelateNo())
|
||||
? materialInventoryParamDO.getRelateNo()
|
||||
: materialInventoryParamDO.getInOrderNumber();
|
||||
inventoryAdjustmentRecord.setRelateNo(relateNo);
|
||||
inventoryAdjustmentRecord.setAdjustAfterStatusCode(materialInventory.getMaterialStatusCode() == null ? "" : materialInventory.getMaterialStatusCode());
|
||||
inventoryAdjustmentRecord.setAdjustBeforeStatusCode(materialInventory.getMaterialStatusCode() == null ? "" : materialInventory.getMaterialStatusCode());
|
||||
inventoryAdjustmentRecord.setAdjustAfterStatusName(materialInventory.getMaterialStatusName() == null ? "" : materialInventory.getMaterialStatusName());
|
||||
@@ -616,23 +622,45 @@ public class MaterialInventoryImpl extends ServiceImpl<MaterialInventoryMapper,
|
||||
if (userPo != null) inventoryAdjustmentRecord.setCreateByName(userPo.getUserName());
|
||||
inventoryAdjustmentRecord.setCreateTime(new Date());
|
||||
|
||||
BigDecimal qty = nz(materialInventoryParamDO.getQuantity());
|
||||
if ("分配库存".equals(adjustAction)) {
|
||||
inventoryAdjustmentRecord.setAllocationBeforeQuantity(materialInventory.getAllocationQuantity());
|
||||
inventoryAdjustmentRecord.setAllocationAfterQuantity(materialInventory.getAllocationQuantity().subtract(materialInventoryParamDO.getQuantity()));
|
||||
inventoryAdjustmentRecord.setFreezeBeforeQuantity(materialInventory.getFreezeQuantity());
|
||||
inventoryAdjustmentRecord.setFreezeAfterQuantity(materialInventory.getFreezeQuantity().add(materialInventoryParamDO.getQuantity()));//调整后 冻结-出库
|
||||
inventoryAdjustmentRecord.setInventoryBeforeQuantity(materialInventory.getInventoryQuantity());
|
||||
inventoryAdjustmentRecord.setInventoryAfterQuantity(materialInventory.getInventoryQuantity());
|
||||
// 调整前:库存数量(净重、毛重、体积、面积)
|
||||
inventoryAdjustmentRecord.setNetWeight(materialInventory.getNetWeight());
|
||||
inventoryAdjustmentRecord.setGrossWeight(materialInventory.getGrossWeight());
|
||||
inventoryAdjustmentRecord.setVolume(materialInventory.getVolume());
|
||||
inventoryAdjustmentRecord.setArea(materialInventory.getArea());
|
||||
// 调整后:库存数量 - 复核时填写的数量
|
||||
inventoryAdjustmentRecord.setAdjustedNetWeight(materialInventory.getNetWeight());
|
||||
inventoryAdjustmentRecord.setAdjustedGrossWeight(materialInventory.getGrossWeight());
|
||||
inventoryAdjustmentRecord.setAdjustedVolume(materialInventory.getVolume());
|
||||
inventoryAdjustmentRecord.setAdjustedArea(materialInventory.getArea());
|
||||
// 总库存不变;可用减少、冻结增加(数量从可用转至冻结)
|
||||
BigDecimal invBefore = nz(materialInventory.getInventoryQuantity());
|
||||
BigDecimal allocBefore = nz(materialInventory.getAllocationQuantity());
|
||||
BigDecimal freezeBefore = nz(materialInventory.getFreezeQuantity());
|
||||
inventoryAdjustmentRecord.setInventoryBeforeQuantity(invBefore); //调整前库存数量
|
||||
inventoryAdjustmentRecord.setInventoryAfterQuantity(invBefore); //调整后库存数量
|
||||
inventoryAdjustmentRecord.setAllocationBeforeQuantity(allocBefore); //调整前可用数量
|
||||
inventoryAdjustmentRecord.setAllocationAfterQuantity(allocBefore.subtract(qty));//调整后可用数量
|
||||
inventoryAdjustmentRecord.setFreezeBeforeQuantity(freezeBefore);//调整前冻结数量
|
||||
inventoryAdjustmentRecord.setFreezeAfterQuantity(freezeBefore.add(qty));//调整后冻结数量
|
||||
inventoryAdjustmentRecord.setNetWeight(nz(materialInventory.getNetWeight()));//净重
|
||||
inventoryAdjustmentRecord.setGrossWeight(nz(materialInventory.getGrossWeight()));//毛重
|
||||
inventoryAdjustmentRecord.setVolume(nz(materialInventory.getVolume()));//体积
|
||||
inventoryAdjustmentRecord.setArea(nz(materialInventory.getArea()));//积
|
||||
inventoryAdjustmentRecord.setAdjustedNetWeight(nz(materialInventory.getNetWeight()));//净重
|
||||
inventoryAdjustmentRecord.setAdjustedGrossWeight(nz(materialInventory.getGrossWeight()));//毛重
|
||||
inventoryAdjustmentRecord.setAdjustedVolume(nz(materialInventory.getVolume()));//体积
|
||||
inventoryAdjustmentRecord.setAdjustedArea(nz(materialInventory.getArea()));//积
|
||||
} else if ("取消分配".equals(adjustAction)) {
|
||||
// 与分配相反:可用增加、冻结减少,总库存不变
|
||||
BigDecimal invBefore = nz(materialInventory.getInventoryQuantity());
|
||||
BigDecimal allocBefore = nz(materialInventory.getAllocationQuantity());
|
||||
BigDecimal freezeBefore = nz(materialInventory.getFreezeQuantity());
|
||||
inventoryAdjustmentRecord.setInventoryBeforeQuantity(invBefore);
|
||||
inventoryAdjustmentRecord.setInventoryAfterQuantity(invBefore);
|
||||
inventoryAdjustmentRecord.setAllocationBeforeQuantity(allocBefore);
|
||||
inventoryAdjustmentRecord.setAllocationAfterQuantity(allocBefore.add(qty));
|
||||
inventoryAdjustmentRecord.setFreezeBeforeQuantity(freezeBefore);
|
||||
inventoryAdjustmentRecord.setFreezeAfterQuantity(freezeBefore.subtract(qty));
|
||||
inventoryAdjustmentRecord.setNetWeight(nz(materialInventory.getNetWeight()));
|
||||
inventoryAdjustmentRecord.setGrossWeight(nz(materialInventory.getGrossWeight()));
|
||||
inventoryAdjustmentRecord.setVolume(nz(materialInventory.getVolume()));
|
||||
inventoryAdjustmentRecord.setArea(nz(materialInventory.getArea()));
|
||||
inventoryAdjustmentRecord.setAdjustedNetWeight(nz(materialInventory.getNetWeight()));
|
||||
inventoryAdjustmentRecord.setAdjustedGrossWeight(nz(materialInventory.getGrossWeight()));
|
||||
inventoryAdjustmentRecord.setAdjustedVolume(nz(materialInventory.getVolume()));
|
||||
inventoryAdjustmentRecord.setAdjustedArea(nz(materialInventory.getArea()));
|
||||
} else if ("入库".equals(adjustAction)){
|
||||
if ("1".equals(materialInventoryParamDO.getIsNew())) {
|
||||
inventoryAdjustmentRecord.setAllocationBeforeQuantity(BigDecimal.ZERO);
|
||||
@@ -670,22 +698,28 @@ public class MaterialInventoryImpl extends ServiceImpl<MaterialInventoryMapper,
|
||||
inventoryAdjustmentRecord.setAdjustedArea(materialInventory.getArea().add(inventoryAdjustmentRecord.getArea()));
|
||||
}
|
||||
} else if ("出库".equals(adjustAction)){
|
||||
inventoryAdjustmentRecord.setAllocationBeforeQuantity(materialInventory.getAllocationQuantity());
|
||||
inventoryAdjustmentRecord.setAllocationAfterQuantity(materialInventory.getAllocationQuantity());
|
||||
inventoryAdjustmentRecord.setFreezeBeforeQuantity(materialInventory.getFreezeQuantity());
|
||||
inventoryAdjustmentRecord.setFreezeAfterQuantity(materialInventory.getFreezeQuantity());//调整后 冻结-出库
|
||||
inventoryAdjustmentRecord.setInventoryBeforeQuantity(materialInventory.getInventoryQuantity());
|
||||
inventoryAdjustmentRecord.setInventoryAfterQuantity(materialInventory.getInventoryQuantity().subtract(materialInventoryParamDO.getQuantity()));
|
||||
// 调整前:库存数量(净重、毛重、体积、面积)
|
||||
inventoryAdjustmentRecord.setNetWeight(materialInventory.getNetWeight());
|
||||
inventoryAdjustmentRecord.setGrossWeight(materialInventory.getGrossWeight());
|
||||
inventoryAdjustmentRecord.setVolume(materialInventory.getVolume());
|
||||
inventoryAdjustmentRecord.setArea(materialInventory.getArea());
|
||||
// 调整后:库存数量 - 复核时填写的数量
|
||||
inventoryAdjustmentRecord.setAdjustedNetWeight(materialInventory.getNetWeight().subtract(inventoryAdjustmentRecord.getNetWeight()));
|
||||
inventoryAdjustmentRecord.setAdjustedGrossWeight(materialInventory.getGrossWeight().subtract(inventoryAdjustmentRecord.getGrossWeight()));
|
||||
inventoryAdjustmentRecord.setAdjustedVolume(materialInventory.getVolume().subtract(inventoryAdjustmentRecord.getVolume()));
|
||||
inventoryAdjustmentRecord.setAdjustedArea(materialInventory.getArea().subtract(inventoryAdjustmentRecord.getArea()));
|
||||
// 出库交接:总库存与冻结同减 checkQuantity;可用数量不变(与 ckjj 中不修改 allocation_quantity 一致)
|
||||
BigDecimal invBefore = nz(materialInventory.getInventoryQuantity());
|
||||
BigDecimal allocBefore = nz(materialInventory.getAllocationQuantity());
|
||||
BigDecimal freezeBefore = nz(materialInventory.getFreezeQuantity());
|
||||
inventoryAdjustmentRecord.setInventoryBeforeQuantity(invBefore);// 调整前:库存数量
|
||||
inventoryAdjustmentRecord.setInventoryAfterQuantity(invBefore.subtract(qty));// 调整后:库存数量
|
||||
inventoryAdjustmentRecord.setAllocationBeforeQuantity(allocBefore);// 调整前:可用数量
|
||||
inventoryAdjustmentRecord.setAllocationAfterQuantity(allocBefore);// 调整后:可用数量
|
||||
inventoryAdjustmentRecord.setFreezeBeforeQuantity(freezeBefore);// 调整前:冻结数量
|
||||
inventoryAdjustmentRecord.setFreezeAfterQuantity(freezeBefore.subtract(qty));// 调整后:冻结数量
|
||||
BigDecimal nw = nz(materialInventory.getNetWeight());
|
||||
BigDecimal gw = nz(materialInventory.getGrossWeight());
|
||||
BigDecimal vol = nz(materialInventory.getVolume());
|
||||
BigDecimal ar = nz(materialInventory.getArea());
|
||||
inventoryAdjustmentRecord.setNetWeight(nw);
|
||||
inventoryAdjustmentRecord.setGrossWeight(gw);
|
||||
inventoryAdjustmentRecord.setVolume(vol);
|
||||
inventoryAdjustmentRecord.setArea(ar);
|
||||
inventoryAdjustmentRecord.setAdjustedNetWeight(nw.subtract(nz(materialInventoryParamDO.getNetWeight())));
|
||||
inventoryAdjustmentRecord.setAdjustedGrossWeight(gw.subtract(nz(materialInventoryParamDO.getGrossWeight())));
|
||||
inventoryAdjustmentRecord.setAdjustedVolume(vol.subtract(nz(materialInventoryParamDO.getVolume())));
|
||||
inventoryAdjustmentRecord.setAdjustedArea(ar.subtract(nz(materialInventoryParamDO.getArea())));
|
||||
} else if ("移位".equals(adjustAction)){
|
||||
inventoryAdjustmentRecord.setAllocationBeforeQuantity(materialInventory.getAllocationQuantity());
|
||||
inventoryAdjustmentRecord.setAllocationAfterQuantity(materialInventoryParamDO.getQuantity());
|
||||
@@ -704,10 +738,10 @@ public class MaterialInventoryImpl extends ServiceImpl<MaterialInventoryMapper,
|
||||
inventoryAdjustmentRecord.setAdjustedVolume(materialInventory.getVolume());
|
||||
inventoryAdjustmentRecord.setAdjustedArea(materialInventory.getArea());
|
||||
} else if ("库存冻结".equals(adjustAction)) {
|
||||
inventoryAdjustmentRecord.setAllocationBeforeQuantity(materialInventory.getAllocationQuantity());
|
||||
inventoryAdjustmentRecord.setAllocationAfterQuantity(materialInventory.getAllocationQuantity().subtract(materialInventoryParamDO.getQuantity()));
|
||||
inventoryAdjustmentRecord.setFreezeBeforeQuantity(materialInventory.getFreezeQuantity());
|
||||
inventoryAdjustmentRecord.setFreezeAfterQuantity(materialInventory.getFreezeQuantity().add(materialInventoryParamDO.getQuantity()));//调整后 冻结-出库
|
||||
inventoryAdjustmentRecord.setAllocationBeforeQuantity(nz(materialInventory.getAllocationQuantity()));
|
||||
inventoryAdjustmentRecord.setAllocationAfterQuantity(nz(materialInventory.getAllocationQuantity()).subtract(qty));
|
||||
inventoryAdjustmentRecord.setFreezeBeforeQuantity(nz(materialInventory.getFreezeQuantity()));
|
||||
inventoryAdjustmentRecord.setFreezeAfterQuantity(nz(materialInventory.getFreezeQuantity()).add(qty));//调整后 冻结-出库
|
||||
inventoryAdjustmentRecord.setInventoryBeforeQuantity(materialInventory.getInventoryQuantity());
|
||||
inventoryAdjustmentRecord.setInventoryAfterQuantity(materialInventory.getInventoryQuantity());
|
||||
|
||||
@@ -729,6 +763,10 @@ public class MaterialInventoryImpl extends ServiceImpl<MaterialInventoryMapper,
|
||||
inventoryAdjustmentRecordMapper.insert(inventoryAdjustmentRecord);
|
||||
}
|
||||
|
||||
private static BigDecimal nz(BigDecimal v) {
|
||||
return v == null ? BigDecimal.ZERO : v;
|
||||
}
|
||||
|
||||
private void getBarCode(MaterialInventory materialInventoryPO, InventoryAdjustmentRecord inventoryAdjustmentRecord) {
|
||||
List<MaterialBarCodePO> materialBarCodePOList = materialBarCodeService.getInfoByMaterialBaseInfoIds(materialInventoryPO.getMaterialBaseInfoId());
|
||||
if (materialBarCodePOList != null && !materialBarCodePOList.isEmpty()) {
|
||||
|
||||
+3
@@ -102,4 +102,7 @@ public class MaterialInventoryParamDO extends MaterialBaseDO {
|
||||
|
||||
private String isNew;
|
||||
|
||||
/** 业务关联单号(出库单号、交接单对应单号等),用于库存调整记录 relate_no;可与入库单号区分 */
|
||||
private String relateNo;
|
||||
|
||||
}
|
||||
+97
-33
@@ -285,11 +285,17 @@ public class OutMaterialDetailImpl extends ServiceImpl<OutMaterialDetailMapper,
|
||||
}
|
||||
StockOutOrderPO stockOutOrderPO = new StockOutOrderPO();
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
List<OutMaterialDetail> outMaterialDetailDbList = outMaterialDetailMapper.selectList(new QueryWrapper<OutMaterialDetail>().lambda()
|
||||
// 同单全部明细(含子行),用于子行补全 material_inventory_id / unique_id
|
||||
List<OutMaterialDetail> orderAllDetailsDb = outMaterialDetailMapper.selectList(new QueryWrapper<OutMaterialDetail>().lambda()
|
||||
.eq(OutMaterialDetail::getOutOrderNumber, outOrderNumber)
|
||||
.eq(OutMaterialDetail::getLevel, 1)
|
||||
.eq(OutMaterialDetail::getDelFlag, 1));
|
||||
List<OutMaterialDetail> outMaterialDetailDbList = orderAllDetailsDb.stream()
|
||||
.filter(d -> d.getLevel() != null && d.getLevel() == 1)
|
||||
.collect(Collectors.toList());
|
||||
Map<Long, OutMaterialDetail> materialDetailMap = outMaterialDetailDbList.stream().collect(Collectors.toMap(OutMaterialDetail::getMaterialDetailId, Function.identity()));
|
||||
Map<Long, OutMaterialDetail> orderDetailByMaterialDetailId = orderAllDetailsDb.stream()
|
||||
.filter(d -> d.getMaterialDetailId() != null)
|
||||
.collect(Collectors.toMap(OutMaterialDetail::getMaterialDetailId, Function.identity(), (a, b) -> a));
|
||||
//批量新增或修改物料信息
|
||||
List<OutMaterialDetail> outMaterialDetailList = new ArrayList<>();
|
||||
BigDecimal totalAllocationQuantity = BigDecimal.ZERO;//入库单总分配作业数量
|
||||
@@ -319,34 +325,50 @@ public class OutMaterialDetailImpl extends ServiceImpl<OutMaterialDetailMapper,
|
||||
for (OutMaterialDetailDO outMaterialDetailDOChild : materialDetailDOChildList){
|
||||
OutMaterialDetail outMaterialDetailChild = new OutMaterialDetail();
|
||||
BeanUtils.copyProperties(outMaterialDetailDOChild, outMaterialDetailChild, IgnoreNullUtil.getNullPropertyNames(outMaterialDetailDOChild));
|
||||
//outMaterialDetailChild.setMaterialDetailId(null);
|
||||
outMaterialDetailChild.setUniqueId(idGenerator.snowflakeId(SnowFlakeConstants.wmsId));
|
||||
// 已落库子行:保留库中 unique_id、material_inventory_id;若前端未传库存行则从库补全,否则 xgkc 会静默跳过子项
|
||||
OutMaterialDetail childDbRow = outMaterialDetailDOChild.getMaterialDetailId() != null
|
||||
? orderDetailByMaterialDetailId.get(outMaterialDetailDOChild.getMaterialDetailId()) : null;
|
||||
if (childDbRow != null && childDbRow.getUniqueId() != null) {
|
||||
outMaterialDetailChild.setUniqueId(childDbRow.getUniqueId());
|
||||
} else {
|
||||
outMaterialDetailChild.setUniqueId(idGenerator.snowflakeId(SnowFlakeConstants.wmsId));
|
||||
}
|
||||
if (outMaterialDetailChild.getMaterialInventoryId() == null && childDbRow != null && childDbRow.getMaterialInventoryId() != null) {
|
||||
outMaterialDetailChild.setMaterialInventoryId(childDbRow.getMaterialInventoryId());
|
||||
}
|
||||
outMaterialDetailChild.setLevel(2);
|
||||
outMaterialDetailChild.setParentUniqueId(outMaterialDetailDO.getUniqueId());
|
||||
outMaterialDetailChild.setCreateBy(loginUser.getUserid());
|
||||
outMaterialDetailChild.setCreateByName(loginUser.getUsername());
|
||||
outMaterialDetailChild.setCreateTime(new Date());
|
||||
BigDecimal allocationQuantity = outMaterialDetailChild.getAllocationQuantity() != null ? outMaterialDetailChild.getAllocationQuantity() : BigDecimal.ZERO;
|
||||
BigDecimal alreadyAllocationQuantity = outMaterialDetailChild.getAlreadyAllocationQuantity() != null ? outMaterialDetailChild.getAlreadyAllocationQuantity() : BigDecimal.ZERO;
|
||||
BigDecimal nowAllocationQuantity = allocationQuantity.subtract(alreadyAllocationQuantity);
|
||||
// 本次分配 = 目标 allocationQuantity − 库表中原已分配(不依赖请求里的 already,避免与 target 相同被算成 0)
|
||||
BigDecimal childTarget = outMaterialDetailChild.getAllocationQuantity() != null ? outMaterialDetailChild.getAllocationQuantity() : BigDecimal.ZERO;
|
||||
BigDecimal childDbAlready = childDbRow != null && childDbRow.getAlreadyAllocationQuantity() != null
|
||||
? childDbRow.getAlreadyAllocationQuantity() : BigDecimal.ZERO;
|
||||
BigDecimal nowAllocationQuantity = childTarget.subtract(childDbAlready);
|
||||
outMaterialDetailChild.setNowAllocationQuantity(nowAllocationQuantity);
|
||||
outMaterialDetailChild.setAlreadyAllocationQuantity(allocationQuantity);
|
||||
outMaterialDetailChild.setAlreadyAllocationQuantity(childTarget);
|
||||
outMaterialDetailListChild.add(outMaterialDetailChild);
|
||||
}
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(outMaterialDetailListChild)){
|
||||
outMaterialDetailList.addAll(outMaterialDetailListChild);
|
||||
// 有子项时,父项不参与库存扣减,避免父项+子项重复扣减导致数量翻倍(子项已代表实际分配)
|
||||
outMaterialDetail.setNowAllocationQuantity(BigDecimal.ZERO);
|
||||
}
|
||||
// 单头「分配数量」= 本计划行主行已分配 + 各子行已分配(主行字段不再存主+子合计)
|
||||
BigDecimal lineAllocatedSum = outMaterialDetail.getAlreadyAllocationQuantity() != null
|
||||
? outMaterialDetail.getAlreadyAllocationQuantity() : BigDecimal.ZERO;
|
||||
// 主行本次分配:目标 − 库表原已分配(与上同理)
|
||||
BigDecimal parentTarget = outMaterialDetail.getAllocationQuantity() != null ? outMaterialDetail.getAllocationQuantity() : BigDecimal.ZERO;
|
||||
BigDecimal parentDbAlready = outMaterialDetailDb.getAlreadyAllocationQuantity() != null ? outMaterialDetailDb.getAlreadyAllocationQuantity() : BigDecimal.ZERO;
|
||||
outMaterialDetail.setNowAllocationQuantity(parentTarget.subtract(parentDbAlready));
|
||||
// 单头分配数量汇总监:主行 + 各子行「本条的目标分配量」;优先 allocationQuantity,避免子行只传 allocation、不传 already 时漏加
|
||||
BigDecimal lineMain = outMaterialDetail.getAllocationQuantity() != null
|
||||
? outMaterialDetail.getAllocationQuantity()
|
||||
: (outMaterialDetail.getAlreadyAllocationQuantity() != null ? outMaterialDetail.getAlreadyAllocationQuantity() : BigDecimal.ZERO);
|
||||
BigDecimal lineAllocatedSum = lineMain;
|
||||
if (!CollectionUtils.isEmpty(materialDetailDOChildList)) {
|
||||
for (OutMaterialDetailDO childDo : materialDetailDOChildList) {
|
||||
BigDecimal childAlloc = childDo.getAlreadyAllocationQuantity() != null
|
||||
? childDo.getAlreadyAllocationQuantity() : BigDecimal.ZERO;
|
||||
lineAllocatedSum = lineAllocatedSum.add(childAlloc);
|
||||
BigDecimal childLine = childDo.getAllocationQuantity() != null
|
||||
? childDo.getAllocationQuantity()
|
||||
: (childDo.getAlreadyAllocationQuantity() != null ? childDo.getAlreadyAllocationQuantity() : BigDecimal.ZERO);
|
||||
lineAllocatedSum = lineAllocatedSum.add(childLine);
|
||||
}
|
||||
}
|
||||
totalAllocationQuantity = totalAllocationQuantity.add(lineAllocatedSum);
|
||||
@@ -355,6 +377,14 @@ public class OutMaterialDetailImpl extends ServiceImpl<OutMaterialDetailMapper,
|
||||
processingCodeCopyingData(outMaterialDetailDO);
|
||||
}
|
||||
}
|
||||
// 本单本次分配增量合计,回写主表「已分配」= 库表原值 + 本次增量
|
||||
BigDecimal orderThisAssignIncrement = BigDecimal.ZERO;
|
||||
for (OutMaterialDetail d : outMaterialDetailList) {
|
||||
if (d.getNowAllocationQuantity() != null && d.getNowAllocationQuantity().compareTo(BigDecimal.ZERO) > 0) {
|
||||
orderThisAssignIncrement = orderThisAssignIncrement.add(d.getNowAllocationQuantity());
|
||||
}
|
||||
}
|
||||
stockOutOrderPO.setAlreadyAllocationQuantity(orderThisAssignIncrement);
|
||||
stockOutOrderPO.setAllocationQuantity(totalAllocationQuantity);
|
||||
//分配(修改库存)
|
||||
xgkc(outMaterialDetailList,outOrderNumber,loginUser);
|
||||
@@ -492,6 +522,12 @@ public class OutMaterialDetailImpl extends ServiceImpl<OutMaterialDetailMapper,
|
||||
continue;
|
||||
}
|
||||
Long materialInventoryId = outMaterialDetail.getMaterialInventoryId();
|
||||
if (materialInventoryId == null) {
|
||||
String hint = outMaterialDetail.getMaterialDetailId() != null
|
||||
? "明细ID=" + outMaterialDetail.getMaterialDetailId()
|
||||
: "明细";
|
||||
throw new ServiceException(hint + " 未绑定库存行,无法分配;请确认子行已选库位或刷新后重试");
|
||||
}
|
||||
|
||||
//分配数量为本次分配数量
|
||||
BigDecimal allocationQuantity = outMaterialDetail.getNowAllocationQuantity();
|
||||
@@ -499,8 +535,10 @@ public class OutMaterialDetailImpl extends ServiceImpl<OutMaterialDetailMapper,
|
||||
allocationQuantity = BigDecimal.ZERO;
|
||||
}
|
||||
MaterialInventory materialInventoryPO = materialInventoryMapper.selectById(materialInventoryId);
|
||||
if (materialInventoryPO != null) {
|
||||
//更新库存数量
|
||||
if (materialInventoryPO == null) {
|
||||
throw new ServiceException("库存行不存在,materialInventoryId=" + materialInventoryId);
|
||||
}
|
||||
//更新库存数量
|
||||
//可用数量
|
||||
BigDecimal oldAllocationQuantity = materialInventoryPO.getAllocationQuantity();
|
||||
//冻结数量
|
||||
@@ -522,6 +560,14 @@ public class OutMaterialDetailImpl extends ServiceImpl<OutMaterialDetailMapper,
|
||||
materialInventoryParamDO.setQuantity(allocationQuantity);
|
||||
materialInventoryParamDO.setType("2");
|
||||
materialInventoryParamDO.setMaterialInventoryId(materialInventoryPO.getMaterialInventoryId());
|
||||
// 关联单号:出库单号 + 明细 uniqueId,避免同一单多库位/多子行只显示一条或唯一键冲突
|
||||
String relateNo = outMaterialDetail.getUniqueId() != null
|
||||
? outOrderNumber + "#" + outMaterialDetail.getUniqueId()
|
||||
: outOrderNumber;
|
||||
materialInventoryParamDO.setRelateNo(relateNo);
|
||||
materialInventoryParamDO.setBatchNumber(outMaterialDetail.getBatchNumber());
|
||||
materialInventoryParamDO.setLotNumber(outMaterialDetail.getLotNo());
|
||||
materialInventoryParamDO.setInOrderNumber(outMaterialDetail.getInOrderNumber());
|
||||
materialInventoryService.kctzjl(materialInventoryParamDO,"分配库存",loginUser);
|
||||
materialInventoryService.xgkc(materialInventoryParamDO);
|
||||
//materialInventoryMapper.updateById(materialInventory);
|
||||
@@ -579,7 +625,6 @@ public class OutMaterialDetailImpl extends ServiceImpl<OutMaterialDetailMapper,
|
||||
// inventoryAdjustmentRecord.setAdjustedVolume(materialInventoryPO.getVolume() == null ? BigDecimal.ZERO : materialInventoryPO.getVolume());
|
||||
// inventoryAdjustmentRecord.setAdjustedArea(materialInventoryPO.getArea() == null ? BigDecimal.ZERO : materialInventoryPO.getArea());
|
||||
// inventoryAdjustmentRecordMapper.insert(inventoryAdjustmentRecord);
|
||||
}
|
||||
/*Long uniqueId = outMaterialDetail.getUniqueId();
|
||||
String outOrderNumber1 = outMaterialDetail.getOutOrderNumber();
|
||||
List<OutMaterialDetail> outMaterialDetails = outMaterialDetailMapper.selectList(new QueryWrapper<OutMaterialDetail>().lambda().eq(OutMaterialDetail::getParentUniqueId, uniqueId).eq(OutMaterialDetail::getOutOrderNumber, outOrderNumber1));
|
||||
@@ -744,9 +789,10 @@ public class OutMaterialDetailImpl extends ServiceImpl<OutMaterialDetailMapper,
|
||||
outMaterialDetail.setUpdateTime(new Date());
|
||||
outMaterialDetail.setAllowModify(1);
|
||||
//判断是否存在子项
|
||||
// actualQuantity 是取消分配的数量,从 outMaterialDetailDO 获取
|
||||
BigDecimal allocationQuantity = outMaterialDetailDO.getActualQuantity();
|
||||
BigDecimal alreadyAllocationQuantity = outMaterialDetailDO.getAlreadyAllocationQuantity();
|
||||
// actualQuantity 是取消分配的数量;有子行时 allocationQuantity 会累加主行+各子行,用于整单校验与主行 allocation 汇总
|
||||
BigDecimal parentCancelQty = outMaterialDetailDO.getActualQuantity() != null
|
||||
? outMaterialDetailDO.getActualQuantity() : BigDecimal.ZERO;
|
||||
BigDecimal allocationQuantity = parentCancelQty;
|
||||
List<OutMaterialDetailDO> materialDetailDOChildList = outMaterialDetailDO.getChildren();
|
||||
BigDecimal childAllocationQuantity = BigDecimal.ZERO;
|
||||
if (!CollectionUtils.isEmpty(materialDetailDOChildList)){
|
||||
@@ -813,15 +859,24 @@ public class OutMaterialDetailImpl extends ServiceImpl<OutMaterialDetailMapper,
|
||||
outMaterialDetailList.add(outMaterialDetailChild);
|
||||
materialDetailIdsByUpdate.add(outMaterialDetailDOChild.getMaterialDetailId());
|
||||
allocationQuantity = allocationQuantity.add(childCancelQty);
|
||||
alreadyAllocationQuantity = alreadyAllocationQuantity.add(childCancelQty);
|
||||
childAllocationQuantity = childAllocationQuantity.add(childDbAllocationQty);
|
||||
}
|
||||
}
|
||||
//判断取消分配数量不能大于已分配数量(取消分配应该检查alreadyAllocationQuantity,而不是allocationQuantity)
|
||||
BigDecimal dbAlreadyAllocationQuantity = outMaterialDetailDb.getAlreadyAllocationQuantity() != null
|
||||
? outMaterialDetailDb.getAlreadyAllocationQuantity()
|
||||
: BigDecimal.ZERO;
|
||||
if(allocationQuantity.compareTo(dbAlreadyAllocationQuantity) > 0){
|
||||
// 已分配数量:主行+(若本次带出的)子行在库中的已分配之和;避免「主30+子20=50」与仅主行 already30 比较误报
|
||||
BigDecimal dbAlreadyAllocationQuantity = outMaterialDetailDb.getAlreadyAllocationQuantity() != null
|
||||
? outMaterialDetailDb.getAlreadyAllocationQuantity()
|
||||
: BigDecimal.ZERO;
|
||||
BigDecimal dbTotalAlreadyAllocated = dbAlreadyAllocationQuantity;
|
||||
if (!CollectionUtils.isEmpty(materialDetailDOChildList)) {
|
||||
for (OutMaterialDetailDO childDo : materialDetailDOChildList) {
|
||||
OutMaterialDetail childDb = materialDetailMap.get(childDo.getMaterialDetailId());
|
||||
if (childDb != null) {
|
||||
dbTotalAlreadyAllocated = dbTotalAlreadyAllocated.add(
|
||||
childDb.getAlreadyAllocationQuantity() != null ? childDb.getAlreadyAllocationQuantity() : BigDecimal.ZERO);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (allocationQuantity.compareTo(dbTotalAlreadyAllocated) > 0) {
|
||||
throw new ServiceException("物料" + outMaterialDetailDb.getMaterialName() + ",取消分配数量不能大于已分配数量");
|
||||
}
|
||||
BigDecimal dbAllocationQuantity = outMaterialDetailDb.getAllocationQuantity() != null
|
||||
@@ -833,7 +888,8 @@ public class OutMaterialDetailImpl extends ServiceImpl<OutMaterialDetailMapper,
|
||||
throw new ServiceException("物料" + outMaterialDetailDb.getMaterialName() + ",取消分配数量不能大于分配总数");
|
||||
}
|
||||
outMaterialDetail.setAllocationQuantity(newAllocationQuantity);
|
||||
outMaterialDetail.setAlreadyAllocationQuantity(dbAlreadyAllocationQuantity.subtract(allocationQuantity));
|
||||
// 主行「已分配」只扣主行本次取消量;子行已在上面各自扣减
|
||||
outMaterialDetail.setAlreadyAllocationQuantity(dbAlreadyAllocationQuantity.subtract(parentCancelQty));
|
||||
|
||||
// 同时清空该明细的目标仓库/库区/库位信息(回到未分配状态)
|
||||
outMaterialDetail.setWarehouseId(null);
|
||||
@@ -855,13 +911,13 @@ public class OutMaterialDetailImpl extends ServiceImpl<OutMaterialDetailMapper,
|
||||
outMaterialDetail.setContainerCode(null);
|
||||
outMaterialDetail.setContainerType(null);
|
||||
outMaterialDetail.setContainerTypeName(null);
|
||||
// 设置 actualQuantity 用于 qxfp 方法更新库存(取消分配的数量)
|
||||
outMaterialDetail.setActualQuantity(allocationQuantity);
|
||||
// 主行 actualQuantity 仅主行取消量;qxfp 用入参 DO 中主/子各自 actualQuantity
|
||||
outMaterialDetail.setActualQuantity(parentCancelQty);
|
||||
outMaterialDetailList.add(outMaterialDetail);
|
||||
materialDetailIdsByUpdate.add(outMaterialDetailDO.getMaterialDetailId());
|
||||
//记录收货单收货总数
|
||||
//记录收货单收货总数(主+子本次取消合计)
|
||||
totalAllocationQuantity = totalAllocationQuantity.add(allocationQuantity);
|
||||
totalAlreadyAllocationQuantity = totalAlreadyAllocationQuantity.add(alreadyAllocationQuantity);
|
||||
totalAlreadyAllocationQuantity = totalAlreadyAllocationQuantity.add(allocationQuantity);
|
||||
|
||||
//抄码商品取消分配
|
||||
if (!CollectionUtils.isEmpty(outMaterialDetailDO.getCopyCodeReferenceIdsCancel())){
|
||||
@@ -893,6 +949,10 @@ public class OutMaterialDetailImpl extends ServiceImpl<OutMaterialDetailMapper,
|
||||
materialInventoryParamDO.setMaterialInventoryId(materialInventoryId);
|
||||
materialInventoryParamDO.setQuantity(allocationQuantity);
|
||||
materialInventoryParamDO.setType("3");
|
||||
String cancelRelateNo = outMaterialDetail.getUniqueId() != null
|
||||
? outOrderNumber + "#" + outMaterialDetail.getUniqueId()
|
||||
: outOrderNumber;
|
||||
materialInventoryParamDO.setRelateNo(cancelRelateNo);
|
||||
materialInventoryService.kctzjl(materialInventoryParamDO,"取消分配",loginUser);
|
||||
materialInventoryService.xgkc(materialInventoryParamDO);
|
||||
// //更新库存数量
|
||||
@@ -984,6 +1044,10 @@ public class OutMaterialDetailImpl extends ServiceImpl<OutMaterialDetailMapper,
|
||||
materialInventoryParamDO.setMaterialInventoryId(materialInventoryId);
|
||||
materialInventoryParamDO.setQuantity(allocationQuantity);
|
||||
materialInventoryParamDO.setType("3");
|
||||
String cancelRelateNoCh = outMaterialDetail.getUniqueId() != null
|
||||
? outOrderNumber + "#" + outMaterialDetail.getUniqueId()
|
||||
: outOrderNumber;
|
||||
materialInventoryParamDO.setRelateNo(cancelRelateNoCh);
|
||||
materialInventoryService.kctzjl(materialInventoryParamDO,"取消分配",loginUser);
|
||||
materialInventoryService.xgkc(materialInventoryParamDO);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user