Browse Source

添加发货数量填充的算法

master
shenzhouyu 2 months ago
parent
commit
89e56a824a
  1. 14
      src/main/java/com/gaotao/modules/api/service/impl/IfsApiIssueAndReturnServiceImpl.java
  2. 63
      src/main/java/com/gaotao/modules/customer/service/impl/CustomerIssueServiceImpl.java

14
src/main/java/com/gaotao/modules/api/service/impl/IfsApiIssueAndReturnServiceImpl.java

@ -114,7 +114,7 @@ public class IfsApiIssueAndReturnServiceImpl implements IfsApiIssueAndReturnServ
return inventoryPartVos;
}catch (Exception e){
e.printStackTrace();
throw new XJException("获取IFS物料列表失败" );
throw new XJException("获取IFS物料列表失败"+e.getMessage() );
}
}
@ -612,7 +612,7 @@ public class IfsApiIssueAndReturnServiceImpl implements IfsApiIssueAndReturnServ
return orderVos;
} catch (Exception e) {
e.printStackTrace();
throw new XJException("获取IFS采购供应商材料失败");
throw new XJException("获取IFS采购供应商材料失败"+e.getMessage());
}
}
@ -716,7 +716,7 @@ public class IfsApiIssueAndReturnServiceImpl implements IfsApiIssueAndReturnServ
return orderVos;
} catch (Exception e) {
e.printStackTrace();
throw new XJException("获取IFS采购供应商材料失败");
throw new XJException("获取IFS采购供应商材料失败"+e.getMessage());
}
}
@ -843,7 +843,7 @@ public class IfsApiIssueAndReturnServiceImpl implements IfsApiIssueAndReturnServ
return inventoryPartInStockVos;
}catch (Exception e) {
e.printStackTrace();
throw new XJException("获取IFS库存在库信息失败");
throw new XJException("获取IFS库存在库信息失败"+e.getMessage());
}
}
@ -867,7 +867,7 @@ public class IfsApiIssueAndReturnServiceImpl implements IfsApiIssueAndReturnServ
return inventoryPartInStockVos;
}catch (Exception e) {
e.printStackTrace();
throw new XJException("获取IFS库存在库信息失败");
throw new XJException("获取IFS库存在库信息失败"+e.getMessage());
}
}
@ -891,7 +891,7 @@ public class IfsApiIssueAndReturnServiceImpl implements IfsApiIssueAndReturnServ
return shipmentVos;
}catch (Exception e) {
e.printStackTrace();
throw new XJException("获取IFS shipment信息失败");
throw new XJException("获取IFS shipment信息失败:"+e.getMessage());
}
}
@ -915,7 +915,7 @@ public class IfsApiIssueAndReturnServiceImpl implements IfsApiIssueAndReturnServ
return shipmentLineVos;
}catch (Exception e) {
e.printStackTrace();
throw new XJException("获取IFS shipmentLine信息失败");
throw new XJException("获取IFS shipmentLine信息失败"+e.getMessage());
}
}

63
src/main/java/com/gaotao/modules/customer/service/impl/CustomerIssueServiceImpl.java

@ -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

Loading…
Cancel
Save