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