|
@ -4,6 +4,7 @@ import java.time.LocalDateTime; |
|
|
import java.time.format.DateTimeFormatter; |
|
|
import java.time.format.DateTimeFormatter; |
|
|
import java.util.Date; |
|
|
import java.util.Date; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Objects; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
import com.ruoyi.common.core.redis.RedisCache; |
|
|
import com.ruoyi.common.core.redis.RedisCache; |
|
@ -161,11 +162,22 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService |
|
|
// 假设此处有一个生成唯一采购计划单号的方法
|
|
|
// 假设此处有一个生成唯一采购计划单号的方法
|
|
|
String purchasePlanCode = generateUniquePurchasePlanCode(); |
|
|
String purchasePlanCode = generateUniquePurchasePlanCode(); |
|
|
|
|
|
|
|
|
|
|
|
//物料相同的只保留一条
|
|
|
|
|
|
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()); |
|
|
|
|
|
|
|
|
// 仅查询一次,因为所有SysMakeorderBom都关联同一生产单号
|
|
|
// 仅查询一次,因为所有SysMakeorderBom都关联同一生产单号
|
|
|
SysMakeOrder sysMakeOrder = sysMakeOrderMapper.selectMakeOrderByMakeNo(insertedSysMakeorderBoms.get(0).getMakeNo()); |
|
|
SysMakeOrder sysMakeOrder = sysMakeOrderMapper.selectMakeOrderByMakeNo(uniqueBoms.get(0).getMakeNo()); |
|
|
|
|
|
|
|
|
//保存所有加工方式为采购的物料
|
|
|
//保存所有加工方式为采购的物料
|
|
|
List<SysMakeorderBom> filterSysMakeorderBoms = insertedSysMakeorderBoms.stream().filter(bom -> "0".equals(bom.getProcessMethod())).collect(Collectors.toList()); |
|
|
List<SysMakeorderBom> filterSysMakeorderBoms = uniqueBoms.stream().filter(bom -> "0".equals(bom.getProcessMethod())).collect(Collectors.toList()); |
|
|
//统计物料种类的数量
|
|
|
//统计物料种类的数量
|
|
|
Integer materialAmount = filterSysMakeorderBoms.size(); |
|
|
Integer materialAmount = filterSysMakeorderBoms.size(); |
|
|
|
|
|
|
|
@ -183,7 +195,7 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService |
|
|
purchasePlanMapper.insertPurchasePlan(purchasePlan); |
|
|
purchasePlanMapper.insertPurchasePlan(purchasePlan); |
|
|
|
|
|
|
|
|
// 批量创建采购计划子项
|
|
|
// 批量创建采购计划子项
|
|
|
insertPurchasePlanChildren(insertedSysMakeorderBoms, purchasePlanCode, sysMakeOrder); |
|
|
insertPurchasePlanChildren(uniqueBoms, purchasePlanCode, sysMakeOrder); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/*假设自生成的采购计划单号*/ |
|
|
/*假设自生成的采购计划单号*/ |
|
@ -214,11 +226,21 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService |
|
|
return purchasePlan; |
|
|
return purchasePlan; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void insertPurchasePlanChildren(List<SysMakeorderBom> insertedSysMakeorderBoms, String purchasePlanCode, SysMakeOrder sysMakeOrder) { |
|
|
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(); |
|
|
Long makeOrderMaterialSum = sysMakeOrder.getMaterialSum(); |
|
|
for (SysMakeorderBom bom : insertedSysMakeorderBoms) { |
|
|
for (SysMakeorderBom bom : uniqueBoms) { |
|
|
if ("0".equals(bom.getProcessMethod())) { |
|
|
if ("0".equals(bom.getProcessMethod())) { |
|
|
PurchasePlanChild purchasePlanChild = new PurchasePlanChild(); |
|
|
PurchasePlanChild purchasePlanChild = new PurchasePlanChild(); |
|
|
purchasePlanChild.setPurchasePlanCode(purchasePlanCode); |
|
|
purchasePlanChild.setPurchasePlanCode(purchasePlanCode); |
|
|