Browse Source

[feat]采

修改采购审核,修改加工方式委外或采购为采购,若修改则删除下阶物料的方法,加上生成采购计划的方法
采购计划新增 生产订单采购审核后生成采购计划方法
采购计划子表新增 批量新增采购计划单物料信息方法
采购计划impl层新增 生产订单采购审核后生成采购计划方法:实现通过采购审核的数据,得到生产bom中所有加工方式为采购的数据,转存到采购计划和采购计划子表中
dev
liuxiaoxu 4 days ago
parent
commit
a7839c8a18
  1. 2
      ruoyi-admin/src/main/java/com/ruoyi/purchase/mapper/PurchasePlanChildMapper.java
  2. 5
      ruoyi-admin/src/main/java/com/ruoyi/purchase/service/IPurchasePlanService.java
  3. 147
      ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchasePlanServiceImpl.java
  4. 12
      ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysMakeOrderServiceImpl.java
  5. 72
      ruoyi-admin/src/main/resources/mapper/purchase/PurchasePlanChildMapper.xml

2
ruoyi-admin/src/main/java/com/ruoyi/purchase/mapper/PurchasePlanChildMapper.java

@ -42,7 +42,7 @@ public interface PurchasePlanChildMapper
* @param purchasePlanChildList 采购计划单物料信息集合 * @param purchasePlanChildList 采购计划单物料信息集合
* @return 结果 * @return 结果
*/ */
public int batchInsertPurchasePlanChild(@Param("list") List<PurchasePlanChild> purchasePlanChildList); public int batchInsertPurchasePlanChild(List<PurchasePlanChild> purchasePlanChildList);
/** /**
* 修改采购计划单物料信息 * 修改采购计划单物料信息

5
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.PurchasePlan;
import com.ruoyi.purchase.domain.PurchasePlanChild; import com.ruoyi.purchase.domain.PurchasePlanChild;
import com.ruoyi.purchase.domain.Vo.PurchasePlanSelectSupplierVo; import com.ruoyi.purchase.domain.Vo.PurchasePlanSelectSupplierVo;
import com.ruoyi.system.domain.SysMakeOrder;
import com.ruoyi.system.domain.SysMakeorderBom; import com.ruoyi.system.domain.SysMakeorderBom;
import java.util.List; import java.util.List;
@ -88,9 +89,9 @@ public interface IPurchasePlanService
public List<PurchasePlan> selectPurchasePlanByPlanCode(String purchasePlanCodes); public List<PurchasePlan> selectPurchasePlanByPlanCode(String purchasePlanCodes);
/** /**
* 生产订单工程审核后生成采购计划 * 生产订单采购审核后生成采购计划
* */ * */
void generatePurchasePlanByMakeOrder(List<SysMakeorderBom> insertedSysMakeorderBoms); void generatePurchasePlanByMakeOrder(SysMakeOrder sysMakeOrder);
/** /**
* 开发修改单审核通过后生成采购计划 * 开发修改单审核通过后生成采购计划

147
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 java.util.stream.Collectors;
import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.exception.BusinessException;
import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils; import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.common.utils.StringUtils; 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.*;
import com.ruoyi.system.domain.Vo.SysSupplierVo; import com.ruoyi.system.domain.Vo.SysSupplierVo;
import com.ruoyi.system.mapper.SysMakeOrderMapper; import com.ruoyi.system.mapper.SysMakeOrderMapper;
import com.ruoyi.system.mapper.SysMakeorderBomMapper;
import com.ruoyi.system.mapper.SysSalesOrderChildMapper; import com.ruoyi.system.mapper.SysSalesOrderChildMapper;
import com.ruoyi.system.mapper.SysSupplierMapper; import com.ruoyi.system.mapper.SysSupplierMapper;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
@ -75,6 +77,10 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService
@Autowired @Autowired
private SysSupplierMapper sysSupplierMapper; private SysSupplierMapper sysSupplierMapper;
@Autowired
private SysMakeorderBomMapper sysMakeorderBomMapper;
/** /**
* 查询采购计划单 * 查询采购计划单
* *
@ -337,106 +343,85 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService
/* /*
* 生产订单工程审核后生成采购计划 * 生产订单采购审核后生成采购计划
* */ * */
@Override @Override
public void generatePurchasePlanByMakeOrder(List<SysMakeorderBom> insertedSysMakeorderBoms) { public void generatePurchasePlanByMakeOrder(SysMakeOrder makeOrder) {
// 假设此处有一个生成唯一采购计划单号的方法 // 生成唯一采购计划单号的方法
String purchasePlanCode = generateUniquePurchasePlanCode(); String purchasePlanCode = generateUniquePurchasePlanCode();
String loginName = ShiroUtils.getLoginName();
List<SysMakeorderBom> uniqueBoms = insertedSysMakeorderBoms.stream() PurchasePlan purchasePlan = new PurchasePlan();
// 分组依据为MaterialNo
.collect(Collectors.groupingBy(SysMakeorderBom::getMaterialNo))
// 把每个分组转为流,然后取第一个元素
.values().stream()
.map(groupedBoms -> groupedBoms.stream().findFirst().orElse(null))
// 过滤掉null值,以防万一某些分组是空的
.filter(Objects::nonNull)
.collect(Collectors.toList());
//过滤掉 只有采购的类型
List<SysMakeorderBom> 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<SysMakeorderBom> 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值不重复的特性 String makeNo = makeOrder.getMakeNo();
Set<String> uniqueSalesOrderMaterialNos = new HashSet<>();
for (SysMakeorderBom filterSysMakeorderBom : filterSysMakeorderBoms) {
uniqueSalesOrderMaterialNos.add(filterSysMakeorderBom.getSalesOrderMaterialNo());
}
// 第二步:查询每个salesOrderMaterialNo对应的SalesOrder数据 List<SysMakeorderBom> sysMakeorderBoms = sysMakeorderBomMapper.selectSysMakeorderBomByMakeNo(makeNo);
Map<String, SysSalesOrderChild> 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);
}
Integer purchasePlanMaterialSum = 0; //保留 只有采购的类型
// 第三步:计算purchasePlanNum List<SysMakeorderBom> filterUniqueBoms = sysMakeorderBoms.stream().filter(bom -> "0".equals(bom.getProcessMethod())).collect(Collectors.toList());
for (SysMakeorderBom filterSysMakeorderBom : filterSysMakeorderBoms) {
String salesOrderMaterialNo = filterSysMakeorderBom.getSalesOrderMaterialNo();
SysSalesOrderChild sysSalesOrderChild = salesOrderChildByMaterialNo.get(salesOrderMaterialNo);
if (sysSalesOrderChild != null) {
//物料数量
Integer materialNum = sysSalesOrderChild.getMaterialNum();
//用量
Integer useNum = filterSysMakeorderBom.getUseNum();
//采购计划数 List<PurchasePlanChild> purchasePlanChildList = new ArrayList<>();
Integer purchasePlanNum = materialNum * useNum;
// 立即创建PurchasePlanChild对象 for (SysMakeorderBom filterUniqueBom : filterUniqueBoms) {
PurchasePlanChild purchasePlanChild = new PurchasePlanChild(); PurchasePlanChild purchasePlanChild = new PurchasePlanChild();
purchasePlanChild.setPurchasePlanCode(purchasePlanCode); String salesOrderMaterialNo = filterUniqueBom.getSalesOrderMaterialNo();
purchasePlanChild.setMaterialNo(filterSysMakeorderBom.getMaterialNo()); String tempMakeNo = filterUniqueBom.getMakeNo();
PurchasePlanChild tempPurchasePlanChild = purchasePlanChildMapper.selectPurchasePlanChildByCodeAndNo(purchasePlanChild); int orderNum = 0;
if (tempPurchasePlanChild != null){ if (StringUtils.isNotEmpty(salesOrderMaterialNo)){
SysMakeorderBom tempMakeorderBom = new SysMakeorderBom();
purchasePlanChild.setPurchasePlanChildId(tempPurchasePlanChild.getPurchasePlanChildId()); tempMakeorderBom.setMaterialNo(salesOrderMaterialNo);
//设置计划采购数 tempMakeorderBom.setMakeNo(tempMakeNo);
purchasePlanChildMapper.updatePurchasePlanChild(purchasePlanChild); SysMakeorderBom oldMakeorderBom = sysMakeorderBomMapper.selectSysMakeorderBomByNo(tempMakeorderBom);
orderNum = oldMakeorderBom.getOrderNum();
purchasePlanChild.setPlanPurchaseNum(orderNum * filterUniqueBom.getUseNum());
purchasePlanChild.setPurchaseNum(orderNum * filterUniqueBom.getUseNum());
}else { }else {
purchasePlanChild.setMaterialName(filterSysMakeorderBom.getMaterialName()); purchasePlanChild.setPlanPurchaseNum(filterUniqueBom.getOrderNum());
purchasePlanChild.setMaterialType(filterSysMakeorderBom.getMaterialType()); purchasePlanChild.setPurchaseNum(filterUniqueBom.getOrderNum());
purchasePlanChild.setWarehouseDept(filterSysMakeorderBom.getWarehouseDept()); }
purchasePlanChild.setMaterialProcessMethod("0"); purchasePlanChild.setPurchasePlanStatus("0");
purchasePlanChild.setMaterialBrand(filterSysMakeorderBom.getBrand()); purchasePlanChild.setPurchasePlanCode(purchasePlanCode);
purchasePlanChild.setMaterialDescribe(filterSysMakeorderBom.getDescribe()); purchasePlanChild.setMaterialNo(filterUniqueBom.getMaterialNo());
purchasePlanChild.setMaterialUnit(filterSysMakeorderBom.getUnit()); purchasePlanChild.setMaterialName(filterUniqueBom.getMaterialName());
purchasePlanChild.setWarehouseDept(filterSysMakeorderBom.getWarehouseDept()); purchasePlanChild.setMaterialUnit(filterUniqueBom.getUnit());
// 物料的计划采购数,使用计算出的purchasePlanNum purchasePlanChild.setMaterialDescribe(filterUniqueBom.getDescribe());
purchasePlanChild.setCreateBy(ShiroUtils.getLoginName()); 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.setCreateTime(new Date());
// 直接保存PurchasePlanChild对象 purchasePlanChild.setCreateBy(loginName);
purchasePlanChildMapper.insertPurchasePlanChild(purchasePlanChild); purchasePlanChildList.add(purchasePlanChild);
} }
// 更新总和 int batchInsertPurchasePlanChildResult = purchasePlanChildMapper.batchInsertPurchasePlanChild(purchasePlanChildList);
purchasePlanMaterialSum += purchasePlanNum; if (batchInsertPurchasePlanChildResult <= 0){
} throw new BusinessException("插入采购计划子表数据失败");
} }
//计算计划采购总数
int planPurchaseSum = purchasePlanChildList.stream().mapToInt(PurchasePlanChild::getPlanPurchaseNum).sum();
// 创建采购计划主记录 purchasePlan.setPurchaseSum(planPurchaseSum);
PurchasePlan purchasePlan = buildPurchasePlan(sysMakeOrder, purchasePlanCode,materialAmount,purchasePlanMaterialSum); 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("插入采购计划数据失败");
} }
} }
/** /**

12
ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysMakeOrderServiceImpl.java

@ -452,12 +452,16 @@ public class SysMakeOrderServiceImpl implements ISysMakeOrderService
makeorderBomMapper.updateSysMakeorderBom(makeBom); makeorderBomMapper.updateSysMakeorderBom(makeBom);
} }
} }
// sysMakeOrder.setMakeStatus("3");//生产状态-待生产 sysMakeOrder.setMakeStatus("3");//生产状态-待生产
// sysMakeOrder.setEceiptStatus("0");//入库状态-待采购 sysMakeOrder.setEceiptStatus("0");//入库状态-待采购
//测试用状态(跳过采购) //测试用状态(跳过采购)
sysMakeOrder.setMakeStatus("4");//生产状态-待生产 // sysMakeOrder.setMakeStatus("4");//生产状态-待生产
sysMakeOrder.setEceiptStatus("7");//入库状态-待采购 // sysMakeOrder.setEceiptStatus("7");//入库状态-待采购
//生成采购计划
purchasePlanService.generatePurchasePlanByMakeOrder(sysMakeOrder);
updateSysMakeOrder(sysMakeOrder); updateSysMakeOrder(sysMakeOrder);
} }

72
ruoyi-admin/src/main/resources/mapper/purchase/PurchasePlanChildMapper.xml

@ -142,6 +142,78 @@
</trim> </trim>
</insert> </insert>
<insert id="batchInsertPurchasePlanChild" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="purchasePlanChildId">
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
<foreach collection="list" item="item" separator=",">
(
#{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}
)
</foreach>
</insert>
<update id="updatePurchasePlanChild" parameterType="PurchasePlanChild"> <update id="updatePurchasePlanChild" parameterType="PurchasePlanChild">
update purchase_plan_child update purchase_plan_child
<trim prefix="SET" suffixOverrides=","> <trim prefix="SET" suffixOverrides=",">

Loading…
Cancel
Save