|
|
|
@ -236,7 +236,7 @@ public class CustomerIssueServiceImpl implements CustomerIssueService { |
|
|
|
BeanUtils.copyProperties(detail, shipmentReserveVo); |
|
|
|
shipmentReserveVos.add(shipmentReserveVo); |
|
|
|
} |
|
|
|
List<ShipmentReserveVo> reserveVos = mapShipmentData(shipmentReserveVos, customerIssueDto.getShipmentLine()); |
|
|
|
List<ShipmentReserveVo> reserveVos = splitReserves(shipmentReserveVos, customerIssueDto.getShipmentLine()); |
|
|
|
|
|
|
|
//调用ifs接口 |
|
|
|
for (ShipmentReserveVo lineVo : reserveVos){ |
|
|
|
@ -279,6 +279,67 @@ public class CustomerIssueServiceImpl implements CustomerIssueService { |
|
|
|
return ids; |
|
|
|
} |
|
|
|
|
|
|
|
public List<ShipmentReserveVo> splitReserves(List<ShipmentReserveVo> reserves, List<ShipmentLineVo> lines) { |
|
|
|
// 构建以site|partNo为键的lines映射表(高效查找) |
|
|
|
Map<String, List<ShipmentLineVo>> lineMap = new HashMap<>(); |
|
|
|
for (ShipmentLineVo line : lines) { |
|
|
|
String key = line.getContract() + "|" + line.getInventoryPartNo(); |
|
|
|
lineMap.computeIfAbsent(key, k -> new ArrayList<>()).add(line); |
|
|
|
} |
|
|
|
|
|
|
|
List<ShipmentReserveVo> result = new ArrayList<>(); |
|
|
|
|
|
|
|
// 遍历reserves进行拆分处理 |
|
|
|
for (ShipmentReserveVo reserve : reserves) { |
|
|
|
String key = reserve.getSite() + "|" + reserve.getPartNo(); |
|
|
|
List<ShipmentLineVo> matchedLines = lineMap.get(key); |
|
|
|
|
|
|
|
if (matchedLines != null && !matchedLines.isEmpty()) { |
|
|
|
// 验证总量一致性 |
|
|
|
BigDecimal totalAvailable = calculateTotalAvailable(matchedLines); |
|
|
|
if (totalAvailable.compareTo(reserve.getTransQty()) != 0) { |
|
|
|
throw new IllegalStateException(String.format( |
|
|
|
"物料总数量不匹配 site %s part %s: reserve %s != available %s", |
|
|
|
reserve.getSite(), reserve.getPartNo(), |
|
|
|
reserve.getTransQty(), totalAvailable)); |
|
|
|
} |
|
|
|
|
|
|
|
// 执行拆分并赋值 |
|
|
|
for (ShipmentLineVo line : matchedLines) { |
|
|
|
result.add(createSplitReserve(reserve, line)); |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 处理无匹配lines的情况(保留原始对象) |
|
|
|
result.add(reserve); |
|
|
|
} |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
private BigDecimal calculateTotalAvailable(List<ShipmentLineVo> lines) { |
|
|
|
return lines.stream() |
|
|
|
.map(line -> line.getInventoryQty().subtract(line.getQtyAssigned())) |
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add); |
|
|
|
} |
|
|
|
|
|
|
|
private ShipmentReserveVo createSplitReserve(ShipmentReserveVo reserve, ShipmentLineVo line) { |
|
|
|
// 创建新对象并复制基础字段 |
|
|
|
ShipmentReserveVo split = new ShipmentReserveVo(); |
|
|
|
BeanUtils.copyProperties(reserve, split); |
|
|
|
|
|
|
|
// 设置拆分后的数量 |
|
|
|
split.setTransQty(line.getInventoryQty().subtract(line.getQtyAssigned())); |
|
|
|
|
|
|
|
// 从line复制附加字段 |
|
|
|
split.setIfsSourceRef1(line.getSourceRef1()); |
|
|
|
split.setIfsSourceRef2(line.getSourceRef2()); |
|
|
|
split.setIfsSourceRef3(line.getSourceRef3()); |
|
|
|
split.setIfsInputUoM(line.getInventoryUom()); |
|
|
|
split.setIfsBlockedForPickByChoice(line.getCreditBlocked()); |
|
|
|
|
|
|
|
return split; |
|
|
|
} |
|
|
|
|
|
|
|
public List<ShipmentReserveVo> mapShipmentData(List<ShipmentReserveVo> reserves, List<ShipmentLineVo> lines) { |
|
|
|
|
|
|
|
// 构建库存地点+零件号的索引Map |
|
|
|
|