You've already forked FrameTour-BE
fix(statistics): 修复统计数据合并中的类型转换问题
- 将订单数据转为 Map 时使用 String.valueOf 处理 Object 类型数值 - 在合并数据时对时间键和金额字段进行字符串类型转换 - 防止因数值类型不匹配导致的数据丢失问题
This commit is contained in:
@@ -111,21 +111,21 @@ public class StatisticsServiceImpl implements StatisticsService {
|
|||||||
List<HashMap<String, String>> statsData,
|
List<HashMap<String, String>> statsData,
|
||||||
List<HashMap<String, String>> orderData) {
|
List<HashMap<String, String>> orderData) {
|
||||||
|
|
||||||
// 将订单数据转为 Map 以便快速查找
|
// 将订单数据转为 Map 以便快速查找(使用 Object 类型处理数值)
|
||||||
Map<String, HashMap<String, String>> orderMap = orderData.stream()
|
Map<String, HashMap<String, String>> orderMap = orderData.stream()
|
||||||
.collect(Collectors.toMap(
|
.collect(Collectors.toMap(
|
||||||
m -> m.get("t"),
|
m -> String.valueOf(m.get("t")),
|
||||||
m -> m,
|
m -> m,
|
||||||
(existing, replacement) -> existing
|
(existing, replacement) -> existing
|
||||||
));
|
));
|
||||||
|
|
||||||
// 合并数据
|
// 合并数据
|
||||||
for (HashMap<String, String> stat : statsData) {
|
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);
|
HashMap<String, String> order = orderMap.get(timeKey);
|
||||||
if (order != null) {
|
if (order != null) {
|
||||||
stat.put("orderCount", order.get("orderCount"));
|
stat.put("orderCount", String.valueOf(order.get("orderCount")));
|
||||||
stat.put("orderAmount", order.get("orderAmount"));
|
stat.put("orderAmount", String.valueOf(order.get("orderAmount")));
|
||||||
} else {
|
} else {
|
||||||
stat.put("orderCount", "0");
|
stat.put("orderCount", "0");
|
||||||
stat.put("orderAmount", "0");
|
stat.put("orderAmount", "0");
|
||||||
|
|||||||
Reference in New Issue
Block a user