Browse Source

[feat]采购管理:

采购计划
新增生产订单工程审核通过后自动生成采购计划数据和采购计划子表数据
新增生产订单工程审核后生产采购计划数据和采购计划子表数据后端接口
新增 新增采购计划数据和采购计划子表数据后端接口
新增根据生产单号查询生产订单和生产订单bom 查询接口
dev
liuxiaoxu 5 months ago
parent
commit
673cdba48e
  1. 5
      ruoyi-admin/src/main/java/com/ruoyi/purchase/service/IPurchasePlanService.java
  2. 82
      ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchasePlanServiceImpl.java
  3. 5
      ruoyi-admin/src/main/java/com/ruoyi/system/mapper/SysMakeOrderMapper.java
  4. 9
      ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysMakeOrderServiceImpl.java
  5. 7
      ruoyi-admin/src/main/resources/mapper/system/SysMakeOrderMapper.xml

5
ruoyi-admin/src/main/java/com/ruoyi/purchase/service/IPurchasePlanService.java

@ -2,6 +2,7 @@ package com.ruoyi.purchase.service;
import com.ruoyi.purchase.domain.PurchasePlan;
import com.ruoyi.purchase.domain.PurchasePlanChild;
import com.ruoyi.system.domain.SysMakeorderBom;
import java.util.List;
@ -77,4 +78,8 @@ public interface IPurchasePlanService
public List<PurchasePlan> selectPurchasePlanByPlanCode(String purchasePlanCodes);
/*
* 生产订单工程审核后生成采购计划
* */
void generatePurchasePlanByMakeOrder(List<SysMakeorderBom> insertedSysMakeorderBoms);
}

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

@ -1,9 +1,18 @@
package com.ruoyi.purchase.service.impl;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.common.utils.StringUtils;
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.stereotype.Service;
import com.ruoyi.purchase.mapper.PurchasePlanMapper;
@ -22,6 +31,12 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService
@Autowired
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));
}
/*
* 生产订单工程审核后生成采购计划
* */
@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);
}
}
}
}

5
ruoyi-admin/src/main/java/com/ruoyi/system/mapper/SysMakeOrderMapper.java

@ -108,4 +108,9 @@ public interface SysMakeOrderMapper
* */
SysMakeOrder selectSaleNoByMakeNo(String makeNo);
/*
* 根据生产单号查询生产单
* */
SysMakeOrder selectMakeOrderByMakeNo(String makeNo);
}

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

@ -7,6 +7,7 @@ import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.erp.domain.ErpBom;
import com.ruoyi.erp.service.IErpBomService;
import com.ruoyi.purchase.service.IPurchasePlanService;
import com.ruoyi.system.domain.SysMakeOrder;
import com.ruoyi.system.domain.SysMakeorderBom;
import com.ruoyi.system.domain.SysSalesOrderChild;
@ -19,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
/**
@ -51,6 +53,9 @@ public class SysMakeOrderServiceImpl implements ISysMakeOrderService
@Autowired
private ISysMakeorderBomService makeorderBomService;
@Autowired
private IPurchasePlanService purchasePlanService;
/**
* 查询生产订单
*
@ -222,6 +227,8 @@ public class SysMakeOrderServiceImpl implements ISysMakeOrderService
@Transactional(rollbackFor = Exception.class)
public void gcReview(SysMakeOrder sysMakeOrder) {
String makeNo = sysMakeOrder.getMakeNo();
// 定义一个列表用于收集新插入的SysMakeorderBom
List<SysMakeorderBom> insertedSysMakeorderBoms = new ArrayList<>();
// 待生产
sysMakeOrder.setMakeStatus("3");
updateByMakeNo(sysMakeOrder);
@ -250,10 +257,12 @@ public class SysMakeOrderServiceImpl implements ISysMakeOrderService
sortNo++;
orderBom.setSortNo(sortNo);
makeorderBomService.insertSysMakeorderBom(orderBom);
insertedSysMakeorderBoms.add(orderBom);
}
}
}
// todo 加工方式“采购”的物料生成采购计划
purchasePlanService.generatePurchasePlanByMakeOrder(insertedSysMakeorderBoms);
}
@Override

7
ruoyi-admin/src/main/resources/mapper/system/SysMakeOrderMapper.xml

@ -257,6 +257,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select makeNo from sys_makeorder
</select>
<select id="selectMakeOrderByMakeNo" parameterType="String" resultMap="SysMakeOrderResult">
<include refid="selectSysMakeOrderVo"/>
where a.makeNo = #{makeNo}
</select>
<select id="selectSaleNoByMakeNo" parameterType="String" resultMap="SysMakeOrderResult">
select saleNo from sys_makeorder
where makeNo = #{makeNo}

Loading…
Cancel
Save