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 SimpleUserCheckTest {
|
|
@Autowired
|
private JdbcTemplate jdbcTemplate;
|
|
@Test
|
public void checkUser2Permission() {
|
System.out.println("=== 检查用户ID=2的评委权限问题 ===");
|
|
try {
|
// 1. 检查用户ID=2是否存在
|
String userExistsSql = "SELECT COUNT(*) as count FROM t_user WHERE id = 2";
|
Map<String, Object> userExists = jdbcTemplate.queryForMap(userExistsSql);
|
System.out.println("用户ID=2是否存在: " + userExists.get("count"));
|
|
// 2. 检查用户ID=2是否关联了评委
|
String judgeExistsSql = "SELECT COUNT(*) as count FROM t_judge WHERE user_id = 2";
|
Map<String, Object> judgeExists = jdbcTemplate.queryForMap(judgeExistsSql);
|
System.out.println("用户ID=2关联的评委数量: " + judgeExists.get("count"));
|
|
// 3. 如果有评委,获取评委ID
|
if (((Number) judgeExists.get("count")).intValue() > 0) {
|
String getJudgeIdSql = "SELECT id, name FROM t_judge WHERE user_id = 2";
|
List<Map<String, Object>> judges = jdbcTemplate.queryForList(getJudgeIdSql);
|
for (Map<String, Object> judge : judges) {
|
Long judgeId = ((Number) judge.get("id")).longValue();
|
String judgeName = (String) judge.get("name");
|
System.out.println("评委ID: " + judgeId + ", 评委姓名: " + judgeName);
|
|
// 4. 检查该评委的活动权限
|
String activityPermissionSql = "SELECT COUNT(*) as count FROM t_activity_judge WHERE judge_id = ?";
|
Map<String, Object> activityPermission = jdbcTemplate.queryForMap(activityPermissionSql, judgeId);
|
System.out.println("评委ID=" + judgeId + " 的活动权限数量: " + activityPermission.get("count"));
|
|
// 5. 列出具体的活动权限
|
if (((Number) activityPermission.get("count")).intValue() > 0) {
|
String activityDetailsSql = "SELECT activity_id, state FROM t_activity_judge WHERE judge_id = ?";
|
List<Map<String, Object>> activities = jdbcTemplate.queryForList(activityDetailsSql, judgeId);
|
System.out.println("具体活动权限:");
|
for (Map<String, Object> activity : activities) {
|
System.out.println(" 活动ID: " + activity.get("activity_id") + ", 状态: " + activity.get("state"));
|
}
|
} else {
|
System.out.println("❌ 该评委没有任何活动的评审权限!");
|
}
|
}
|
} else {
|
System.out.println("❌ 用户ID=2 没有关联任何评委记录!");
|
|
// 查看所有有用户ID的评委
|
String allJudgesWithUserSql = "SELECT id, name, user_id FROM t_judge WHERE user_id IS NOT NULL";
|
List<Map<String, Object>> allJudges = jdbcTemplate.queryForList(allJudgesWithUserSql);
|
System.out.println("所有有用户ID的评委:");
|
for (Map<String, Object> judge : allJudges) {
|
System.out.println(" 评委ID: " + judge.get("id") +
|
", 姓名: " + judge.get("name") +
|
", 用户ID: " + judge.get("user_id"));
|
}
|
}
|
|
} catch (Exception e) {
|
System.out.println("检查权限时发生异常: " + e.getMessage());
|
e.printStackTrace();
|
}
|
}
|
}
|