From 63f2890ad079ef994b4de46f34689813612a3482 Mon Sep 17 00:00:00 2001 From: liuxiaoxu <1793812695@qq.com> Date: Mon, 1 Jul 2024 20:12:37 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E9=87=87=E8=B4=AD=E7=AE=A1=E7=90=86=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=94=9F=E6=88=90=E8=AE=A2=E5=8D=95=E9=83=A8?= =?UTF-8?q?=E9=97=A8=E8=AF=84=E5=AE=A1=E5=90=8E=E8=BD=AC=E9=87=87=E8=B4=AD?= =?UTF-8?q?=E8=AE=A1=E5=88=92=EF=BC=8C=E7=89=A9=E6=96=99=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E7=89=A9=E6=96=99=E5=90=88=E8=AE=A1=E5=92=8C?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E5=90=88=E8=AE=A1=E5=87=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/PurchasePlanServiceImpl.java | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchasePlanServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchasePlanServiceImpl.java index 8aa6a405..dbd40f0d 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchasePlanServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchasePlanServiceImpl.java @@ -4,6 +4,7 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; import com.ruoyi.common.core.redis.RedisCache; @@ -161,11 +162,22 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService // 假设此处有一个生成唯一采购计划单号的方法 String purchasePlanCode = generateUniquePurchasePlanCode(); + //物料相同的只保留一条 + List uniqueBoms = insertedSysMakeorderBoms.stream() + // 分组依据为MaterialNo + .collect(Collectors.groupingBy(SysMakeorderBom::getMaterialNo)) + // 把每个分组转为流,然后取第一个元素 + .values().stream() + .map(groupedBoms -> groupedBoms.stream().findFirst().orElse(null)) + // 过滤掉null值,以防万一某些分组是空的 + .filter(Objects::nonNull) + .collect(Collectors.toList()); + // 仅查询一次,因为所有SysMakeorderBom都关联同一生产单号 - SysMakeOrder sysMakeOrder = sysMakeOrderMapper.selectMakeOrderByMakeNo(insertedSysMakeorderBoms.get(0).getMakeNo()); + SysMakeOrder sysMakeOrder = sysMakeOrderMapper.selectMakeOrderByMakeNo(uniqueBoms.get(0).getMakeNo()); //保存所有加工方式为采购的物料 - List filterSysMakeorderBoms = insertedSysMakeorderBoms.stream().filter(bom -> "0".equals(bom.getProcessMethod())).collect(Collectors.toList()); + List filterSysMakeorderBoms = uniqueBoms.stream().filter(bom -> "0".equals(bom.getProcessMethod())).collect(Collectors.toList()); //统计物料种类的数量 Integer materialAmount = filterSysMakeorderBoms.size(); @@ -183,7 +195,7 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService purchasePlanMapper.insertPurchasePlan(purchasePlan); // 批量创建采购计划子项 - insertPurchasePlanChildren(insertedSysMakeorderBoms, purchasePlanCode, sysMakeOrder); + insertPurchasePlanChildren(uniqueBoms, purchasePlanCode, sysMakeOrder); } /*假设自生成的采购计划单号*/ @@ -214,11 +226,21 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService return purchasePlan; } - private void insertPurchasePlanChildren(List insertedSysMakeorderBoms, String purchasePlanCode, SysMakeOrder sysMakeOrder) { + private void insertPurchasePlanChildren(List uniqueBoms, String purchasePlanCode, SysMakeOrder sysMakeOrder) { + +// List uniqueBoms = insertedSysMakeorderBoms.stream() +// // 分组依据为MaterialNo +// .collect(Collectors.groupingBy(SysMakeorderBom::getMaterialNo)) +// // 把每个分组转为流,然后取第一个元素 +// .values().stream() +// .map(groupedBoms -> groupedBoms.stream().findFirst().orElse(null)) +// // 过滤掉null值,以防万一某些分组是空的 +// .filter(Objects::nonNull) +// .collect(Collectors.toList()); //生产订单中的订单数量 Long makeOrderMaterialSum = sysMakeOrder.getMaterialSum(); - for (SysMakeorderBom bom : insertedSysMakeorderBoms) { + for (SysMakeorderBom bom : uniqueBoms) { if ("0".equals(bom.getProcessMethod())) { PurchasePlanChild purchasePlanChild = new PurchasePlanChild(); purchasePlanChild.setPurchasePlanCode(purchasePlanCode);