fix(statistics): 修复统计数据合并中的类型转换问题

- 将订单数据转为 Map 时使用 String.valueOf 处理 Object 类型数值
- 在合并数据时对时间键和金额字段进行字符串类型转换
- 防止因数值类型不匹配导致的数据丢失问题
This commit is contained in:
2026-01-12 22:36:00 +08:00
parent f8c6604a8a
commit 93e28828ad

View File

@@ -111,21 +111,21 @@ public class StatisticsServiceImpl implements StatisticsService {
List<HashMap<String, String>> statsData,
List<HashMap<String, String>> orderData) {
// 将订单数据转为 Map 以便快速查找
// 将订单数据转为 Map 以便快速查找(使用 Object 类型处理数值)
Map<String, HashMap<String, String>> orderMap = orderData.stream()
.collect(Collectors.toMap(
m -> m.get("t"),
m -> String.valueOf(m.get("t")),
m -> m,
(existing, replacement) -> existing
));
// 合并数据
for (HashMap<String, String> stat : statsData) {
String timeKey = stat.get("t");
String timeKey = String.valueOf(stat.get("t"));
HashMap<String, String> order = orderMap.get(timeKey);
if (order != null) {
stat.put("orderCount", order.get("orderCount"));
stat.put("orderAmount", order.get("orderAmount"));
stat.put("orderCount", String.valueOf(order.get("orderCount")));
stat.put("orderAmount", String.valueOf(order.get("orderAmount")));
} else {
stat.put("orderCount", "0");
stat.put("orderAmount", "0");