From 1450a5398719c2ff356867d1175b3f4601f30f50 Mon Sep 17 00:00:00 2001 From: liuxiaoxu <1793812695@qq.com> Date: Fri, 5 Jul 2024 20:07:07 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E7=94=9F=E4=BA=A7=E7=AE=A1=E7=90=86=20?= =?UTF-8?q?=E9=87=87=E8=B4=AD=E7=AE=A1=E7=90=86=20=E9=94=80=E5=94=AE?= =?UTF-8?q?=E7=AE=A1=E7=90=86=20=E4=BF=AE=E6=94=B9=E7=94=9F=E4=BA=A7?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E9=83=A8=E9=97=A8=E4=B8=BB=E7=AE=A1=E5=AE=A1?= =?UTF-8?q?=E6=A0=B8=E9=80=9A=E8=BF=87=E5=90=8E=20=E7=94=9F=E6=88=90?= =?UTF-8?q?=E9=87=87=E8=B4=AD=E8=AE=A1=E5=88=92=E8=AE=A2=E5=8D=95=E7=9A=84?= =?UTF-8?q?=E6=96=B9=E6=B3=95=20=E9=87=87=E8=B4=AD=E8=AE=A1=E5=88=92?= =?UTF-8?q?=E5=AD=90=E8=A1=A8=E6=96=B0=E5=A2=9E=20=E9=80=9A=E8=BF=87?= =?UTF-8?q?=E7=89=A9=E6=96=99=E5=8F=B7=E5=92=8C=E9=87=87=E8=B4=AD=E8=AE=A1?= =?UTF-8?q?=E5=88=92=E5=8D=95=E5=8F=B7=E6=9F=A5=E8=AF=A2=E9=87=87=E8=B4=AD?= =?UTF-8?q?=E8=AE=A1=E5=88=92=E5=AD=90=E8=A1=A8=E6=95=B0=E6=8D=AE=E5=90=8E?= =?UTF-8?q?=E7=AB=AF=E6=8E=A5=E5=8F=A3=20=E4=BF=AE=E6=94=B9=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E9=87=87=E8=B4=AD=E8=AE=A1=E5=88=92=E4=B8=BB=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E7=89=A9=E6=96=99=E5=90=88=E8=AE=A1=E5=92=8C=E6=95=B0?= =?UTF-8?q?=E9=87=8F=E5=90=88=E8=AE=A1=E7=9A=84=E8=AE=A1=E7=AE=97=E6=96=B9?= =?UTF-8?q?=E6=B3=95=20=E4=BF=AE=E6=94=B9=20=E9=87=87=E8=B4=AD=E8=AE=A1?= =?UTF-8?q?=E5=88=92=E5=AD=90=E8=A1=A8=E7=94=9F=E6=88=90=E7=9A=84=E6=97=B6?= =?UTF-8?q?=E5=80=99=E8=AE=A1=E5=88=92=E9=87=87=E8=B4=AD=E6=95=B0=E7=9A=84?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E6=96=B9=E6=B3=95=20=E6=96=B0=E5=A2=9E=20?= =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E7=89=A9=E6=96=99=E5=8F=B7=E5=92=8C=E9=94=80?= =?UTF-8?q?=E5=94=AE=E8=AE=A2=E5=8D=95=E5=8F=B7=E6=9F=A5=E8=AF=A2=E9=94=80?= =?UTF-8?q?=E5=94=AE=E8=AE=A2=E5=8D=95=E5=AD=90=E8=A1=A8=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=90=8E=E7=AB=AF=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/PurchasePlanChildMapper.java | 5 + .../service/impl/PurchasePlanServiceImpl.java | 142 +++++++++++------- .../mapper/SysSalesOrderChildMapper.java | 4 + .../purchase/PurchasePlanChildMapper.xml | 9 ++ .../system/SysSalesOrderChildMapper.xml | 10 ++ 5 files changed, 113 insertions(+), 57 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/purchase/mapper/PurchasePlanChildMapper.java b/ruoyi-admin/src/main/java/com/ruoyi/purchase/mapper/PurchasePlanChildMapper.java index 72e8c520..930451b9 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/purchase/mapper/PurchasePlanChildMapper.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/purchase/mapper/PurchasePlanChildMapper.java @@ -81,4 +81,9 @@ public interface PurchasePlanChildMapper List getPurchasePlanChildByPlanCodes(String[] purchasePlanCodes); + /* + * + * 通过物料号和采购计划单号查询采购计划子表数据 + * */ + PurchasePlanChild selectPurchasePlanChildByCodeAndNo(PurchasePlanChild purchasePlanChild); } 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 29ecf592..6a0b4fb7 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 @@ -2,9 +2,7 @@ package com.ruoyi.purchase.service.impl; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.util.Date; -import java.util.List; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; import com.ruoyi.common.core.redis.RedisCache; @@ -16,7 +14,9 @@ import com.ruoyi.purchase.domain.PurchasePlanChild; import com.ruoyi.purchase.mapper.PurchasePlanChildMapper; import com.ruoyi.system.domain.SysMakeOrder; import com.ruoyi.system.domain.SysMakeorderBom; +import com.ruoyi.system.domain.SysSalesOrderChild; import com.ruoyi.system.mapper.SysMakeOrderMapper; +import com.ruoyi.system.mapper.SysSalesOrderChildMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.purchase.mapper.PurchasePlanMapper; @@ -45,6 +45,9 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService @Autowired private RedisCache redisCache; + @Autowired + private SysSalesOrderChildMapper salesOrderChildMapper; + /** * 查询采购计划单 * @@ -164,7 +167,6 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService // 假设此处有一个生成唯一采购计划单号的方法 String purchasePlanCode = generateUniquePurchasePlanCode(); - //物料相同的只保留一条 List uniqueBoms = insertedSysMakeorderBoms.stream() // 分组依据为MaterialNo .collect(Collectors.groupingBy(SysMakeorderBom::getMaterialNo)) @@ -175,29 +177,95 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService .filter(Objects::nonNull) .collect(Collectors.toList()); + //过滤掉 只有采购的类型 + List filterUniqueBoms = uniqueBoms.stream().filter(bom -> "0".equals(bom.getProcessMethod())).collect(Collectors.toList()); + //统计物料种类的数量 + Integer materialAmount = filterUniqueBoms.size(); + + // 仅查询一次,因为所有SysMakeorderBom都关联同一生产单号 - SysMakeOrder sysMakeOrder = sysMakeOrderMapper.selectMakeOrderByMakeNo(uniqueBoms.get(0).getMakeNo()); + SysMakeOrder sysMakeOrder = sysMakeOrderMapper.selectMakeOrderByMakeNo(insertedSysMakeorderBoms.get(0).getMakeNo()); //保存所有加工方式为采购的物料 - List filterSysMakeorderBoms = uniqueBoms.stream().filter(bom -> "0".equals(bom.getProcessMethod())).collect(Collectors.toList()); - //统计物料种类的数量 - Integer materialAmount = filterSysMakeorderBoms.size(); + List filterSysMakeorderBoms = insertedSysMakeorderBoms.stream().filter(bom -> "0".equals(bom.getProcessMethod())).collect(Collectors.toList()); + + + //所有数据的销售订单号相同,只需查一条的销售订单号 + String quoteId = filterSysMakeorderBoms.get(0).getSalesOrderCode(); + + // 第一步:收集所有不同的salesOrderMaterialNo 利用set key值不重复的特性 + Set uniqueSalesOrderMaterialNos = new HashSet<>(); + for (SysMakeorderBom filterSysMakeorderBom : filterSysMakeorderBoms) { + uniqueSalesOrderMaterialNos.add(filterSysMakeorderBom.getSalesOrderMaterialNo()); + } + + // 第二步:查询每个salesOrderMaterialNo对应的SalesOrder数据 + Map salesOrderChildByMaterialNo = new HashMap<>(); + for (String salesOrderMaterialNo : uniqueSalesOrderMaterialNos) { + SysSalesOrderChild sysSalesOrderChild = new SysSalesOrderChild(); + sysSalesOrderChild.setMaterialCode(salesOrderMaterialNo); + sysSalesOrderChild.setQuoteId(quoteId); + SysSalesOrderChild salesOrderChild = salesOrderChildMapper.selectSalesOrderChildByCodeAndNo(sysSalesOrderChild); + salesOrderChildByMaterialNo.put(salesOrderMaterialNo, salesOrderChild); + } + + Long purchasePlanMaterialSum = 0L; + // 第三步:计算purchasePlanNum + for (SysMakeorderBom filterSysMakeorderBom : filterSysMakeorderBoms) { + String salesOrderMaterialNo = filterSysMakeorderBom.getSalesOrderMaterialNo(); + SysSalesOrderChild sysSalesOrderChild = salesOrderChildByMaterialNo.get(salesOrderMaterialNo); + if (sysSalesOrderChild != null) { + //物料数量 + long materialNum = sysSalesOrderChild.getMaterialNum(); + //用量 + long useNum = filterSysMakeorderBom.getUseNum(); + + //采购计划数 + long purchasePlanNum = materialNum * useNum; + + // 立即创建PurchasePlanChild对象 + PurchasePlanChild purchasePlanChild = new PurchasePlanChild(); + purchasePlanChild.setPurchasePlanCode(purchasePlanCode); + purchasePlanChild.setMaterialCode(filterSysMakeorderBom.getMaterialNo()); + + PurchasePlanChild tempPurchasePlanChild = purchasePlanChildMapper.selectPurchasePlanChildByCodeAndNo(purchasePlanChild); + if (tempPurchasePlanChild != null){ + + purchasePlanChild.setPurchasePlanChildId(tempPurchasePlanChild.getPurchasePlanChildId()); + long addMaterialNum = tempPurchasePlanChild.getMaterialNum() + purchasePlanNum; + //设置计划采购数 + purchasePlanChild.setMaterialNum(addMaterialNum); + purchasePlanChildMapper.updatePurchasePlanChild(purchasePlanChild); + }else { + purchasePlanChild.setMaterialName(filterSysMakeorderBom.getMaterialName()); + purchasePlanChild.setMaterialType(filterSysMakeorderBom.getMaterialType()); + purchasePlanChild.setWarehouseDept(filterSysMakeorderBom.getWarehouseDept()); + purchasePlanChild.setProcessMethod("0"); + purchasePlanChild.setBrand(filterSysMakeorderBom.getBrand()); + purchasePlanChild.setDescribe(filterSysMakeorderBom.getDescribe()); + purchasePlanChild.setUnit(filterSysMakeorderBom.getUnit()); + purchasePlanChild.setWarehouseDept(filterSysMakeorderBom.getWarehouseDept()); + // 物料的计划采购数,使用计算出的purchasePlanNum + purchasePlanChild.setMaterialNum(purchasePlanNum); + purchasePlanChild.setCreateBy(ShiroUtils.getLoginName()); + purchasePlanChild.setCreateTime(new Date()); + purchasePlanChild.setUnit(filterSysMakeorderBom.getUnit()); + + // 直接保存PurchasePlanChild对象 + purchasePlanChildMapper.insertPurchasePlanChild(purchasePlanChild); + } + + // 更新总和 + purchasePlanMaterialSum += purchasePlanNum; + } + } - //统计数量合计 - //生产订单中的订单数量 - Long makeOrderMaterialSum = sysMakeOrder.getMaterialSum(); - //加工方式为采购的所有物料用量合计 - Long sum = filterSysMakeorderBoms.stream().mapToLong(SysMakeorderBom::getUseNum).sum(); - Long purchasePlanMaterialSum = makeOrderMaterialSum * sum; // 创建采购计划主记录 PurchasePlan purchasePlan = buildPurchasePlan(sysMakeOrder, purchasePlanCode,materialAmount,purchasePlanMaterialSum); - purchasePlanMapper.insertPurchasePlan(purchasePlan); - // 批量创建采购计划子项 - insertPurchasePlanChildren(uniqueBoms, purchasePlanCode, sysMakeOrder); } /*假设自生成的采购计划单号*/ @@ -228,44 +296,4 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService return purchasePlan; } - 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 : uniqueBoms) { - if ("0".equals(bom.getProcessMethod())) { - PurchasePlanChild purchasePlanChild = new PurchasePlanChild(); - purchasePlanChild.setPurchasePlanCode(purchasePlanCode); - purchasePlanChild.setMaterialCode(bom.getMaterialNo()); - purchasePlanChild.setMaterialName(bom.getMaterialName()); - purchasePlanChild.setMaterialType(bom.getMaterialType()); - //新增物料入库部门 - purchasePlanChild.setWarehouseDept(bom.getWarehouseDept()); - purchasePlanChild.setProcessMethod("0"); - purchasePlanChild.setBrand(bom.getBrand()); - purchasePlanChild.setDescribe(bom.getDescribe()); - purchasePlanChild.setUnit(bom.getUnit()); - purchasePlanChild.setWarehouseDept(bom.getWarehouseDept()); - //物料用量 - Long useNum = bom.getUseNum(); - //物料的计划采购数 - purchasePlanChild.setMaterialNum(useNum * makeOrderMaterialSum); - purchasePlanChild.setCreateBy(ShiroUtils.getLoginName()); - purchasePlanChild.setCreateTime(new Date()); - purchasePlanChild.setUnit(bom.getUnit()); - purchasePlanChildMapper.insertPurchasePlanChild(purchasePlanChild); - } - } - } - } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/mapper/SysSalesOrderChildMapper.java b/ruoyi-admin/src/main/java/com/ruoyi/system/mapper/SysSalesOrderChildMapper.java index 9d455049..8cdb9959 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/mapper/SysSalesOrderChildMapper.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/mapper/SysSalesOrderChildMapper.java @@ -23,4 +23,8 @@ public interface SysSalesOrderChildMapper { int deleteSysSalesOrderChildByQuoteIds(String[] ids); SysSalesOrderChild selectOneByQuoteIdAndMaterialCode(@Param("quoteId") String quoteId, @Param("materialCode") String materialCode); + /* + * 根据物料号和销售订单号查询销售订单子表数据 + * */ + SysSalesOrderChild selectSalesOrderChildByCodeAndNo(SysSalesOrderChild sysSalesOrderChild); } diff --git a/ruoyi-admin/src/main/resources/mapper/purchase/PurchasePlanChildMapper.xml b/ruoyi-admin/src/main/resources/mapper/purchase/PurchasePlanChildMapper.xml index 656f4fe1..6faa76ab 100644 --- a/ruoyi-admin/src/main/resources/mapper/purchase/PurchasePlanChildMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/purchase/PurchasePlanChildMapper.xml @@ -73,6 +73,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + insert into purchase_plan_child diff --git a/ruoyi-admin/src/main/resources/mapper/system/SysSalesOrderChildMapper.xml b/ruoyi-admin/src/main/resources/mapper/system/SysSalesOrderChildMapper.xml index 958b9309..862af4b3 100644 --- a/ruoyi-admin/src/main/resources/mapper/system/SysSalesOrderChildMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/system/SysSalesOrderChildMapper.xml @@ -75,6 +75,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where a.quoteId = #{quoteId} and a.materialCode = #{materialCode} + + + + insert into sys_sales_order_child