From 2a855813965c160cc6f84ff08c8670623780ddd8 Mon Sep 17 00:00:00 2001 From: liuxiaoxu <1793812695@qq.com> Date: Sat, 6 Jul 2024 16:20:51 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E7=94=9F=E4=BA=A7=E7=AE=A1=E7=90=86=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A7=94=E5=86=85=E5=8A=A0=E5=B7=A5=E8=B4=B9?= =?UTF-8?q?=E5=8D=95=E4=BB=B7=E7=9A=84=E8=AE=A1=E7=AE=97=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=EF=BC=8C=E5=A6=82=E6=9E=9C=E5=90=8C=E4=B8=80=E7=A7=8D=E7=89=A9?= =?UTF-8?q?=E6=96=99=E9=9C=80=E8=A6=81=E5=A1=AB=E5=86=99=E7=9B=B8=E5=90=8C?= =?UTF-8?q?=E7=9A=84=E5=A7=94=E5=86=85=E5=8A=A0=E5=B7=A5=E8=B4=B9=E5=8D=95?= =?UTF-8?q?=E4=BB=B7=EF=BC=8C=E4=B8=8D=E7=84=B6=E5=B0=B1=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=EF=BC=9A=E8=AF=B7=E4=BF=9D=E6=8C=81=E5=A7=94=E5=86=85=E5=8A=A0?= =?UTF-8?q?=E5=B7=A5=E8=B4=B9=E5=8D=95=E4=BB=B7=E4=B8=80=E8=87=B4=EF=BC=9B?= =?UTF-8?q?=20=E8=AE=A1=E7=AE=97=E5=A7=94=E5=86=85=E5=8A=A0=E5=B7=A5?= =?UTF-8?q?=E8=B4=B9=E6=80=BB=E4=BB=B7=E4=B8=BA=E7=9B=B8=E5=90=8C=E7=89=A9?= =?UTF-8?q?=E6=96=99=E7=B4=AF=E5=8A=A0=E5=90=8E=E7=9A=84=E6=9C=AC=E6=AC=A1?= =?UTF-8?q?=E5=A7=94=E5=86=85=E5=AE=8C=E6=88=90=E6=95=B0=E5=92=8C=E5=A7=94?= =?UTF-8?q?=E5=86=85=E5=8A=A0=E5=B7=A5=E8=B4=B9=E5=8D=95=E4=BB=B7=E7=9A=84?= =?UTF-8?q?=E4=B9=98=E7=A7=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/ErpInboundOrderServiceImpl.java | 46 ++++++++++++++++--- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/erp/service/impl/ErpInboundOrderServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/erp/service/impl/ErpInboundOrderServiceImpl.java index 361e5ede..a90abb9a 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/erp/service/impl/ErpInboundOrderServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/erp/service/impl/ErpInboundOrderServiceImpl.java @@ -3,6 +3,7 @@ package com.ruoyi.erp.service.impl; import java.math.BigDecimal; import java.util.Date; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @@ -160,18 +161,51 @@ public class ErpInboundOrderServiceImpl implements IErpInboundOrderService - BigDecimal makeInTotalPrice = BigDecimal.ZERO; - //计算委内数据的加工费总价 + // 首先,创建一个Map来收集每个物料号及其对应的加工费单价的列表 + Map> processFeesByMaterialNo = filteredErpInboundOrderDetails.stream() + .collect(Collectors.groupingBy( + ErpInboundOrderDetail::getMaterialNo, // 分组依据:物料号 + Collectors.mapping( + ErpInboundOrderDetail::getProcessFeeUnitPrice, // 映射:从每个细节中获取加工费单价 + Collectors.toList() // 收集:将映射结果收集到List中 + ) + )); + + // 然后,检查是否有任何物料号的加工费单价不一致 + boolean hasInconsistentFees = processFeesByMaterialNo.values().stream() + .anyMatch(prices -> prices.stream().distinct().count() > 1); + + // 如果发现加工费单价不一致,则抛出异常 + if (hasInconsistentFees) { + throw new BusinessException("请保持委内加工费单价一致"); + } + + + +// 计算本次委内完成数合计 + long addCurrentNum = filteredErpInboundOrderDetails.stream() + .mapToLong(ErpInboundOrderDetail::getCurrentNum) // 假设getCurrentNum()返回的是int或long类型 + .sum(); + + // 将long类型的addCurrentNum转换为BigDecimal类型 + BigDecimal bigAddCurrentNum = BigDecimal.valueOf(addCurrentNum); + + // 检查是否存在加工费单价为null的情况 boolean hasMakeInTotalPriceNull = filteredErpInboundOrderDetails.stream() .anyMatch(item -> item.getProcessFeeUnitPrice() == null); if (hasMakeInTotalPriceNull) { throw new BusinessException("存在委内加工费为空,请检查!"); } - // 计算各个字段的总和 - makeInTotalPrice = filteredErpInboundOrderDetails.stream() - .map(ErpInboundOrderDetail::getProcessFeeUnitPrice) - .reduce(BigDecimal.ZERO,BigDecimal::add); + + // 确保processFeeUnitPrice不为null,避免NullPointerException + BigDecimal processFeeUnitPrice = filteredErpInboundOrderDetails.get(0).getProcessFeeUnitPrice(); + if (processFeeUnitPrice == null) { + throw new BusinessException("加工费单价未找到,请检查!"); + } + + // 计算委内加工费总价 + BigDecimal makeInTotalPrice = bigAddCurrentNum.multiply(processFeeUnitPrice); //加入到品质单中 qualityOrder.setMakeInTotalPrice(makeInTotalPrice); //添加委内加工品质单详情数据