From 6a1994e703809b9f52a9ceedfde908fe3fc07533 Mon Sep 17 00:00:00 2001 From: liuxiaoxu <1793812695@qq.com> Date: Sat, 23 Nov 2024 10:05:51 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[feat]=E9=87=87=E8=B4=AD=E7=AE=A1=E7=90=86?= =?UTF-8?q?=20=E9=87=87=E8=B4=AD=E8=AE=A1=E5=88=92=E6=96=B0=E5=A2=9E=20?= =?UTF-8?q?=E6=9F=A5=E6=89=BE=E6=9C=80=E6=96=B0=E5=AE=A1=E6=A0=B8=E9=80=9A?= =?UTF-8?q?=E8=BF=87=E7=9A=84=E7=89=A9=E6=96=99=E9=87=87=E8=B4=AD=E6=8A=A5?= =?UTF-8?q?=E4=BB=B7=E6=96=B9=E6=B3=95=EF=BC=8C=E7=8E=B0=E5=9C=A8=E9=87=87?= =?UTF-8?q?=E8=B4=AD=E8=AE=A1=E5=88=92=E7=AC=AC=E4=BA=8C=E6=AD=A5=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E9=87=87=E8=B4=AD=E8=AE=A2=E5=8D=95=E7=9A=84=E7=89=A9?= =?UTF-8?q?=E6=96=99=E9=87=91=E9=A2=9D=E6=95=B0=E6=8D=AE=E6=9D=A5=E8=87=AA?= =?UTF-8?q?=E9=87=87=E8=B4=AD=E6=8A=A5=E4=BB=B7=E6=9C=80=E6=96=B0=E5=AE=A1?= =?UTF-8?q?=E6=A0=B8=E9=80=9A=E8=BF=87=E7=9A=84=20=E9=87=87=E8=B4=AD?= =?UTF-8?q?=E6=8A=A5=E4=BB=B7=E5=8E=86=E5=8F=B2=E6=96=B0=E5=A2=9E=20?= =?UTF-8?q?=E9=80=9A=E8=BF=87=E4=BE=9B=E5=BA=94=E5=95=86=E7=BC=96=E5=8F=B7?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=8E=86=E5=8F=B2=E6=8A=A5=E4=BB=B7=E5=AE=A1?= =?UTF-8?q?=E6=A0=B8=E9=80=9A=E8=BF=87=E7=9A=84=E6=95=B0=E6=8D=AE=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/PurchaseQuoteHistoryMapper.java | 5 ++ .../service/impl/PurchasePlanServiceImpl.java | 73 ++++++++++++++++--- .../purchase/PurchaseQuoteHistoryMapper.xml | 21 ++++-- 3 files changed, 82 insertions(+), 17 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/purchase/mapper/PurchaseQuoteHistoryMapper.java b/ruoyi-admin/src/main/java/com/ruoyi/purchase/mapper/PurchaseQuoteHistoryMapper.java index 8bd8989f..20e6769b 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/purchase/mapper/PurchaseQuoteHistoryMapper.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/purchase/mapper/PurchaseQuoteHistoryMapper.java @@ -94,4 +94,9 @@ public interface PurchaseQuoteHistoryMapper * 通过供应商编号和物料编号更新采购报价历史数据 * */ public int updatePurchaseQuoteHistoryByCode(PurchaseQuoteHistory purchaseQuoteHistory); + + /** + * 通过供应商编号查询历史报价审核通过的数据 + * */ + List selectPurchaseQuoteHistoryListBySupplierCode(String supplierCode); } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchasePlanServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchasePlanServiceImpl.java index 84757718..aaf34493 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchasePlanServiceImpl.java +++ b/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 purchaseQuoteChildList = purchaseQuoteChildMapper.selectQuoteChildBySupplierCode(supplierCode); //采购计划子表数据 List purchasePlanChildList = purchasePlanChildMapper.selectPurchasePlanChildPlanCodeList(purchasePlanCodeList); + // 创建一个映射,以便快速查找物料号对应的最新报价历史 + Map quoteHistoryMap = new HashMap<>(); + + // 获取所有物料号 + Set materialCodes = purchasePlanChildList.stream() + .map(PurchasePlanChild::getMaterialNo) + .collect(Collectors.toSet()); + + // 遍历每个物料号,获取最新的报价数据 + for (String materialCode : materialCodes) { + PurchaseQuoteHistory purchaseQuoteHistory = new PurchaseQuoteHistory(); + purchaseQuoteHistory.setSupplierCode(supplierCode); + purchaseQuoteHistory.setMaterialCode(materialCode); + + List purchaseQuoteHistories = selectPurchaseQuoteHistoryList(purchaseQuoteHistory); + + // 找到最新的报价记录 + Optional latestQuoteHistory = purchaseQuoteHistories.stream() + .filter(item -> "1".equals(item.getIsLatest())) + .findFirst(); + + latestQuoteHistory.ifPresent(history -> quoteHistoryMap.put(materialCode, history)); + } + + // 合并相同物料料号的数据 Map 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 selectPurchaseQuoteHistoryList(PurchaseQuoteHistory purchaseQuoteHistory) { + // 最新的报价 + PurchaseQuoteHistory latestQuoteHistory = purchaseQuoteHistoryMapper.findLatestPurchaseQuoteHistory(purchaseQuoteHistory); + if (latestQuoteHistory != null) { + List 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); + } + + + + + /** * 新增采购计划单 * diff --git a/ruoyi-admin/src/main/resources/mapper/purchase/PurchaseQuoteHistoryMapper.xml b/ruoyi-admin/src/main/resources/mapper/purchase/PurchaseQuoteHistoryMapper.xml index 2ec801eb..8e514b43 100644 --- a/ruoyi-admin/src/main/resources/mapper/purchase/PurchaseQuoteHistoryMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/purchase/PurchaseQuoteHistoryMapper.xml @@ -60,7 +60,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where purchase_quote_child_id = #{purchaseQuoteChildId} - + + + + + + insert into purchase_quote_history @@ -257,12 +270,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - \ No newline at end of file From b2657ffcc4a38e9c400c85c7e2a39d1fc2b58c9e Mon Sep 17 00:00:00 2001 From: liuxiaoxu <1793812695@qq.com> Date: Sat, 23 Nov 2024 10:39:52 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[feat]=E9=87=87=E8=B4=AD=E7=AE=A1=E7=90=86?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E9=87=87=E8=B4=AD=E8=AE=A1=E5=88=92?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=87=87=E8=B4=AD=E8=AE=A2=E5=8D=95=EF=BC=8C?= =?UTF-8?q?=E9=87=87=E8=B4=AD=E8=AE=A1=E5=88=92=E5=88=9A=E5=BC=80=E5=A7=8B?= =?UTF-8?q?=E5=92=8C=E5=AD=90=E8=A1=A8=E6=B2=A1=E6=9C=89=E4=B8=8D=E5=90=AB?= =?UTF-8?q?=E7=A8=8E=E5=8D=95=E4=BB=B7=E5=92=8C=E5=90=AB=E7=A8=8E=E5=8D=95?= =?UTF-8?q?=E4=BB=B7=EF=BC=8C=E6=B7=BB=E5=8A=A0=E9=87=87=E8=B4=AD=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E7=9A=84=E6=97=B6=E5=80=99=EF=BC=8C=E6=8A=8A=E4=BB=8E?= =?UTF-8?q?=E5=90=8E=E7=AB=AF=E6=9F=A5=E8=AF=A2=E7=9A=84=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E5=AE=A1=E6=A0=B8=E9=80=9A=E8=BF=87=E7=9A=84=E9=87=87=E8=B4=AD?= =?UTF-8?q?=E6=8A=A5=E4=BB=B7=E7=9A=84=E6=95=B0=E6=8D=AE=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=88=B0=E9=87=87=E8=B4=AD=E8=AE=A1=E5=88=92=E5=AD=90=E8=A1=A8?= =?UTF-8?q?=E5=92=8C=E4=B8=BB=E8=A1=A8=E4=B8=AD=EF=BC=8C=E4=B8=BB=E8=A1=A8?= =?UTF-8?q?=E6=98=AF=E5=AD=90=E8=A1=A8=E7=9A=84=E5=90=88=E8=AE=A1=EF=BC=9B?= =?UTF-8?q?=E5=B9=B6=E4=B8=94=E5=A6=82=E6=9E=9C=E4=B8=8D=E5=90=AB=E7=A8=8E?= =?UTF-8?q?=E5=8D=95=E4=BB=B7=E3=80=81=E5=90=AB=E7=A8=8E=E5=8D=95=E4=BB=B7?= =?UTF-8?q?=E3=80=81=E6=9C=80=E6=96=B0=E6=8A=A5=E4=BB=B7=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E5=80=BC=E4=B8=8D=E8=83=BD=E6=8F=90=E4=BA=A4=EF=BC=8C=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=EF=BC=9A=E6=97=A0=E7=89=A9=E6=96=99=E6=8A=A5=E4=BB=B7?= =?UTF-8?q?=EF=BC=8C=E8=AF=B7=E5=85=88=E9=80=9A=E8=BF=87=E9=87=87=E8=B4=AD?= =?UTF-8?q?=E6=8A=A5=E4=BB=B7=E5=AE=A1=E6=A0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/PurchaseOrderServiceImpl.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchaseOrderServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchaseOrderServiceImpl.java index a5b54e49..6984762b 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/purchase/service/impl/PurchaseOrderServiceImpl.java +++ b/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 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");