-- ============================================================ -- 基础设施信息(menu_id=2070「管网基础设施信息」)新增 9 个菜单 -- -- | 菜单名称 | component | 说明 | -- |-----------------|----------------------------------------------------|-----------------------------| -- | 管道信息 | subSystem/pipeNetwork/facilities/pipeNetwork/index | 已有页面迁移到 facilities 下 | -- | 窨井信息 | subSystem/pipeNetwork/facilities/manhole/index | 已有页面迁移 + 表改造 | -- | 泵站信息 | subSystem/pipeNetwork/facilities/pumpStation/index | 供排水共用,station_type 区分| -- | 供水-水厂信息 | subSystem/pipeNetwork/facilities/waterPlant/index | 已有页面复用 | -- | 供水-水源地信息 | subSystem/pipeNetwork/facilities/waterSource/index | 已有页面复用 | -- | 供水-用水户信息 | subSystem/pipeNetwork/facilities/waterUser/index | 已有页面复用 | -- | 供水-消火栓信息 | subSystem/pipeNetwork/facilities/waterFireHydrant/index | 新建功能 + 新建表 | -- | 排水-闸门信息 | subSystem/pipeNetwork/facilities/drainageGate/index | 从 drainage_engineering_facility 拆分 | -- | 排水-调蓄设施信息 | subSystem/pipeNetwork/facilities/drainageStorage/index | 从 drainage_engineering_facility 拆分 | -- -- 约束边界: -- · 本脚本只在 2070 节点下**新增**菜单,不动任何老菜单、老页面; -- · 老业务后续再统一改造,本脚本不涉及数据迁移。 -- -- 脚本形态: -- 纯常规 SQL(KingbaseES / PG 兼容),**不含 DO $$ / 存储过程 / 匿名块**, -- 可在 KES 控制台整段执行,也可逐条执行。 -- -- 重要: -- · component 必须写成 views 下的相对路径且**带 /index**(目录式落地), -- 否则前端 loadView 匹配不到 → 路由组件为空 → 白屏。 -- 依据:src/store/modules/permission.js 的 import.meta.glob('./../../views/**/*.vue')。 -- · menu_id 显式取 MAX(menu_id)+1(本库自增计数器未推进,不能省略主键)。 -- · 幂等:按 component 判重,已存在则不重复插入、不重复授权。 -- · 「管道信息」组件已迁移到 subSystem/pipeNetwork/facilities/pipeNetwork/index -- (原 assetInfo/netWorkBase 已移除),STEP 4 会把仍指向旧路径的历史菜单一并改正。 -- · 父目录定位:menu_id=2070 → 名称「管网基础设施信息」兜底;两者都取不到时 -- STEP 0 的 parent_menu_id 为 NULL,STEP 1/STEP 2 自动跳过(不报错、不写脏数据), -- 此时需先确认真实 menu_id 再重跑。 -- -- 执行后请重新登录一次,让前端重新拉取菜单。 -- 数据库:KingbaseES(PG 兼容),schema = app_user。 -- ============================================================ -- 前置:结束上一次失败执行遗留的 aborted 事务 ROLLBACK; BEGIN; SET search_path TO app_user, public; -- ------------------------------------------------------------ -- STEP 0:定位父目录「管网基础设施信息」(三路兜底,仅作核对/供后续语句复用) -- ------------------------------------------------------------ SELECT COALESCE( (SELECT m.menu_id FROM app_user.sys_menu m WHERE m.menu_id = 2070 LIMIT 1), (SELECT m.menu_id FROM app_user.sys_menu m WHERE m.menu_name = '管网基础设施信息' AND m.menu_type IN ('M', 'C') ORDER BY m.menu_id LIMIT 1) ) AS parent_menu_id; -- ------------------------------------------------------------ -- STEP 0.5:核对 2070 已改造为目录 -- 期望:menu_type = 'M',component = 'ParentView'(不再是管道信息页面) -- 若 component 仍指向管道信息页面(迁移前为 -- 'subSystem/pipeNetwork/assetInfo/netWorkBase/index'), -- 说明 2070 还没目录化:本脚本仍会插入 9 条,但 STEP 4 会把 2070 也指向 -- 新路径,出现「同一个管道信息页面两个入口」。 -- 请先执行 migration_menu_2070_directory.sql。 -- ------------------------------------------------------------ SELECT menu_id, menu_name, parent_id, menu_type, path, component FROM app_user.sys_menu WHERE menu_id = 2070; -- ------------------------------------------------------------ -- STEP 1:新增 9 个菜单(按 component 判重,幂等) -- ------------------------------------------------------------ INSERT INTO app_user.sys_menu (menu_id, menu_name, parent_id, order_num, path, component, "query", route_name, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark) SELECT (SELECT COALESCE(MAX(menu_id), 0) FROM app_user.sys_menu) + t.rn, t.menu_name, t.parent_id, t.order_num, t.path, t.component, '', t.route_name, 1, 0, 'C', '0', '0', '', t.icon, 'admin', CURRENT_TIMESTAMP, t.remark FROM ( SELECT s.menu_name, s.order_num, s.path, s.component, s.route_name, s.icon, s.remark, p.parent_id, ROW_NUMBER() OVER (ORDER BY s.order_num, s.component) AS rn FROM (VALUES ('管道信息', 1, 'facilityPipeNetwork', 'subSystem/pipeNetwork/facilities/pipeNetwork/index', 'FacilityPipeNetwork', 'tree-table', '基础设施信息-管道信息'), ('窨井信息', 2, 'facilityManhole', 'subSystem/pipeNetwork/facilities/manhole/index', 'FacilityManhole', 'guide', '基础设施信息-窨井信息'), ('泵站信息', 3, 'facilityPumpStation', 'subSystem/pipeNetwork/facilities/pumpStation/index', 'FacilityPumpStation', 'component', '基础设施信息-泵站信息(供水排水共用)'), ('供水-水厂信息', 4, 'facilityWaterPlant', 'subSystem/pipeNetwork/facilities/waterPlant/index', 'FacilityWaterPlant', 'build', '基础设施信息-供水水厂'), ('供水-水源地信息', 5, 'facilityWaterSource', 'subSystem/pipeNetwork/facilities/waterSource/index', 'FacilityWaterSource', 'tree', '基础设施信息-供水水源地'), ('供水-用水户信息', 6, 'facilityWaterUser', 'subSystem/pipeNetwork/facilities/waterUser/index', 'FacilityWaterUser', 'user', '基础设施信息-供水用水户'), ('供水-消火栓信息', 7, 'facilityFireHydrant', 'subSystem/pipeNetwork/facilities/waterFireHydrant/index', 'FacilityFireHydrant', 'form', '基础设施信息-供水消火栓'), ('排水-闸门信息', 8, 'facilityDrainageGate', 'subSystem/pipeNetwork/facilities/drainageGate/index', 'FacilityDrainageGate', 'form', '基础设施信息-排水闸门'), ('排水-调蓄设施信息', 9, 'facilityDrainageStorage','subSystem/pipeNetwork/facilities/drainageStorage/index', 'FacilityDrainageStorage','table', '基础设施信息-排水调蓄设施') ) AS s(menu_name, order_num, path, component, route_name, icon, remark) CROSS JOIN ( SELECT COALESCE( (SELECT m.menu_id FROM app_user.sys_menu m WHERE m.menu_id = 2070 LIMIT 1), (SELECT m.menu_id FROM app_user.sys_menu m WHERE m.menu_name = '管网基础设施信息' AND m.menu_type IN ('M', 'C') ORDER BY m.menu_id LIMIT 1) ) AS parent_id ) p WHERE p.parent_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM app_user.sys_menu m WHERE m.component = s.component) ) t; -- ------------------------------------------------------------ -- STEP 2:把新菜单授权给所有已拥有 2070 的角色(跟随父级扩散) -- ------------------------------------------------------------ INSERT INTO app_user.sys_role_menu (role_id, menu_id) SELECT DISTINCT rm.role_id, m.menu_id FROM app_user.sys_role_menu rm JOIN app_user.sys_menu m ON m.parent_id = rm.menu_id WHERE rm.menu_id = (SELECT COALESCE( (SELECT m1.menu_id FROM app_user.sys_menu m1 WHERE m1.menu_id = 2070 LIMIT 1), (SELECT m2.menu_id FROM app_user.sys_menu m2 WHERE m2.menu_name = '管网基础设施信息' AND m2.menu_type IN ('M', 'C') ORDER BY m2.menu_id LIMIT 1) )) AND m.component IN ('subSystem/pipeNetwork/facilities/pipeNetwork/index', 'subSystem/pipeNetwork/facilities/manhole/index', 'subSystem/pipeNetwork/facilities/pumpStation/index', 'subSystem/pipeNetwork/facilities/waterPlant/index', 'subSystem/pipeNetwork/facilities/waterSource/index', 'subSystem/pipeNetwork/facilities/waterUser/index', 'subSystem/pipeNetwork/facilities/waterFireHydrant/index', 'subSystem/pipeNetwork/facilities/drainageGate/index', 'subSystem/pipeNetwork/facilities/drainageStorage/index') AND NOT EXISTS (SELECT 1 FROM app_user.sys_role_menu e WHERE e.role_id = rm.role_id AND e.menu_id = m.menu_id); -- ------------------------------------------------------------ -- STEP 3:已存在同 component 的菜单只补齐排序/名称 -- (不改 component、不动老菜单) -- ------------------------------------------------------------ UPDATE app_user.sys_menu m SET order_num = s.order_num, menu_name = s.menu_name, update_by = 'admin', update_time = CURRENT_TIMESTAMP FROM (VALUES ('管道信息', 1, 'subSystem/pipeNetwork/facilities/pipeNetwork/index'), ('窨井信息', 2, 'subSystem/pipeNetwork/facilities/manhole/index'), ('泵站信息', 3, 'subSystem/pipeNetwork/facilities/pumpStation/index'), ('供水-水厂信息', 4, 'subSystem/pipeNetwork/facilities/waterPlant/index'), ('供水-水源地信息', 5, 'subSystem/pipeNetwork/facilities/waterSource/index'), ('供水-用水户信息', 6, 'subSystem/pipeNetwork/facilities/waterUser/index'), ('供水-消火栓信息', 7, 'subSystem/pipeNetwork/facilities/waterFireHydrant/index'), ('排水-闸门信息', 8, 'subSystem/pipeNetwork/facilities/drainageGate/index'), ('排水-调蓄设施信息', 9, 'subSystem/pipeNetwork/facilities/drainageStorage/index') ) AS s(menu_name, order_num, component) WHERE m.component = s.component AND m.parent_id = (SELECT COALESCE( (SELECT m1.menu_id FROM app_user.sys_menu m1 WHERE m1.menu_id = 2070 LIMIT 1), (SELECT m2.menu_id FROM app_user.sys_menu m2 WHERE m2.menu_name = '管网基础设施信息' AND m2.menu_type IN ('M', 'C') ORDER BY m2.menu_id LIMIT 1) )) AND (m.order_num <> s.order_num OR m.menu_name <> s.menu_name); -- ------------------------------------------------------------ -- STEP 4:修正历史菜单对「管道信息」旧 component 的引用 -- 管道信息页面已由 subSystem/pipeNetwork/assetInfo/netWorkBase/index -- 迁移到 subSystem/pipeNetwork/facilities/pipeNetwork/index, -- 现场若还有其它菜单指向旧路径,统一改到新路径(否则组件找不到 → 白屏)。 -- 前置:必须已执行 migration_menu_2070_directory.sql, -- 否则会把 2070 目录重新指回管道信息页面。 -- ------------------------------------------------------------ UPDATE app_user.sys_menu SET component = 'subSystem/pipeNetwork/facilities/pipeNetwork/index', update_by = 'admin', update_time = CURRENT_TIMESTAMP WHERE component = 'subSystem/pipeNetwork/assetInfo/netWorkBase/index'; COMMIT; -- ============================================================ -- 执行后核对(只读): -- SELECT menu_id, menu_name, parent_id, order_num, path, component, visible, status -- FROM app_user.sys_menu -- WHERE parent_id = (SELECT menu_id FROM app_user.sys_menu WHERE menu_id = 2070) -- ORDER BY order_num, menu_id; -- -- -- 组件文件必须存在,否则前端白屏(逐条核对) -- -- subSystem/pipeNetwork/facilities/pipeNetwork/index.vue -- -- subSystem/pipeNetwork/facilities/manhole/index.vue -- -- subSystem/pipeNetwork/facilities/pumpStation/index.vue -- -- subSystem/pipeNetwork/facilities/waterPlant/index.vue -- -- subSystem/pipeNetwork/facilities/waterSource/index.vue -- -- subSystem/pipeNetwork/facilities/waterUser/index.vue -- -- subSystem/pipeNetwork/facilities/waterFireHydrant/index.vue -- -- subSystem/pipeNetwork/facilities/drainageGate/index.vue -- -- subSystem/pipeNetwork/facilities/drainageStorage/index.vue -- -- 回滚(删除本脚本新增的 9 个菜单及其授权): -- BEGIN; -- SET search_path TO app_user, public; -- DELETE FROM app_user.sys_role_menu WHERE menu_id IN ( -- SELECT menu_id FROM app_user.sys_menu -- WHERE component IN ('subSystem/pipeNetwork/facilities/pipeNetwork/index', -- 'subSystem/pipeNetwork/facilities/manhole/index', -- 'subSystem/pipeNetwork/facilities/pumpStation/index', -- 'subSystem/pipeNetwork/facilities/waterPlant/index', -- 'subSystem/pipeNetwork/facilities/waterSource/index', -- 'subSystem/pipeNetwork/facilities/waterUser/index', -- 'subSystem/pipeNetwork/facilities/waterFireHydrant/index', -- 'subSystem/pipeNetwork/facilities/drainageGate/index', -- 'subSystem/pipeNetwork/facilities/drainageStorage/index')); -- DELETE FROM app_user.sys_menu WHERE component IN ( -- 'subSystem/pipeNetwork/facilities/pipeNetwork/index', -- 'subSystem/pipeNetwork/facilities/manhole/index', -- 'subSystem/pipeNetwork/facilities/pumpStation/index', -- 'subSystem/pipeNetwork/facilities/waterPlant/index', -- 'subSystem/pipeNetwork/facilities/waterSource/index', -- 'subSystem/pipeNetwork/facilities/waterUser/index', -- 'subSystem/pipeNetwork/facilities/waterFireHydrant/index', -- 'subSystem/pipeNetwork/facilities/drainageGate/index', -- 'subSystem/pipeNetwork/facilities/drainageStorage/index'); -- COMMIT; -- ============================================================