feat(ops): 新增当月vs上月工单趋势对比数据(monthlyTrendData)
在 DashboardStatsRespVO 中新增 MonthlyTrendData/MonthData 内部类, 在 OpsStatisticsServiceImpl 中新增 buildMonthlyTrendData 方法, 复用已有的 selectCreatedCountGroupByDate 查询按日统计当月和上月每日创建工单数。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -48,6 +48,9 @@ public class DashboardStatsRespVO {
|
|||||||
@Schema(description = "工牌队列统计(近7天每天的排队数量)")
|
@Schema(description = "工牌队列统计(近7天每天的排队数量)")
|
||||||
private BadgeQueueStats badgeQueueStats;
|
private BadgeQueueStats badgeQueueStats;
|
||||||
|
|
||||||
|
@Schema(description = "当月与上月工单趋势对比")
|
||||||
|
private MonthlyTrendData monthlyTrendData;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@@ -135,4 +138,26 @@ public class DashboardStatsRespVO {
|
|||||||
private List<Integer> queueData;
|
private List<Integer> queueData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class MonthlyTrendData {
|
||||||
|
@Schema(description = "当月数据")
|
||||||
|
private MonthData currentMonth;
|
||||||
|
@Schema(description = "上月数据")
|
||||||
|
private MonthData lastMonth;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class MonthData {
|
||||||
|
@Schema(description = "日期列表")
|
||||||
|
private List<String> dates;
|
||||||
|
@Schema(description = "每日创建工单数")
|
||||||
|
private List<Integer> createdData;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,6 +142,9 @@ public class OpsStatisticsServiceImpl implements OpsStatisticsService {
|
|||||||
// 11. 工牌队列统计(近7天每天排队的工单数 = QUEUED 状态)
|
// 11. 工牌队列统计(近7天每天排队的工单数 = QUEUED 状态)
|
||||||
BadgeQueueStats badgeQueueStats = buildBadgeQueueStats(orderType, sevenDaysAgo, LocalDate.now());
|
BadgeQueueStats badgeQueueStats = buildBadgeQueueStats(orderType, sevenDaysAgo, LocalDate.now());
|
||||||
|
|
||||||
|
// 12. 当月 vs 上月工单趋势对比
|
||||||
|
MonthlyTrendData monthlyTrendData = buildMonthlyTrendData(orderType);
|
||||||
|
|
||||||
return DashboardStatsRespVO.builder()
|
return DashboardStatsRespVO.builder()
|
||||||
.pendingCount(pendingCount)
|
.pendingCount(pendingCount)
|
||||||
.inProgressCount(inProgressCount)
|
.inProgressCount(inProgressCount)
|
||||||
@@ -154,6 +157,7 @@ public class OpsStatisticsServiceImpl implements OpsStatisticsService {
|
|||||||
.heatmapData(heatmapData)
|
.heatmapData(heatmapData)
|
||||||
.functionTypeRanking(functionTypeRanking)
|
.functionTypeRanking(functionTypeRanking)
|
||||||
.badgeQueueStats(badgeQueueStats)
|
.badgeQueueStats(badgeQueueStats)
|
||||||
|
.monthlyTrendData(monthlyTrendData)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1047,4 +1051,54 @@ public class OpsStatisticsServiceImpl implements OpsStatisticsService {
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建当月 vs 上月工单趋势对比数据
|
||||||
|
*/
|
||||||
|
private MonthlyTrendData buildMonthlyTrendData(String orderType) {
|
||||||
|
LocalDate today = LocalDate.now();
|
||||||
|
LocalDate currentMonthStart = today.withDayOfMonth(1);
|
||||||
|
|
||||||
|
// 上月:上月1日 ~ 上月末
|
||||||
|
LocalDate lastMonthStart = currentMonthStart.minusMonths(1);
|
||||||
|
LocalDate lastMonthEnd = currentMonthStart.minusDays(1);
|
||||||
|
|
||||||
|
DashboardStatsRespVO.MonthData currentMonth = buildMonthData(orderType, currentMonthStart, today);
|
||||||
|
DashboardStatsRespVO.MonthData lastMonth = buildMonthData(orderType, lastMonthStart, lastMonthEnd);
|
||||||
|
|
||||||
|
return MonthlyTrendData.builder()
|
||||||
|
.currentMonth(currentMonth)
|
||||||
|
.lastMonth(lastMonth)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建指定日期范围的每日创建工单数据
|
||||||
|
*/
|
||||||
|
private DashboardStatsRespVO.MonthData buildMonthData(String orderType, LocalDate startDate, LocalDate endDate) {
|
||||||
|
LocalDateTime startDateTime = startDate.atStartOfDay();
|
||||||
|
LocalDateTime endDateTime = endDate.plusDays(1).atStartOfDay();
|
||||||
|
|
||||||
|
List<DateCountRespVO> rows = opsOrderMapper.selectCreatedCountGroupByDate(
|
||||||
|
orderType, startDateTime, endDateTime);
|
||||||
|
Map<String, Integer> countMap = rows.stream()
|
||||||
|
.collect(Collectors.toMap(
|
||||||
|
row -> row.getStatDate().toString(),
|
||||||
|
row -> row.getCnt().intValue(),
|
||||||
|
(a, b) -> a
|
||||||
|
));
|
||||||
|
|
||||||
|
List<String> dates = new ArrayList<>();
|
||||||
|
List<Integer> createdData = new ArrayList<>();
|
||||||
|
|
||||||
|
for (LocalDate d = startDate; !d.isAfter(endDate); d = d.plusDays(1)) {
|
||||||
|
dates.add(d.toString()); // yyyy-MM-dd 格式
|
||||||
|
createdData.add(countMap.getOrDefault(d.toString(), 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
return DashboardStatsRespVO.MonthData.builder()
|
||||||
|
.dates(dates)
|
||||||
|
.createdData(createdData)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user