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 b9782463..8aa6a405 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 @@ -4,6 +4,7 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.List; +import java.util.stream.Collectors; import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.utils.DateUtils; @@ -163,8 +164,22 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService // 仅查询一次,因为所有SysMakeorderBom都关联同一生产单号 SysMakeOrder sysMakeOrder = sysMakeOrderMapper.selectMakeOrderByMakeNo(insertedSysMakeorderBoms.get(0).getMakeNo()); + //保存所有加工方式为采购的物料 + List filterSysMakeorderBoms = insertedSysMakeorderBoms.stream().filter(bom -> "0".equals(bom.getProcessMethod())).collect(Collectors.toList()); + //统计物料种类的数量 + Integer materialAmount = filterSysMakeorderBoms.size(); + + //统计数量合计 + //生产订单中的订单数量 + Long makeOrderMaterialSum = sysMakeOrder.getMaterialSum(); + //加工方式为采购的所有物料用量合计 + Long sum = filterSysMakeorderBoms.stream().mapToLong(SysMakeorderBom::getUseNum).sum(); + + Long purchasePlanMaterialSum = makeOrderMaterialSum * sum; // 创建采购计划主记录 - PurchasePlan purchasePlan = buildPurchasePlan(sysMakeOrder, purchasePlanCode); + PurchasePlan purchasePlan = buildPurchasePlan(sysMakeOrder, purchasePlanCode,materialAmount,purchasePlanMaterialSum); + + purchasePlanMapper.insertPurchasePlan(purchasePlan); // 批量创建采购计划子项 @@ -178,18 +193,16 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService return redisCache.generateBillNo("CGJH"); } - private PurchasePlan buildPurchasePlan(SysMakeOrder sysMakeOrder, String purchasePlanCode) { + private PurchasePlan buildPurchasePlan(SysMakeOrder sysMakeOrder, String purchasePlanCode,Integer materialAmount,Long purchasePlanMaterialSum) { 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.setMaterialAmount((long) materialAmount); + + //添加数量合计 + purchasePlan.setMaterialSum(purchasePlanMaterialSum); purchasePlan.setNoRmbSum(sysMakeOrder.getNoRate()); purchasePlan.setRmbSum(sysMakeOrder.getRate()); purchasePlan.setApplyUser(sysMakeOrder.getSalesman()); @@ -202,6 +215,9 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService } private void insertPurchasePlanChildren(List insertedSysMakeorderBoms, String purchasePlanCode, SysMakeOrder sysMakeOrder) { + + //生产订单中的订单数量 + Long makeOrderMaterialSum = sysMakeOrder.getMaterialSum(); for (SysMakeorderBom bom : insertedSysMakeorderBoms) { if ("0".equals(bom.getProcessMethod())) { PurchasePlanChild purchasePlanChild = new PurchasePlanChild(); @@ -211,12 +227,16 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService purchasePlanChild.setMaterialType(bom.getMaterialType()); //新增物料入库部门 purchasePlanChild.setWarehouseDept(bom.getWarehouseDept()); - purchasePlanChild.setProcessMethod("采购"); + purchasePlanChild.setProcessMethod("0"); purchasePlanChild.setBrand(bom.getBrand()); purchasePlanChild.setDescribe(bom.getDescribe()); - purchasePlanChild.setMaterialNum(bom.getUseNum()); + //物料用量 + 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/service/impl/SysMakeOrderServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysMakeOrderServiceImpl.java index 5495e766..5db56e28 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 @@ -258,23 +258,41 @@ public class SysMakeOrderServiceImpl implements ISysMakeOrderService String materialCode = sysSalesOrderChild.getMaterialCode(); // 0阶 ErpBom erpBom = erpBomService.selectErpBomByOneMaterialNo(materialCode); - Long id = erpBom.getId(); - // 查询1阶及以下 - ErpBom oneLevelBom = new ErpBom(); - oneLevelBom.setParentId(id); - List subBomList = erpBomService.selectErpBomAllLevelList(oneLevelBom); - for (int j = 0; j < subBomList.size(); j++) { - ErpBom subBom = subBomList.get(j); - SysMakeorderBom orderBom = new SysMakeorderBom(); - BeanUtils.copyProperties(subBom,orderBom, "id","delFlag","createBy","createTime","updateBy","updateTime","remark"); - orderBom.setMakeNo(makeNo); - orderBom.setSalesOrderCode(saleNo); - orderBom.setSalesOrderMaterialNo(materialCode); - sortNo++; - orderBom.setSortNo(sortNo); - makeorderBomService.insertSysMakeorderBom(orderBom); - insertedSysMakeorderBoms.add(orderBom); + if (erpBom != null){ + Long id = erpBom.getId(); + // 查询1阶及以下 + ErpBom oneLevelBom = new ErpBom(); + oneLevelBom.setParentId(id); + List subBomList = erpBomService.selectErpBomAllLevelList(oneLevelBom); + for (int j = 0; j < subBomList.size(); j++) { + ErpBom subBom = subBomList.get(j); + SysMakeorderBom orderBom = new SysMakeorderBom(); + BeanUtils.copyProperties(subBom,orderBom, "id","delFlag","createBy","createTime","updateBy","updateTime","remark"); + orderBom.setMakeNo(makeNo); + orderBom.setSalesOrderCode(saleNo); + orderBom.setSalesOrderMaterialNo(materialCode); + sortNo++; + orderBom.setSortNo(sortNo); + makeorderBomService.insertSysMakeorderBom(orderBom); + insertedSysMakeorderBoms.add(orderBom); + } + }else { + ErpBom oneLevelBom = new ErpBom(); + List subBomList = erpBomService.selectErpBomAllLevelList(oneLevelBom); + for (int j = 0; j < subBomList.size(); j++) { + ErpBom subBom = subBomList.get(j); + SysMakeorderBom orderBom = new SysMakeorderBom(); + BeanUtils.copyProperties(subBom,orderBom, "id","delFlag","createBy","createTime","updateBy","updateTime","remark"); + orderBom.setMakeNo(makeNo); + orderBom.setSalesOrderCode(saleNo); + orderBom.setSalesOrderMaterialNo(materialCode); + sortNo++; + orderBom.setSortNo(sortNo); + makeorderBomService.insertSysMakeorderBom(orderBom); + insertedSysMakeorderBoms.add(orderBom); + } } + } } // todo 加工方式“采购”的物料生成采购计划 diff --git a/ruoyi-admin/src/main/resources/mapper/erp/ErpBomMapper.xml b/ruoyi-admin/src/main/resources/mapper/erp/ErpBomMapper.xml index 869e14a6..4d61fe05 100644 --- a/ruoyi-admin/src/main/resources/mapper/erp/ErpBomMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/erp/ErpBomMapper.xml @@ -115,7 +115,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and erp.create_time between #{params.beginCreateTime} and #{params.endCreateTime} and erp.material_no like concat('%', #{params.materialNo}, '%') and erp.material_no = #{materialNo} - and erp.bomNo = #{bomNo} + and erp.bom_no = #{bomNo} and erp.material_name like concat('%', #{materialName}, '%') and erp.audit_status = #{auditStatus} and erp.use_status = #{useStatus} diff --git a/ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/detail.html b/ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/detail.html index ba9d8bb1..aa78314f 100644 --- a/ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/detail.html +++ b/ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/detail.html @@ -107,7 +107,7 @@ }, columns: [ {field: 'purchasePlanId',title: '主键id',visible: false}, - {field: 'materialNo',title: '料号',}, + {field: 'materialCode',title: '料号',}, {field: 'photoUrl',title: '图片', formatter: function(value, row, index) {return $.table.imageView(value);} }, @@ -117,14 +117,12 @@ }, {field: 'describe',title: '描述',}, {field: 'brand',title: '品牌',}, - {field: 'processMethod',title: '半成品类型', + {field: 'processMethod',title: '加工方式', formatter: function(value, row, index) {return $.table.selectDictLabel(processMethodDatas, value);} }, {field: 'unit',title: '单位', - formatter: function(value, row, index) {return $.table.selectDictLabel(sysUnitClassDatas, value);} }, - {field: 'planNum',title: '计划采购数', - formatter: function(value, row, index) {return $.table.selectDictLabel(sysUnitClassDatas, value);} + {field: 'materialNum',title: '计划采购数', }, ]} $.table.init(option); diff --git a/ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/purchasePlan.html b/ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/purchasePlan.html index 33c03ab2..66e45649 100644 --- a/ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/purchasePlan.html +++ b/ruoyi-admin/src/main/resources/templates/purchase/purchasePlan/purchasePlan.html @@ -144,12 +144,10 @@ }, {field: 'describe',title: '描述',}, {field: 'brand',title: '品牌',}, - {field: 'processMethod',title: '加工类型', + {field: 'processMethod',title: '加工方式', formatter: function(value, row, index) {return $.table.selectDictLabel(processMethodDatas, value);} }, - {field: 'unit',title: '单位', - formatter: function(value, row, index) {return $.table.selectDictLabel(sysUnitClassDatas, value);} - }, + {field: 'unit',title: '单位', }, {field: 'warehouseDept',title: '入库部门',visible: false}, {field: 'materialNum',title: '计划采购数',}, ]