lrj
昨天 9f8395fab13ca4b230a0f7d62636e209745c91d4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.rongyichuang.dashboard.service;
 
import com.rongyichuang.activity.repository.ActivityRepository;
import com.rongyichuang.judge.repository.JudgeRepository;
import com.rongyichuang.player.repository.ActivityPlayerRepository;
import com.rongyichuang.player.repository.PlayerRepository;
import com.rongyichuang.dashboard.dto.response.DashboardStatsResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
/**
 * Dashboard 统计数据服务
 */
@Service
public class DashboardService {
 
    @Autowired
    private ActivityRepository activityRepository;
    
    @Autowired
    private PlayerRepository playerRepository;
    
    @Autowired
    private ActivityPlayerRepository activityPlayerRepository;
    
    @Autowired
    private JudgeRepository judgeRepository;
 
    /**
     * 获取Dashboard统计数据
     */
    public DashboardStatsResponse getDashboardStats() {
        DashboardStatsResponse stats = new DashboardStatsResponse();
        
        // 当前进行比赛数量(状态为1的比赛,pid=0表示主比赛)
        long activeActivities = activityRepository.countActiveActivities();
        stats.setActiveActivities((int) activeActivities);
        
        // 参赛总人数(状态为1的选手)
        long totalPlayers = playerRepository.countByState(1);
        stats.setTotalPlayers((int) totalPlayers);
        
        // 报名待审核人数(activityPlayer状态为1表示待审核)
        long pendingReviews = activityPlayerRepository.countByState(1);
        stats.setPendingReviews((int) pendingReviews);
        
        // 评委总数(状态为1的评委)
        long totalJudges = judgeRepository.countByState(1);
        stats.setTotalJudges((int) totalJudges);
        
        return stats;
    }
}