# ============================
# 权限控制SQL - 档案管理和履约者管理模块
# @author steelwei
# @date 2026-03-04
# 说明: 本SQL适用于使用雪花ID的系统，需要手动执行并记录生成的ID
# ============================

-- ============================
-- 执行说明：
-- 1. 逐条执行INSERT语句
-- 2. 执行后查询 SELECT LAST_INSERT_ID() 获取生成的ID
-- 3. 将生成的ID用于后续的parent_id
-- 或者直接在后台菜单管理界面手动添加
-- ============================

-- ============================
-- 1. 档案管理模块菜单和权限
-- ============================

-- 档案管理一级菜单 (执行后记录生成的ID，假设为 @archieves_menu_id)
INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, query, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, remark) 
VALUES ('档案管理', 0, 4, 'archieves', NULL, '', 1, 0, 'M', '0', '0', '', 'peoples', 103, 1, sysdate(), '档案管理目录');

-- 用户管理菜单 (parent_id 需要替换为上面生成的档案管理菜单ID)
-- 执行后记录生成的ID，假设为 @customer_menu_id
INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, query, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, remark) 
VALUES ('用户管理', (SELECT menu_id FROM sys_menu WHERE menu_name='档案管理' AND parent_id=0 ORDER BY create_time DESC LIMIT 1), 1, 'customer', 'archieves/customer/index', '', 1, 0, 'C', '0', '0', 'archieves:customer:list', 'user', 103, 1, sysdate(), '用户管理菜单');

-- 用户管理按钮权限 (parent_id 为用户管理菜单ID)
INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, query, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, remark) 
VALUES ('用户查询', (SELECT menu_id FROM sys_menu WHERE menu_name='用户管理' AND perms='archieves:customer:list' ORDER BY create_time DESC LIMIT 1), 1, '#', '', '', 1, 0, 'F', '0', '0', 'archieves:customer:query', '#', 103, 1, sysdate(), '');

INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, query, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, remark) 
VALUES ('用户新增', (SELECT menu_id FROM sys_menu WHERE menu_name='用户管理' AND perms='archieves:customer:list' ORDER BY create_time DESC LIMIT 1), 2, '#', '', '', 1, 0, 'F', '0', '0', 'archieves:customer:add', '#', 103, 1, sysdate(), '');

INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, query, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, remark) 
VALUES ('用户编辑', (SELECT menu_id FROM sys_menu WHERE menu_name='用户管理' AND perms='archieves:customer:list' ORDER BY create_time DESC LIMIT 1), 3, '#', '', '', 1, 0, 'F', '0', '0', 'archieves:customer:edit', '#', 103, 1, sysdate(), '');

INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, query, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, remark) 
VALUES ('用户删除', (SELECT menu_id FROM sys_menu WHERE menu_name='用户管理' AND perms='archieves:customer:list' ORDER BY create_time DESC LIMIT 1), 4, '#', '', '', 1, 0, 'F', '0', '0', 'archieves:customer:remove', '#', 103, 1, sysdate(), '');

INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, query, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, remark) 
VALUES ('用户导出', (SELECT menu_id FROM sys_menu WHERE menu_name='用户管理' AND perms='archieves:customer:list' ORDER BY create_time DESC LIMIT 1), 5, '#', '', '', 1, 0, 'F', '0', '0', 'archieves:customer:export', '#', 103, 1, sysdate(), '');

-- 宠物管理菜单
INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, query, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, remark) 
VALUES ('宠物管理', (SELECT menu_id FROM sys_menu WHERE menu_name='档案管理' AND parent_id=0 ORDER BY create_time DESC LIMIT 1), 2, 'pet', 'archieves/pet/index', '', 1, 0, 'C', '0', '0', 'archieves:pet:list', 'pets', 103, 1, sysdate(), '宠物管理菜单');

-- 宠物管理按钮权限
INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, query, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, remark) 
VALUES ('宠物查询', (SELECT menu_id FROM sys_menu WHERE menu_name='宠物管理' AND perms='archieves:pet:list' ORDER BY create_time DESC LIMIT 1), 1, '#', '', '', 1, 0, 'F', '0', '0', 'archieves:pet:query', '#', 103, 1, sysdate(), '');

INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, query, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, remark) 
VALUES ('宠物新增', (SELECT menu_id FROM sys_menu WHERE menu_name='宠物管理' AND perms='archieves:pet:list' ORDER BY create_time DESC LIMIT 1), 2, '#', '', '', 1, 0, 'F', '0', '0', 'archieves:pet:add', '#', 103, 1, sysdate(), '');

INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, query, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, remark) 
VALUES ('宠物编辑', (SELECT menu_id FROM sys_menu WHERE menu_name='宠物管理' AND perms='archieves:pet:list' ORDER BY create_time DESC LIMIT 1), 3, '#', '', '', 1, 0, 'F', '0', '0', 'archieves:pet:edit', '#', 103, 1, sysdate(), '');

INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, query, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, remark) 
VALUES ('宠物删除', (SELECT menu_id FROM sys_menu WHERE menu_name='宠物管理' AND perms='archieves:pet:list' ORDER BY create_time DESC LIMIT 1), 4, '#', '', '', 1, 0, 'F', '0', '0', 'archieves:pet:remove', '#', 103, 1, sysdate(), '');

INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, query, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, remark) 
VALUES ('宠物导出', (SELECT menu_id FROM sys_menu WHERE menu_name='宠物管理' AND perms='archieves:pet:list' ORDER BY create_time DESC LIMIT 1), 5, '#', '', '', 1, 0, 'F', '0', '0', 'archieves:pet:export', '#', 103, 1, sysdate(), '');

-- 标签管理菜单（档案）
INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, query, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, remark) 
VALUES ('标签管理', (SELECT menu_id FROM sys_menu WHERE menu_name='档案管理' AND parent_id=0 ORDER BY create_time DESC LIMIT 1), 3, 'tag', 'archieves/tag/index', '', 1, 0, 'C', '0', '0', 'archieves:tag:list', 'price-tag', 103, 1, sysdate(), '标签管理菜单');

-- 标签管理按钮权限
INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, query, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, remark) 
VALUES ('标签查询', (SELECT menu_id FROM sys_menu WHERE menu_name='标签管理' AND perms='archieves:tag:list' ORDER BY create_time DESC LIMIT 1), 1, '#', '', '', 1, 0, 'F', '0', '0', 'archieves:tag:query', '#', 103, 1, sysdate(), '');
INSERT INTO sys_menu VALUES('2032', '标签新增', '2030', '2', '#', '', '', 1, 0, 'F', '0', '0', 'archieves:tag:add', '#', 103, 1, sysdate(), NULL, NULL, '');
INSERT INTO sys_menu VALUES('2033', '标签编辑', '2030', '3', '#', '', '', 1, 0, 'F', '0', '0', 'archieves:tag:edit', '#', 103, 1, sysdate(), NULL, NULL, '');
INSERT INTO sys_menu VALUES('2034', '标签删除', '2030', '4', '#', '', '', 1, 0, 'F', '0', '0', 'archieves:tag:remove', '#', 103, 1, sysdate(), NULL, NULL, '');
INSERT INTO sys_menu VALUES('2035', '标签导出', '2030', '5', '#', '', '', 1, 0, 'F', '0', '0', 'archieves:tag:export', '#', 103, 1, sysdate(), NULL, NULL, '');

-- ============================
-- 2. 履约者管理模块菜单和权限
-- ============================

-- 履约者管理一级菜单
INSERT INTO sys_menu VALUES('2100', '履约者管理', '0', '5', 'fulfiller', NULL, '', 1, 0, 'M', '0', '0', '', 'peoples', 103, 1, sysdate(), NULL, NULL, '履约者管理目录');

-- 履约者池菜单
INSERT INTO sys_menu VALUES('2110', '履约者池', '2100', '1', 'pool', 'fulfiller/pool/index', '', 1, 0, 'C', '0', '0', 'fulfiller:pool:list', 'user', 103, 1, sysdate(), NULL, NULL, '履约者池菜单');
INSERT INTO sys_menu VALUES('2111', '履约者查询', '2110', '1', '#', '', '', 1, 0, 'F', '0', '0', 'fulfiller:pool:query', '#', 103, 1, sysdate(), NULL, NULL, '');
INSERT INTO sys_menu VALUES('2112', '履约者新增', '2110', '2', '#', '', '', 1, 0, 'F', '0', '0', 'fulfiller:pool:add', '#', 103, 1, sysdate(), NULL, NULL, '');
INSERT INTO sys_menu VALUES('2113', '履约者编辑', '2110', '3', '#', '', '', 1, 0, 'F', '0', '0', 'fulfiller:pool:edit', '#', 103, 1, sysdate(), NULL, NULL, '');
INSERT INTO sys_menu VALUES('2114', '履约者删除', '2110', '4', '#', '', '', 1, 0, 'F', '0', '0', 'fulfiller:pool:remove', '#', 103, 1, sysdate(), NULL, NULL, '');
INSERT INTO sys_menu VALUES('2115', '履约者导出', '2110', '5', '#', '', '', 1, 0, 'F', '0', '0', 'fulfiller:pool:export', '#', 103, 1, sysdate(), NULL, NULL, '');

-- 审核管理菜单
INSERT INTO sys_menu VALUES('2120', '审核管理', '2100', '2', 'audit', 'fulfiller/audit/index', '', 1, 0, 'C', '0', '0', 'fulfiller:audit:list', 'edit', 103, 1, sysdate(), NULL, NULL, '审核管理菜单');
INSERT INTO sys_menu VALUES('2121', '审核查询', '2120', '1', '#', '', '', 1, 0, 'F', '0', '0', 'fulfiller:audit:query', '#', 103, 1, sysdate(), NULL, NULL, '');
INSERT INTO sys_menu VALUES('2122', '审核通过', '2120', '2', '#', '', '', 1, 0, 'F', '0', '0', 'fulfiller:audit:approve', '#', 103, 1, sysdate(), NULL, NULL, '');
INSERT INTO sys_menu VALUES('2123', '审核驳回', '2120', '3', '#', '', '', 1, 0, 'F', '0', '0', 'fulfiller:audit:reject', '#', 103, 1, sysdate(), NULL, NULL, '');
INSERT INTO sys_menu VALUES('2124', '审核删除', '2120', '4', '#', '', '', 1, 0, 'F', '0', '0', 'fulfiller:audit:remove', '#', 103, 1, sysdate(), NULL, NULL, '');
INSERT INTO sys_menu VALUES('2125', '审核导出', '2120', '5', '#', '', '', 1, 0, 'F', '0', '0', 'fulfiller:audit:export', '#', 103, 1, sysdate(), NULL, NULL, '');

-- 标签管理菜单（履约者）
INSERT INTO sys_menu VALUES('2130', '标签管理', '2100', '3', 'tag', 'fulfiller/tag/index', '', 1, 0, 'C', '0', '0', 'fulfiller:tag:list', 'price-tag', 103, 1, sysdate(), NULL, NULL, '履约者标签管理菜单');
INSERT INTO sys_menu VALUES('2131', '标签查询', '2130', '1', '#', '', '', 1, 0, 'F', '0', '0', 'fulfiller:tag:query', '#', 103, 1, sysdate(), NULL, NULL, '');
INSERT INTO sys_menu VALUES('2132', '标签新增', '2130', '2', '#', '', '', 1, 0, 'F', '0', '0', 'fulfiller:tag:add', '#', 103, 1, sysdate(), NULL, NULL, '');
INSERT INTO sys_menu VALUES('2133', '标签编辑', '2130', '3', '#', '', '', 1, 0, 'F', '0', '0', 'fulfiller:tag:edit', '#', 103, 1, sysdate(), NULL, NULL, '');
INSERT INTO sys_menu VALUES('2134', '标签删除', '2130', '4', '#', '', '', 1, 0, 'F', '0', '0', 'fulfiller:tag:remove', '#', 103, 1, sysdate(), NULL, NULL, '');
INSERT INTO sys_menu VALUES('2135', '标签导出', '2130', '5', '#', '', '', 1, 0, 'F', '0', '0', 'fulfiller:tag:export', '#', 103, 1, sysdate(), NULL, NULL, '');

-- ============================
-- 3. 为管理员角色分配权限（可选，根据实际需求调整）
-- ============================

-- 档案管理权限分配给角色ID=2（管理员）
INSERT INTO sys_role_menu VALUES ('2', '2001');
INSERT INTO sys_role_menu VALUES ('2', '2010');
INSERT INTO sys_role_menu VALUES ('2', '2011');
INSERT INTO sys_role_menu VALUES ('2', '2012');
INSERT INTO sys_role_menu VALUES ('2', '2013');
INSERT INTO sys_role_menu VALUES ('2', '2014');
INSERT INTO sys_role_menu VALUES ('2', '2015');
INSERT INTO sys_role_menu VALUES ('2', '2020');
INSERT INTO sys_role_menu VALUES ('2', '2021');
INSERT INTO sys_role_menu VALUES ('2', '2022');
INSERT INTO sys_role_menu VALUES ('2', '2023');
INSERT INTO sys_role_menu VALUES ('2', '2024');
INSERT INTO sys_role_menu VALUES ('2', '2025');
INSERT INTO sys_role_menu VALUES ('2', '2030');
INSERT INTO sys_role_menu VALUES ('2', '2031');
INSERT INTO sys_role_menu VALUES ('2', '2032');
INSERT INTO sys_role_menu VALUES ('2', '2033');
INSERT INTO sys_role_menu VALUES ('2', '2034');
INSERT INTO sys_role_menu VALUES ('2', '2035');

-- 履约者管理权限分配给角色ID=2（管理员）
INSERT INTO sys_role_menu VALUES ('2', '2100');
INSERT INTO sys_role_menu VALUES ('2', '2110');
INSERT INTO sys_role_menu VALUES ('2', '2111');
INSERT INTO sys_role_menu VALUES ('2', '2112');
INSERT INTO sys_role_menu VALUES ('2', '2113');
INSERT INTO sys_role_menu VALUES ('2', '2114');
INSERT INTO sys_role_menu VALUES ('2', '2115');
INSERT INTO sys_role_menu VALUES ('2', '2120');
INSERT INTO sys_role_menu VALUES ('2', '2121');
INSERT INTO sys_role_menu VALUES ('2', '2122');
INSERT INTO sys_role_menu VALUES ('2', '2123');
INSERT INTO sys_role_menu VALUES ('2', '2124');
INSERT INTO sys_role_menu VALUES ('2', '2125');
INSERT INTO sys_role_menu VALUES ('2', '2130');
INSERT INTO sys_role_menu VALUES ('2', '2131');
INSERT INTO sys_role_menu VALUES ('2', '2132');
INSERT INTO sys_role_menu VALUES ('2', '2133');
INSERT INTO sys_role_menu VALUES ('2', '2134');
INSERT INTO sys_role_menu VALUES ('2', '2135');
