| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- # -*- coding: utf-8 -*-
- """Upsert 通知配置菜单 (Id=1310300010106) 到共享库。
- 做法:以 审批统计(Id=1310300010105) 记录为模板深拷贝,覆盖 Id / Title / Path / Name / Component / Icon / OrderNo。
- 然后将所有已授权给 105 的 Role / Tenant 复制到 106。
- """
- import pymysql
- conn = pymysql.connect(
- host='123.60.180.165', port=3306,
- user='aidopremote', password='1234567890aiDOP#',
- database='aidopdev', charset='utf8mb4', autocommit=True,
- )
- try:
- with conn.cursor(pymysql.cursors.DictCursor) as cur:
- cur.execute("SELECT 1 FROM SysMenu WHERE Id = 1310300010106")
- if cur.fetchone():
- print("menu exists, skip insert")
- else:
- cur.execute("SELECT * FROM SysMenu WHERE Id = 1310300010105")
- src = cur.fetchone()
- if not src:
- print("!! 源菜单 1310300010105 不存在,中止。先执行菜单种子修复脚本。")
- raise SystemExit(1)
- new_row = dict(src)
- new_row['Id'] = 1310300010106
- new_row['Title'] = '通知配置'
- new_row['Path'] = '/aidop/flowManage/flowNotifyConfig'
- new_row['Name'] = 'flowNotifyConfig'
- new_row['Component'] = '/approvalFlow/notifyConfig/index'
- new_row['Icon'] = 'ele-Bell'
- new_row['OrderNo'] = 150
- new_row['Remark'] = '审批流通知模板与渠道配置管理'
- cols = list(new_row.keys())
- placeholders = ", ".join(["%s"] * len(cols))
- col_list = ", ".join(f"`{c}`" for c in cols)
- sql = f"INSERT INTO SysMenu ({col_list}) VALUES ({placeholders})"
- cur.execute(sql, list(new_row.values()))
- print(f"menu inserted: 通知配置 Id=1310300010106")
- # Role 授权复制
- cur.execute("SELECT DISTINCT RoleId FROM SysRoleMenu WHERE MenuId = 1310300010105")
- role_ids = [r['RoleId'] for r in cur.fetchall()]
- print(f"roles with 审批统计 access: {role_ids}")
- for rid in role_ids:
- cur.execute("SELECT 1 FROM SysRoleMenu WHERE RoleId=%s AND MenuId=1310300010106", (rid,))
- if cur.fetchone():
- continue
- cur.execute("SELECT * FROM SysRoleMenu WHERE RoleId=%s AND MenuId=1310300010105 LIMIT 1", (rid,))
- src = cur.fetchone()
- if not src:
- continue
- new_row = dict(src)
- new_row['Id'] = None
- new_row['MenuId'] = 1310300010106
- # 使用 UUID_SHORT
- cols = [c for c in new_row.keys() if c != 'Id']
- placeholders = ", ".join(["%s"] * len(cols))
- col_list = ", ".join(f"`{c}`" for c in cols) + ", `Id`"
- sql = f"INSERT INTO SysRoleMenu ({col_list}) VALUES ({placeholders}, UUID_SHORT())"
- cur.execute(sql, [new_row[c] for c in cols])
- print(f" granted RoleMenu: Role={rid} -> Menu=106")
- # Tenant 授权复制
- cur.execute("SELECT DISTINCT TenantId FROM SysTenantMenu WHERE MenuId = 1310300010105")
- t_ids = [r['TenantId'] for r in cur.fetchall()]
- print(f"tenants with 审批统计 access: {t_ids}")
- for tid in t_ids:
- cur.execute("SELECT 1 FROM SysTenantMenu WHERE TenantId=%s AND MenuId=1310300010106", (tid,))
- if cur.fetchone():
- continue
- cur.execute("SELECT * FROM SysTenantMenu WHERE TenantId=%s AND MenuId=1310300010105 LIMIT 1", (tid,))
- src = cur.fetchone()
- if not src:
- continue
- new_row = dict(src)
- new_row['Id'] = None
- new_row['MenuId'] = 1310300010106
- cols = [c for c in new_row.keys() if c != 'Id']
- placeholders = ", ".join(["%s"] * len(cols))
- col_list = ", ".join(f"`{c}`" for c in cols) + ", `Id`"
- sql = f"INSERT INTO SysTenantMenu ({col_list}) VALUES ({placeholders}, UUID_SHORT())"
- cur.execute(sql, [new_row[c] for c in cols])
- print(f" granted TenantMenu: Tenant={tid} -> Menu=106")
- print("verify:")
- cur.execute("SELECT Id, Pid, Title, Path, Component FROM SysMenu WHERE Id=1310300010106")
- print(cur.fetchone())
- cur.execute("SELECT COUNT(*) AS n FROM SysRoleMenu WHERE MenuId=1310300010106")
- print("RoleMenu count:", cur.fetchone())
- cur.execute("SELECT COUNT(*) AS n FROM SysTenantMenu WHERE MenuId=1310300010106")
- print("TenantMenu count:", cur.fetchone())
- finally:
- conn.close()
- print("done")
|