Browse Source

Merge remote-tracking branch 'origin/dev' into dev

dev
王晓迪 3 days ago
parent
commit
4662ce6b03
  1. 5
      ruoyi-admin/src/main/java/com/ruoyi/purchase/mapper/PurchaseQuoteHistoryMapper.java
  2. 35
      ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchaseOrderServiceImpl.java
  3. 73
      ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchasePlanServiceImpl.java
  4. 21
      ruoyi-admin/src/main/resources/mapper/purchase/PurchaseQuoteHistoryMapper.xml

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

@ -94,4 +94,9 @@ public interface PurchaseQuoteHistoryMapper
* 通过供应商编号和物料编号更新采购报价历史数据
* */
public int updatePurchaseQuoteHistoryByCode(PurchaseQuoteHistory purchaseQuoteHistory);
/**
* 通过供应商编号查询历史报价审核通过的数据
* */
List<PurchaseQuoteHistory> selectPurchaseQuoteHistoryListBySupplierCode(String supplierCode);
}

35
ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchaseOrderServiceImpl.java

@ -351,6 +351,21 @@ public class PurchaseOrderServiceImpl implements IPurchaseOrderService
throw new BusinessException("请填写本次采购数量");
}
// 判断价格是否为空,如果为空,提示,无物料报价,需要通过采购报价审核
boolean anyNullLatestQuoteRmb = purchasePlanSelectMaterialVoList.stream().anyMatch(item -> item.getLatestQuoteRmb() == null);
if (anyNullLatestQuoteRmb) {
throw new BusinessException("无物料报价,请先通过采购报价审核");
}
boolean anyNullRmbSum = purchasePlanSelectMaterialVoList.stream().anyMatch(item -> item.getMaterialRmbSum() == null);
if (anyNullRmbSum) {
throw new BusinessException("无物料报价,请先通过采购报价审核");
}
boolean anyNullNoRmbSum = purchasePlanSelectMaterialVoList.stream().anyMatch(item -> item.getMaterialNoRmbSum() == null);
if (anyNullNoRmbSum) {
throw new BusinessException("无物料报价,请先通过采购报价审核");
}
purchaseOrder.setPurchaseOrderCode(redisCache.generateBillNo("CG"));
purchaseOrder.setPurchasePlanCode(purchasePlanOne.getPurchasePlanCodes());
purchaseOrder.setPaymentStatus("0");
@ -467,6 +482,10 @@ public class PurchaseOrderServiceImpl implements IPurchaseOrderService
oldChild.setUpdateTime(new Date());
oldChild.setUpdateBy(ShiroUtils.getLoginName());
oldChild.setThisPurchaseNum(thisPurchaseNum);
oldChild.setMaterialNoRmbSum(purchasePlanSelectMaterialVo.getMaterialNoRmbSum());
oldChild.setMaterialRmbSum(purchasePlanSelectMaterialVo.getMaterialRmbSum());
oldChild.setLatestQuoteRmb(purchasePlanSelectMaterialVo.getLatestQuoteRmb());
//收集更新后的子表数据
purchasePlanChildren.add(oldChild);
int result = purchasePlanChildMapper.updatePurchasePlanChild(oldChild);
@ -489,6 +508,10 @@ public class PurchaseOrderServiceImpl implements IPurchaseOrderService
.collect(Collectors.groupingBy(PurchasePlanChild::getPurchasePlanCode));
List<PurchasePlanSelectMaterialVo> purchasePlanSelectMaterialVoList = addPurchaseOrder.getPurchasePlanSelectMaterialVoList();
PurchasePlanOne purchasePlanOne = addPurchaseOrder.getPurchasePlanOne();
String purchasePlanCodes = purchasePlanOne.getPurchasePlanCodes();
//得到本次采购的所有采购计划单号
@ -530,6 +553,18 @@ public class PurchaseOrderServiceImpl implements IPurchaseOrderService
int currentPurchaseSum = purchasePlan.getPurchaseSum();
purchasePlan.setPurchaseSum(currentPurchaseSum - thisPurchaseSum);
// 计算合计值
double totalNoRmbSum = children.stream().mapToDouble(vo -> vo.getMaterialNoRmbSum().doubleValue()).sum();
double totalRmbSum = children.stream().mapToDouble(vo -> vo.getMaterialRmbSum().doubleValue()).sum();
// 将结果转换回 BigDecimal
BigDecimal totalBigDecimalNoRmbSum = BigDecimal.valueOf(totalNoRmbSum);
BigDecimal totalBigDecimalRmbSum = BigDecimal.valueOf(totalRmbSum);
purchasePlan.setRmbSum(totalBigDecimalRmbSum.add(purchasePlan.getRmbSum()));
purchasePlan.setNoRmbSum(totalBigDecimalNoRmbSum.add(purchasePlan.getNoRmbSum()));
// 更新采购计划状态
if (purchasePlan.getActualPurchaseSum() < purchasePlan.getPlanPurchaseSum()) {
purchasePlan.setPurchasePlanStatus("1");

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

@ -17,14 +17,9 @@ import com.ruoyi.erp.domain.vo.ErpDevelopModifyorderVo;
import com.ruoyi.erp.mapper.ErpDevelopModifyorderDetailMapper;
import com.ruoyi.erp.service.IErpBomService;
import com.ruoyi.purchase.controller.PurchaseQuoteController;
import com.ruoyi.purchase.domain.PurchasePlan;
import com.ruoyi.purchase.domain.PurchasePlanChild;
import com.ruoyi.purchase.domain.PurchaseQuote;
import com.ruoyi.purchase.domain.PurchaseQuoteChild;
import com.ruoyi.purchase.domain.*;
import com.ruoyi.purchase.domain.Vo.PurchasePlanSelectSupplierVo;
import com.ruoyi.purchase.mapper.PurchasePlanChildMapper;
import com.ruoyi.purchase.mapper.PurchaseQuoteChildMapper;
import com.ruoyi.purchase.mapper.PurchaseQuoteMapper;
import com.ruoyi.purchase.mapper.*;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.domain.Vo.SysSupplierVo;
import com.ruoyi.system.mapper.SysMakeOrderMapper;
@ -34,7 +29,6 @@ import com.ruoyi.system.mapper.SysSupplierMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.purchase.mapper.PurchasePlanMapper;
import com.ruoyi.purchase.service.IPurchasePlanService;
import com.ruoyi.common.core.text.Convert;
import org.springframework.transaction.annotation.Transactional;
@ -75,6 +69,9 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService
@Autowired
private PurchaseQuoteChildMapper purchaseQuoteChildMapper;
@Autowired
private PurchaseQuoteHistoryMapper purchaseQuoteHistoryMapper;
@Autowired
private SysSupplierMapper sysSupplierMapper;
@ -207,17 +204,50 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService
String supplierCode = purchasePlan.getSupplierCode();
List<PurchaseQuoteChild> purchaseQuoteChildList = purchaseQuoteChildMapper.selectQuoteChildBySupplierCode(supplierCode);
//采购计划子表数据
List<PurchasePlanChild> purchasePlanChildList = purchasePlanChildMapper.selectPurchasePlanChildPlanCodeList(purchasePlanCodeList);
// 创建一个映射,以便快速查找物料号对应的最新报价历史
Map<String, PurchaseQuoteHistory> quoteHistoryMap = new HashMap<>();
// 获取所有物料号
Set<String> materialCodes = purchasePlanChildList.stream()
.map(PurchasePlanChild::getMaterialNo)
.collect(Collectors.toSet());
// 遍历每个物料号,获取最新的报价数据
for (String materialCode : materialCodes) {
PurchaseQuoteHistory purchaseQuoteHistory = new PurchaseQuoteHistory();
purchaseQuoteHistory.setSupplierCode(supplierCode);
purchaseQuoteHistory.setMaterialCode(materialCode);
List<PurchaseQuoteHistory> purchaseQuoteHistories = selectPurchaseQuoteHistoryList(purchaseQuoteHistory);
// 找到最新的报价记录
Optional<PurchaseQuoteHistory> latestQuoteHistory = purchaseQuoteHistories.stream()
.filter(item -> "1".equals(item.getIsLatest()))
.findFirst();
latestQuoteHistory.ifPresent(history -> quoteHistoryMap.put(materialCode, history));
}
// 合并相同物料料号的数据
Map<String, PurchasePlanChild> mergedMap = purchasePlanChildList.stream()
.collect(Collectors.toMap(
PurchasePlanChild::getMaterialNo,
item -> item,
item -> {
// 设置最新的报价数据
PurchaseQuoteHistory quoteHistory = quoteHistoryMap.get(item.getMaterialNo());
if (quoteHistory != null) {
item.setLatestQuoteRmb(quoteHistory.getMaterialRmb());
item.setMaterialNoRmbSum(quoteHistory.getMaterialNormb());
item.setMaterialRmbSum(quoteHistory.getMaterialRmb());
}
return item;
},
(existingItem, newItem) -> {
existingItem.setPurchaseNum(
(existingItem.getPurchaseNum() != null ? existingItem.getPurchaseNum() : 0) +
@ -266,6 +296,29 @@ public class PurchasePlanServiceImpl implements IPurchasePlanService
}
//查找最新审核通过的物料采购报价
public List<PurchaseQuoteHistory> selectPurchaseQuoteHistoryList(PurchaseQuoteHistory purchaseQuoteHistory) {
// 最新的报价
PurchaseQuoteHistory latestQuoteHistory = purchaseQuoteHistoryMapper.findLatestPurchaseQuoteHistory(purchaseQuoteHistory);
if (latestQuoteHistory != null) {
List<PurchaseQuoteHistory> purchaseQuoteHistories = purchaseQuoteHistoryMapper.selectPurchaseQuoteHistoryList(purchaseQuoteHistory);
purchaseQuoteHistories.forEach(item -> {
if (Objects.equals(item.getPurchaseQuoteChildId(), latestQuoteHistory.getPurchaseQuoteChildId())) {
item.setIsLatest("1");
} else {
item.setIsLatest("0");
}
});
return purchaseQuoteHistories;
}
return purchaseQuoteHistoryMapper.selectPurchaseQuoteHistoryList(purchaseQuoteHistory);
}
/**
* 新增采购计划单
*

21
ruoyi-admin/src/main/resources/mapper/purchase/PurchaseQuoteHistoryMapper.xml

@ -60,7 +60,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectPurchaseQuoteHistoryVo"/>
where purchase_quote_child_id = #{purchaseQuoteChildId}
</select>
<select id="findLatestPurchaseQuoteHistory" parameterType="String" resultMap="PurchaseQuoteHistoryResult">
<include refid="selectPurchaseQuoteHistoryVo"/>
where supplier_code = #{supplierCode} and material_code = #{materialCode} and audit_status = '1'
order by update_time desc
limit 1
</select>
<select id="selectPurchaseQuoteHistoryListBySupplierCode" parameterType="String" resultMap="PurchaseQuoteHistoryResult">
<include refid="selectPurchaseQuoteHistoryVo"/>
where supplier_code = #{supplierCode} and audit_status = '1'
</select>
<insert id="insertPurchaseQuoteHistory" parameterType="PurchaseQuoteHistory" useGeneratedKeys="true" keyProperty="purchaseQuoteChildId">
insert into purchase_quote_history
<trim prefix="(" suffix=")" suffixOverrides=",">
@ -257,12 +270,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</update>
<select id="findLatestPurchaseQuoteHistory" parameterType="String" resultMap="PurchaseQuoteHistoryResult" >
<include refid="selectPurchaseQuoteHistoryVo"/>
where supplier_code = #{supplierCode} and material_code = #{materialCode} and audit_status = '1'
order by update_time desc
limit 1
</select>
</mapper>
Loading…
Cancel
Save