1
This commit is contained in:
@@ -222,7 +222,7 @@ public class InstructionServiceImpl implements IInstructionService {
|
|||||||
return Collections.singletonList(sb.toString());
|
return Collections.singletonList(sb.toString());
|
||||||
}
|
}
|
||||||
if (input.startsWith("慢单")) {
|
if (input.startsWith("慢单")) {
|
||||||
// 慢单:分销标记分组 -> 型号统计 + 详情
|
// 慢单:分销标记分组 -> 型号统计 + 详情 + 算钱文本
|
||||||
List<LocalDate> range = parseDateRange(input.replaceFirst("^慢单", "").trim());
|
List<LocalDate> range = parseDateRange(input.replaceFirst("^慢单", "").trim());
|
||||||
if (range == null) {
|
if (range == null) {
|
||||||
LocalDate today = effectiveToday().toLocalDate();
|
LocalDate today = effectiveToday().toLocalDate();
|
||||||
@@ -239,11 +239,24 @@ 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, Double> globalModelAmounts = 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> modelAmounts = orders.stream().collect(Collectors.groupingBy(JDOrder::getModelNumber, Collectors.summingDouble(o -> {
|
||||||
|
if (o.getPaymentAmount() != null && o.getRebateAmount() != null) {
|
||||||
|
return o.getPaymentAmount() - o.getRebateAmount();
|
||||||
|
}
|
||||||
|
return 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());
|
||||||
@@ -251,7 +264,14 @@ public class InstructionServiceImpl implements IInstructionService {
|
|||||||
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;
|
||||||
summary.append("型号:").append(em.getKey() != null ? em.getKey() : "未知").append(" 数量:").append(c).append("\n");
|
String model = em.getKey() != null ? em.getKey() : "未知";
|
||||||
|
|
||||||
|
summary.append("型号:").append(model).append(" 数量:").append(c).append("\n");
|
||||||
|
|
||||||
|
// 累积到全局统计
|
||||||
|
globalModelCounts.put(model, globalModelCounts.getOrDefault(model, 0) + c);
|
||||||
|
Double amount = modelAmounts.get(model);
|
||||||
|
globalModelAmounts.put(model, globalModelAmounts.getOrDefault(model, 0.0) + (amount != null ? amount : 0.0));
|
||||||
}
|
}
|
||||||
summary.append("总计:").append(totalCount).append("\n详情:");
|
summary.append("总计:").append(totalCount).append("\n详情:");
|
||||||
|
|
||||||
@@ -263,10 +283,39 @@ public class InstructionServiceImpl implements IInstructionService {
|
|||||||
idx++;
|
idx++;
|
||||||
detail.append("\n").append(idx).append(" ────────────\n").append("单:").append(o.getRemark() != null ? o.getRemark() : "未提供").append("\n备注:").append(o.getStatus() != null ? o.getStatus() : " ").append("\n型号:").append(o.getModelNumber() != null ? o.getModelNumber() : "未提供").append("\n地址:").append(o.getAddress() != null ? o.getAddress() : "未提供").append("\n物流链接:\n").append(o.getLogisticsLink() != null ? o.getLogisticsLink() : "无");
|
detail.append("\n").append(idx).append(" ────────────\n").append("单:").append(o.getRemark() != null ? o.getRemark() : "未提供").append("\n备注:").append(o.getStatus() != null ? o.getStatus() : " ").append("\n型号:").append(o.getModelNumber() != null ? o.getModelNumber() : "未提供").append("\n地址:").append(o.getAddress() != null ? o.getAddress() : "未提供").append("\n物流链接:\n").append(o.getLogisticsLink() != null ? o.getLogisticsLink() : "无");
|
||||||
}
|
}
|
||||||
StringBuilder single = new StringBuilder();
|
// 拆分为多条消息 - 订单详情
|
||||||
single.append("分销标记:").append(dm).append("\n").append(summary).append(detail).append("\n");
|
StringBuilder infoSingle = new StringBuilder();
|
||||||
outputs.add(single.toString().trim());
|
infoSingle.append("分销标记:").append(dm).append("\n").append(summary).append(detail).append("\n");
|
||||||
|
outputs.add(infoSingle.toString().trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 添加算钱文本(全局统计版本)
|
||||||
|
if (!globalModelCounts.isEmpty()) {
|
||||||
|
StringBuilder priceText = new StringBuilder();
|
||||||
|
priceText.append("算钱文本:\n");
|
||||||
|
|
||||||
|
// 先输出型号和数量
|
||||||
|
List<Map.Entry<String, Integer>> sortedEntries = globalModelCounts.entrySet().stream()
|
||||||
|
.sorted(Comparator.comparing(Map.Entry::getKey))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
for (Map.Entry<String, Integer> entry : sortedEntries) {
|
||||||
|
String model = entry.getKey();
|
||||||
|
int count = entry.getValue();
|
||||||
|
priceText.append("型号:").append(model).append(" 数量:").append(count).append("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 再输出金额计算
|
||||||
|
for (Map.Entry<String, Integer> entry : sortedEntries) {
|
||||||
|
String model = entry.getKey();
|
||||||
|
int count = entry.getValue();
|
||||||
|
Double amount = globalModelAmounts.getOrDefault(model, 0.0);
|
||||||
|
priceText.append(String.format("%.2f", amount)).append("-").append(String.format("%.0f", (double) count * 200)).append("\n"); // 假设每台200元返现
|
||||||
|
}
|
||||||
|
|
||||||
|
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