From e6ced140401243afbfae09451b0ec44ae12ae38d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E6=AC=A7=EF=BC=88=E6=9E=97=E5=B9=B3=E5=87=A1?= =?UTF-8?q?=EF=BC=89?= Date: Thu, 9 Oct 2025 18:04:45 +0800 Subject: [PATCH] 1 --- .../service/impl/InstructionServiceImpl.java | 82 +++++++++++-------- 1 file changed, 46 insertions(+), 36 deletions(-) diff --git a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/InstructionServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/InstructionServiceImpl.java index 917cb23..c9a7124 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/InstructionServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/InstructionServiceImpl.java @@ -248,6 +248,8 @@ public class InstructionServiceImpl implements IInstructionService { Map globalModelCounts = new HashMap<>(); Map globalPaymentAmounts = new HashMap<>(); Map globalRebateAmounts = new HashMap<>(); + // 记录每个型号的最高单价订单 + Map globalMaxPriceOrders = new HashMap<>(); for (Map.Entry> e : dmEntries) { String dm = e.getKey() != null ? e.getKey() : "未提供"; @@ -274,6 +276,18 @@ public class InstructionServiceImpl implements IInstructionService { Double rebateAmount = modelRebateAmounts.get(model); globalPaymentAmounts.put(model, globalPaymentAmounts.getOrDefault(model, 0.0) + (paymentAmount != null ? paymentAmount : 0.0)); globalRebateAmounts.put(model, globalRebateAmounts.getOrDefault(model, 0.0) + (rebateAmount != null ? rebateAmount : 0.0)); + + // 找到该型号价格最高的订单 + for (JDOrder order : orders) { + if (model.equals(order.getModelNumber())) { + JDOrder currentMax = globalMaxPriceOrders.get(model); + if (currentMax == null || + (order.getPaymentAmount() != null && + (currentMax.getPaymentAmount() == null || order.getPaymentAmount() > currentMax.getPaymentAmount()))) { + globalMaxPriceOrders.put(model, order); + } + } + } } summary.append("总计:").append(totalCount).append("\n详情:"); @@ -311,16 +325,25 @@ public class InstructionServiceImpl implements IInstructionService { // 输出金额计算(单台价格-返现+佣金=净价×数量=总价) double grandTotal = 0.0; StringBuilder calculationLines = new StringBuilder(); + List totalPricesList = new ArrayList<>(); for (Map.Entry entry : sortedEntries) { String model = entry.getKey(); - double paymentAmount = globalPaymentAmounts.getOrDefault(model, 0.0); - double rebateAmount = globalRebateAmounts.getOrDefault(model, 0.0); int count = entry.getValue(); - // 计算单台价格(总付款金额 / 数量)用于显示 - double singlePayment = count > 0 ? paymentAmount / count : 0.0; - double singleRebate = count > 0 ? rebateAmount / count : 0.0; + // 获取该型号最高价格的订单 + JDOrder maxPriceOrder = globalMaxPriceOrders.get(model); + double singlePayment = 0.0; + double singleRebate = 0.0; + + if (maxPriceOrder != null) { + singlePayment = maxPriceOrder.getPaymentAmount() != null ? maxPriceOrder.getPaymentAmount() : 0.0; + singleRebate = maxPriceOrder.getRebateAmount() != null ? maxPriceOrder.getRebateAmount() : 0.0; + } + + // 四舍五入到2位小数 + singlePayment = Math.round(singlePayment * 100.0) / 100.0; + singleRebate = Math.round(singleRebate * 100.0) / 100.0; // 从Redis获取佣金 double commission = 0.0; @@ -333,20 +356,25 @@ public class InstructionServiceImpl implements IInstructionService { // 如果获取失败,佣金为0 } - // 用总金额计算,避免精度损失:总价 = 总付款 - 总返现 + (佣金 × 数量) - double totalPrice = paymentAmount - rebateAmount + (commission * count); - grandTotal += totalPrice; + // 计算净价(单台价格 - 返现 + 佣金) + double netPrice = singlePayment - singleRebate + commission; + // 四舍五入到2位小数 + netPrice = Math.round(netPrice * 100.0) / 100.0; - // 计算净价用于显示(总价 / 数量) - double netPrice = count > 0 ? totalPrice / count : 0.0; + // 计算总价 + double totalPrice = netPrice * count; + // 四舍五入到2位小数 + totalPrice = Math.round(totalPrice * 100.0) / 100.0; + totalPricesList.add(totalPrice); + grandTotal += totalPrice; // 格式:单台价格-返现+佣金=净价×数量=总价 if (count == 1) { // 数量为1时,不显示×1 - calculationLines.append(String.format("%.1f-%.0f+%.0f=%.1f\n", + calculationLines.append(String.format("%.2f-%.2f+%.2f=%.2f\n", singlePayment, singleRebate, commission, totalPrice)); } else { - calculationLines.append(String.format("%.1f-%.0f+%.0f=%.1f×%d=%.1f\n", + calculationLines.append(String.format("%.2f-%.2f+%.2f=%.2f×%d=%.2f\n", singlePayment, singleRebate, commission, netPrice, count, totalPrice)); } } @@ -357,33 +385,15 @@ public class InstructionServiceImpl implements IInstructionService { if (sortedEntries.size() > 1) { priceText.append("\n"); // 构建汇总公式 - StringBuilder summaryFormula = new StringBuilder(); - for (int i = 0; i < sortedEntries.size(); i++) { - Map.Entry entry = sortedEntries.get(i); - String model = entry.getKey(); - double paymentAmount = globalPaymentAmounts.getOrDefault(model, 0.0); - double rebateAmount = globalRebateAmounts.getOrDefault(model, 0.0); - int count = entry.getValue(); - - double commission = 0.0; - try { - com.ruoyi.jarvis.domain.ProductJdConfig config = productJdConfigService.selectProductJdConfigByModel(model); - if (config != null && config.getCommission() != null) { - commission = config.getCommission().doubleValue(); - } - } catch (Exception e) { - } - - // 用总金额计算 - double totalPrice = paymentAmount - rebateAmount + (commission * count); - + for (int i = 0; i < totalPricesList.size(); i++) { if (i > 0) { - summaryFormula.append("+"); + priceText.append("+"); } - summaryFormula.append(String.format("%.1f", totalPrice)); + priceText.append(String.format("%.2f", totalPricesList.get(i))); } - summaryFormula.append(String.format("=%.1f", grandTotal)); - priceText.append(summaryFormula); + // 四舍五入汇总到2位小数 + grandTotal = Math.round(grandTotal * 100.0) / 100.0; + priceText.append(String.format("=%.2f", grandTotal)); } outputs.add(priceText.toString().trim());