|
|
@@ -467,8 +467,9 @@ public class TjfxAnalysisDataServiceImpl implements TjfxAnalysisDataService { |
|
|
|
* @throws Exception 可能在处理过程中抛出异常 |
|
|
|
*/ |
|
|
|
public static List<Map<String, Object>> aggregate(List<Map<String, Object>> input) throws Exception { |
|
|
|
// 按product_code 分组(保持插入顺序) |
|
|
|
// 按product_code 分组(保持插入顺序),并过滤null值 |
|
|
|
Map<String, List<Map<String, Object>>> grouped = input.stream() |
|
|
|
.filter(m -> m.get("product_code") != null) // 过滤product_code为null的记录 |
|
|
|
.collect(Collectors.groupingBy(m -> (String) m.get("product_code"), LinkedHashMap::new, Collectors.toList())); |
|
|
|
|
|
|
|
List<Map<String, Object>> result = new ArrayList<>(); |
|
|
@@ -506,26 +507,26 @@ public class TjfxAnalysisDataServiceImpl implements TjfxAnalysisDataService { |
|
|
|
.add(courseEntry.getValue()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 排序并转回 List<String> |
|
|
|
Map<String, List<String>> categorySets = new LinkedHashMap<>(); |
|
|
|
for (Map.Entry<String, Set<String>> courseEntry : categorySet.entrySet()) { |
|
|
|
List<String> sortedScores = new ArrayList<>(courseEntry.getValue()); |
|
|
|
Collections.sort(sortedScores); // 升序 |
|
|
|
List<String> scoresStr = sortedScores.stream() |
|
|
|
.map(String::valueOf) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
categorySets.put(courseEntry.getKey(), scoresStr); |
|
|
|
} |
|
|
|
// 排序并转回 List<String> - 移到内部循环外 |
|
|
|
Map<String, List<String>> categorySets = new LinkedHashMap<>(); |
|
|
|
for (Map.Entry<String, Set<String>> courseEntry : categorySet.entrySet()) { |
|
|
|
List<String> sortedScores = new ArrayList<>(courseEntry.getValue()); |
|
|
|
Collections.sort(sortedScores); // 升序 |
|
|
|
List<String> scoresStr = sortedScores.stream() |
|
|
|
.map(String::valueOf) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
categorySets.put(courseEntry.getKey(), scoresStr); |
|
|
|
} |
|
|
|
|
|
|
|
// 组装聚合结果 |
|
|
|
aggregated.put("brand", new ArrayList<>(brandNames)); |
|
|
|
aggregated.put("shop_name", new ArrayList<>(shopNames)); |
|
|
|
aggregated.put("customer_name", new ArrayList<>(customerNames)); |
|
|
|
aggregated.putAll(categorySets); |
|
|
|
// 组装聚合结果 - 移到内部循环外 |
|
|
|
aggregated.put("brand", new ArrayList<>(brandNames)); |
|
|
|
aggregated.put("shop_name", new ArrayList<>(shopNames)); |
|
|
|
aggregated.put("customer_name", new ArrayList<>(customerNames)); |
|
|
|
aggregated.putAll(categorySets); |
|
|
|
|
|
|
|
result.add(aggregated); |
|
|
|
} |
|
|
|
result.add(aggregated); |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |