Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -192,6 +192,8 @@ public class InstructionServiceImpl implements IInstructionService {
|
|||||||
if (kw.isEmpty()) return Collections.singletonList("请输入搜索关键词");
|
if (kw.isEmpty()) return Collections.singletonList("请输入搜索关键词");
|
||||||
List<JDOrder> list = jdOrderService.selectJDOrderList(new JDOrder());
|
List<JDOrder> list = jdOrderService.selectJDOrderList(new JDOrder());
|
||||||
if (list == null) list = Collections.emptyList();
|
if (list == null) list = Collections.emptyList();
|
||||||
|
// 统一截取分销标记
|
||||||
|
list.forEach(order -> order.setDistributionMark(truncateDistributionMark(order.getDistributionMark())));
|
||||||
String low = kw.toLowerCase(Locale.ROOT);
|
String low = kw.toLowerCase(Locale.ROOT);
|
||||||
List<JDOrder> matched = list.stream().filter(o -> contains(o.getRemark(), low) || contains(o.getOrderId(), low) || contains(o.getModelNumber(), low) || contains(o.getAddress(), low) || contains(o.getBuyer(), low)).limit(50).collect(Collectors.toList());
|
List<JDOrder> matched = list.stream().filter(o -> contains(o.getRemark(), low) || contains(o.getOrderId(), low) || contains(o.getModelNumber(), low) || contains(o.getAddress(), low) || contains(o.getBuyer(), low)).limit(50).collect(Collectors.toList());
|
||||||
if (matched.isEmpty()) return Collections.singletonList("未找到匹配的订单");
|
if (matched.isEmpty()) return Collections.singletonList("未找到匹配的订单");
|
||||||
@@ -214,6 +216,8 @@ public class InstructionServiceImpl implements IInstructionService {
|
|||||||
Date end = Date.from(range.get(1).atTime(LocalTime.MAX).atZone(ZoneId.systemDefault()).toInstant());
|
Date end = Date.from(range.get(1).atTime(LocalTime.MAX).atZone(ZoneId.systemDefault()).toInstant());
|
||||||
List<JDOrder> list = jdOrderService.selectJDOrderList(new JDOrder());
|
List<JDOrder> list = jdOrderService.selectJDOrderList(new JDOrder());
|
||||||
if (list == null) list = Collections.emptyList();
|
if (list == null) list = Collections.emptyList();
|
||||||
|
// 统一截取分销标记
|
||||||
|
list.forEach(order -> order.setDistributionMark(truncateDistributionMark(order.getDistributionMark())));
|
||||||
List<JDOrder> filtered = list.stream().filter(o -> o.getOrderTime() != null && !o.getOrderTime().before(start) && !o.getOrderTime().after(end)).collect(Collectors.toList());
|
List<JDOrder> filtered = list.stream().filter(o -> o.getOrderTime() != null && !o.getOrderTime().before(start) && !o.getOrderTime().after(end)).collect(Collectors.toList());
|
||||||
if (filtered.isEmpty()) return Collections.singletonList("今天没有订单。");
|
if (filtered.isEmpty()) return Collections.singletonList("今天没有订单。");
|
||||||
// 按 remark 排序
|
// 按 remark 排序
|
||||||
@@ -235,6 +239,8 @@ public class InstructionServiceImpl implements IInstructionService {
|
|||||||
Date end = Date.from(range.get(1).atTime(LocalTime.MAX).atZone(ZoneId.systemDefault()).toInstant());
|
Date end = Date.from(range.get(1).atTime(LocalTime.MAX).atZone(ZoneId.systemDefault()).toInstant());
|
||||||
List<JDOrder> list = jdOrderService.selectJDOrderList(new JDOrder());
|
List<JDOrder> list = jdOrderService.selectJDOrderList(new JDOrder());
|
||||||
if (list == null) list = Collections.emptyList();
|
if (list == null) list = Collections.emptyList();
|
||||||
|
// 统一截取分销标记
|
||||||
|
list.forEach(order -> order.setDistributionMark(truncateDistributionMark(order.getDistributionMark())));
|
||||||
List<JDOrder> filtered = list.stream().filter(o -> o.getOrderTime() != null && !o.getOrderTime().before(start) && !o.getOrderTime().after(end)).collect(Collectors.toList());
|
List<JDOrder> filtered = list.stream().filter(o -> o.getOrderTime() != null && !o.getOrderTime().before(start) && !o.getOrderTime().after(end)).collect(Collectors.toList());
|
||||||
if (filtered.isEmpty()) return Collections.singletonList("今天没有订单。");
|
if (filtered.isEmpty()) return Collections.singletonList("今天没有订单。");
|
||||||
|
|
||||||
@@ -243,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;
|
||||||
@@ -270,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -303,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("单")) {
|
||||||
@@ -925,10 +924,37 @@ private String handleTF(String input) {
|
|||||||
return LocalDate.of(y, mo, d);
|
return LocalDate.of(y, mo, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 截取分销标记,如果长度大于4则进行截取
|
||||||
|
* @param v 原始分销标记
|
||||||
|
* @return 截取后的分销标记
|
||||||
|
*/
|
||||||
|
private String truncateDistributionMark(String v) {
|
||||||
|
if (v == null) return "";
|
||||||
|
|
||||||
|
// 如果长度大于4,进行截取
|
||||||
|
if (v.length() > 4) {
|
||||||
|
// 查找第一个左括号的位置
|
||||||
|
int leftParenIndex = v.indexOf('(');
|
||||||
|
if (leftParenIndex > 0) {
|
||||||
|
// 截取到左括号之前的部分
|
||||||
|
return v.substring(0, leftParenIndex);
|
||||||
|
} else {
|
||||||
|
// 如果没有括号,直接截取前4个字符
|
||||||
|
return v.substring(0, 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
private String mapDistribution(String v) {
|
private String mapDistribution(String v) {
|
||||||
if (v == null) return "";
|
if (v == null) return "";
|
||||||
if (v.startsWith("H")) return "鸿";
|
|
||||||
if (v.startsWith("F")) return "凡";
|
String processedV = truncateDistributionMark(v);
|
||||||
|
|
||||||
|
if (processedV.startsWith("H")) return "鸿";
|
||||||
|
if (processedV.startsWith("F")) return "凡";
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -955,3 +981,4 @@ private String handleTF(String input) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user