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");