1
This commit is contained in:
@@ -249,26 +249,21 @@ public class InstructionServiceImpl implements IInstructionService {
|
|||||||
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, Double> globalPaymentAmounts = new HashMap<>();
|
|
||||||
Map<String, Double> globalRebateAmounts = 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();
|
||||||
|
|
||||||
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> 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());
|
||||||
modelEntries.sort(Comparator.comparing(en -> en.getKey() == null ? "" : en.getKey()));
|
modelEntries.sort(Comparator.comparing(en -> en.getKey() == null ? "" : en.getKey()));
|
||||||
|
|
||||||
|
// 记录该分组中每个型号的最高单价订单
|
||||||
|
Map<String, JDOrder> groupMaxPriceOrders = new HashMap<>();
|
||||||
|
Map<String, Integer> groupModelCounts = new HashMap<>();
|
||||||
|
|
||||||
for (Map.Entry<String, Long> em : modelEntries) {
|
for (Map.Entry<String, Long> em : modelEntries) {
|
||||||
int c = em.getValue().intValue();
|
int c = em.getValue().intValue();
|
||||||
totalCount += c;
|
totalCount += c;
|
||||||
@@ -276,21 +271,17 @@ public class InstructionServiceImpl implements IInstructionService {
|
|||||||
|
|
||||||
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);
|
groupModelCounts.put(model, c);
|
||||||
Double paymentAmount = modelPaymentAmounts.get(model);
|
|
||||||
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) {
|
for (JDOrder order : orders) {
|
||||||
if (model.equals(order.getModelNumber())) {
|
if (model.equals(order.getModelNumber())) {
|
||||||
JDOrder currentMax = globalMaxPriceOrders.get(model);
|
JDOrder currentMax = groupMaxPriceOrders.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);
|
groupMaxPriceOrders.put(model, order);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -309,102 +300,104 @@ public class InstructionServiceImpl implements IInstructionService {
|
|||||||
StringBuilder infoSingle = new StringBuilder();
|
StringBuilder infoSingle = new StringBuilder();
|
||||||
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 (!groupModelCounts.isEmpty()) {
|
||||||
StringBuilder priceText = new StringBuilder();
|
StringBuilder priceText = new StringBuilder();
|
||||||
|
priceText.append("分销标记:").append(dm).append(" - 算钱\n");
|
||||||
|
|
||||||
// 先输出型号和数量
|
// 先输出型号和数量
|
||||||
List<Map.Entry<String, Integer>> sortedEntries = globalModelCounts.entrySet().stream()
|
List<Map.Entry<String, Integer>> sortedEntries = groupModelCounts.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");
|
|
||||||
|
|
||||||
// 输出金额计算(单台价格-返现+佣金=净价×数量=总价)
|
|
||||||
double grandTotal = 0.0;
|
|
||||||
StringBuilder calculationLines = new StringBuilder();
|
|
||||||
List<Double> totalPricesList = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Map.Entry<String, Integer> entry : sortedEntries) {
|
|
||||||
String model = entry.getKey();
|
|
||||||
int count = entry.getValue();
|
|
||||||
|
|
||||||
// 获取该型号最高价格的订单
|
|
||||||
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;
|
|
||||||
try {
|
|
||||||
com.ruoyi.jarvis.domain.ProductJdConfig config = productJdConfigService.selectProductJdConfigByModel(model);
|
|
||||||
if (config != null && config.getCommission() != null) {
|
|
||||||
commission = config.getCommission().doubleValue();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
// 如果获取失败,佣金为0
|
|
||||||
}
|
|
||||||
|
|
||||||
// 计算净价(单台价格 - 返现 + 佣金)
|
|
||||||
double netPrice = singlePayment - singleRebate + commission;
|
|
||||||
// 四舍五入到2位小数
|
|
||||||
netPrice = Math.round(netPrice * 100.0) / 100.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("%.2f-%.2f+%.2f=%.2f\n",
|
|
||||||
singlePayment, singleRebate, commission, totalPrice));
|
|
||||||
} else {
|
|
||||||
calculationLines.append(String.format("%.2f-%.2f+%.2f=%.2f×%d=%.2f\n",
|
|
||||||
singlePayment, singleRebate, commission, netPrice, count, totalPrice));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
priceText.append(calculationLines);
|
|
||||||
|
|
||||||
// 输出汇总(各型号总价相加)
|
|
||||||
if (sortedEntries.size() > 1) {
|
|
||||||
priceText.append("\n");
|
priceText.append("\n");
|
||||||
// 构建汇总公式
|
|
||||||
for (int i = 0; i < totalPricesList.size(); i++) {
|
|
||||||
if (i > 0) {
|
|
||||||
priceText.append("+");
|
|
||||||
}
|
|
||||||
priceText.append(String.format("%.2f", totalPricesList.get(i)));
|
|
||||||
}
|
|
||||||
// 四舍五入汇总到2位小数
|
|
||||||
grandTotal = Math.round(grandTotal * 100.0) / 100.0;
|
|
||||||
priceText.append(String.format("=%.2f", grandTotal));
|
|
||||||
}
|
|
||||||
|
|
||||||
outputs.add(priceText.toString().trim());
|
// 输出金额计算(单台价格-返现+佣金=净价×数量=总价)
|
||||||
|
double grandTotal = 0.0;
|
||||||
|
StringBuilder calculationLines = new StringBuilder();
|
||||||
|
List<Double> totalPricesList = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Map.Entry<String, Integer> entry : sortedEntries) {
|
||||||
|
String model = entry.getKey();
|
||||||
|
int count = entry.getValue();
|
||||||
|
|
||||||
|
// 获取该型号最高价格的订单
|
||||||
|
JDOrder maxPriceOrder = groupMaxPriceOrders.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;
|
||||||
|
try {
|
||||||
|
com.ruoyi.jarvis.domain.ProductJdConfig config = productJdConfigService.selectProductJdConfigByModel(model);
|
||||||
|
if (config != null && config.getCommission() != null) {
|
||||||
|
commission = config.getCommission().doubleValue();
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
// 如果获取失败,佣金为0
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算净价(单台价格 - 返现 + 佣金)
|
||||||
|
double netPrice = singlePayment - singleRebate + commission;
|
||||||
|
// 四舍五入到2位小数
|
||||||
|
netPrice = Math.round(netPrice * 100.0) / 100.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("%.2f-%.2f+%.2f=%.2f\n",
|
||||||
|
singlePayment, singleRebate, commission, totalPrice));
|
||||||
|
} else {
|
||||||
|
calculationLines.append(String.format("%.2f-%.2f+%.2f=%.2f×%d=%.2f\n",
|
||||||
|
singlePayment, singleRebate, commission, netPrice, count, totalPrice));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
priceText.append(calculationLines);
|
||||||
|
|
||||||
|
// 输出汇总(各型号总价相加)
|
||||||
|
if (sortedEntries.size() > 1) {
|
||||||
|
priceText.append("\n");
|
||||||
|
// 构建汇总公式
|
||||||
|
for (int i = 0; i < totalPricesList.size(); i++) {
|
||||||
|
if (i > 0) {
|
||||||
|
priceText.append("+");
|
||||||
|
}
|
||||||
|
priceText.append(String.format("%.2f", totalPricesList.get(i)));
|
||||||
|
}
|
||||||
|
// 四舍五入汇总到2位小数
|
||||||
|
grandTotal = Math.round(grandTotal * 100.0) / 100.0;
|
||||||
|
priceText.append(String.format("=%.2f", grandTotal));
|
||||||
|
}
|
||||||
|
|
||||||
|
outputs.add(priceText.toString().trim());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return outputs.isEmpty() ? Collections.singletonList("无数据") : outputs;
|
return outputs.isEmpty() ? Collections.singletonList("无数据") : outputs;
|
||||||
}
|
}
|
||||||
if (input.startsWith("单")) {
|
if (input.startsWith("单")) {
|
||||||
|
|||||||
Reference in New Issue
Block a user