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();
|
}
|
}
|
}
|