"""检查备课模块相关的数据库表"""
import mysql.connector

conn = mysql.connector.connect(
    host="mysql.eazygame.cn",
    port=14013,
    user="root",
    password="wx1998WX",
    database="next_edu"
)
cursor = conn.cursor()

# 检查 class_subject_teachers 表
try:
    cursor.execute("DESCRIBE class_subject_teachers")
    cols = cursor.fetchall()
    print("=== class_subject_teachers 表结构 ===")
    for c in cols:
        print(f"  {c[0]}: {c[1]}")
except Exception as e:
    print(f"❌ class_subject_teachers 表不存在: {e}")

# 检查教师的 class_subject_teachers 数据
try:
    cursor.execute("""
        SELECT * FROM class_subject_teachers
        WHERE teacher_id = 'user_T_C1'
    """)
    rows = cursor.fetchall()
    print(f"\n=== 教师 T_C1 的 class_subject_teachers 数据 ({len(rows)} 行) ===")
    for r in rows:
        print(f"  {r}")
except Exception as e:
    print(f"❌ 查询失败: {e}")

# 检查 lesson_plans 表结构
try:
    cursor.execute("DESCRIBE lesson_plans")
    cols = cursor.fetchall()
    print("\n=== lesson_plans 表结构 ===")
    for c in cols:
        print(f"  {c[0]}: {c[1]}")
except Exception as e:
    print(f"❌ lesson_plans 表不存在: {e}")

# 检查 lesson_plans 数据
try:
    cursor.execute("""
        SELECT id, title, status, creator_id, subject_id, grade_id
        FROM lesson_plans
        LIMIT 10
    """)
    rows = cursor.fetchall()
    print(f"\n=== lesson_plans 数据 ({len(rows)} 行) ===")
    for r in rows:
        print(f"  {r}")
except Exception as e:
    print(f"❌ 查询失败: {e}")

# 检查 subjects 表
try:
    cursor.execute("SELECT * FROM subjects")
    rows = cursor.fetchall()
    print(f"\n=== subjects 数据 ({len(rows)} 行) ===")
    for r in rows:
        print(f"  {r}")
except Exception as e:
    print(f"❌ 查询失败: {e}")

cursor.close()
conn.close()
