110 lines
4.2 KiB
Python
110 lines
4.2 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 recreate_workorder_menu():
|
||
engine = create_async_engine(DATABASE_URL, echo=False)
|
||
|
||
async with engine.connect() as conn:
|
||
print("=" * 80)
|
||
print("Recreating Work Order Claim Menu")
|
||
print("=" * 80)
|
||
|
||
# 1. 找到测试工单目录(ID:2098)
|
||
print("\n[1] Finding Test Work Order directory...")
|
||
result = await conn.execute(text("""
|
||
SELECT menu_id, menu_name, path FROM sys_menu WHERE menu_id = 2098
|
||
"""))
|
||
row = result.fetchone()
|
||
if row:
|
||
parent_id = row[0]
|
||
print(f" Found: ID:{row[0]} | {row[1]} | Path:{row[2]}")
|
||
else:
|
||
print(" [ERROR] Test Work Order directory not found!")
|
||
return
|
||
|
||
# 2. 检查是否已存在工单领取菜单
|
||
print("\n[2] Checking if work order claim menu exists...")
|
||
result = await conn.execute(text("""
|
||
SELECT COUNT(*) FROM sys_menu WHERE path = 'claim' AND parent_id = 2098
|
||
"""))
|
||
count = result.scalar()
|
||
|
||
if count > 0:
|
||
print(" Work order claim menu already exists")
|
||
else:
|
||
# 3. 创建工单领取菜单
|
||
print("\n[3] Creating work order claim menu...")
|
||
await conn.execute(text(f"""
|
||
INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component,
|
||
is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time)
|
||
VALUES ('工单领取', 2098, 3, 'claim', 'workorder/claim/index',
|
||
0, 0, 'C', '0', '0', 'workorder:claim:list', 'el-icon-s-claim', 'admin', NOW())
|
||
"""))
|
||
await conn.commit()
|
||
print(" [OK] Work order claim menu created")
|
||
|
||
# 获取新创建的菜单ID
|
||
result = await conn.execute(text("""
|
||
SELECT menu_id FROM sys_menu WHERE path = 'claim' AND parent_id = 2098
|
||
"""))
|
||
claim_menu_id = result.scalar()
|
||
|
||
# 4. 创建按钮权限
|
||
print("\n[4] Creating button permissions...")
|
||
buttons = [
|
||
('工单领取查询', 'workorder:claim:query', 1),
|
||
('工单领取', 'workorder:claim:claim', 2),
|
||
('批量领取', 'workorder:claim:batch', 3),
|
||
]
|
||
|
||
for btn_name, btn_perm, order in buttons:
|
||
await conn.execute(text(f"""
|
||
INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component,
|
||
is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time)
|
||
VALUES ('{btn_name}', {claim_menu_id}, {order}, '#', NULL,
|
||
0, 0, 'F', '0', '0', '{btn_perm}', NULL, 'admin', NOW())
|
||
"""))
|
||
await conn.commit()
|
||
print(" [OK] Button permissions created")
|
||
|
||
# 5. 验证
|
||
print("\n[5] Verification:")
|
||
result = await conn.execute(text("""
|
||
SELECT m.menu_id, m.menu_name, m.path, m.component, m.menu_type, p.menu_name as parent_name
|
||
FROM sys_menu m
|
||
LEFT JOIN sys_menu p ON m.parent_id = p.menu_id
|
||
WHERE m.parent_id = 2098
|
||
ORDER BY m.order_num
|
||
"""))
|
||
rows = result.fetchall()
|
||
print(f" Children of Test Work Order directory:")
|
||
for row in rows:
|
||
print(f" ID:{row[0]} | {row[1]} | Path:{row[2]} | Type:{row[4]}")
|
||
|
||
print("\n" + "=" * 80)
|
||
print("Recreate Complete")
|
||
print("=" * 80)
|
||
print("\nPlease logout and login again to refresh the menu")
|
||
|
||
await engine.dispose()
|
||
|
||
if __name__ == '__main__':
|
||
asyncio.run(recreate_workorder_menu())
|