lrj
2 天以前 93eb6b470773bc49ea6e1a9d4cbd914eb95d525b
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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 org.springframework.test.context.ActiveProfiles;
 
import java.util.List;
import java.util.Map;
 
@SpringBootTest
@ActiveProfiles("test")
public class CheckUserPermissionTest {
 
    @Autowired
    private JdbcTemplate jdbcTemplate;
 
    @Test
    public void checkUserJudgePermission() {
        System.out.println("=== 检查用户ID=2的评委权限 ===");
        
        try {
            // 先查看用户表结构
            String describeUserSql = "DESCRIBE t_user";
            List<Map<String, Object>> userTableStructure = jdbcTemplate.queryForList(describeUserSql);
            System.out.println("用户表结构:");
            for (Map<String, Object> column : userTableStructure) {
                System.out.println("字段: " + column.get("Field") + ", 类型: " + column.get("Type"));
            }
            
            // 1. 检查用户ID=2是否关联了评委记录
            String userJudgeSql = "SELECT u.id as user_id, u.phone, j.id as judge_id, j.name as judge_name " +
                                 "FROM t_user u LEFT JOIN t_judge j ON u.id = j.user_id WHERE u.id = 2";
            List<Map<String, Object>> userJudgeData = jdbcTemplate.queryForList(userJudgeSql);
            
            System.out.println("\n用户评委关联数据:");
            for (Map<String, Object> row : userJudgeData) {
                System.out.println("用户ID: " + row.get("user_id") + 
                                 ", 手机号: " + row.get("phone") + 
                                 ", 评委ID: " + row.get("judge_id") + 
                                 ", 评委姓名: " + row.get("judge_name"));
            }
            
            // 2. 如果有评委记录,检查评委的活动权限
            if (!userJudgeData.isEmpty() && userJudgeData.get(0).get("judge_id") != null) {
                Long judgeId = ((Number) userJudgeData.get(0).get("judge_id")).longValue();
                
                String activityJudgeSql = "SELECT aj.activity_id, aj.judge_id, aj.state, a.name as activity_name " +
                                         "FROM t_activity_judge aj " +
                                         "LEFT JOIN t_activity a ON aj.activity_id = a.id " +
                                         "WHERE aj.judge_id = ?";
                List<Map<String, Object>> activityJudgeData = jdbcTemplate.queryForList(activityJudgeSql, judgeId);
                
                System.out.println("\n评委活动权限数据:");
                for (Map<String, Object> row : activityJudgeData) {
                    System.out.println("活动ID: " + row.get("activity_id") + 
                                     ", 活动名称: " + row.get("activity_name") + 
                                     ", 评委ID: " + row.get("judge_id") + 
                                     ", 状态: " + row.get("state"));
                }
                
                if (activityJudgeData.isEmpty()) {
                    System.out.println("❌ 评委ID=" + judgeId + " 没有任何活动的评审权限");
                }
            } else {
                System.out.println("❌ 用户ID=2 没有关联评委记录");
            }
            
            // 3. 检查所有活动的信息
            String allActivitiesSql = "SELECT id, name, state FROM t_activity ORDER BY id";
            List<Map<String, Object>> allActivities = jdbcTemplate.queryForList(allActivitiesSql);
            
            System.out.println("\n所有活动信息:");
            for (Map<String, Object> row : allActivities) {
                System.out.println("活动ID: " + row.get("id") + 
                                 ", 活动名称: " + row.get("name") + 
                                 ", 状态: " + row.get("state"));
            }
            
            // 4. 检查所有评委信息
            String allJudgesSql = "SELECT id, name, user_id FROM t_judge ORDER BY id";
            List<Map<String, Object>> allJudges = jdbcTemplate.queryForList(allJudgesSql);
            
            System.out.println("\n所有评委信息:");
            for (Map<String, Object> row : allJudges) {
                System.out.println("评委ID: " + row.get("id") + 
                                 ", 评委姓名: " + row.get("name") + 
                                 ", 用户ID: " + row.get("user_id"));
            }
            
        } catch (Exception e) {
            System.out.println("检查权限时发生异常: " + e.getMessage());
            e.printStackTrace();
        }
    }
}