refactor(controller): 移除自动注入改用静态方法获取用户ID
All checks were successful
test/timeline-server/pipeline/head This commit looks good

移除StatisticsController中自动注入的UserContextUtils,改为直接调用静态方法UserContextUtils.getCurrentUserId()获取用户ID,简化代码结构并减少依赖注入
This commit is contained in:
2026-02-26 11:04:46 +08:00
parent 5bc4a227a8
commit f1beb94e60

View File

@@ -20,9 +20,6 @@ public class StatisticsController {
@Autowired @Autowired
private StatisticsService statisticsService; private StatisticsService statisticsService;
@Autowired
private UserContextUtils userContextUtils;
/** /**
* 获取用户统计概览 * 获取用户统计概览
* GET /api/v1/statistics/overview * GET /api/v1/statistics/overview
@@ -30,9 +27,9 @@ public class StatisticsController {
*/ */
@GetMapping("/overview") @GetMapping("/overview")
public ResponseEntity<UserStatisticsDto> getStatisticsOverview() { public ResponseEntity<UserStatisticsDto> getStatisticsOverview() {
String userId = userContextUtils.getCurrentUserId(); String userId = UserContextUtils.getCurrentUserId();
log.info("获取用户统计概览: userId={}", userId); log.info("获取用户统计概览: userId={}", userId);
UserStatisticsDto statistics = statisticsService.getStatisticsOverview(userId); UserStatisticsDto statistics = statisticsService.getStatisticsOverview(userId);
return ResponseEntity.success(statistics); return ResponseEntity.success(statistics);
} }
@@ -43,9 +40,9 @@ public class StatisticsController {
*/ */
@GetMapping("/uploads") @GetMapping("/uploads")
public ResponseEntity<Object> getUploadTrends() { public ResponseEntity<Object> getUploadTrends() {
String userId = userContextUtils.getCurrentUserId(); String userId = UserContextUtils.getCurrentUserId();
log.info("获取上传趋势: userId={}", userId); log.info("获取上传趋势: userId={}", userId);
Object trends = statisticsService.getUploadTrends(userId); Object trends = statisticsService.getUploadTrends(userId);
return ResponseEntity.success(trends); return ResponseEntity.success(trends);
} }
@@ -56,9 +53,9 @@ public class StatisticsController {
*/ */
@GetMapping("/storage") @GetMapping("/storage")
public ResponseEntity<Object> getStorageBreakdown() { public ResponseEntity<Object> getStorageBreakdown() {
String userId = userContextUtils.getCurrentUserId(); String userId = UserContextUtils.getCurrentUserId();
log.info("获取存储分类: userId={}", userId); log.info("获取存储分类: userId={}", userId);
Object breakdown = statisticsService.getStorageBreakdown(userId); Object breakdown = statisticsService.getStorageBreakdown(userId);
return ResponseEntity.success(breakdown); return ResponseEntity.success(breakdown);
} }
@@ -69,9 +66,9 @@ public class StatisticsController {
*/ */
@PostMapping("/refresh") @PostMapping("/refresh")
public ResponseEntity<Void> refreshStatistics() { public ResponseEntity<Void> refreshStatistics() {
String userId = userContextUtils.getCurrentUserId(); String userId = UserContextUtils.getCurrentUserId();
log.info("强制刷新统计数据: userId={}", userId); log.info("强制刷新统计数据: userId={}", userId);
statisticsService.refreshStatistics(userId); statisticsService.refreshStatistics(userId);
return ResponseEntity.success(null); return ResponseEntity.success(null);
} }