#!/usr/bin/env python3 """分析测试类别结构""" import asyncio from sqlalchemy.ext.asyncio import create_async_engine from sqlalchemy import text DB_CONFIG = { 'host': '123.57.81.127', 'port': 3306, 'user': 'cpy_admin', 'password': 'Tgzz2025+', 'database': 'ruoyi-fastapi' } DATABASE_URL = ( f"mysql+asyncmy://{DB_CONFIG['user']}:{DB_CONFIG['password']}@" f"{DB_CONFIG['host']}:{DB_CONFIG['port']}/{DB_CONFIG['database']}" ) async def analyze_test_category(): engine = create_async_engine(DATABASE_URL, echo=False) async with engine.connect() as conn: print("=" * 80) print("Test Category Structure Analysis") print("=" * 80) # 1. 检查 test_category 表结构 print("\n[1] test_category table structure:") result = await conn.execute(text("DESCRIBE test_category")) rows = result.fetchall() for row in rows: print(f" {row[0]:<20} | {row[1]:<20} | {row[2]:<10} | {row[3]}") # 2. 检查现有测试类别数据 print("\n[2] Current test_category data:") result = await conn.execute(text(""" SELECT id, name, parent_id, level, category_code, sort_order, report_config_type FROM test_category ORDER BY parent_id, sort_order """)) rows = result.fetchall() for row in rows: parent_str = f"Parent:{row[2]}" if row[2] else "Root" print(f" ID:{row[0]:<3} | {row[1]:<15} | {parent_str:<12} | Level:{row[3]} | Code:{row[4]} | Sort:{row[5]} | ReportType:{row[6]}") # 3. 检查 test_item 表结构 print("\n[3] test_item table structure:") result = await conn.execute(text("DESCRIBE test_item")) rows = result.fetchall() for row in rows: print(f" {row[0]:<20} | {row[1]:<20} | {row[2]:<10} | {row[3]}") # 4. 检查现有测试单元数据 print("\n[4] Current test_item data:") result = await conn.execute(text(""" SELECT id, name, test_category_id, eut_type_id FROM test_item ORDER BY test_category_id """)) rows = result.fetchall() for row in rows: print(f" ID:{row[0]:<3} | {row[1]:<15} | CategoryID:{row[2]} | EutTypeID:{row[3]}") # 5. 检查 test_category_detail 表 print("\n[5] test_category_detail table structure:") result = await conn.execute(text("DESCRIBE test_category_detail")) rows = result.fetchall() for row in rows: print(f" {row[0]:<20} | {row[1]:<20} | {row[2]:<10} | {row[3]}") # 6. 检查 test_category_detail 数据 print("\n[6] Current test_category_detail data:") result = await conn.execute(text(""" SELECT id, test_category_id, detail_type, detail_name, detail_value FROM test_category_detail ORDER BY test_category_id, detail_type """)) rows = result.fetchall() for row in rows: print(f" ID:{row[0]:<3} | CategoryID:{row[1]} | Type:{row[2]:<15} | Name:{row[3]:<15} | Value:{row[4]}") print("\n" + "=" * 80) print("Analysis Complete") print("=" * 80) await engine.dispose() if __name__ == '__main__': asyncio.run(analyze_test_category())