Browse Source

[fix] 生产管理 采购管理 销售管理

修改生产订单部门主管审核通过后 生成采购计划订单的方法
采购计划子表新增 通过物料号和采购计划单号查询采购计划子表数据后端接口
修改 新增采购计划主表的物料合计和数量合计的计算方法
修改 采购计划子表生成的时候计划采购数的计算方法
新增 根据物料号和销售订单号查询销售订单子表数据后端接口
dev
liuxiaoxu 4 months ago
parent
commit
1450a53987
  1. 5
      ruoyi-admin/src/main/java/com/ruoyi/purchase/mapper/PurchasePlanChildMapper.java
  2. 142
      ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchasePlanServiceImpl.java
  3. 4
      ruoyi-admin/src/main/java/com/ruoyi/system/mapper/SysSalesOrderChildMapper.java
  4. 9
      ruoyi-admin/src/main/resources/mapper/purchase/PurchasePlanChildMapper.xml
  5. 10
      ruoyi-admin/src/main/resources/mapper/system/SysSalesOrderChildMapper.xml

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

@ -81,4 +81,9 @@ public interface PurchasePlanChildMapper
List<PurchasePlanChild> getPurchasePlanChildByPlanCodes(String[] purchasePlanCodes);
/*
*
* 通过物料号和采购计划单号查询采购计划子表数据
* */
PurchasePlanChild selectPurchasePlanChildByCodeAndNo(PurchasePlanChild purchasePlanChild);
}

142
ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchasePlanServiceImpl.java

@ -2,9 +2,7 @@ package com.ruoyi.purchase.service.impl;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
import com.ruoyi.common.core.redis.RedisCache;
@ -16,7 +14,9 @@ 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.domain.SysSalesOrderChild;
import com.ruoyi.system.mapper.SysMakeOrderMapper;
import com.ruoyi.system.mapper.SysSalesOrderChildMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.purchase.mapper.PurchasePlanMapper;
@ -45,6 +45,9 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService
@Autowired
private RedisCache redisCache;
@Autowired
private SysSalesOrderChildMapper salesOrderChildMapper;
/**
* 查询采购计划单
*
@ -164,7 +167,6 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService
// 假设此处有一个生成唯一采购计划单号的方法
String purchasePlanCode = generateUniquePurchasePlanCode();
//物料相同的只保留一条
List<SysMakeorderBom> uniqueBoms = insertedSysMakeorderBoms.stream()
// 分组依据为MaterialNo
.collect(Collectors.groupingBy(SysMakeorderBom::getMaterialNo))
@ -175,29 +177,95 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService
.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(uniqueBoms.get(0).getMakeNo());
SysMakeOrder sysMakeOrder = sysMakeOrderMapper.selectMakeOrderByMakeNo(insertedSysMakeorderBoms.get(0).getMakeNo());
//保存所有加工方式为采购的物料
List<SysMakeorderBom> filterSysMakeorderBoms = uniqueBoms.stream().filter(bom -> "0".equals(bom.getProcessMethod())).collect(Collectors.toList());
//统计物料种类的数量
Integer materialAmount = filterSysMakeorderBoms.size();
List<SysMakeorderBom> filterSysMakeorderBoms = insertedSysMakeorderBoms.stream().filter(bom -> "0".equals(bom.getProcessMethod())).collect(Collectors.toList());
//所有数据的销售订单号相同,只需查一条的销售订单号
String quoteId = filterSysMakeorderBoms.get(0).getSalesOrderCode();
// 第一步:收集所有不同的salesOrderMaterialNo 利用set key值不重复的特性
Set<String> uniqueSalesOrderMaterialNos = new HashSet<>();
for (SysMakeorderBom filterSysMakeorderBom : filterSysMakeorderBoms) {
uniqueSalesOrderMaterialNos.add(filterSysMakeorderBom.getSalesOrderMaterialNo());
}
// 第二步:查询每个salesOrderMaterialNo对应的SalesOrder数据
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);
}
Long purchasePlanMaterialSum = 0L;
// 第三步:计算purchasePlanNum
for (SysMakeorderBom filterSysMakeorderBom : filterSysMakeorderBoms) {
String salesOrderMaterialNo = filterSysMakeorderBom.getSalesOrderMaterialNo();
SysSalesOrderChild sysSalesOrderChild = salesOrderChildByMaterialNo.get(salesOrderMaterialNo);
if (sysSalesOrderChild != null) {
//物料数量
long materialNum = sysSalesOrderChild.getMaterialNum();
//用量
long useNum = filterSysMakeorderBom.getUseNum();
//采购计划数
long purchasePlanNum = materialNum * useNum;
// 立即创建PurchasePlanChild对象
PurchasePlanChild purchasePlanChild = new PurchasePlanChild();
purchasePlanChild.setPurchasePlanCode(purchasePlanCode);
purchasePlanChild.setMaterialCode(filterSysMakeorderBom.getMaterialNo());
PurchasePlanChild tempPurchasePlanChild = purchasePlanChildMapper.selectPurchasePlanChildByCodeAndNo(purchasePlanChild);
if (tempPurchasePlanChild != null){
purchasePlanChild.setPurchasePlanChildId(tempPurchasePlanChild.getPurchasePlanChildId());
long addMaterialNum = tempPurchasePlanChild.getMaterialNum() + purchasePlanNum;
//设置计划采购数
purchasePlanChild.setMaterialNum(addMaterialNum);
purchasePlanChildMapper.updatePurchasePlanChild(purchasePlanChild);
}else {
purchasePlanChild.setMaterialName(filterSysMakeorderBom.getMaterialName());
purchasePlanChild.setMaterialType(filterSysMakeorderBom.getMaterialType());
purchasePlanChild.setWarehouseDept(filterSysMakeorderBom.getWarehouseDept());
purchasePlanChild.setProcessMethod("0");
purchasePlanChild.setBrand(filterSysMakeorderBom.getBrand());
purchasePlanChild.setDescribe(filterSysMakeorderBom.getDescribe());
purchasePlanChild.setUnit(filterSysMakeorderBom.getUnit());
purchasePlanChild.setWarehouseDept(filterSysMakeorderBom.getWarehouseDept());
// 物料的计划采购数,使用计算出的purchasePlanNum
purchasePlanChild.setMaterialNum(purchasePlanNum);
purchasePlanChild.setCreateBy(ShiroUtils.getLoginName());
purchasePlanChild.setCreateTime(new Date());
purchasePlanChild.setUnit(filterSysMakeorderBom.getUnit());
// 直接保存PurchasePlanChild对象
purchasePlanChildMapper.insertPurchasePlanChild(purchasePlanChild);
}
// 更新总和
purchasePlanMaterialSum += purchasePlanNum;
}
}
//统计数量合计
//生产订单中的订单数量
Long makeOrderMaterialSum = sysMakeOrder.getMaterialSum();
//加工方式为采购的所有物料用量合计
Long sum = filterSysMakeorderBoms.stream().mapToLong(SysMakeorderBom::getUseNum).sum();
Long purchasePlanMaterialSum = makeOrderMaterialSum * sum;
// 创建采购计划主记录
PurchasePlan purchasePlan = buildPurchasePlan(sysMakeOrder, purchasePlanCode,materialAmount,purchasePlanMaterialSum);
purchasePlanMapper.insertPurchasePlan(purchasePlan);
// 批量创建采购计划子项
insertPurchasePlanChildren(uniqueBoms, purchasePlanCode, sysMakeOrder);
}
/*假设自生成的采购计划单号*/
@ -228,44 +296,4 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService
return purchasePlan;
}
private void insertPurchasePlanChildren(List<SysMakeorderBom> uniqueBoms, String purchasePlanCode, SysMakeOrder sysMakeOrder) {
// List<SysMakeorderBom> 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());
//生产订单中的订单数量
Long makeOrderMaterialSum = sysMakeOrder.getMaterialSum();
for (SysMakeorderBom bom : uniqueBoms) {
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.setWarehouseDept(bom.getWarehouseDept());
purchasePlanChild.setProcessMethod("0");
purchasePlanChild.setBrand(bom.getBrand());
purchasePlanChild.setDescribe(bom.getDescribe());
purchasePlanChild.setUnit(bom.getUnit());
purchasePlanChild.setWarehouseDept(bom.getWarehouseDept());
//物料用量
Long useNum = bom.getUseNum();
//物料的计划采购数
purchasePlanChild.setMaterialNum(useNum * makeOrderMaterialSum);
purchasePlanChild.setCreateBy(ShiroUtils.getLoginName());
purchasePlanChild.setCreateTime(new Date());
purchasePlanChild.setUnit(bom.getUnit());
purchasePlanChildMapper.insertPurchasePlanChild(purchasePlanChild);
}
}
}
}

4
ruoyi-admin/src/main/java/com/ruoyi/system/mapper/SysSalesOrderChildMapper.java

@ -23,4 +23,8 @@ public interface SysSalesOrderChildMapper {
int deleteSysSalesOrderChildByQuoteIds(String[] ids);
SysSalesOrderChild selectOneByQuoteIdAndMaterialCode(@Param("quoteId") String quoteId, @Param("materialCode") String materialCode);
/*
* 根据物料号和销售订单号查询销售订单子表数据
* */
SysSalesOrderChild selectSalesOrderChildByCodeAndNo(SysSalesOrderChild sysSalesOrderChild);
}

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

@ -73,6 +73,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach>
</select>
<select id="selectPurchasePlanChildByCodeAndNo" parameterType="PurchasePlanChild" resultMap="PurchasePlanChildResult">
<include refid="selectPurchasePlanChildVo"/>
where purchase_plan_code = #{purchasePlanCode}
and material_code = #{materialCode}
</select>
<insert id="insertPurchasePlanChild" parameterType="PurchasePlanChild" useGeneratedKeys="true" keyProperty="purchasePlanChildId">
insert into purchase_plan_child
<trim prefix="(" suffix=")" suffixOverrides=",">

10
ruoyi-admin/src/main/resources/mapper/system/SysSalesOrderChildMapper.xml

@ -75,6 +75,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where a.quoteId = #{quoteId}
and a.materialCode = #{materialCode}
</select>
<select id="selectSalesOrderChildByCodeAndNo" resultMap="SysSalesOrderChildResult">
select id, quoteId, materialId, materialCode, materialName, materialType, processMethod, brand,
warehouseDept,materialNum
from sys_sales_order_child
where quoteId = #{quoteId}
and materialCode = #{materialCode}
</select>
<insert id="insertSysSalesOrderChild" parameterType="SysSalesOrderChild" useGeneratedKeys="true" keyProperty="id">
insert into sys_sales_order_child
<trim prefix="(" suffix=")" suffixOverrides=",">

Loading…
Cancel
Save