-- ============================================================
-- Task 1: 创建拆分后的独立权限菜单
-- ============================================================

-- ============================================================
-- 1.1 隐患Tab级权限拆分
-- ============================================================

-- 本单位工程隐患 (2660) 下
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT 2880, '本单位-新建', 2660, 1, '', '', 1, 0, 'F', 0, 0, 'hidd:selfEng:add', '#', 'admin', NOW(), '本单位工程隐患-新建'
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'hidd:selfEng:add');

INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT 2881, '本单位-编辑', 2660, 2, '', '', 1, 0, 'F', 0, 0, 'hidd:selfEng:edit', '#', 'admin', NOW(), '本单位工程隐患-编辑'
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'hidd:selfEng:edit');

INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT 2882, '本单位-删除', 2660, 3, '', '', 1, 0, 'F', 0, 0, 'hidd:selfEng:remove', '#', 'admin', NOW(), '本单位工程隐患-删除'
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'hidd:selfEng:remove');

INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT 2883, '本单位-整改', 2660, 4, '', '', 1, 0, 'F', 0, 0, 'hidd:selfEng:rectify', '#', 'admin', NOW(), '本单位工程隐患-整改'
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'hidd:selfEng:rectify');

INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT 2884, '本单位-销号申请', 2660, 5, '', '', 1, 0, 'F', 0, 0, 'hidd:selfEng:writeoff', '#', 'admin', NOW(), '本单位工程隐患-销号申请'
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'hidd:selfEng:writeoff');

INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT 2885, '本单位-上报', 2660, 6, '', '', 1, 0, 'F', 0, 0, 'hidd:selfEng:report', '#', 'admin', NOW(), '本单位工程隐患-上报'
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'hidd:selfEng:report');

INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT 2886, '本单位-导出', 2660, 7, '', '', 1, 0, 'F', 0, 0, 'hidd:selfEng:export', '#', 'admin', NOW(), '本单位工程隐患-导出'
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'hidd:selfEng:export');

-- 下级单位隐患 (2661) 下
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT 2887, '下级单位-导出', 2661, 1, '', '', 1, 0, 'F', 0, 0, 'hidd:subEng:export', '#', 'admin', NOW(), '下级单位隐患-导出'
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'hidd:subEng:export');

-- 本单位标段隐患 (2662) 下
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT 2890, '标段-新建', 2662, 1, '', '', 1, 0, 'F', 0, 0, 'hidd:bidEng:add', '#', 'admin', NOW(), '本单位标段隐患-新建'
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'hidd:bidEng:add');

INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT 2891, '标段-编辑', 2662, 2, '', '', 1, 0, 'F', 0, 0, 'hidd:bidEng:edit', '#', 'admin', NOW(), '本单位标段隐患-编辑'
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'hidd:bidEng:edit');

INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT 2892, '标段-删除', 2662, 3, '', '', 1, 0, 'F', 0, 0, 'hidd:bidEng:remove', '#', 'admin', NOW(), '本单位标段隐患-删除'
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'hidd:bidEng:remove');

INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT 2893, '标段-整改', 2662, 4, '', '', 1, 0, 'F', 0, 0, 'hidd:bidEng:rectify', '#', 'admin', NOW(), '本单位标段隐患-整改'
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'hidd:bidEng:rectify');

INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT 2894, '标段-销号申请', 2662, 5, '', '', 1, 0, 'F', 0, 0, 'hidd:bidEng:writeoff', '#', 'admin', NOW(), '本单位标段隐患-销号申请'
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'hidd:bidEng:writeoff');

INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT 2895, '标段-上报', 2662, 6, '', '', 1, 0, 'F', 0, 0, 'hidd:bidEng:report', '#', 'admin', NOW(), '本单位标段隐患-上报'
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'hidd:bidEng:report');

INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT 2896, '标段-导出', 2662, 7, '', '', 1, 0, 'F', 0, 0, 'hidd:bidEng:export', '#', 'admin', NOW(), '本单位标段隐患-导出'
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'hidd:bidEng:export');

-- 施工单位隐患 (2663) 下
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT 2900, '施工-新建', 2663, 1, '', '', 1, 0, 'F', 0, 0, 'hidd:consEng:add', '#', 'admin', NOW(), '施工单位隐患-新建'
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'hidd:consEng:add');

INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT 2901, '施工-编辑', 2663, 2, '', '', 1, 0, 'F', 0, 0, 'hidd:consEng:edit', '#', 'admin', NOW(), '施工单位隐患-编辑'
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'hidd:consEng:edit');

INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT 2902, '施工-删除', 2663, 3, '', '', 1, 0, 'F', 0, 0, 'hidd:consEng:remove', '#', 'admin', NOW(), '施工单位隐患-删除'
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'hidd:consEng:remove');

INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT 2903, '施工-导出', 2663, 4, '', '', 1, 0, 'F', 0, 0, 'hidd:consEng:export', '#', 'admin', NOW(), '施工单位隐患-导出'
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'hidd:consEng:export');

-- 参建单位隐患 (2664) 下
INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT 2910, '参建-新建', 2664, 1, '', '', 1, 0, 'F', 0, 0, 'hidd:partEng:add', '#', 'admin', NOW(), '参建单位隐患-新建'
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'hidd:partEng:add');

INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT 2911, '参建-编辑', 2664, 2, '', '', 1, 0, 'F', 0, 0, 'hidd:partEng:edit', '#', 'admin', NOW(), '参建单位隐患-编辑'
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'hidd:partEng:edit');

INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT 2912, '参建-删除', 2664, 3, '', '', 1, 0, 'F', 0, 0, 'hidd:partEng:remove', '#', 'admin', NOW(), '参建单位隐患-删除'
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'hidd:partEng:remove');

INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT 2913, '参建-导出', 2664, 4, '', '', 1, 0, 'F', 0, 0, 'hidd:partEng:export', '#', 'admin', NOW(), '参建单位隐患-导出'
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'hidd:partEng:export');

-- ============================================================
-- 1.2 隐患月报独立权限拆分
-- ============================================================

INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT 2920, '月报同意', 2003, 13, '', '', 1, 0, 'F', 0, 0, 'hidd:month:agree', '#', 'admin', NOW(), '隐患月报同意按钮权限'
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'hidd:month:agree');

INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT 2921, '月报不同意', 2003, 14, '', '', 1, 0, 'F', 0, 0, 'hidd:month:disagree', '#', 'admin', NOW(), '隐患月报不同意按钮权限'
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'hidd:month:disagree');

INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT 2922, '月报回撤', 2003, 15, '', '', 1, 0, 'F', 0, 0, 'hidd:month:recall', '#', 'admin', NOW(), '隐患月报回撤按钮权限'
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'hidd:month:recall');

-- ============================================================
-- 1.3 事故月报独立权限拆分
-- ============================================================

INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT 2930, '事故月报待审批', 2402, 7, '', '', 1, 0, 'F', 0, 0, 'acci:month:approve', '#', 'admin', NOW(), '事故月报待审批按钮权限'
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'acci:month:approve');

INSERT INTO sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
SELECT 2931, '事故月报一键解锁', 2402, 8, '', '', 1, 0, 'F', 0, 0, 'acci:month:unlock', '#', 'admin', NOW(), '事故月报一键解锁按钮权限'
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE perms = 'acci:month:unlock');

-- ============================================================
-- 验证
-- ============================================================
SELECT menu_id, menu_name, parent_id, perms FROM sys_menu WHERE menu_id >= 2880 ORDER BY menu_id;
