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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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 CheckMediaRecordsTest {
 
    @Autowired
    private JdbcTemplate jdbcTemplate;
 
    @Test
    public void checkMediaRecords() {
        System.out.println("=== 检查数据库表结构 ===");
        
        try {
            // 首先查看所有表
            String showTables = "SHOW TABLES";
            List<Map<String, Object>> tables = jdbcTemplate.queryForList(showTables);
            
            System.out.println("数据库中的表:");
            for (Map<String, Object> table : tables) {
                System.out.println("- " + table.values().iterator().next());
            }
            
            // 检查是否有media相关的表
            System.out.println("\n=== 检查media相关表 ===");
            for (Map<String, Object> table : tables) {
                String tableName = table.values().iterator().next().toString();
                if (tableName.toLowerCase().contains("media")) {
                    System.out.println("找到media相关表: " + tableName);
                    
                    try {
                        // 查看表结构
                        String descTable = "DESC " + tableName;
                        List<Map<String, Object>> columns = jdbcTemplate.queryForList(descTable);
                        System.out.println("表结构:");
                        for (Map<String, Object> column : columns) {
                            System.out.println("  " + column.get("Field") + " - " + column.get("Type"));
                        }
                        
                        // 查看记录数量
                        String countSql = "SELECT COUNT(*) as count FROM " + tableName;
                        Map<String, Object> countResult = jdbcTemplate.queryForMap(countSql);
                        System.out.println("记录数量: " + countResult.get("count"));
                        
                        // 如果有记录,查看最近几条
                        Long count = (Long) countResult.get("count");
                        if (count > 0) {
                            String sampleSql = "SELECT * FROM " + tableName + " ORDER BY id DESC LIMIT 3";
                            List<Map<String, Object>> samples = jdbcTemplate.queryForList(sampleSql);
                            System.out.println("最近3条记录:");
                            for (Map<String, Object> sample : samples) {
                                System.out.println("  " + sample);
                            }
                            
                            // 如果是t_media表,专门查询targetType=5的记录
                            if ("t_media".equals(tableName)) {
                                try {
                                    List<Map<String, Object>> targetType5Records = jdbcTemplate.queryForList(
                                        "SELECT * FROM t_media WHERE target_type = 5 ORDER BY create_time DESC"
                                    );
                                    System.out.println("targetType=5的记录数量: " + targetType5Records.size());
                                    if (!targetType5Records.isEmpty()) {
                                        System.out.println("targetType=5的记录:");
                                        for (Map<String, Object> record : targetType5Records) {
                                            System.out.println("  " + record);
                                        }
                                    } else {
                                        System.out.println("没有找到targetType=5的记录");
                                    }
                                } catch (Exception e) {
                                    System.out.println("查询targetType=5记录失败: " + e.getMessage());
                                }
                            }
                        }
                    } catch (Exception e) {
                        System.out.println("查询表 " + tableName + " 时出错: " + e.getMessage());
                    }
                    System.out.println();
                }
            }
            
            // 查看activity_player相关的表
            System.out.println("=== 检查activity_player相关表 ===");
            for (Map<String, Object> table : tables) {
                String tableName = table.values().iterator().next().toString();
                if (tableName.toLowerCase().contains("activity") && tableName.toLowerCase().contains("player")) {
                    System.out.println("找到activity_player相关表: " + tableName);
                    
                    try {
                        // 查看记录数量
                        String countSql = "SELECT COUNT(*) as count FROM " + tableName;
                        Map<String, Object> countResult = jdbcTemplate.queryForMap(countSql);
                        System.out.println("记录数量: " + countResult.get("count"));
                        
                        // 查看最近几条记录
                        String sampleSql = "SELECT * FROM " + tableName + " ORDER BY id DESC LIMIT 3";
                        List<Map<String, Object>> samples = jdbcTemplate.queryForList(sampleSql);
                        System.out.println("最近3条记录:");
                        for (Map<String, Object> sample : samples) {
                            System.out.println("  " + sample);
                        }
                    } catch (Exception e) {
                        System.out.println("查询表 " + tableName + " 时出错: " + e.getMessage());
                    }
                    System.out.println();
                }
            }
            
        } catch (Exception e) {
            System.out.println("数据库查询出错: " + e.getMessage());
            e.printStackTrace();
        }
    }
}