Revert "1"

This reverts commit d2db86f2ac.
This commit is contained in:
2025-10-10 02:15:15 +08:00
parent d2db86f2ac
commit 35ae723926

View File

@@ -242,15 +242,15 @@ public class InstructionServiceImpl implements IInstructionService {
List<String> outputs = new ArrayList<>(); List<String> outputs = new ArrayList<>();
List<Map.Entry<String, List<JDOrder>>> dmEntries = new ArrayList<>(byDM.entrySet()); List<Map.Entry<String, List<JDOrder>>> dmEntries = new ArrayList<>(byDM.entrySet());
dmEntries.sort(Comparator.comparing(en -> en.getKey() == null ? "" : en.getKey())); dmEntries.sort(Comparator.comparing(en -> en.getKey() == null ? "" : en.getKey()));
// 全局型号数量和金额统计 // 全局型号数量和金额统计
Map<String, Integer> globalModelCounts = new HashMap<>(); Map<String, Integer> globalModelCounts = new HashMap<>();
Map<String, Double> globalPaymentAmounts = new HashMap<>(); Map<String, Double> globalPaymentAmounts = new HashMap<>();
Map<String, Double> globalRebateAmounts = new HashMap<>(); Map<String, Double> globalRebateAmounts = new HashMap<>();
// 记录每个型号的最高单价订单 // 记录每个型号的最高单价订单
Map<String, JDOrder> globalMaxPriceOrders = new HashMap<>(); Map<String, JDOrder> globalMaxPriceOrders = new HashMap<>();
for (Map.Entry<String, List<JDOrder>> e : dmEntries) { for (Map.Entry<String, List<JDOrder>> e : dmEntries) {
String dm = e.getKey() != null ? e.getKey() : "未提供"; String dm = e.getKey() != null ? e.getKey() : "未提供";
List<JDOrder> orders = e.getValue(); List<JDOrder> orders = e.getValue();
@@ -258,7 +258,7 @@ public class InstructionServiceImpl implements IInstructionService {
Map<String, Long> byModel = orders.stream().collect(Collectors.groupingBy(JDOrder::getModelNumber, Collectors.counting())); Map<String, Long> byModel = orders.stream().collect(Collectors.groupingBy(JDOrder::getModelNumber, Collectors.counting()));
Map<String, Double> modelPaymentAmounts = orders.stream().collect(Collectors.groupingBy(JDOrder::getModelNumber, Collectors.summingDouble(o -> o.getPaymentAmount() != null ? o.getPaymentAmount() : 0.0))); Map<String, Double> modelPaymentAmounts = orders.stream().collect(Collectors.groupingBy(JDOrder::getModelNumber, Collectors.summingDouble(o -> o.getPaymentAmount() != null ? o.getPaymentAmount() : 0.0)));
Map<String, Double> modelRebateAmounts = orders.stream().collect(Collectors.groupingBy(JDOrder::getModelNumber, Collectors.summingDouble(o -> o.getRebateAmount() != null ? o.getRebateAmount() : 0.0))); Map<String, Double> modelRebateAmounts = orders.stream().collect(Collectors.groupingBy(JDOrder::getModelNumber, Collectors.summingDouble(o -> o.getRebateAmount() != null ? o.getRebateAmount() : 0.0)));
int totalCount = 0; int totalCount = 0;
StringBuilder summary = new StringBuilder(); StringBuilder summary = new StringBuilder();
List<Map.Entry<String, Long>> modelEntries = new ArrayList<>(byModel.entrySet()); List<Map.Entry<String, Long>> modelEntries = new ArrayList<>(byModel.entrySet());
@@ -267,22 +267,22 @@ public class InstructionServiceImpl implements IInstructionService {
int c = em.getValue().intValue(); int c = em.getValue().intValue();
totalCount += c; totalCount += c;
String model = em.getKey() != null ? em.getKey() : "未知"; String model = em.getKey() != null ? em.getKey() : "未知";
summary.append("型号:").append(model).append(" 数量:").append(c).append("\n"); summary.append("型号:").append(model).append(" 数量:").append(c).append("\n");
// 累积到全局统计 // 累积到全局统计
globalModelCounts.put(model, globalModelCounts.getOrDefault(model, 0) + c); globalModelCounts.put(model, globalModelCounts.getOrDefault(model, 0) + c);
Double paymentAmount = modelPaymentAmounts.get(model); Double paymentAmount = modelPaymentAmounts.get(model);
Double rebateAmount = modelRebateAmounts.get(model); Double rebateAmount = modelRebateAmounts.get(model);
globalPaymentAmounts.put(model, globalPaymentAmounts.getOrDefault(model, 0.0) + (paymentAmount != null ? paymentAmount : 0.0)); 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)); globalRebateAmounts.put(model, globalRebateAmounts.getOrDefault(model, 0.0) + (rebateAmount != null ? rebateAmount : 0.0));
// 找到该型号价格最高的订单 // 找到该型号价格最高的订单
for (JDOrder order : orders) { for (JDOrder order : orders) {
if (model.equals(order.getModelNumber())) { if (model.equals(order.getModelNumber())) {
JDOrder currentMax = globalMaxPriceOrders.get(model); JDOrder currentMax = globalMaxPriceOrders.get(model);
if (currentMax == null || if (currentMax == null ||
(order.getPaymentAmount() != null && (order.getPaymentAmount() != null &&
(currentMax.getPaymentAmount() == null || order.getPaymentAmount() > currentMax.getPaymentAmount()))) { (currentMax.getPaymentAmount() == null || order.getPaymentAmount() > currentMax.getPaymentAmount()))) {
globalMaxPriceOrders.put(model, order); globalMaxPriceOrders.put(model, order);
} }
@@ -304,47 +304,47 @@ public class InstructionServiceImpl implements IInstructionService {
infoSingle.append("分销标记:").append(dm).append("\n").append(summary).append(detail).append("\n"); infoSingle.append("分销标记:").append(dm).append("\n").append(summary).append(detail).append("\n");
outputs.add(infoSingle.toString().trim()); outputs.add(infoSingle.toString().trim());
} }
// 添加算钱文本(全局统计版本) // 添加算钱文本(全局统计版本)
if (!globalModelCounts.isEmpty()) { if (!globalModelCounts.isEmpty()) {
StringBuilder priceText = new StringBuilder(); StringBuilder priceText = new StringBuilder();
// 先输出型号和数量 // 先输出型号和数量
List<Map.Entry<String, Integer>> sortedEntries = globalModelCounts.entrySet().stream() List<Map.Entry<String, Integer>> sortedEntries = globalModelCounts.entrySet().stream()
.sorted(Comparator.comparing(Map.Entry::getKey)) .sorted(Comparator.comparing(Map.Entry::getKey))
.collect(Collectors.toList()); .collect(Collectors.toList());
for (Map.Entry<String, Integer> entry : sortedEntries) { for (Map.Entry<String, Integer> entry : sortedEntries) {
String model = entry.getKey(); String model = entry.getKey();
int count = entry.getValue(); int count = entry.getValue();
priceText.append("型号:").append(model).append(" 数量:").append(count).append("\n"); priceText.append("型号:").append(model).append(" 数量:").append(count).append("\n");
} }
priceText.append("\n"); priceText.append("\n");
// 输出金额计算(单台价格-返现+佣金=净价×数量=总价) // 输出金额计算(单台价格-返现+佣金=净价×数量=总价)
double grandTotal = 0.0; double grandTotal = 0.0;
StringBuilder calculationLines = new StringBuilder(); StringBuilder calculationLines = new StringBuilder();
List<Double> totalPricesList = new ArrayList<>(); List<Double> totalPricesList = new ArrayList<>();
for (Map.Entry<String, Integer> entry : sortedEntries) { for (Map.Entry<String, Integer> entry : sortedEntries) {
String model = entry.getKey(); String model = entry.getKey();
int count = entry.getValue(); int count = entry.getValue();
// 获取该型号最高价格的订单 // 获取该型号最高价格的订单
JDOrder maxPriceOrder = globalMaxPriceOrders.get(model); JDOrder maxPriceOrder = globalMaxPriceOrders.get(model);
double singlePayment = 0.0; double singlePayment = 0.0;
double singleRebate = 0.0; double singleRebate = 0.0;
if (maxPriceOrder != null) { if (maxPriceOrder != null) {
singlePayment = maxPriceOrder.getPaymentAmount() != null ? maxPriceOrder.getPaymentAmount() : 0.0; singlePayment = maxPriceOrder.getPaymentAmount() != null ? maxPriceOrder.getPaymentAmount() : 0.0;
singleRebate = maxPriceOrder.getRebateAmount() != null ? maxPriceOrder.getRebateAmount() : 0.0; singleRebate = maxPriceOrder.getRebateAmount() != null ? maxPriceOrder.getRebateAmount() : 0.0;
} }
// 四舍五入到2位小数 // 四舍五入到2位小数
singlePayment = Math.round(singlePayment * 100.0) / 100.0; singlePayment = Math.round(singlePayment * 100.0) / 100.0;
singleRebate = Math.round(singleRebate * 100.0) / 100.0; singleRebate = Math.round(singleRebate * 100.0) / 100.0;
// 从Redis获取佣金 // 从Redis获取佣金
double commission = 0.0; double commission = 0.0;
try { try {
@@ -355,32 +355,32 @@ public class InstructionServiceImpl implements IInstructionService {
} catch (Exception e) { } catch (Exception e) {
// 如果获取失败佣金为0 // 如果获取失败佣金为0
} }
// 计算净价(单台价格 - 返现 + 佣金) // 计算净价(单台价格 - 返现 + 佣金)
double netPrice = singlePayment - singleRebate + commission; double netPrice = singlePayment - singleRebate + commission;
// 四舍五入到2位小数 // 四舍五入到2位小数
netPrice = Math.round(netPrice * 100.0) / 100.0; netPrice = Math.round(netPrice * 100.0) / 100.0;
// 计算总价 // 计算总价
double totalPrice = netPrice * count; double totalPrice = netPrice * count;
// 四舍五入到2位小数 // 四舍五入到2位小数
totalPrice = Math.round(totalPrice * 100.0) / 100.0; totalPrice = Math.round(totalPrice * 100.0) / 100.0;
totalPricesList.add(totalPrice); totalPricesList.add(totalPrice);
grandTotal += totalPrice; grandTotal += totalPrice;
// 格式:单台价格-返现+佣金=净价×数量=总价 // 格式:单台价格-返现+佣金=净价×数量=总价
if (count == 1) { if (count == 1) {
// 数量为1时不显示×1 // 数量为1时不显示×1
calculationLines.append(String.format("%.2f-%.2f+%.2f=%.2f\n", calculationLines.append(String.format("%.2f-%.2f+%.2f=%.2f\n",
singlePayment, singleRebate, commission, totalPrice)); singlePayment, singleRebate, commission, totalPrice));
} else { } else {
calculationLines.append(String.format("%.2f-%.2f+%.2f=%.2f×%d=%.2f\n", calculationLines.append(String.format("%.2f-%.2f+%.2f=%.2f×%d=%.2f\n",
singlePayment, singleRebate, commission, netPrice, count, totalPrice)); singlePayment, singleRebate, commission, netPrice, count, totalPrice));
} }
} }
priceText.append(calculationLines); priceText.append(calculationLines);
// 输出汇总(各型号总价相加) // 输出汇总(各型号总价相加)
if (sortedEntries.size() > 1) { if (sortedEntries.size() > 1) {
priceText.append("\n"); priceText.append("\n");
@@ -395,10 +395,10 @@ public class InstructionServiceImpl implements IInstructionService {
grandTotal = Math.round(grandTotal * 100.0) / 100.0; grandTotal = Math.round(grandTotal * 100.0) / 100.0;
priceText.append(String.format("=%.2f", grandTotal)); priceText.append(String.format("=%.2f", grandTotal));
} }
outputs.add(priceText.toString().trim()); outputs.add(priceText.toString().trim());
} }
return outputs.isEmpty() ? Collections.singletonList("无数据") : outputs; return outputs.isEmpty() ? Collections.singletonList("无数据") : outputs;
} }
if (input.startsWith("")) { if (input.startsWith("")) {
@@ -646,7 +646,7 @@ public class InstructionServiceImpl implements IInstructionService {
if (isEmpty(order.getAddress())) missing.append("收货地址\n"); if (isEmpty(order.getAddress())) missing.append("收货地址\n");
if (isEmpty(order.getModelNumber())) missing.append("型号\n"); if (isEmpty(order.getModelNumber())) missing.append("型号\n");
if (missing.length() > 0) { if (missing.length() > 0) {
String warn = "录单警告!!! \n缺少表单字段 \n" + missing; String warn = "[炸弹] [炸弹] [炸弹] 录单警告!!! \n缺少表单字段 \n" + missing;
return warn; return warn;
} }