From 83fb67a142115df4413ca64127a844531e8e4561 Mon Sep 17 00:00:00 2001 From: b2894lxlx <517289602@qq.com> Date: Tue, 18 Aug 2026 21:48:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BA=94=E6=94=B6=E5=BA=94?= =?UTF-8?q?=E4=BB=98=E6=98=8E=E7=BB=86=E5=8D=95=E4=BB=B7=E7=94=9F=E6=88=90?= =?UTF-8?q?=E4=B8=8D=E5=AF=B9=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ReceivablePayableDetailServiceImpl.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/ReceivablePayableDetailServiceImpl.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/ReceivablePayableDetailServiceImpl.java index d0e8be8..6a06d17 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/ReceivablePayableDetailServiceImpl.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/ReceivablePayableDetailServiceImpl.java @@ -357,11 +357,13 @@ public class ReceivablePayableDetailServiceImpl try { String planId = matchedPlanId(waybill, contract); if (Func.isEmpty(planId)) continue; + // 自动生成只按合同计费方案计算,matchOnly=true 禁止回退读取运单自身其他费用。 List matchedFees = calculatedFees(waybill, contract, planId, true); if (matchedFees.isEmpty()) continue; + BigDecimal contractUnitPrice = resolveContractUnitPrice(matchedFees); for (String settlementType : List.of("payable", "receivable")) { if (existsByWaybill(waybill.getId(), settlementType)) continue; - ReceivablePayableDetail detail = buildDetail(waybill, contract, settlementType, matchedFees); + ReceivablePayableDetail detail = buildDetail(waybill, contract, settlementType, matchedFees, contractUnitPrice); save(detail); for (ReceivablePayableCargoFee fee : matchedFees) { ReceivablePayableCargoFee copy = BeanUtil.copyProperties(fee, ReceivablePayableCargoFee.class); @@ -510,6 +512,11 @@ public class ReceivablePayableDetailServiceImpl } private ReceivablePayableDetail buildDetail(Waybill waybill, ContractManage contract, String settlementType, List fees) { + return buildDetail(waybill, contract, settlementType, fees, resolveContractUnitPrice(fees)); + } + + private ReceivablePayableDetail buildDetail(Waybill waybill, ContractManage contract, String settlementType, + List fees, BigDecimal unitPrice) { BigDecimal freight = fees.stream().filter(this::isFreight).map(ReceivablePayableCargoFee::getAfterAmount).reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal total = fees.stream().map(ReceivablePayableCargoFee::getAfterAmount).reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal other = total.subtract(freight).setScale(2, RoundingMode.HALF_UP); @@ -538,7 +545,7 @@ public class ReceivablePayableDetailServiceImpl detail.setQuantityUnit(waybill.getQuantityUnit()); detail.setMileage(waybill.getMileage()); detail.setBatchNo(waybill.getBatchNo()); - detail.setUnitPrice(waybill.getUnitPrice()); + detail.setUnitPrice(unitPrice); detail.setCurrency("RMB"); detail.setFreightAmount(freight); detail.setOtherFeeAmount(other); @@ -549,6 +556,19 @@ public class ReceivablePayableDetailServiceImpl return detail; } + private BigDecimal resolveContractUnitPrice(List fees) { + return fees.stream() + .filter(this::isFreight) + .map(ReceivablePayableCargoFee::getUnitPrice) + .filter(Objects::nonNull) + .findFirst() + .orElseGet(() -> fees.stream() + .map(ReceivablePayableCargoFee::getUnitPrice) + .filter(Objects::nonNull) + .findFirst() + .orElse(BigDecimal.ZERO)); + } + private ReceivablePayableCargoFee buildCargoFee(Long detailId, Waybill waybill) { BigDecimal quantity = money(waybill.getQuantity()); BigDecimal unitPrice = money(waybill.getUnitPrice()); @@ -807,6 +827,7 @@ public class ReceivablePayableDetailServiceImpl detail.setFreightAmount(freight); detail.setOtherFeeAmount(total.subtract(freight)); detail.setTotalAmount(total); + detail.setUnitPrice(resolveContractUnitPrice(fees)); detail.setFeeItemsJson(JsonUtil.toJson(fees.stream().collect(HashMap::new, (map, fee) -> map.put(fee.getCargoName(), fee.getAfterAmount()), HashMap::putAll))); updateById(detail); }