|
|
@ -9,6 +9,11 @@ import com.ruoyi.common.core.redis.RedisCache; |
|
|
|
import com.ruoyi.common.utils.DateUtils; |
|
|
|
import com.ruoyi.common.utils.ShiroUtils; |
|
|
|
import com.ruoyi.common.utils.StringUtils; |
|
|
|
import com.ruoyi.erp.domain.ErpBom; |
|
|
|
import com.ruoyi.erp.domain.ErpDevelopModifyorderDetail; |
|
|
|
import com.ruoyi.erp.domain.vo.ErpDevelopModifyorderVo; |
|
|
|
import com.ruoyi.erp.mapper.ErpDevelopModifyorderDetailMapper; |
|
|
|
import com.ruoyi.erp.service.IErpBomService; |
|
|
|
import com.ruoyi.purchase.domain.PurchasePlan; |
|
|
|
import com.ruoyi.purchase.domain.PurchasePlanChild; |
|
|
|
import com.ruoyi.purchase.mapper.PurchasePlanChildMapper; |
|
|
@ -17,6 +22,7 @@ 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.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import com.ruoyi.purchase.mapper.PurchasePlanMapper; |
|
|
@ -48,6 +54,12 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService |
|
|
|
@Autowired |
|
|
|
private SysSalesOrderChildMapper salesOrderChildMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ErpDevelopModifyorderDetailMapper developModifyorderDetailMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private IErpBomService erpBomService; |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询采购计划单 |
|
|
|
* |
|
|
@ -267,6 +279,128 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 开发修改单审核通过后生成采购计划 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public void generatePurchasePlanByDevelopModifyorder(ErpDevelopModifyorderVo erpDevelopModifyorderVo) { |
|
|
|
String developOrderCode = erpDevelopModifyorderVo.getDevelopOrderCode(); |
|
|
|
String loginName = ShiroUtils.getLoginName(); |
|
|
|
String purchasePlanCode = generateUniquePurchasePlanCode(); |
|
|
|
|
|
|
|
List<ErpDevelopModifyorderDetail> erpDevelopModifyorderDetailList = developModifyorderDetailMapper.selectDevelopModifyDetailMaterialByCode(developOrderCode); |
|
|
|
|
|
|
|
// // 只需要加工方式为采购的
|
|
|
|
// List<ErpDevelopModifyorderDetail> filterDevelopModifyorderDetailList = erpDevelopModifyorderDetailList.stream()
|
|
|
|
// .filter(detail -> "0".equals(detail.getMaterialProcessMethod()))
|
|
|
|
// .collect(Collectors.toList());
|
|
|
|
|
|
|
|
List<PurchasePlanChild> purchasePlanChildList = new ArrayList<>(); |
|
|
|
PurchasePlan purchasePlan = new PurchasePlan(); |
|
|
|
purchasePlan.setPurchasePlanCode(purchasePlanCode); |
|
|
|
purchasePlan.setCreateTime(new Date()); |
|
|
|
purchasePlan.setCreateBy(loginName); |
|
|
|
// 标明来源是开发修改单
|
|
|
|
purchasePlan.setPurchasePlanType("3"); |
|
|
|
// 标明为待申请
|
|
|
|
purchasePlan.setPurchasePlanStatus("0"); |
|
|
|
purchasePlan.setCorrelationCode(erpDevelopModifyorderVo.getDevelopOrderCode()); |
|
|
|
// 处理开发修改单详情
|
|
|
|
for (ErpDevelopModifyorderDetail erpDevelopModifyorderDetail : erpDevelopModifyorderDetailList) { |
|
|
|
// 获取0阶层物料
|
|
|
|
Integer bomId = erpDevelopModifyorderDetail.getBomId(); |
|
|
|
// 插入开发修改单详情的数据
|
|
|
|
PurchasePlanChild tempPurchasePlanChild = createPurchasePlanChild(purchasePlanCode, erpDevelopModifyorderDetail, loginName); |
|
|
|
purchasePlanChildList.add(tempPurchasePlanChild); |
|
|
|
|
|
|
|
if (bomId != null) { |
|
|
|
// 插入子阶的数据
|
|
|
|
ErpBom oneLevelBom = new ErpBom(); |
|
|
|
oneLevelBom.setParentId(Long.valueOf(bomId)); |
|
|
|
List<ErpBom> subBomList = erpBomService.selectErpBomAllLevelList(oneLevelBom); |
|
|
|
// 只需要加工方式为采购的
|
|
|
|
List<ErpBom> filterSubBomList = subBomList.stream() |
|
|
|
.filter(bom -> "0".equals(bom.getProcessMethod())) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
for (ErpBom subBom : filterSubBomList) { |
|
|
|
PurchasePlanChild purchasePlanChild = createPurchasePlanChild(purchasePlanCode, subBom, loginName); |
|
|
|
purchasePlanChild.setMaterialNum(erpDevelopModifyorderDetail.getMaterialNum() * subBom.getUseNum()); |
|
|
|
purchasePlanChildList.add(purchasePlanChild); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 合并相同materialCode的数据
|
|
|
|
List<PurchasePlanChild> mergedPurchasePlanChildList = mergePurchasePlanChildList(purchasePlanChildList); |
|
|
|
// 只需要加工方式为采购的
|
|
|
|
List<PurchasePlanChild> filterMergedPurchasePlanChildList = mergedPurchasePlanChildList.stream().filter(child -> "0".equals(child.getProcessMethod())).collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
|
|
purchasePlan.setMaterialAmount(Long.valueOf(filterMergedPurchasePlanChildList.size())); |
|
|
|
// 计算所有 PurchasePlanChild 的 materialNum 总和
|
|
|
|
Long totalMaterialNum = filterMergedPurchasePlanChildList.stream() |
|
|
|
.mapToLong(PurchasePlanChild::getMaterialNum) |
|
|
|
.sum(); |
|
|
|
purchasePlan.setMaterialSum(totalMaterialNum); |
|
|
|
// 批量新增采购计划子表
|
|
|
|
// purchasePlanChildMapper.batchInsertPurchasePlanChild(filterMergedPurchasePlanChildList);
|
|
|
|
|
|
|
|
for (PurchasePlanChild purchasePlanChild : filterMergedPurchasePlanChildList) { |
|
|
|
|
|
|
|
purchasePlanChildMapper.insertPurchasePlanChild(purchasePlanChild); |
|
|
|
} |
|
|
|
|
|
|
|
// 新增保存 PurchasePlan 到数据库
|
|
|
|
purchasePlanMapper.insertPurchasePlan(purchasePlan); |
|
|
|
} |
|
|
|
|
|
|
|
private PurchasePlanChild createPurchasePlanChild(String purchasePlanCode, ErpDevelopModifyorderDetail detail, String loginName) { |
|
|
|
PurchasePlanChild purchasePlanChild = new PurchasePlanChild(); |
|
|
|
purchasePlanChild.setPurchasePlanCode(purchasePlanCode); |
|
|
|
purchasePlanChild.setCreateTime(new Date()); |
|
|
|
purchasePlanChild.setCreateBy(loginName); |
|
|
|
purchasePlanChild.setMaterialCode(detail.getMaterialNo()); |
|
|
|
purchasePlanChild.setMaterialName(detail.getMaterialName()); |
|
|
|
purchasePlanChild.setMaterialType(detail.getMaterialType()); |
|
|
|
purchasePlanChild.setBrand(detail.getMaterialBrand()); |
|
|
|
purchasePlanChild.setUnit(detail.getMaterialUnit()); |
|
|
|
purchasePlanChild.setDescribe(detail.getMaterialDescribe()); |
|
|
|
purchasePlanChild.setMaterialNum(Long.valueOf(detail.getMaterialNum())); |
|
|
|
return purchasePlanChild; |
|
|
|
} |
|
|
|
|
|
|
|
private PurchasePlanChild createPurchasePlanChild(String purchasePlanCode, ErpBom bom, String loginName) { |
|
|
|
PurchasePlanChild purchasePlanChild = new PurchasePlanChild(); |
|
|
|
purchasePlanChild.setPurchasePlanCode(purchasePlanCode); |
|
|
|
purchasePlanChild.setCreateTime(new Date()); |
|
|
|
purchasePlanChild.setCreateBy(loginName); |
|
|
|
purchasePlanChild.setMaterialCode(bom.getMaterialNo()); |
|
|
|
purchasePlanChild.setMaterialName(bom.getMaterialName()); |
|
|
|
purchasePlanChild.setMaterialType(bom.getMaterialType()); |
|
|
|
purchasePlanChild.setProcessMethod(bom.getProcessMethod()); |
|
|
|
purchasePlanChild.setBrand(bom.getBrand()); |
|
|
|
purchasePlanChild.setUnit(bom.getUnit()); |
|
|
|
purchasePlanChild.setDescribe(bom.getDescribe()); |
|
|
|
// MaterialNum will be set later based on the parent's quantity and useNum
|
|
|
|
return purchasePlanChild; |
|
|
|
} |
|
|
|
|
|
|
|
private List<PurchasePlanChild> mergePurchasePlanChildList(List<PurchasePlanChild> purchasePlanChildList) { |
|
|
|
Map<String, PurchasePlanChild> aggregatedMap = new HashMap<>(); |
|
|
|
|
|
|
|
for (PurchasePlanChild purchasePlanChild : purchasePlanChildList) { |
|
|
|
String materialCode = purchasePlanChild.getMaterialCode(); |
|
|
|
if (aggregatedMap.containsKey(materialCode)) { |
|
|
|
PurchasePlanChild existing = aggregatedMap.get(materialCode); |
|
|
|
existing.setMaterialNum(existing.getMaterialNum() + purchasePlanChild.getMaterialNum()); |
|
|
|
} else { |
|
|
|
aggregatedMap.put(materialCode, purchasePlanChild); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return new ArrayList<>(aggregatedMap.values()); |
|
|
|
} |
|
|
|
|
|
|
|
/*假设自生成的采购计划单号*/ |
|
|
|
private String generateUniquePurchasePlanCode() { |
|
|
|
// 实现生成唯一采购计划单号的逻辑
|
|
|
|