diff --git a/viewsh-module-ops/viewsh-module-ops-biz/src/main/java/com/viewsh/module/ops/controller/admin/workorder/vo/statistics/DashboardStatsRespVO.java b/viewsh-module-ops/viewsh-module-ops-biz/src/main/java/com/viewsh/module/ops/controller/admin/workorder/vo/statistics/DashboardStatsRespVO.java index 6ddc7af..e91f533 100644 --- a/viewsh-module-ops/viewsh-module-ops-biz/src/main/java/com/viewsh/module/ops/controller/admin/workorder/vo/statistics/DashboardStatsRespVO.java +++ b/viewsh-module-ops/viewsh-module-ops-biz/src/main/java/com/viewsh/module/ops/controller/admin/workorder/vo/statistics/DashboardStatsRespVO.java @@ -48,6 +48,9 @@ public class DashboardStatsRespVO { @Schema(description = "工牌队列统计(近7天每天的排队数量)") private BadgeQueueStats badgeQueueStats; + @Schema(description = "当月与上月工单趋势对比") + private MonthlyTrendData monthlyTrendData; + @Data @Builder @NoArgsConstructor @@ -135,4 +138,26 @@ public class DashboardStatsRespVO { private List 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 dates; + @Schema(description = "每日创建工单数") + private List createdData; + } + } diff --git a/viewsh-module-ops/viewsh-module-ops-biz/src/main/java/com/viewsh/module/ops/service/statistics/OpsStatisticsServiceImpl.java b/viewsh-module-ops/viewsh-module-ops-biz/src/main/java/com/viewsh/module/ops/service/statistics/OpsStatisticsServiceImpl.java index 5cec58f..31ac0bf 100644 --- a/viewsh-module-ops/viewsh-module-ops-biz/src/main/java/com/viewsh/module/ops/service/statistics/OpsStatisticsServiceImpl.java +++ b/viewsh-module-ops/viewsh-module-ops-biz/src/main/java/com/viewsh/module/ops/service/statistics/OpsStatisticsServiceImpl.java @@ -142,6 +142,9 @@ public class OpsStatisticsServiceImpl implements OpsStatisticsService { // 11. 工牌队列统计(近7天每天排队的工单数 = QUEUED 状态) BadgeQueueStats badgeQueueStats = buildBadgeQueueStats(orderType, sevenDaysAgo, LocalDate.now()); + // 12. 当月 vs 上月工单趋势对比 + MonthlyTrendData monthlyTrendData = buildMonthlyTrendData(orderType); + return DashboardStatsRespVO.builder() .pendingCount(pendingCount) .inProgressCount(inProgressCount) @@ -154,6 +157,7 @@ public class OpsStatisticsServiceImpl implements OpsStatisticsService { .heatmapData(heatmapData) .functionTypeRanking(functionTypeRanking) .badgeQueueStats(badgeQueueStats) + .monthlyTrendData(monthlyTrendData) .build(); } @@ -1047,4 +1051,54 @@ public class OpsStatisticsServiceImpl implements OpsStatisticsService { 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 rows = opsOrderMapper.selectCreatedCountGroupByDate( + orderType, startDateTime, endDateTime); + Map countMap = rows.stream() + .collect(Collectors.toMap( + row -> row.getStatDate().toString(), + row -> row.getCnt().intValue(), + (a, b) -> a + )); + + List dates = new ArrayList<>(); + List 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(); + } + }