From 3bcdb4119f86411a12ea418f134ee645fd11387d Mon Sep 17 00:00:00 2001 From: lzh Date: Sun, 1 Mar 2026 16:09:17 +0800 Subject: [PATCH] =?UTF-8?q?feat(ops):=20=E6=96=B0=E5=A2=9E=E5=BD=93?= =?UTF-8?q?=E6=9C=88vs=E4=B8=8A=E6=9C=88=E5=B7=A5=E5=8D=95=E8=B6=8B?= =?UTF-8?q?=E5=8A=BF=E5=AF=B9=E6=AF=94=E6=95=B0=E6=8D=AE=EF=BC=88monthlyTr?= =?UTF-8?q?endData=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在 DashboardStatsRespVO 中新增 MonthlyTrendData/MonthData 内部类, 在 OpsStatisticsServiceImpl 中新增 buildMonthlyTrendData 方法, 复用已有的 selectCreatedCountGroupByDate 查询按日统计当月和上月每日创建工单数。 Co-Authored-By: Claude Opus 4.6 --- .../vo/statistics/DashboardStatsRespVO.java | 25 +++++++++ .../statistics/OpsStatisticsServiceImpl.java | 54 +++++++++++++++++++ 2 files changed, 79 insertions(+) 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(); + } + }