lrj
6 天以前 4fa9591629721797386fc11836e3a9deb69cd58c
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
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 TableStructureTest {
 
    @Autowired
    private JdbcTemplate jdbcTemplate;
 
    @Test
    public void testActivityPlayerRatingItemTableStructure() {
        try {
            String sql = "DESCRIBE t_activity_player_rating_item";
            List<Map<String, Object>> result = jdbcTemplate.queryForList(sql);
            System.out.println("=== t_activity_player_rating_item 表结构 ===");
            for (Map<String, Object> row : result) {
                System.out.println(row);
            }
        } catch (Exception e) {
            System.out.println("查询表结构失败: " + e.getMessage());
            e.printStackTrace();
        }
    }
 
    @Test
    public void testActivityPlayerTableStructure() {
        try {
            String sql = "DESCRIBE t_activity_player";
            List<Map<String, Object>> result = jdbcTemplate.queryForList(sql);
            System.out.println("=== t_activity_player 表结构 ===");
            for (Map<String, Object> row : result) {
                System.out.println(row);
            }
        } catch (Exception e) {
            System.out.println("查询表结构失败: " + e.getMessage());
            e.printStackTrace();
        }
    }
 
    @Test
    public void testVerifyRatingData() {
        // 查询刚才插入的评分数据
        String sql = "SELECT * FROM t_activity_player_rating_item WHERE player_id = 12 ORDER BY create_time DESC LIMIT 5";
        List<Map<String, Object>> results = jdbcTemplate.queryForList(sql);
        
        System.out.println("最新的评分数据:");
        for (Map<String, Object> row : results) {
            System.out.println(row);
        }
        
        // 查询总分更新情况
        String totalScoreSql = "SELECT id, total_score, update_time FROM t_activity_player WHERE id = 12";
        List<Map<String, Object>> totalResults = jdbcTemplate.queryForList(totalScoreSql);
        
        System.out.println("总分更新情况:");
        for (Map<String, Object> row : totalResults) {
            System.out.println(row);
        }
    }
 
    @Test
    public void testInsertSample() {
        try {
            String sql = "INSERT INTO t_activity_player_rating_item " +
                    "(activity_id, player_id, rating_scheme_id, rating_item_id, score, feedback, create_time, update_time, version) " +
                    "VALUES (1, 1, 1, 1, 85.5, 'test', NOW(), NOW(), 0)";
            int result = jdbcTemplate.update(sql);
            System.out.println("插入测试记录成功,影响行数: " + result);
        } catch (Exception e) {
            System.out.println("插入测试记录失败: " + e.getMessage());
            e.printStackTrace();
        }
    }
 
    @Test
    public void testJudgeTableStructure() {
        try {
            String sql = "DESCRIBE t_judge";
            List<Map<String, Object>> result = jdbcTemplate.queryForList(sql);
            System.out.println("=== t_judge 表结构 ===");
            for (Map<String, Object> row : result) {
                System.out.println(row);
            }
        } catch (Exception e) {
            System.out.println("查询表结构失败: " + e.getMessage());
            e.printStackTrace();
        }
    }
 
    @Test
    public void testExecuteMigration() {
        try {
            // 为t_judge表添加缺失的字段
            String[] sqls = {
                "ALTER TABLE t_judge ADD COLUMN title VARCHAR(128) COMMENT '职位/头衔'",
                "ALTER TABLE t_judge ADD COLUMN company VARCHAR(128) COMMENT '公司/机构'", 
                "ALTER TABLE t_judge ADD COLUMN introduction TEXT COMMENT '个人介绍'"
            };
            
            for (String sql : sqls) {
                try {
                    jdbcTemplate.execute(sql);
                    System.out.println("执行成功: " + sql);
                } catch (Exception e) {
                    if (e.getMessage().contains("Duplicate column name")) {
                        System.out.println("字段已存在,跳过: " + sql);
                    } else {
                        System.out.println("执行失败: " + sql + " - " + e.getMessage());
                    }
                }
            }
        } catch (Exception e) {
            System.out.println("执行迁移失败: " + e.getMessage());
            e.printStackTrace();
        }
    }
 
    @Test
    public void testRollbackAvatarFields() {
        try {
            // 移除不必要的avatar相关字段
            String[] sqls = {
                "ALTER TABLE t_judge DROP COLUMN avatar_url",
                "ALTER TABLE t_judge DROP COLUMN avatar_media_id"
            };
            
            for (String sql : sqls) {
                try {
                    jdbcTemplate.execute(sql);
                    System.out.println("回滚成功: " + sql);
                } catch (Exception e) {
                    if (e.getMessage().contains("check that column/key exists")) {
                        System.out.println("字段不存在,跳过: " + sql);
                    } else {
                        System.out.println("回滚失败: " + sql + " - " + e.getMessage());
                    }
                }
            }
        } catch (Exception e) {
            System.out.println("执行回滚失败: " + e.getMessage());
            e.printStackTrace();
        }
    }
}