_apply_notify_tpl_cfg.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # -*- coding: utf-8 -*-
  2. """P4-16 扩展:模板 / 渠道覆盖层 DDL + 通知配置菜单落库。
  3. 对应决策:
  4. - 共享开发库 EnableInitDb/EnableInitTable 均为 false,需手动执行 DDL。
  5. - FlowNotifyTemplateService.EnsureSystemTemplates() 会在后端启动时幂等写入 9 条默认模板,
  6. 故本脚本仅负责建表;模板预置由后端自动完成。
  7. - 通知配置菜单(Id=1310300010106)需要手动 upsert。
  8. """
  9. import pymysql
  10. from pathlib import Path
  11. DDL = Path(r"d:/Projects/Ai-DOP/SourceCode/ZZYDOP/doc/migrations/2026-04-16_approval_flow_notify_tpl_cfg.sql")
  12. raw = DDL.read_text(encoding='utf-8')
  13. lines = [ln for ln in raw.splitlines() if not ln.strip().startswith('--')]
  14. clean = '\n'.join(lines)
  15. statements = [s.strip() for s in clean.split(';') if s.strip()]
  16. print(f"parsed {len(statements)} DDL statements")
  17. conn = pymysql.connect(
  18. host='123.60.180.165', port=3306,
  19. user='aidopremote', password='1234567890aiDOP#',
  20. database='aidopdev', charset='utf8mb4', autocommit=True,
  21. )
  22. try:
  23. with conn.cursor() as cur:
  24. for st in statements:
  25. print(f"--> {st[:80]}...")
  26. cur.execute(st)
  27. print(" done")
  28. for t in ("ApprovalFlowNotifyTemplate", "ApprovalFlowNotifyConfig"):
  29. cur.execute(f"SHOW TABLES LIKE '{t}'")
  30. print(f"{t}: {cur.fetchall()}")
  31. # 通知配置菜单 upsert
  32. cur.execute("SELECT Id, Title FROM SysMenu WHERE Id = 1310300010106")
  33. existed = cur.fetchone()
  34. if existed:
  35. print(f"menu exists: {existed}")
  36. else:
  37. cur.execute("""
  38. INSERT INTO SysMenu (Id, Pid, Title, Path, Name, Component, Icon, Type, OrderNo, IsEnabled, ShowInTab, IsHidden, IsFrameShow, IsLinkOut, CreateTime, UpdateTime, IsDelete)
  39. VALUES (1310300010106, 1310300010100, '通知配置',
  40. '/aidop/flowManage/flowNotifyConfig', 'flowNotifyConfig',
  41. '/approvalFlow/notifyConfig/index', 'ele-Bell',
  42. 2, 150, 1, 1, 0, 1, 0, NOW(), NOW(), 0)
  43. """)
  44. print("menu inserted: 通知配置")
  45. # 将菜单授权给超级管理员默认角色(1300000000101)
  46. cur.execute("SELECT COUNT(*) FROM SysRoleMenu WHERE RoleId = 1300000000101 AND MenuId = 1310300010106")
  47. if cur.fetchone()[0] == 0:
  48. cur.execute("INSERT INTO SysRoleMenu (Id, RoleId, MenuId, IsDelete) VALUES (UUID_SHORT(), 1300000000101, 1310300010106, 0)")
  49. print("SysRoleMenu grant inserted: 超级管理员 -> 通知配置")
  50. # 授权给默认租户
  51. cur.execute("SELECT COUNT(*) FROM SysTenantMenu WHERE TenantId = 1300000000100 AND MenuId = 1310300010106")
  52. if cur.fetchone()[0] == 0:
  53. cur.execute("INSERT INTO SysTenantMenu (Id, TenantId, MenuId, IsDelete) VALUES (UUID_SHORT(), 1300000000100, 1310300010106, 0)")
  54. print("SysTenantMenu grant inserted: 默认租户 -> 通知配置")
  55. finally:
  56. conn.close()
  57. print("all done")