#!/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 fix_router_path(): engine = create_async_engine(DATABASE_URL, echo=False) async with engine.connect() as conn: print("=" * 80) print("Fixing Router Path - Adding Leading Slash") print("=" * 80) # 1. 修复工单管理目录 print("\n[1] Fixing Work Order Management Directory...") await conn.execute(text(""" UPDATE sys_menu SET path = '/workorder' WHERE menu_id = 2112 """)) await conn.commit() print(" [OK] Path changed to: /workorder") # 2. 修复工单领取菜单 print("\n[2] Fixing Work Order Claim Menu...") await conn.execute(text(""" UPDATE sys_menu SET path = '/workorder/claim' WHERE menu_id = 2113 """)) await conn.commit() print(" [OK] Path changed to: /workorder/claim") # 3. 检查其他可能需要修复的菜单 print("\n[3] Checking other menus that may need fixing...") result = await conn.execute(text(""" SELECT menu_id, menu_name, path, menu_type FROM sys_menu WHERE parent_id = 0 AND path NOT LIKE '/%' AND menu_type IN ('M', 'C') AND path IS NOT NULL AND path != '' ORDER BY menu_id """)) rows = result.fetchall() for row in rows: print(f" ID:{row[0]} | Type:{row[3]} | Current Path: {row[2]}") # 4. 修复所有一级目录和菜单的路径 print("\n[4] Fixing all top-level menu paths...") await conn.execute(text(""" UPDATE sys_menu SET path = CONCAT('/', path) WHERE parent_id = 0 AND path NOT LIKE '/%' AND path IS NOT NULL AND path != '' """)) await conn.commit() print(" [OK] All top-level menu paths fixed") # 5. 验证修复结果 print("\n[5] Verification:") result = await conn.execute(text(""" SELECT menu_id, menu_name, path, menu_type FROM sys_menu WHERE menu_id IN (2112, 2113) """)) rows = result.fetchall() for row in rows: print(f" ID:{row[0]} | {row[1]} | Path: {row[2]} | Type:{row[3]}") print("\n" + "=" * 80) print("Fix Complete") print("=" * 80) print("\nPlease logout and login again to refresh the menu") await engine.dispose() if __name__ == '__main__': asyncio.run(fix_router_path())