|
@ -1,9 +1,18 @@ |
|
|
package com.ruoyi.purchase.service.impl; |
|
|
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.List; |
|
|
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.purchase.domain.PurchasePlan; |
|
|
import com.ruoyi.purchase.domain.PurchasePlan; |
|
|
|
|
|
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.mapper.SysMakeOrderMapper; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import com.ruoyi.purchase.mapper.PurchasePlanMapper; |
|
|
import com.ruoyi.purchase.mapper.PurchasePlanMapper; |
|
@ -22,6 +31,12 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService |
|
|
@Autowired |
|
|
@Autowired |
|
|
private PurchasePlanMapper purchasePlanMapper; |
|
|
private PurchasePlanMapper purchasePlanMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private SysMakeOrderMapper sysMakeOrderMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private PurchasePlanChildMapper purchasePlanChildMapper; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 查询采购计划单 |
|
|
* 查询采购计划单 |
|
|
* |
|
|
* |
|
@ -129,4 +144,71 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService |
|
|
return purchasePlanMapper.selectPurchasePlanByPlanCode(Convert.toStrArray(purchasePlanCodes)); |
|
|
return purchasePlanMapper.selectPurchasePlanByPlanCode(Convert.toStrArray(purchasePlanCodes)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
* 生产订单工程审核后生成采购计划 |
|
|
|
|
|
* */ |
|
|
|
|
|
@Override |
|
|
|
|
|
public void generatePurchasePlanByMakeOrder(List<SysMakeorderBom> insertedSysMakeorderBoms) { |
|
|
|
|
|
// 假设此处有一个生成唯一采购计划单号的方法
|
|
|
|
|
|
String purchasePlanCode = generateUniquePurchasePlanCode(); |
|
|
|
|
|
|
|
|
|
|
|
// 仅查询一次,因为所有SysMakeorderBom都关联同一生产单号
|
|
|
|
|
|
SysMakeOrder sysMakeOrder = sysMakeOrderMapper.selectMakeOrderByMakeNo(insertedSysMakeorderBoms.get(0).getMakeNo()); |
|
|
|
|
|
|
|
|
|
|
|
// 创建采购计划主记录
|
|
|
|
|
|
PurchasePlan purchasePlan = buildPurchasePlan(sysMakeOrder, purchasePlanCode); |
|
|
|
|
|
purchasePlanMapper.insertPurchasePlan(purchasePlan); |
|
|
|
|
|
|
|
|
|
|
|
// 批量创建采购计划子项
|
|
|
|
|
|
insertPurchasePlanChildren(insertedSysMakeorderBoms, purchasePlanCode, sysMakeOrder); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*假设自生成的采购计划单号*/ |
|
|
|
|
|
private String generateUniquePurchasePlanCode() { |
|
|
|
|
|
// 实现生成唯一采购计划单号的逻辑
|
|
|
|
|
|
// 示例代码,实际情况可能依赖于日期、序列号等
|
|
|
|
|
|
return "PP-" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private PurchasePlan buildPurchasePlan(SysMakeOrder sysMakeOrder, String purchasePlanCode) { |
|
|
|
|
|
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.setNoRmbSum(sysMakeOrder.getNoRate()); |
|
|
|
|
|
purchasePlan.setRmbSum(sysMakeOrder.getRate()); |
|
|
|
|
|
purchasePlan.setApplyUser(sysMakeOrder.getSalesman()); |
|
|
|
|
|
purchasePlan.setCreateBy(ShiroUtils.getLoginName()); |
|
|
|
|
|
purchasePlan.setCreateTime(new Date()); |
|
|
|
|
|
purchasePlan.setPurchasePlanStatus("0"); |
|
|
|
|
|
return purchasePlan; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void insertPurchasePlanChildren(List<SysMakeorderBom> insertedSysMakeorderBoms, String purchasePlanCode, SysMakeOrder sysMakeOrder) { |
|
|
|
|
|
for (SysMakeorderBom bom : insertedSysMakeorderBoms) { |
|
|
|
|
|
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.setProcessMethod("采购"); |
|
|
|
|
|
purchasePlanChild.setBrand(bom.getBrand()); |
|
|
|
|
|
purchasePlanChild.setDescribe(bom.getDescribe()); |
|
|
|
|
|
purchasePlanChild.setMaterialNum(bom.getUseNum()); |
|
|
|
|
|
purchasePlanChild.setCreateBy(ShiroUtils.getLoginName()); |
|
|
|
|
|
purchasePlanChild.setCreateTime(new Date()); |
|
|
|
|
|
purchasePlanChildMapper.insertPurchasePlanChild(purchasePlanChild); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|