55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
|
|
#!/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 find_parent():
|
||
|
|
engine = create_async_engine(DATABASE_URL, echo=False)
|
||
|
|
|
||
|
|
async with engine.connect() as conn:
|
||
|
|
print("=" * 80)
|
||
|
|
print("Finding Parent Menu")
|
||
|
|
print("=" * 80)
|
||
|
|
|
||
|
|
# 查找测试相关的目录
|
||
|
|
result = await conn.execute(text("""
|
||
|
|
SELECT menu_id, menu_name, path, parent_id, menu_type
|
||
|
|
FROM sys_menu
|
||
|
|
WHERE (menu_name LIKE '%测试%' OR path LIKE '%test%') AND menu_type = 'M'
|
||
|
|
ORDER BY menu_id
|
||
|
|
"""))
|
||
|
|
rows = result.fetchall()
|
||
|
|
print("\nTest related directories:")
|
||
|
|
for row in rows:
|
||
|
|
print(f" ID:{row[0]} | {row[1]} | Path:{row[2]} | Parent:{row[3]}")
|
||
|
|
|
||
|
|
# 查找基础数据管理
|
||
|
|
result = await conn.execute(text("""
|
||
|
|
SELECT menu_id, menu_name, path FROM sys_menu WHERE menu_name = '基础数据管理' AND menu_type = 'M'
|
||
|
|
"""))
|
||
|
|
row = result.fetchone()
|
||
|
|
if row:
|
||
|
|
print(f"\n基础数据管理: ID:{row[0]} | Path:{row[2]}")
|
||
|
|
|
||
|
|
print("\n" + "=" * 80)
|
||
|
|
|
||
|
|
await engine.dispose()
|
||
|
|
|
||
|
|
if __name__ == '__main__':
|
||
|
|
asyncio.run(find_parent())
|