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