From 673cdba48e9e7c23444ac2e4202878b85e8587df Mon Sep 17 00:00:00 2001 From: liuxiaoxu <1793812695@qq.com> Date: Tue, 18 Jun 2024 13:50:14 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=E9=87=87=E8=B4=AD=E7=AE=A1=E7=90=86:=20?= =?UTF-8?q?=E9=87=87=E8=B4=AD=E8=AE=A1=E5=88=92=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E7=94=9F=E4=BA=A7=E8=AE=A2=E5=8D=95=E5=B7=A5=E7=A8=8B=E5=AE=A1?= =?UTF-8?q?=E6=A0=B8=E9=80=9A=E8=BF=87=E5=90=8E=E8=87=AA=E5=8A=A8=E7=94=9F?= =?UTF-8?q?=E6=88=90=E9=87=87=E8=B4=AD=E8=AE=A1=E5=88=92=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=92=8C=E9=87=87=E8=B4=AD=E8=AE=A1=E5=88=92=E5=AD=90=E8=A1=A8?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=20=E6=96=B0=E5=A2=9E=E7=94=9F=E4=BA=A7?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=B7=A5=E7=A8=8B=E5=AE=A1=E6=A0=B8=E5=90=8E?= =?UTF-8?q?=E7=94=9F=E4=BA=A7=E9=87=87=E8=B4=AD=E8=AE=A1=E5=88=92=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=92=8C=E9=87=87=E8=B4=AD=E8=AE=A1=E5=88=92=E5=AD=90?= =?UTF-8?q?=E8=A1=A8=E6=95=B0=E6=8D=AE=E5=90=8E=E7=AB=AF=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=20=E6=96=B0=E5=A2=9E=20=E6=96=B0=E5=A2=9E=E9=87=87=E8=B4=AD?= =?UTF-8?q?=E8=AE=A1=E5=88=92=E6=95=B0=E6=8D=AE=E5=92=8C=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=E6=96=B0=E5=A2=9E=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E7=94=9F=E4=BA=A7=E5=8D=95=E5=8F=B7=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E7=94=9F=E4=BA=A7=E8=AE=A2=E5=8D=95=E5=92=8C=E7=94=9F=E4=BA=A7?= =?UTF-8?q?=E8=AE=A2=E5=8D=95bom=20=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/IPurchasePlanService.java | 5 ++ .../service/impl/PurchasePlanServiceImpl.java | 82 +++++++++++++++++++ .../system/mapper/SysMakeOrderMapper.java | 5 ++ .../service/impl/SysMakeOrderServiceImpl.java | 9 ++ .../mapper/system/SysMakeOrderMapper.xml | 7 ++ 5 files changed, 108 insertions(+) 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 eff62dfd..02e40068 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 @@ -2,6 +2,7 @@ package com.ruoyi.purchase.service; import com.ruoyi.purchase.domain.PurchasePlan; import com.ruoyi.purchase.domain.PurchasePlanChild; +import com.ruoyi.system.domain.SysMakeorderBom; import java.util.List; @@ -77,4 +78,8 @@ public interface IPurchasePlanService public List selectPurchasePlanByPlanCode(String purchasePlanCodes); + /* + * 生产订单工程审核后生成采购计划 + * */ + void generatePurchasePlanByMakeOrder(List insertedSysMakeorderBoms); } 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 df31ecec..ec1b1495 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 @@ -1,9 +1,18 @@ package com.ruoyi.purchase.service.impl; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Date; import java.util.List; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.ShiroUtils; +import com.ruoyi.common.utils.StringUtils; import com.ruoyi.purchase.domain.PurchasePlan; +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.mapper.SysMakeOrderMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.purchase.mapper.PurchasePlanMapper; @@ -22,6 +31,12 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService @Autowired private PurchasePlanMapper purchasePlanMapper; + @Autowired + private SysMakeOrderMapper sysMakeOrderMapper; + + @Autowired + private PurchasePlanChildMapper purchasePlanChildMapper; + /** * 查询采购计划单 * @@ -129,4 +144,71 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService return purchasePlanMapper.selectPurchasePlanByPlanCode(Convert.toStrArray(purchasePlanCodes)); } + + /* + * 生产订单工程审核后生成采购计划 + * */ + @Override + public void generatePurchasePlanByMakeOrder(List insertedSysMakeorderBoms) { + // 假设此处有一个生成唯一采购计划单号的方法 + String purchasePlanCode = generateUniquePurchasePlanCode(); + + // 仅查询一次,因为所有SysMakeorderBom都关联同一生产单号 + SysMakeOrder sysMakeOrder = sysMakeOrderMapper.selectMakeOrderByMakeNo(insertedSysMakeorderBoms.get(0).getMakeNo()); + + // 创建采购计划主记录 + PurchasePlan purchasePlan = buildPurchasePlan(sysMakeOrder, purchasePlanCode); + purchasePlanMapper.insertPurchasePlan(purchasePlan); + + // 批量创建采购计划子项 + insertPurchasePlanChildren(insertedSysMakeorderBoms, purchasePlanCode, sysMakeOrder); + } + + /*假设自生成的采购计划单号*/ + private String generateUniquePurchasePlanCode() { + // 实现生成唯一采购计划单号的逻辑 + // 示例代码,实际情况可能依赖于日期、序列号等 + return "PP-" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")); + } + + private PurchasePlan buildPurchasePlan(SysMakeOrder sysMakeOrder, String purchasePlanCode) { + PurchasePlan purchasePlan = new PurchasePlan(); + purchasePlan.setCorrelationCode(sysMakeOrder.getMakeNo()); + purchasePlan.setPurchasePlanCode(purchasePlanCode); + purchasePlan.setPurchasePlanType("1"); + if (StringUtils.isNotBlank(sysMakeOrder.getMaterial())) { + purchasePlan.setMaterialAmount(Long.parseLong(sysMakeOrder.getMaterial())); + } else { + // 如果该字段允许为NULL或有默认值,可以这样设置 + purchasePlan.setMaterialAmount(0L); // 或者设定一个默认值,例如:0L + } + purchasePlan.setMaterialSum(sysMakeOrder.getMaterialSum()); + purchasePlan.setNoRmbSum(sysMakeOrder.getNoRate()); + purchasePlan.setRmbSum(sysMakeOrder.getRate()); + purchasePlan.setApplyUser(sysMakeOrder.getSalesman()); + purchasePlan.setCreateBy(ShiroUtils.getLoginName()); + purchasePlan.setCreateTime(new Date()); + purchasePlan.setPurchasePlanStatus("0"); + return purchasePlan; + } + + private void insertPurchasePlanChildren(List insertedSysMakeorderBoms, String purchasePlanCode, SysMakeOrder sysMakeOrder) { + for (SysMakeorderBom bom : insertedSysMakeorderBoms) { + 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.setProcessMethod("采购"); + purchasePlanChild.setBrand(bom.getBrand()); + purchasePlanChild.setDescribe(bom.getDescribe()); + purchasePlanChild.setMaterialNum(bom.getUseNum()); + purchasePlanChild.setCreateBy(ShiroUtils.getLoginName()); + purchasePlanChild.setCreateTime(new Date()); + purchasePlanChildMapper.insertPurchasePlanChild(purchasePlanChild); + } + } + } + } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/mapper/SysMakeOrderMapper.java b/ruoyi-admin/src/main/java/com/ruoyi/system/mapper/SysMakeOrderMapper.java index 6ea81d53..9f0311d9 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/mapper/SysMakeOrderMapper.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/mapper/SysMakeOrderMapper.java @@ -108,4 +108,9 @@ public interface SysMakeOrderMapper * */ SysMakeOrder selectSaleNoByMakeNo(String makeNo); + + /* + * 根据生产单号查询生产单 + * */ + SysMakeOrder selectMakeOrderByMakeNo(String makeNo); } 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 1d4c5b5e..25929610 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 @@ -7,6 +7,7 @@ import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.ShiroUtils; import com.ruoyi.erp.domain.ErpBom; import com.ruoyi.erp.service.IErpBomService; +import com.ruoyi.purchase.service.IPurchasePlanService; import com.ruoyi.system.domain.SysMakeOrder; import com.ruoyi.system.domain.SysMakeorderBom; import com.ruoyi.system.domain.SysSalesOrderChild; @@ -19,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.List; /** @@ -51,6 +53,9 @@ public class SysMakeOrderServiceImpl implements ISysMakeOrderService @Autowired private ISysMakeorderBomService makeorderBomService; + @Autowired + private IPurchasePlanService purchasePlanService; + /** * 查询生产订单 * @@ -222,6 +227,8 @@ public class SysMakeOrderServiceImpl implements ISysMakeOrderService @Transactional(rollbackFor = Exception.class) public void gcReview(SysMakeOrder sysMakeOrder) { String makeNo = sysMakeOrder.getMakeNo(); + // 定义一个列表用于收集新插入的SysMakeorderBom + List insertedSysMakeorderBoms = new ArrayList<>(); // 待生产 sysMakeOrder.setMakeStatus("3"); updateByMakeNo(sysMakeOrder); @@ -250,10 +257,12 @@ public class SysMakeOrderServiceImpl implements ISysMakeOrderService sortNo++; orderBom.setSortNo(sortNo); makeorderBomService.insertSysMakeorderBom(orderBom); + insertedSysMakeorderBoms.add(orderBom); } } } // todo 加工方式“采购”的物料生成采购计划 + purchasePlanService.generatePurchasePlanByMakeOrder(insertedSysMakeorderBoms); } @Override diff --git a/ruoyi-admin/src/main/resources/mapper/system/SysMakeOrderMapper.xml b/ruoyi-admin/src/main/resources/mapper/system/SysMakeOrderMapper.xml index f982a194..47e8e327 100644 --- a/ruoyi-admin/src/main/resources/mapper/system/SysMakeOrderMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/system/SysMakeOrderMapper.xml @@ -257,6 +257,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select makeNo from sys_makeorder + + + +