refactor(oa): 优化日趋势数据处理

- 增加空数据处理:当源数据为空或无记录时,自动生成近7天的默认数据
- 完善数据转换:对value值进行空值处理,若无值则默认为0
This commit is contained in:
2025-09-17 16:59:40 +08:00
parent 73b8652251
commit 0fe77fa3c5

View File

@@ -144,6 +144,20 @@ public class GearDashboardServiceImpl implements IGearDashboardService {
List<DailyTrendVO> trends = new ArrayList<>();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM-dd");
// 如果数据为空或没有元素则返回包含7天默认数据的列表
if (data == null || data.isEmpty()) {
// 创建近7天的默认数据
for (int i = 6; i >= 0; i--) {
DailyTrendVO trend = new DailyTrendVO();
LocalDate date = LocalDate.now().minusDays(i);
trend.setDate(date.format(formatter));
trend.setLabel(trend.getDate());
trend.setValue(BigDecimal.ZERO);
trends.add(trend);
}
return trends;
}
for (Map<String, Object> item : data) {
DailyTrendVO trend = new DailyTrendVO();
@@ -163,6 +177,9 @@ public class GearDashboardServiceImpl implements IGearDashboardService {
trend.setValue(new BigDecimal((Integer) valueObj));
} else if (valueObj instanceof Long) {
trend.setValue(new BigDecimal((Long) valueObj));
} else {
// 如果没有值则设置为0
trend.setValue(BigDecimal.ZERO);
}
trend.setLabel(trend.getDate());
@@ -172,6 +189,7 @@ public class GearDashboardServiceImpl implements IGearDashboardService {
return trends;
}
/**
* 计算增长率
*/