新增通知规则实体、扫描任务、API与管理界面,重构站内通知支持用户/电工双类型,移除硬编码的证照到期提醒,新增工单派单、电工审核结果等通知触发场景,调整菜单与数据库结构适配新通知体系。
384 lines
23 KiB
PL/PgSQL
384 lines
23 KiB
PL/PgSQL
-- ============================================================
|
||
-- 鑫潼智电系统 PostgreSQL 种子数据脚本 V1.0
|
||
--
|
||
-- 依赖: db_init.sql(须先执行,确保表结构已创建)
|
||
--
|
||
-- 用法:
|
||
-- psql -U postgres -d xintong -f db_seed.sql
|
||
--
|
||
-- 特性:
|
||
-- - 独立事务(BEGIN/COMMIT)
|
||
-- - 幂等执行:
|
||
-- sys_role / sys_menu / sys_user / sys_user_role / sys_role_menu
|
||
-- 使用 ON CONFLICT (id / 联合主键) DO UPDATE | DO NOTHING
|
||
-- sys_dict 无业务唯一键,使用 TRUNCATE RESTART IDENTITY 清空重建
|
||
-- sys_user 可能被业务表外键引用,禁用 TRUNCATE CASCADE
|
||
-- - 显式重置序列,确保 id 不漂移
|
||
--
|
||
-- 内容:
|
||
-- 1. 初始角色(ADMIN / SALESMAN / WORKER / CUSTOMER)
|
||
-- 2. 初始菜单(顶级 6 + 系统管理子菜单 6 + 运营派单子菜单 13 等,共 50 条)
|
||
-- 3. 初始字典(客户/设备/派单/支付等业务字典)
|
||
-- 4. 管理员账户(admin / admin123456)
|
||
-- 5. 用户-角色绑定 / 角色-菜单绑定
|
||
-- ============================================================
|
||
|
||
BEGIN;
|
||
|
||
-- ------------------------------------------------------------
|
||
-- 1. 初始角色(显式指定 id:1=ADMIN 2=SALESMAN 3=WORKER 4=CUSTOMER)
|
||
-- ------------------------------------------------------------
|
||
INSERT INTO sys_role (id, role_code, role_name, description, sort_order) VALUES
|
||
(1, 'ADMIN', '运营管理员', '全部菜单权限,管理所有客户', 1),
|
||
(2, 'SALESMAN', '业务员', '客户/项目/方案/合同/回访', 2),
|
||
(3, 'WORKER', '共享电工', 'APP 接单处理,无后台菜单', 3),
|
||
(4, 'CUSTOMER', '客户', '小程序查看用电/报警/报修', 4)
|
||
ON CONFLICT (id) DO UPDATE SET
|
||
role_code = EXCLUDED.role_code,
|
||
role_name = EXCLUDED.role_name,
|
||
description = EXCLUDED.description,
|
||
sort_order = EXCLUDED.sort_order;
|
||
|
||
-- 重置 sys_role 自增序列
|
||
SELECT setval('sys_role_id_seq', 4, true);
|
||
|
||
-- ------------------------------------------------------------
|
||
-- 2. 初始菜单(顶级菜单,显式指定 id:1-6,系统管理/运营派单为目录类型 menu_type=1,其余为 menu_type=2)
|
||
-- ------------------------------------------------------------
|
||
INSERT INTO sys_menu (id, parent_id, menu_name, menu_path, component, icon, sort_order, menu_type, permission, visible) VALUES
|
||
(1, NULL, '客户管理', '/customer', NULL, 'TeamOutlined', 1, 1, 'customer:list', 1),
|
||
(2, NULL, '项目管理', '/project', NULL, 'ProjectOutlined', 2, 1, 'project:list', 1),
|
||
(3, NULL, '运营派单', '/dispatch', NULL, 'ScheduleOutlined', 3, 1, 'dispatch:list', 1),
|
||
(4, NULL, '设备监控', '/device', NULL, 'MonitorOutlined', 4, 2, 'device:list', 1),
|
||
(5, NULL, '统计报表', '/report', NULL, 'BarChartOutlined', 5, 2, 'report:list', 1),
|
||
(6, NULL, '系统管理', '/system', NULL, 'SettingOutlined', 6, 1, 'system:list', 1)
|
||
ON CONFLICT (id) DO UPDATE SET
|
||
parent_id = EXCLUDED.parent_id,
|
||
menu_name = EXCLUDED.menu_name,
|
||
menu_path = EXCLUDED.menu_path,
|
||
component = EXCLUDED.component,
|
||
icon = EXCLUDED.icon,
|
||
sort_order = EXCLUDED.sort_order,
|
||
menu_type = EXCLUDED.menu_type,
|
||
permission = EXCLUDED.permission,
|
||
visible = EXCLUDED.visible;
|
||
|
||
-- 初始菜单(系统管理子菜单,parent_id=6,显式指定 id:7-11)
|
||
INSERT INTO sys_menu (id, parent_id, menu_name, menu_path, component, icon, sort_order, menu_type, permission, visible) VALUES
|
||
(7, 6, '用户管理', '/system/user', 'system/user/index', 'UserOutlined', 1, 2, 'system:user', 1),
|
||
(8, 6, '角色管理', '/system/role', 'system/role/index', 'SafetyCertificateOutlined', 2, 2, 'system:role', 1),
|
||
(9, 6, '菜单管理', '/system/menu', 'system/menu/index', 'MenuOutlined', 3, 2, 'system:menu', 1),
|
||
(10, 6, '数据字典', '/system/dict', 'system/dict/index', 'BookOutlined', 4, 2, 'system:dict', 1),
|
||
(11, 6, '操作日志', '/log/operation', 'log/operation/index', 'FileTextOutlined', 5, 2, 'system:log', 1)
|
||
ON CONFLICT (id) DO UPDATE SET
|
||
parent_id = EXCLUDED.parent_id,
|
||
menu_name = EXCLUDED.menu_name,
|
||
menu_path = EXCLUDED.menu_path,
|
||
component = EXCLUDED.component,
|
||
icon = EXCLUDED.icon,
|
||
sort_order = EXCLUDED.sort_order,
|
||
menu_type = EXCLUDED.menu_type,
|
||
permission = EXCLUDED.permission,
|
||
visible = EXCLUDED.visible;
|
||
|
||
-- 初始菜单(客户管理子菜单,parent_id=1,显式指定 id:12-23)
|
||
INSERT INTO sys_menu (id, parent_id, menu_name, menu_path, component, icon, sort_order, menu_type, permission, visible) VALUES
|
||
(12, 1, '客户档案管理', '/customer/info', 'customer/info/index', 'UserOutlined', 1, 2, 'customer:list', 1),
|
||
(13, 1, '客户部门', '/customer/department', 'customer/department/index', 'TeamOutlined', 2, 2, 'customer:department', 1),
|
||
(14, 1, '客户小程序授权管理', '/customer/account', 'customer/account/index', 'xt-xiaochengxu', 3, 2, 'customer:account', 1),
|
||
(15, 1, '新增客户', NULL, NULL, NULL, 1, 3, 'customer:create', 1),
|
||
(16, 1, '编辑客户', NULL, NULL, NULL, 2, 3, 'customer:update', 1),
|
||
(17, 1, '删除客户', NULL, NULL, NULL, 3, 3, 'customer:delete', 1),
|
||
(18, 1, '新增部门', NULL, NULL, NULL, 4, 3, 'department:create', 1),
|
||
(19, 1, '编辑部门', NULL, NULL, NULL, 5, 3, 'department:update', 1),
|
||
(20, 1, '删除部门', NULL, NULL, NULL, 6, 3, 'department:delete', 1),
|
||
(21, 1, '新增账号', NULL, NULL, NULL, 7, 3, 'account:create', 1),
|
||
(22, 1, '编辑账号', NULL, NULL, NULL, 8, 3, 'account:update', 1),
|
||
(23, 1, '删除账号', NULL, NULL, NULL, 9, 3, 'account:delete', 1)
|
||
ON CONFLICT (id) DO UPDATE SET
|
||
parent_id = EXCLUDED.parent_id,
|
||
menu_name = EXCLUDED.menu_name,
|
||
menu_path = EXCLUDED.menu_path,
|
||
component = EXCLUDED.component,
|
||
icon = EXCLUDED.icon,
|
||
sort_order = EXCLUDED.sort_order,
|
||
menu_type = EXCLUDED.menu_type,
|
||
permission = EXCLUDED.permission,
|
||
visible = EXCLUDED.visible;
|
||
|
||
-- 初始菜单(项目域子菜单 + 客户扩展子菜单,id:24-31 + 空间拓扑 32 + 安装派单 33)
|
||
-- 项目域:客户拜访(customer:visit) / 项目勘察(project:survey) / 项目方案(project:plan)
|
||
-- 合同管理(project:contract) / 安装派单(project:install)
|
||
-- 项目验收(project:acceptance) / 回访记录(project:visit)
|
||
-- 客户域:空间拓扑与用电架构(customer:topology)
|
||
-- 注:客户拜访归属“项目管理”,但仍沿用 /customer/visit 路径与 customer:visit 权限码
|
||
INSERT INTO sys_menu (id, parent_id, menu_name, menu_path, component, icon, sort_order, menu_type, permission, visible) VALUES
|
||
(24, 2, '客户拜访', '/customer/visit', 'customer/visit/index', 'xt-jihuabaifang', 1, 2, 'customer:visit', 1),
|
||
(27, 2, '项目勘察', '/project/survey', 'project/survey/index', 'xt-xiangmukancha', 2, 2, 'project:survey', 1),
|
||
(28, 2, '项目方案', '/project/plan', 'project/plan/index', 'xt-xiangmufangan', 3, 2, 'project:plan', 1),
|
||
(29, 2, '合同管理', '/project/contract', 'project/contract/index', 'FileDoneOutlined', 4, 2, 'project:contract', 1),
|
||
(33, 2, '项目安装', '/project/install', 'project/install/index', 'ToolOutlined', 5, 2, 'project:install', 1),
|
||
(30, 2, '项目验收', '/project/acceptance', 'project/acceptance/index', 'ThunderboltOutlined', 6, 2, 'project:acceptance',1),
|
||
(31, 2, '回访记录', '/project/visit', 'project/visit/index', 'AuditOutlined', 7, 2, 'project:visit', 1),
|
||
(32, 1, '空间拓扑与用电架构', '/customer/topology', 'customer/topology/index', 'xt-topology', 5, 2, 'customer:topology',1)
|
||
ON CONFLICT (id) DO UPDATE SET
|
||
parent_id = EXCLUDED.parent_id,
|
||
menu_name = EXCLUDED.menu_name,
|
||
menu_path = EXCLUDED.menu_path,
|
||
component = EXCLUDED.component,
|
||
icon = EXCLUDED.icon,
|
||
sort_order = EXCLUDED.sort_order,
|
||
menu_type = EXCLUDED.menu_type,
|
||
permission = EXCLUDED.permission,
|
||
visible = EXCLUDED.visible;
|
||
|
||
-- 初始菜单(运营派单子菜单,parent_id=3,id:55-56)
|
||
-- 运营派单域统一 id 分配(避免历史上 36/37 被两段 INSERT 复用而互相覆盖):
|
||
-- 34 运维费定价 / 35 勘察费用(归属项目管理 parent_id=2) / 36 电工登记管理
|
||
-- 37-46 按钮权限
|
||
-- 55 报修派单 / 56 维保派单
|
||
INSERT INTO sys_menu (id, parent_id, menu_name, menu_path, component, icon, sort_order, menu_type, permission, visible) VALUES
|
||
(55, 3, '报修派单', '/dispatch/repair', 'dispatch/repair/index', 'ToolOutlined', 4, 2, 'dispatch:repair', 1),
|
||
(56, 3, '维保派单', '/dispatch/maintenance', 'dispatch/maintenance/index', 'ToolOutlined', 5, 2, 'dispatch:maintenance',1)
|
||
ON CONFLICT (id) DO UPDATE SET
|
||
parent_id = EXCLUDED.parent_id,
|
||
menu_name = EXCLUDED.menu_name,
|
||
menu_path = EXCLUDED.menu_path,
|
||
component = EXCLUDED.component,
|
||
icon = EXCLUDED.icon,
|
||
sort_order = EXCLUDED.sort_order,
|
||
menu_type = EXCLUDED.menu_type,
|
||
permission = EXCLUDED.permission,
|
||
visible = EXCLUDED.visible;
|
||
|
||
-- 运营派单子菜单(parent_id=3;其中 35 勘察费用及其按钮 40/41/42 已归属项目管理 parent_id=2;id:34/36 为菜单项,37-39/43-46 为按钮权限)
|
||
INSERT INTO sys_menu (id, parent_id, menu_name, menu_path, component, icon, sort_order, menu_type, permission, visible) VALUES
|
||
(34, 3, '运维费定价', '/dispatch/price', 'dispatch/price/index', 'MoneyCollectOutlined', 2, 2, 'dispatch:price', 1),
|
||
(35, 2, '勘察费用', '/dispatch/cost', 'dispatch/cost/index', 'AccountBookOutlined', 8, 2, 'dispatch:cost', 1),
|
||
(36, 3, '电工登记管理', '/dispatch/worker', 'dispatch/worker/index', 'ToolOutlined', 1, 2, 'dispatch:worker', 1),
|
||
(37, 3, '新增价目', NULL, NULL, NULL, 1, 3, 'price:create', 1),
|
||
(38, 3, '编辑价目', NULL, NULL, NULL, 2, 3, 'price:update', 1),
|
||
(39, 3, '删除价目', NULL, NULL, NULL, 3, 3, 'price:delete', 1),
|
||
(40, 2, '新增勘察费用', NULL, NULL, NULL, 9, 3, 'cost:create', 1),
|
||
(41, 2, '编辑勘察费用', NULL, NULL, NULL, 10, 3, 'cost:update', 1),
|
||
(42, 2, '删除勘察费用', NULL, NULL, NULL, 11, 3, 'cost:delete', 1),
|
||
(43, 3, '新增电工', NULL, NULL, NULL, 7, 3, 'worker:create', 1),
|
||
(44, 3, '编辑电工', NULL, NULL, NULL, 8, 3, 'worker:update', 1),
|
||
(45, 3, '删除电工', NULL, NULL, NULL, 9, 3, 'worker:delete', 1),
|
||
(46, 3, '审核电工', NULL, NULL, NULL, 10, 3, 'worker:audit', 1)
|
||
ON CONFLICT (id) DO UPDATE SET
|
||
parent_id = EXCLUDED.parent_id,
|
||
menu_name = EXCLUDED.menu_name,
|
||
menu_path = EXCLUDED.menu_path,
|
||
component = EXCLUDED.component,
|
||
icon = EXCLUDED.icon,
|
||
sort_order = EXCLUDED.sort_order,
|
||
menu_type = EXCLUDED.menu_type,
|
||
permission = EXCLUDED.permission,
|
||
visible = EXCLUDED.visible;
|
||
|
||
-- 重置 sys_menu 自增序列
|
||
SELECT setval('sys_menu_id_seq', 50, true);
|
||
|
||
-- ------------------------------------------------------------
|
||
-- 3. 初始字典(sys_dict 无业务唯一键,清空重建以支持幂等执行)
|
||
-- ------------------------------------------------------------
|
||
TRUNCATE sys_dict RESTART IDENTITY;
|
||
|
||
INSERT INTO sys_dict (dict_type, dict_label, dict_value, sort_order) VALUES
|
||
('customer_status', '意向', '1', 1),
|
||
('customer_status', '签约', '2', 2),
|
||
('customer_status', '运维中', '3', 3),
|
||
('customer_status', '终止', '4', 4),
|
||
('equip_type', '配电间', '配电间', 1),
|
||
('equip_type', '配电井', '配电井', 2),
|
||
('equip_type', '配电箱', '配电箱', 3),
|
||
('device_type', '网关', '网关', 1),
|
||
('device_type', '探测器', '探测器', 2),
|
||
('device_type', '采集器', '采集器', 3),
|
||
('dispatch_status', '待指派', '0', 1),
|
||
('dispatch_status', '现场勘察中', '1', 2),
|
||
('dispatch_status', '待技术复核', '2', 3),
|
||
('dispatch_status', '已归档', '3', 4),
|
||
('dispatch_status', '已取消', '5', 5),
|
||
('pay_cycle', '按月支付', '按月', 1),
|
||
('pay_cycle', '按年支付', '按年', 2),
|
||
('dispatch_type', '勘察派单', 'survey', 1),
|
||
('dispatch_type', '安装派单', 'install', 2),
|
||
('dispatch_type', '报警派单', 'alarm', 3),
|
||
('dispatch_type', '维修派单', 'repair', 4),
|
||
('dispatch_type', '维保派单', 'maintenance', 5),
|
||
('om_service_type', '维修', '维修', 1),
|
||
('om_service_type', '维保', '维保', 2),
|
||
('om_service_type', '报警处理', '报警处理', 3),
|
||
('om_service_type', '巡检', '巡检', 4),
|
||
('om_service_type', '其他', '其他', 5),
|
||
('om_price_mode', '按次', '1', 1),
|
||
('om_price_mode', '按工时', '2', 2),
|
||
('om_price_mode', '材料', '3', 3),
|
||
('om_price_unit', '次', '次', 1),
|
||
('om_price_unit', '小时', '小时', 2),
|
||
('om_price_unit', '个', '个', 3),
|
||
('om_price_unit', '米', '米', 4),
|
||
('om_price_unit', '根', '根', 5),
|
||
('worker_cert_type', '低压电工证', '低压电工证', 1),
|
||
('worker_cert_type', '高压电工证', '高压电工证', 2),
|
||
('worker_cert_type', '特种作业证', '特种作业证', 3),
|
||
('worker_cert_type', '登高证', '登高证', 4),
|
||
('worker_cert_type', '其他', '其他', 5),
|
||
('worker_audit_status', '待审核', '0', 1),
|
||
('worker_audit_status', '已通过', '1', 2),
|
||
('worker_audit_status', '已驳回', '2', 3);
|
||
|
||
-- ------------------------------------------------------------
|
||
-- 4. 管理员账户(显式指定 id=1,密码哈希为 bcrypt('admin123456'))
|
||
-- sys_user 可能被业务表外键引用,使用 ON CONFLICT 而非 TRUNCATE,避免业务数据被级联清空
|
||
-- ------------------------------------------------------------
|
||
INSERT INTO sys_user (id, username, password_hash, real_name, phone, email, status) VALUES
|
||
(1, 'admin', '$2a$10$GC/0CaPf9Ti/yeNVSZ8L3OKvCS1MrAY.aohg9UerB6heyp78Fo17.', '运营管理员', NULL, NULL, 1)
|
||
ON CONFLICT (id) DO UPDATE SET
|
||
username = EXCLUDED.username,
|
||
password_hash = EXCLUDED.password_hash,
|
||
real_name = EXCLUDED.real_name,
|
||
phone = EXCLUDED.phone,
|
||
email = EXCLUDED.email,
|
||
status = EXCLUDED.status;
|
||
|
||
-- 重置 sys_user 自增序列
|
||
SELECT setval('sys_user_id_seq', 1, true);
|
||
|
||
-- ------------------------------------------------------------
|
||
-- 5. 用户-角色绑定:admin → ADMIN
|
||
-- ------------------------------------------------------------
|
||
INSERT INTO sys_user_role (user_id, role_id) VALUES (1, 1)
|
||
ON CONFLICT (user_id, role_id) DO NOTHING;
|
||
|
||
-- ------------------------------------------------------------
|
||
-- 6. 角色-菜单绑定:ADMIN 拥有全部 46 条菜单,SALESMAN 拥有客户域+项目+统计报表
|
||
-- WORKER、CUSTOMER 不绑定任何菜单
|
||
-- ------------------------------------------------------------
|
||
INSERT INTO sys_role_menu (role_id, menu_id) VALUES
|
||
(1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9), (1, 10), (1, 11),
|
||
(1, 12), (1, 13), (1, 14), (1, 15), (1, 16), (1, 17), (1, 18), (1, 19), (1, 20), (1, 21), (1, 22), (1, 23),
|
||
(1, 24), (1, 27), (1, 28), (1, 29), (1, 30), (1, 31), (1, 32), (1, 33), (1, 55), (1, 56),
|
||
(1, 34), (1, 35), (1, 36), (1, 37), (1, 38), (1, 39), (1, 40), (1, 41), (1, 42), (1, 43), (1, 44), (1, 45), (1, 46),
|
||
(2, 1), (2, 2), (2, 5),
|
||
(2, 12), (2, 13), (2, 14), (2, 15), (2, 16), (2, 17), (2, 18), (2, 19), (2, 20), (2, 21), (2, 22), (2, 23),
|
||
(2, 24), (2, 27), (2, 28), (2, 29), (2, 30), (2, 31), (2, 32), (2, 33), (2, 55), (2, 56)
|
||
ON CONFLICT (role_id, menu_id) DO NOTHING;
|
||
|
||
-- 移除已废弃的菜单(客户建筑/客户房间,id=25/26)及其角色绑定(幂等清理,确保每次执行都收敛)
|
||
DELETE FROM sys_role_menu WHERE menu_id IN (25, 26);
|
||
DELETE FROM sys_menu WHERE id IN (25, 26);
|
||
|
||
-- ------------------------------------------------------------
|
||
-- 7. 定时任务域菜单(系统管理 parent_id=6,id:47 为菜单项,48-50 为按钮权限)
|
||
-- ------------------------------------------------------------
|
||
INSERT INTO sys_menu (id, parent_id, menu_name, menu_path, component, icon, sort_order, menu_type, permission, visible) VALUES
|
||
(47, 6, '定时任务', '/system/job', 'system/job/index', 'ClockCircleOutlined', 6, 2, 'system:job', 1),
|
||
(48, 47, '编辑定时任务', NULL, NULL, NULL, 1, 3, 'system:job:update', 1),
|
||
(49, 47, '立即执行', NULL, NULL, NULL, 2, 3, 'system:job:run', 1),
|
||
(50, 47, '清理日志', NULL, NULL, NULL, 3, 3, 'system:job:log:clear', 1)
|
||
ON CONFLICT (id) DO UPDATE SET
|
||
parent_id = EXCLUDED.parent_id,
|
||
menu_name = EXCLUDED.menu_name,
|
||
menu_path = EXCLUDED.menu_path,
|
||
component = EXCLUDED.component,
|
||
icon = EXCLUDED.icon,
|
||
sort_order = EXCLUDED.sort_order,
|
||
menu_type = EXCLUDED.menu_type,
|
||
permission = EXCLUDED.permission,
|
||
visible = EXCLUDED.visible;
|
||
|
||
-- 角色-菜单绑定:ADMIN(role_id=1)拥有 47-50
|
||
INSERT INTO sys_role_menu (role_id, menu_id) VALUES
|
||
(1, 47), (1, 48), (1, 49), (1, 50)
|
||
ON CONFLICT (role_id, menu_id) DO NOTHING;
|
||
|
||
-- ------------------------------------------------------------
|
||
-- 8. 定时任务种子(sys_job,按 job_key 幂等)
|
||
-- ------------------------------------------------------------
|
||
INSERT INTO sys_job (job_key, job_name, cron_expression, params, retry_times, retry_interval, status, remark) VALUES
|
||
('demo_heartbeat', '示例心跳', '*/5 * * * *', '{"message":"heartbeat"}'::jsonb, 0, 60, 1,
|
||
'示例心跳任务:用于验证调度链路,默认每 5 分钟写入一条 info 日志'),
|
||
('log_clean', '日志清理', '0 3 * * *', '{"keepDays":90}'::jsonb, 2, 60, 1,
|
||
'日志清理任务:每日 03:00 清理早于 keepDays 天的操作日志与任务日志,默认保留 90 天')
|
||
ON CONFLICT (job_key) DO NOTHING;
|
||
|
||
-- ------------------------------------------------------------
|
||
-- 9. 通知域菜单(系统管理 parent_id=6,id:51 为菜单项,52-54 为按钮权限)
|
||
-- ------------------------------------------------------------
|
||
INSERT INTO sys_menu (id, parent_id, menu_name, menu_path, component, icon, sort_order, menu_type, permission, visible) VALUES
|
||
(51, 6, '通知管理', '/system/notice', 'system/notice/index', 'BellOutlined', 7, 2, 'notice:rule', 1),
|
||
(52, 51, '保存规则', NULL, NULL, NULL, 1, 3, 'notice:rule:update', 1),
|
||
(53, 51, '删除规则', NULL, NULL, NULL, 2, 3, 'notice:rule:delete', 1),
|
||
(54, 51, '群发消息', NULL, NULL, NULL, 3, 3, 'notice:batch', 1)
|
||
ON CONFLICT (id) DO UPDATE SET
|
||
parent_id = EXCLUDED.parent_id,
|
||
menu_name = EXCLUDED.menu_name,
|
||
menu_path = EXCLUDED.menu_path,
|
||
component = EXCLUDED.component,
|
||
icon = EXCLUDED.icon,
|
||
sort_order = EXCLUDED.sort_order,
|
||
menu_type = EXCLUDED.menu_type,
|
||
permission = EXCLUDED.permission,
|
||
visible = EXCLUDED.visible;
|
||
|
||
-- 角色-菜单绑定:ADMIN(role_id=1)拥有 51-54
|
||
INSERT INTO sys_role_menu (role_id, menu_id) VALUES
|
||
(1, 51), (1, 52), (1, 53), (1, 54)
|
||
ON CONFLICT (role_id, menu_id) DO NOTHING;
|
||
|
||
-- 重置 sys_menu 自增序列
|
||
SELECT setval('sys_menu_id_seq', 56, true);
|
||
|
||
-- ------------------------------------------------------------
|
||
-- 10. 通知规则扫描任务种子(sys_job,按 job_key 幂等)
|
||
-- ------------------------------------------------------------
|
||
INSERT INTO sys_job (job_key, job_name, cron_expression, params, retry_times, retry_interval, status, remark) VALUES
|
||
('notice_scan', '通知规则扫描', '0 0 8 * * *', '{}'::jsonb, 1, 300, 1,
|
||
'遍历启用的扫描式通知规则,按模板与接收对象生成站内通知(幂等,默认每日 08:00)')
|
||
ON CONFLICT (job_key) DO NOTHING;
|
||
|
||
-- ------------------------------------------------------------
|
||
-- 11. 通知规则种子(sys_notice_rule,按 rule_key 幂等;接收对象可在「通知管理」页调整)
|
||
-- ------------------------------------------------------------
|
||
INSERT INTO sys_notice_rule (rule_key, rule_name, event_key, trigger_mode, enabled, advance_days, title_tpl, content_tpl, receiver_config, remark) VALUES
|
||
('cert_expire', '电工资质证照到期提醒', 'cert_expire', 1, 1, 30,
|
||
'电工【{workerName}】的{certType}{expireState}',
|
||
'证书编号:{certNo};发证机关:{issueAuthority};有效期至:{expireDate};{remainDaysText},请及时提醒电工办理续期',
|
||
'{"users":{"roles":["ADMIN"],"ids":[]},"workers":{"mode":"event","ids":[]}}'::jsonb,
|
||
'扫描 worker_cert 中 advance_days 天内到期或已过期的证照,通知 ADMIN 与证照所属电工'),
|
||
('worker_audit_result', '电工入驻审核结果通知', 'worker_audit_result', 2, 1, NULL,
|
||
'您的入驻审核{auditState}',
|
||
'审核{auditState};{auditRemarkText}如资料有误,请修改后重新提交。',
|
||
'{"users":{"roles":[],"ids":[]},"workers":{"mode":"event","ids":[]}}'::jsonb,
|
||
'审核通过/驳回时实时通知电工本人(业务埋点触发)'),
|
||
('dispatch_assign', '工单派单通知', 'dispatch_assign', 2, 1, NULL,
|
||
'您有新的{orderTypeName}工单',
|
||
'工单编号:{orderNo};客户:{customerName};{detailText}请及时在电工端查看并接单。',
|
||
'{"users":{"roles":[],"ids":[]},"workers":{"mode":"event","ids":[]}}'::jsonb,
|
||
'勘察/安装/维保/报修派单时实时通知被指派电工(业务埋点触发)'),
|
||
('contract_expire', '客户合同到期提醒', 'contract_expire', 1, 1, 30,
|
||
'客户【{customerName}】的合同{expireState}',
|
||
'合同编号:{contractNo};合同名称:{contractName};到期日:{endDate};{remainDaysText},请及时跟进续签。',
|
||
'{"users":{"roles":["ADMIN"],"ids":[]},"workers":{"mode":"none","ids":[]}}'::jsonb,
|
||
'扫描 contract 中 advance_days 天内到期或已过期的合同,通知 ADMIN'),
|
||
('visit_plan', '客户拜访计划提醒', 'visit_plan', 1, 1, 0,
|
||
'客户拜访计划待执行:{customerName}',
|
||
'计划拜访日期:{planDate};{remainDaysText}。请及时完成拜访。',
|
||
'{"users":{"roles":["ADMIN"],"ids":[]},"workers":{"mode":"none","ids":[]}}'::jsonb,
|
||
'扫描 customer_visit 中未执行且计划日期已到/超期的拜访计划,通知 ADMIN'),
|
||
('order_timeout', '工单超时未接单提醒', 'order_timeout', 1, 1, 1,
|
||
'工单超时未接单:{orderTypeName}',
|
||
'工单编号:{orderNo};客户:{customerName};已派单 {staleDays} 天仍未接单,请及时跟进。',
|
||
'{"users":{"roles":["ADMIN"],"ids":[]},"workers":{"mode":"none","ids":[]}}'::jsonb,
|
||
'扫描派单后超过 advance_days 天仍未接单的工单,通知 ADMIN')
|
||
ON CONFLICT (rule_key) DO NOTHING;
|
||
|
||
COMMIT;
|
||
|
||
-- ============================================================
|
||
-- 完 · 系统表种子数据(4 角色 + 54 菜单 + 43 字典 + 1 管理员 + 3 定时任务 + 6 通知规则 + 绑定关系)
|
||
-- ============================================================
|