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