|
|
|
@ -280,7 +280,38 @@ public class CustomerIssueServiceImpl implements CustomerIssueService { |
|
|
|
} |
|
|
|
|
|
|
|
public List<ShipmentReserveVo> splitReserves(List<ShipmentReserveVo> reserves, List<ShipmentLineVo> lines) { |
|
|
|
// 构建以site|partNo为键的lines映射表(高效查找) |
|
|
|
// 统计所有 lines 按 key (contract|inventoryPartNo) 分组的总数量 |
|
|
|
Map<String, BigDecimal> lineTotalMap = new HashMap<>(); |
|
|
|
for (ShipmentLineVo line : lines) { |
|
|
|
String key = line.getContract() + "|" + line.getInventoryPartNo(); |
|
|
|
BigDecimal availableQty = line.getInventoryQty().subtract(line.getQtyAssigned()); |
|
|
|
lineTotalMap.put(key, lineTotalMap.getOrDefault(key, BigDecimal.ZERO).add(availableQty)); |
|
|
|
} |
|
|
|
|
|
|
|
// 统计所有 reserves 按 key (site|partNo) 分组的总数量 |
|
|
|
Map<String, BigDecimal> reserveTotalMap = new HashMap<>(); |
|
|
|
for (ShipmentReserveVo reserve : reserves) { |
|
|
|
String key = reserve.getSite() + "|" + reserve.getPartNo(); |
|
|
|
reserveTotalMap.put(key, reserveTotalMap.getOrDefault(key, BigDecimal.ZERO).add(reserve.getTransQty())); |
|
|
|
} |
|
|
|
|
|
|
|
// 验证总量一致性:比较两个 map 中每个 key 的总数量是否一致 |
|
|
|
// 注意:假设 contract 对应 site,inventoryPartNo 对应 partNo,所以两个 key 格式的值应该相同 |
|
|
|
Set<String> allKeys = new HashSet<>(); |
|
|
|
allKeys.addAll(lineTotalMap.keySet()); |
|
|
|
allKeys.addAll(reserveTotalMap.keySet()); |
|
|
|
|
|
|
|
for (String key : allKeys) { |
|
|
|
BigDecimal lineTotal = lineTotalMap.getOrDefault(key, BigDecimal.ZERO); |
|
|
|
BigDecimal reserveTotal = reserveTotalMap.getOrDefault(key, BigDecimal.ZERO); |
|
|
|
if (lineTotal.compareTo(reserveTotal) != 0) { |
|
|
|
throw new IllegalStateException(String.format( |
|
|
|
"物料总数量不匹配 key %s: reserve总量 %s != line总量 %s", |
|
|
|
key, reserveTotal, lineTotal)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 构建以contract|inventoryPartNo为键的lines映射表(用于后续拆分) |
|
|
|
Map<String, List<ShipmentLineVo>> lineMap = new HashMap<>(); |
|
|
|
for (ShipmentLineVo line : lines) { |
|
|
|
String key = line.getContract() + "|" + line.getInventoryPartNo(); |
|
|
|
@ -291,19 +322,11 @@ public class CustomerIssueServiceImpl implements CustomerIssueService { |
|
|
|
|
|
|
|
// 遍历reserves进行拆分处理 |
|
|
|
for (ShipmentReserveVo reserve : reserves) { |
|
|
|
// 使用 site|partNo 格式查找(假设 contract=site, inventoryPartNo=partNo,所以 key 值相同) |
|
|
|
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)); |
|
|
|
|