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); //添加委内加工品质单详情数据