From a7839c8a1891af6a9ebadec009b96b80dddeca1c Mon Sep 17 00:00:00 2001 From: liuxiaoxu <1793812695@qq.com> Date: Fri, 22 Nov 2024 10:53:23 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=E9=87=87=20=E4=BF=AE=E6=94=B9=E9=87=87?= =?UTF-8?q?=E8=B4=AD=E5=AE=A1=E6=A0=B8=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=8A=A0?= =?UTF-8?q?=E5=B7=A5=E6=96=B9=E5=BC=8F=E5=A7=94=E5=A4=96=E6=88=96=E9=87=87?= =?UTF-8?q?=E8=B4=AD=E4=B8=BA=E9=87=87=E8=B4=AD=EF=BC=8C=E8=8B=A5=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=88=99=E5=88=A0=E9=99=A4=E4=B8=8B=E9=98=B6=E7=89=A9?= =?UTF-8?q?=E6=96=99=E7=9A=84=E6=96=B9=E6=B3=95=EF=BC=8C=E5=8A=A0=E4=B8=8A?= =?UTF-8?q?=E7=94=9F=E6=88=90=E9=87=87=E8=B4=AD=E8=AE=A1=E5=88=92=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?=E6=96=B0=E5=A2=9E=20=E7=94=9F=E4=BA=A7=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E9=87=87=E8=B4=AD=E5=AE=A1=E6=A0=B8=E5=90=8E=E7=94=9F=E6=88=90?= =?UTF-8?q?=E9=87=87=E8=B4=AD=E8=AE=A1=E5=88=92=E6=96=B9=E6=B3=95=20?= =?UTF-8?q?=E9=87=87=E8=B4=AD=E8=AE=A1=E5=88=92=E5=AD=90=E8=A1=A8=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=20=E6=89=B9=E9=87=8F=E6=96=B0=E5=A2=9E=E9=87=87?= =?UTF-8?q?=E8=B4=AD=E8=AE=A1=E5=88=92=E5=8D=95=E7=89=A9=E6=96=99=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=96=B9=E6=B3=95=20=E9=87=87=E8=B4=AD=E8=AE=A1?= =?UTF-8?q?=E5=88=92impl=E5=B1=82=E6=96=B0=E5=A2=9E=20=E7=94=9F=E4=BA=A7?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E9=87=87=E8=B4=AD=E5=AE=A1=E6=A0=B8=E5=90=8E?= =?UTF-8?q?=E7=94=9F=E6=88=90=E9=87=87=E8=B4=AD=E8=AE=A1=E5=88=92=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=9A=E5=AE=9E=E7=8E=B0=E9=80=9A=E8=BF=87=E9=87=87?= =?UTF-8?q?=E8=B4=AD=E5=AE=A1=E6=A0=B8=E7=9A=84=E6=95=B0=E6=8D=AE=EF=BC=8C?= =?UTF-8?q?=E5=BE=97=E5=88=B0=E7=94=9F=E4=BA=A7bom=E4=B8=AD=E6=89=80?= =?UTF-8?q?=E6=9C=89=E5=8A=A0=E5=B7=A5=E6=96=B9=E5=BC=8F=E4=B8=BA=E9=87=87?= =?UTF-8?q?=E8=B4=AD=E7=9A=84=E6=95=B0=E6=8D=AE=EF=BC=8C=E8=BD=AC=E5=AD=98?= =?UTF-8?q?=E5=88=B0=E9=87=87=E8=B4=AD=E8=AE=A1=E5=88=92=E5=92=8C=E9=87=87?= =?UTF-8?q?=E8=B4=AD=E8=AE=A1=E5=88=92=E5=AD=90=E8=A1=A8=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/PurchasePlanChildMapper.java | 2 +- .../service/IPurchasePlanService.java | 5 +- .../service/impl/PurchasePlanServiceImpl.java | 163 ++++++++---------- .../service/impl/SysMakeOrderServiceImpl.java | 12 +- .../purchase/PurchasePlanChildMapper.xml | 72 ++++++++ 5 files changed, 158 insertions(+), 96 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 bc0de6a2..f0a659d2 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 @@ -42,7 +42,7 @@ public interface PurchasePlanChildMapper * @param purchasePlanChildList 采购计划单物料信息集合 * @return 结果 */ - public int batchInsertPurchasePlanChild(@Param("list") List purchasePlanChildList); + public int batchInsertPurchasePlanChild(List purchasePlanChildList); /** * 修改采购计划单物料信息 diff --git a/ruoyi-admin/src/main/java/com/ruoyi/purchase/service/IPurchasePlanService.java b/ruoyi-admin/src/main/java/com/ruoyi/purchase/service/IPurchasePlanService.java index fc217129..81c62b95 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/purchase/service/IPurchasePlanService.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/purchase/service/IPurchasePlanService.java @@ -4,6 +4,7 @@ import com.ruoyi.erp.domain.vo.ErpDevelopModifyorderVo; import com.ruoyi.purchase.domain.PurchasePlan; import com.ruoyi.purchase.domain.PurchasePlanChild; import com.ruoyi.purchase.domain.Vo.PurchasePlanSelectSupplierVo; +import com.ruoyi.system.domain.SysMakeOrder; import com.ruoyi.system.domain.SysMakeorderBom; import java.util.List; @@ -88,9 +89,9 @@ public interface IPurchasePlanService public List selectPurchasePlanByPlanCode(String purchasePlanCodes); /** - * 生产订单工程审核后生成采购计划 + * 生产订单采购审核后生成采购计划 * */ - void generatePurchasePlanByMakeOrder(List insertedSysMakeorderBoms); + void generatePurchasePlanByMakeOrder(SysMakeOrder sysMakeOrder); /** * 开发修改单审核通过后生成采购计划 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 eb60c7e8..68751d86 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 @@ -7,6 +7,7 @@ import java.util.*; import java.util.stream.Collectors; import com.ruoyi.common.core.redis.RedisCache; +import com.ruoyi.common.exception.BusinessException; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.ShiroUtils; import com.ruoyi.common.utils.StringUtils; @@ -26,6 +27,7 @@ import com.ruoyi.purchase.mapper.PurchaseQuoteMapper; import com.ruoyi.system.domain.*; import com.ruoyi.system.domain.Vo.SysSupplierVo; import com.ruoyi.system.mapper.SysMakeOrderMapper; +import com.ruoyi.system.mapper.SysMakeorderBomMapper; import com.ruoyi.system.mapper.SysSalesOrderChildMapper; import com.ruoyi.system.mapper.SysSupplierMapper; import org.springframework.beans.BeanUtils; @@ -75,6 +77,10 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService @Autowired private SysSupplierMapper sysSupplierMapper; + + @Autowired + private SysMakeorderBomMapper sysMakeorderBomMapper; + /** * 查询采购计划单 * @@ -337,106 +343,85 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService /* - * 生产订单工程审核后生成采购计划 + * 生产订单采购审核后生成采购计划 * */ @Override - public void generatePurchasePlanByMakeOrder(List insertedSysMakeorderBoms) { - // 假设此处有一个生成唯一采购计划单号的方法 + public void generatePurchasePlanByMakeOrder(SysMakeOrder makeOrder) { + // 生成唯一采购计划单号的方法 String purchasePlanCode = generateUniquePurchasePlanCode(); + String loginName = ShiroUtils.getLoginName(); - 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()); - - //过滤掉 只有采购的类型 - List filterUniqueBoms = uniqueBoms.stream().filter(bom -> "0".equals(bom.getProcessMethod())).collect(Collectors.toList()); - //统计物料种类的数量 - Integer materialAmount = filterUniqueBoms.size(); - - // 仅查询一次,因为所有SysMakeorderBom都关联同一生产单号 - SysMakeOrder sysMakeOrder = sysMakeOrderMapper.selectMakeOrderByMakeNo(insertedSysMakeorderBoms.get(0).getMakeNo()); - - //保存所有加工方式为采购的物料 - List filterSysMakeorderBoms = insertedSysMakeorderBoms.stream().filter(bom -> "0".equals(bom.getProcessMethod())).collect(Collectors.toList()); - - if(StringUtils.isNotEmpty(filterUniqueBoms)){ - //所有数据的销售订单号相同,只需查一条的销售订单号 - String quoteId = filterSysMakeorderBoms.get(0).getSalesOrderCode(); - - // 第一步:收集所有不同的salesOrderMaterialNo 利用set key值不重复的特性 - Set uniqueSalesOrderMaterialNos = new HashSet<>(); - for (SysMakeorderBom filterSysMakeorderBom : filterSysMakeorderBoms) { - uniqueSalesOrderMaterialNos.add(filterSysMakeorderBom.getSalesOrderMaterialNo()); - } + PurchasePlan purchasePlan = new PurchasePlan(); - // 第二步:查询每个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); - } + String makeNo = makeOrder.getMakeNo(); - Integer purchasePlanMaterialSum = 0; - // 第三步:计算purchasePlanNum - for (SysMakeorderBom filterSysMakeorderBom : filterSysMakeorderBoms) { - String salesOrderMaterialNo = filterSysMakeorderBom.getSalesOrderMaterialNo(); - SysSalesOrderChild sysSalesOrderChild = salesOrderChildByMaterialNo.get(salesOrderMaterialNo); - if (sysSalesOrderChild != null) { - //物料数量 - Integer materialNum = sysSalesOrderChild.getMaterialNum(); - //用量 - Integer useNum = filterSysMakeorderBom.getUseNum(); - - //采购计划数 - Integer purchasePlanNum = materialNum * useNum; - - // 立即创建PurchasePlanChild对象 - PurchasePlanChild purchasePlanChild = new PurchasePlanChild(); - purchasePlanChild.setPurchasePlanCode(purchasePlanCode); - purchasePlanChild.setMaterialNo(filterSysMakeorderBom.getMaterialNo()); - - PurchasePlanChild tempPurchasePlanChild = purchasePlanChildMapper.selectPurchasePlanChildByCodeAndNo(purchasePlanChild); - if (tempPurchasePlanChild != null){ - - purchasePlanChild.setPurchasePlanChildId(tempPurchasePlanChild.getPurchasePlanChildId()); - //设置计划采购数 - purchasePlanChildMapper.updatePurchasePlanChild(purchasePlanChild); - }else { - purchasePlanChild.setMaterialName(filterSysMakeorderBom.getMaterialName()); - purchasePlanChild.setMaterialType(filterSysMakeorderBom.getMaterialType()); - purchasePlanChild.setWarehouseDept(filterSysMakeorderBom.getWarehouseDept()); - purchasePlanChild.setMaterialProcessMethod("0"); - purchasePlanChild.setMaterialBrand(filterSysMakeorderBom.getBrand()); - purchasePlanChild.setMaterialDescribe(filterSysMakeorderBom.getDescribe()); - purchasePlanChild.setMaterialUnit(filterSysMakeorderBom.getUnit()); - purchasePlanChild.setWarehouseDept(filterSysMakeorderBom.getWarehouseDept()); - // 物料的计划采购数,使用计算出的purchasePlanNum - purchasePlanChild.setCreateBy(ShiroUtils.getLoginName()); - purchasePlanChild.setCreateTime(new Date()); - // 直接保存PurchasePlanChild对象 - purchasePlanChildMapper.insertPurchasePlanChild(purchasePlanChild); - } - - // 更新总和 - purchasePlanMaterialSum += purchasePlanNum; - } + List sysMakeorderBoms = sysMakeorderBomMapper.selectSysMakeorderBomByMakeNo(makeNo); + + //保留 只有采购的类型 + List filterUniqueBoms = sysMakeorderBoms.stream().filter(bom -> "0".equals(bom.getProcessMethod())).collect(Collectors.toList()); + + List purchasePlanChildList = new ArrayList<>(); + + for (SysMakeorderBom filterUniqueBom : filterUniqueBoms) { + PurchasePlanChild purchasePlanChild = new PurchasePlanChild(); + String salesOrderMaterialNo = filterUniqueBom.getSalesOrderMaterialNo(); + String tempMakeNo = filterUniqueBom.getMakeNo(); + + int orderNum = 0; + if (StringUtils.isNotEmpty(salesOrderMaterialNo)){ + SysMakeorderBom tempMakeorderBom = new SysMakeorderBom(); + tempMakeorderBom.setMaterialNo(salesOrderMaterialNo); + tempMakeorderBom.setMakeNo(tempMakeNo); + SysMakeorderBom oldMakeorderBom = sysMakeorderBomMapper.selectSysMakeorderBomByNo(tempMakeorderBom); + orderNum = oldMakeorderBom.getOrderNum(); + + purchasePlanChild.setPlanPurchaseNum(orderNum * filterUniqueBom.getUseNum()); + purchasePlanChild.setPurchaseNum(orderNum * filterUniqueBom.getUseNum()); + }else { + purchasePlanChild.setPlanPurchaseNum(filterUniqueBom.getOrderNum()); + purchasePlanChild.setPurchaseNum(filterUniqueBom.getOrderNum()); } + purchasePlanChild.setPurchasePlanStatus("0"); + purchasePlanChild.setPurchasePlanCode(purchasePlanCode); + purchasePlanChild.setMaterialNo(filterUniqueBom.getMaterialNo()); + purchasePlanChild.setMaterialName(filterUniqueBom.getMaterialName()); + purchasePlanChild.setMaterialUnit(filterUniqueBom.getUnit()); + purchasePlanChild.setMaterialDescribe(filterUniqueBom.getDescribe()); + purchasePlanChild.setMaterialProcessMethod(filterUniqueBom.getProcessMethod()); + purchasePlanChild.setMaterialBrand(filterUniqueBom.getBrand()); + purchasePlanChild.setMaterialType(filterUniqueBom.getMaterialType()); + purchasePlanChild.setMaterialPhotourl(filterUniqueBom.getPhotoUrl()); + purchasePlanChild.setMaterialModel(filterUniqueBom.getMaterialModel()); + purchasePlanChild.setWarehouseDept(filterUniqueBom.getWarehouseDept()); + purchasePlanChild.setCreateTime(new Date()); + purchasePlanChild.setCreateBy(loginName); + purchasePlanChildList.add(purchasePlanChild); + } + int batchInsertPurchasePlanChildResult = purchasePlanChildMapper.batchInsertPurchasePlanChild(purchasePlanChildList); + if (batchInsertPurchasePlanChildResult <= 0){ + throw new BusinessException("插入采购计划子表数据失败"); + } + + //计算计划采购总数 + int planPurchaseSum = purchasePlanChildList.stream().mapToInt(PurchasePlanChild::getPlanPurchaseNum).sum(); - // 创建采购计划主记录 - PurchasePlan purchasePlan = buildPurchasePlan(sysMakeOrder, purchasePlanCode,materialAmount,purchasePlanMaterialSum); + purchasePlan.setPurchaseSum(planPurchaseSum); + purchasePlan.setPlanPurchaseSum(planPurchaseSum); - purchasePlanMapper.insertPurchasePlan(purchasePlan); + purchasePlan.setMaterialSum(filterUniqueBoms.size()); + purchasePlan.setPurchasePlanType("1");//生产单 + purchasePlan.setPurchasePlanCode(purchasePlanCode); + purchasePlan.setPurchasePlanStatus("0"); + purchasePlan.setCorrelationCode(makeOrder.getMakeNo()); + purchasePlan.setCreateTime(new Date()); + purchasePlan.setCreateBy(loginName); + + int insertPurchasePlanResult = purchasePlanMapper.insertPurchasePlan(purchasePlan); + if (insertPurchasePlanResult <= 0){ + throw new BusinessException("插入采购计划数据失败"); } + } /** diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysMakeOrderServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysMakeOrderServiceImpl.java index 78796e79..9d702027 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysMakeOrderServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysMakeOrderServiceImpl.java @@ -452,12 +452,16 @@ public class SysMakeOrderServiceImpl implements ISysMakeOrderService makeorderBomMapper.updateSysMakeorderBom(makeBom); } } -// sysMakeOrder.setMakeStatus("3");//生产状态-待生产 -// sysMakeOrder.setEceiptStatus("0");//入库状态-待采购 + sysMakeOrder.setMakeStatus("3");//生产状态-待生产 + sysMakeOrder.setEceiptStatus("0");//入库状态-待采购 //测试用状态(跳过采购) - sysMakeOrder.setMakeStatus("4");//生产状态-待生产 - sysMakeOrder.setEceiptStatus("7");//入库状态-待采购 +// sysMakeOrder.setMakeStatus("4");//生产状态-待生产 +// sysMakeOrder.setEceiptStatus("7");//入库状态-待采购 + + //生成采购计划 + purchasePlanService.generatePurchasePlanByMakeOrder(sysMakeOrder); + updateSysMakeOrder(sysMakeOrder); } diff --git a/ruoyi-admin/src/main/resources/mapper/purchase/PurchasePlanChildMapper.xml b/ruoyi-admin/src/main/resources/mapper/purchase/PurchasePlanChildMapper.xml index 70e4e011..0342064b 100644 --- a/ruoyi-admin/src/main/resources/mapper/purchase/PurchasePlanChildMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/purchase/PurchasePlanChildMapper.xml @@ -142,6 +142,78 @@ + + + insert into purchase_plan_child ( + purchase_plan_code, + purchase_plan_status, + correlation_code, + purchase_plan_type, + material_no, + material_name, + material_type, + material_photoUrl, + material_brand, + material_unit, + material_describe, + material_process_method, + material_model, + warehouse_dept, + material_noRmb_sum, + material_rmb_sum, + plan_purchase_num, + purchase_num, + actual_purchase_num, + shared_inventory_occupancy_num, + cancel_num, + plan_delivery_time, + this_purchase_num, + shared_available_inventory_num, + latest_quote_rmb, + create_by, + create_time, + remark, + del_flag + ) values + + ( + #{item.purchasePlanCode}, + #{item.purchasePlanStatus}, + #{item.correlationCode}, + #{item.purchasePlanType}, + #{item.materialNo}, + #{item.materialName}, + #{item.materialType}, + #{item.materialPhotourl}, + #{item.materialBrand}, + #{item.materialUnit}, + #{item.materialDescribe}, + #{item.materialProcessMethod}, + #{item.materialModel}, + #{item.warehouseDept}, + #{item.materialNoRmbSum}, + #{item.materialRmbSum}, + #{item.planPurchaseNum}, + #{item.purchaseNum}, + #{item.actualPurchaseNum}, + #{item.sharedInventoryOccupancyNum}, + #{item.cancelNum}, + #{item.planDeliveryTime}, + #{item.thisPurchaseNum}, + #{item.sharedAvailableInventoryNum}, + #{item.latestQuoteRmb}, + #{item.createBy}, + #{item.createTime}, + #{item.remark}, + #{item.delFlag} + ) + + + + + + + update purchase_plan_child