refactor(ops): 重构统计模块,支持日期参数化查询及代码质量优化
Some checks failed
Java CI with Maven / build (11) (push) Has been cancelled
Java CI with Maven / build (17) (push) Has been cancelled
Java CI with Maven / build (8) (push) Has been cancelled

- 客流接口支持指定日期查询(getTrafficRealtime、getTrafficTrend、getAreaTrafficRealtime)
- 移除昨日对比趋势字段(yesterdayHourlyTrend),简化为单日期模式
- 漏斗图改为工单状态分布(FunnelItem→StatusDistributionItem),使用 SQL COUNT 替代内存分组
- 新增工牌队列统计(BadgeQueueStats),按 orderType 过滤避免跨类型数据混入
- 在线工牌计数仅统计 IDLE/BUSY 状态(排除 PAUSED/OFFLINE)
- 修复通配符导入和全限定类名引用,规范化 import 语句

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
lzh
2026-03-01 00:17:26 +08:00
parent 7d1012bba7
commit 1c8eee9db4
8 changed files with 218 additions and 156 deletions

View File

@@ -2,6 +2,7 @@ package com.viewsh.module.ops.config;
import com.viewsh.module.ops.api.badge.BadgeDeviceStatusDTO;
import com.viewsh.module.ops.dal.dataobject.area.OpsAreaDeviceRelationDO;
import com.viewsh.module.ops.enums.BadgeDeviceStatusEnum;
import com.viewsh.module.ops.environment.service.badge.BadgeDeviceStatusService;
import com.viewsh.module.ops.service.area.AreaDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -32,7 +33,11 @@ public class StatisticsConfiguration {
return new int[]{0, 0};
}
List<BadgeDeviceStatusDTO> activeBadges = badgeDeviceStatusService.listActiveBadges();
int onlineCount = activeBadges.size();
// 只计算 IDLE 和 BUSY 状态的工牌作为在线数(不含 PAUSED 和 OFFLINE
int onlineCount = (int) activeBadges.stream()
.filter(b -> b.getStatus() == BadgeDeviceStatusEnum.IDLE
|| b.getStatus() == BadgeDeviceStatusEnum.BUSY)
.count();
// 从区域设备关联表查询所有已注册的工牌设备总数
int totalCount = onlineCount;
if (areaDeviceService != null) {

View File

@@ -42,23 +42,26 @@ public class OpsTrafficController {
@GetMapping("/realtime")
@Operation(summary = "全局实时客流监测")
@PreAuthorize("@ss.hasPermission('ops:traffic:query')")
public CommonResult<TrafficRealtimeRespVO> getTrafficRealtime() {
public CommonResult<TrafficRealtimeRespVO> getTrafficRealtime(
@RequestParam(value = "date", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date) {
if (opsStatisticsService == null) {
log.warn("[getTrafficRealtime] OpsStatisticsService 未注入,返回默认值");
return success(TrafficRealtimeRespVO.builder().build());
}
return success(opsStatisticsService.getTrafficRealtime());
return success(opsStatisticsService.getTrafficRealtime(date));
}
@GetMapping("/trend")
@Operation(summary = "全局近7天客流趋势统计")
@Operation(summary = "客流趋势统计")
@PreAuthorize("@ss.hasPermission('ops:traffic:query')")
public CommonResult<TrafficTrendRespVO> getTrafficTrend() {
public CommonResult<TrafficTrendRespVO> getTrafficTrend(
@RequestParam(value = "startDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate,
@RequestParam(value = "endDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate) {
if (opsStatisticsService == null) {
log.warn("[getTrafficTrend] OpsStatisticsService 未注入,返回默认值");
return success(TrafficTrendRespVO.builder().build());
}
return success(opsStatisticsService.getTrafficTrend());
return success(opsStatisticsService.getTrafficTrend(startDate, endDate));
}
@GetMapping("/device/realtime")
@@ -79,7 +82,8 @@ public class OpsTrafficController {
@Parameter(name = "areaIds", description = "区域ID列表", required = true)
@PreAuthorize("@ss.hasPermission('ops:traffic:query')")
public CommonResult<TrafficRealtimeRespVO> getAreaTrafficRealtime(
@RequestParam("areaIds") List<Long> areaIds) {
@RequestParam("areaIds") List<Long> areaIds,
@RequestParam(value = "date", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date) {
if (opsStatisticsService == null) {
log.warn("[getAreaTrafficRealtime] OpsStatisticsService 未注入,返回默认值");
return success(TrafficRealtimeRespVO.builder().build());
@@ -87,7 +91,7 @@ public class OpsTrafficController {
if (areaIds.size() > 200) {
areaIds = areaIds.subList(0, 200);
}
return success(opsStatisticsService.getAreaTrafficRealtime(areaIds));
return success(opsStatisticsService.getAreaTrafficRealtime(areaIds, date));
}
@GetMapping("/device/trend")