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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package com.rongyichuang;
 
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.JdbcTemplate;
 
import java.util.List;
import java.util.Map;
 
@SpringBootTest
public class CheckActivityDataTest {
 
    @Autowired
    private JdbcTemplate jdbcTemplate;
 
    @Test
    public void checkActivityData() {
        try {
            // 检查t_activity表结构
            String descSql = "DESC t_activity";
            List<Map<String, Object>> columns = jdbcTemplate.queryForList(descSql);
            System.out.println("=== t_activity 表结构 ===");
            for (Map<String, Object> column : columns) {
                System.out.println("字段: " + column.get("Field") + 
                                 ", 类型: " + column.get("Type") + 
                                 ", 是否为空: " + column.get("Null") + 
                                 ", 键: " + column.get("Key") + 
                                 ", 默认值: " + column.get("Default"));
            }
            
            // 统计活动数据
            String countSql = "SELECT COUNT(*) as total FROM t_activity";
            Integer totalCount = jdbcTemplate.queryForObject(countSql, Integer.class);
            System.out.println("\n=== 活动数据统计 ===");
            System.out.println("活动记录总数: " + totalCount);
            
            // 按状态统计
            String countByStateSql = "SELECT state, COUNT(*) as count FROM t_activity GROUP BY state";
            List<Map<String, Object>> stateStats = jdbcTemplate.queryForList(countByStateSql);
            System.out.println("\n=== 按状态统计 ===");
            for (Map<String, Object> stat : stateStats) {
                System.out.println("状态: " + stat.get("state") + ", 数量: " + stat.get("count"));
            }
            
            // 按pid统计(区分比赛和阶段)
            String countByPidSql = "SELECT pid, COUNT(*) as count FROM t_activity GROUP BY pid";
            List<Map<String, Object>> pidStats = jdbcTemplate.queryForList(countByPidSql);
            System.out.println("\n=== 按PID统计(0=比赛,>0=阶段) ===");
            for (Map<String, Object> stat : pidStats) {
                System.out.println("PID: " + stat.get("pid") + ", 数量: " + stat.get("count"));
            }
            
            // 查看前5条活动数据
            String dataSql = "SELECT id, pid, name, state, create_time FROM t_activity ORDER BY id LIMIT 5";
            List<Map<String, Object>> activityData = jdbcTemplate.queryForList(dataSql);
            System.out.println("\n=== 前5条活动数据 ===");
            for (Map<String, Object> activity : activityData) {
                System.out.println("ID: " + activity.get("id") + 
                                 ", PID: " + activity.get("pid") + 
                                 ", 名称: " + activity.get("name") + 
                                 ", 状态: " + activity.get("state") + 
                                 ", 创建时间: " + activity.get("create_time"));
            }
            
            // 查看有效的比赛(pid=0, state=1)
            String competitionSql = "SELECT id, name, state, signup_deadline, match_time FROM t_activity WHERE pid = 0 AND state = 1 ORDER BY id";
            List<Map<String, Object>> competitions = jdbcTemplate.queryForList(competitionSql);
            System.out.println("\n=== 有效的比赛数据 ===");
            for (Map<String, Object> competition : competitions) {
                System.out.println("ID: " + competition.get("id") + 
                                 ", 名称: " + competition.get("name") + 
                                 ", 状态: " + competition.get("state") + 
                                 ", 报名截止: " + competition.get("signup_deadline") + 
                                 ", 比赛时间: " + competition.get("match_time"));
            }
            
        } catch (Exception e) {
            System.out.println("查询失败: " + e.getMessage());
            e.printStackTrace();
        }
    }
}