backend/src/test/java/com/rongyichuang/DatabaseConnectionTest.java
@@ -8,9 +8,6 @@
import java.util.List;
import java.util.Map;
/**
 * 数据库连接测试
 */
@SpringBootTest
public class DatabaseConnectionTest {
@@ -20,48 +17,43 @@
    @Test
    public void testDatabaseConnection() {
        try {
            // 测试数据库连接
            String sql = "SELECT 1 as test";
            Integer result = jdbcTemplate.queryForObject(sql, Integer.class);
            System.out.println("数据库连接测试成功,结果: " + result);
            // 检查数据库连接
            String result = jdbcTemplate.queryForObject("SELECT 1", String.class);
            System.out.println("✅ 数据库连接成功: " + result);
            
            // 查询所有表
            String tablesSql = "SHOW TABLES";
            List<Map<String, Object>> tables = jdbcTemplate.queryForList(tablesSql);
            System.out.println("数据库中的表:");
            for (Map<String, Object> table : tables) {
                System.out.println("- " + table.values().iterator().next());
            }
        } catch (Exception e) {
            System.err.println("数据库连接测试失败: " + e.getMessage());
            e.printStackTrace();
        }
    }
    @Test
    public void testTableStructure() {
        try {
            // 获取表结构信息
            String[] tables = {"t_activity", "t_judge", "t_player", "t_rating_scheme", "t_carousel", "t_employee", "t_media", "t_tag"};
            for (String tableName : tables) {
                try {
                    String sql = "DESCRIBE " + tableName;
                    List<Map<String, Object>> columns = jdbcTemplate.queryForList(sql);
                    System.out.println("\n表 " + tableName + " 的结构:");
            // 检查t_wx_login_record表是否存在
            try {
                String checkTableSql = "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'ryc' AND table_name = 't_wx_login_record'";
                Integer tableExists = jdbcTemplate.queryForObject(checkTableSql, Integer.class);
                if (tableExists != null && tableExists > 0) {
                    System.out.println("✅ t_wx_login_record表存在");
                    // 查看表结构
                    String describeTableSql = "DESCRIBE t_wx_login_record";
                    List<Map<String, Object>> columns = jdbcTemplate.queryForList(describeTableSql);
                    System.out.println("表结构:");
                    for (Map<String, Object> column : columns) {
                        System.out.println("  " + column.get("Field") + " - " + column.get("Type") +
                                         (column.get("Null").equals("NO") ? " NOT NULL" : "") +
                                         (column.get("Key").equals("PRI") ? " PRIMARY KEY" : ""));
                        System.out.println("- " + column.get("Field") + ": " + column.get("Type") +
                                         (column.get("Null").equals("NO") ? " NOT NULL" : " NULL") +
                                         (column.get("Default") != null ? " DEFAULT " + column.get("Default") : ""));
                    }
                } catch (Exception e) {
                    System.out.println("表 " + tableName + " 不存在或查询失败: " + e.getMessage());
                    // 检查表中是否有数据
                    String countSql = "SELECT COUNT(*) FROM t_wx_login_record";
                    Integer recordCount = jdbcTemplate.queryForObject(countSql, Integer.class);
                    System.out.println("表中记录数: " + recordCount);
                } else {
                    System.out.println("❌ t_wx_login_record表不存在");
                }
            } catch (Exception e) {
                System.out.println("❌ 检查t_wx_login_record表时出错: " + e.getMessage());
                e.printStackTrace();
            }
            
        } catch (Exception e) {
            System.err.println("查询表结构失败: " + e.getMessage());
            System.out.println("❌ 数据库连接失败: " + e.getMessage());
            e.printStackTrace();
        }
    }