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> tables = jdbcTemplate.queryForList(showTables); System.out.println("数据库中的表:"); for (Map table : tables) { System.out.println("- " + table.values().iterator().next()); } // 检查是否有media相关的表 System.out.println("\n=== 检查media相关表 ==="); for (Map 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> columns = jdbcTemplate.queryForList(descTable); System.out.println("表结构:"); for (Map column : columns) { System.out.println(" " + column.get("Field") + " - " + column.get("Type")); } // 查看记录数量 String countSql = "SELECT COUNT(*) as count FROM " + tableName; Map 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> samples = jdbcTemplate.queryForList(sampleSql); System.out.println("最近3条记录:"); for (Map sample : samples) { System.out.println(" " + sample); } // 如果是t_media表,专门查询targetType=5的记录 if ("t_media".equals(tableName)) { try { List> 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 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 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 countResult = jdbcTemplate.queryForMap(countSql); System.out.println("记录数量: " + countResult.get("count")); // 查看最近几条记录 String sampleSql = "SELECT * FROM " + tableName + " ORDER BY id DESC LIMIT 3"; List> samples = jdbcTemplate.queryForList(sampleSql); System.out.println("最近3条记录:"); for (Map 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(); } } }