/*
 审批流程权限配置SQL
 
 Date: 2025-09-06
 Author: simon lin
*/

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- 添加审批流程一级菜单
INSERT INTO `sys_menu` VALUES (2120, '审批流程', 0, 4, 'approval', NULL, NULL, '', 1, 0, 'M', '0', '0', NULL, 'validCode', 'admin', NOW(), '', NULL, '审批流程管理目录');

-- 添加二级菜单：我的待办
INSERT INTO `sys_menu` VALUES (2121, '我的待办', 2120, 1, 'pending', 'system/approval/pending/index', NULL, '', 1, 0, 'C', '0', '0', 'system:approval:pending:list', 'time-range', 'admin', NOW(), '', NULL, '我的待办任务菜单');

-- 添加二级菜单：我的已办
INSERT INTO `sys_menu` VALUES (2122, '我的已办', 2120, 2, 'completed', 'system/approval/completed/index', NULL, '', 1, 0, 'C', '0', '0', 'system:approval:completed:list', 'checkbox', 'admin', NOW(), '', NULL, '我的已办任务菜单');

-- 添加二级菜单：我的申请
INSERT INTO `sys_menu` VALUES (2123, '我的申请', 2120, 3, 'submitted', 'system/approval/submitted/index', NULL, '', 1, 0, 'C', '0', '0', 'system:approval:submitted:list', 'documentation', 'admin', NOW(), '', NULL, '我的申请列表菜单');

-- 添加二级菜单：发起申请
INSERT INTO `sys_menu` VALUES (2124, '发起申请', 2120, 4, 'submit', 'system/approval/submit/index', NULL, '', 1, 0, 'C', '0', '0', 'system:approval:submit', 'edit', 'admin', NOW(), '', NULL, '发起申请菜单');

-- 添加二级菜单：流程管理（仅管理员可见）
INSERT INTO `sys_menu` VALUES (2125, '流程管理', 2120, 5, 'workflow', 'system/approval/workflow/index', NULL, '', 1, 0, 'C', '0', '0', 'system:approval:workflow:list', 'tree-table', 'admin', NOW(), '', NULL, '流程管理菜单');

-- 审批功能权限按钮
INSERT INTO `sys_menu` VALUES (2130, '查看待办任务', 2121, 1, '#', '', NULL, '', 1, 0, 'F', '0', '0', 'system:approval:query', '#', 'admin', NOW(), '', NULL, '');
INSERT INTO `sys_menu` VALUES (2131, '审批任务', 2121, 2, '#', '', NULL, '', 1, 0, 'F', '0', '0', 'system:approval:approve', '#', 'admin', NOW(), '', NULL, '');
INSERT INTO `sys_menu` VALUES (2132, '驳回任务', 2121, 3, '#', '', NULL, '', 1, 0, 'F', '0', '0', 'system:approval:reject', '#', 'admin', NOW(), '', NULL, '');

-- 发起申请功能权限按钮
INSERT INTO `sys_menu` VALUES (2133, '启动流程', 2124, 1, '#', '', NULL, '', 1, 0, 'F', '0', '0', 'system:approval:start', '#', 'admin', NOW(), '', NULL, '');
INSERT INTO `sys_menu` VALUES (2134, '取消流程', 2123, 1, '#', '', NULL, '', 1, 0, 'F', '0', '0', 'system:approval:cancel', '#', 'admin', NOW(), '', NULL, '');

-- 流程管理功能权限按钮（管理员专用）
INSERT INTO `sys_menu` VALUES (2135, '流程定义查询', 2125, 1, '#', '', NULL, '', 1, 0, 'F', '0', '0', 'system:approval:workflow:query', '#', 'admin', NOW(), '', NULL, '');
INSERT INTO `sys_menu` VALUES (2136, '流程定义新增', 2125, 2, '#', '', NULL, '', 1, 0, 'F', '0', '0', 'system:approval:workflow:add', '#', 'admin', NOW(), '', NULL, '');
INSERT INTO `sys_menu` VALUES (2137, '流程定义修改', 2125, 3, '#', '', NULL, '', 1, 0, 'F', '0', '0', 'system:approval:workflow:edit', '#', 'admin', NOW(), '', NULL, '');
INSERT INTO `sys_menu` VALUES (2138, '流程定义删除', 2125, 4, '#', '', NULL, '', 1, 0, 'F', '0', '0', 'system:approval:workflow:remove', '#', 'admin', NOW(), '', NULL, '');

-- 为角色分配权限的辅助表
-- 创建角色菜单关联表的插入语句（根据角色分配相应权限）

-- 超级管理员(role_id=1)：拥有所有权限
INSERT INTO `sys_role_menu` (role_id, menu_id) VALUES 
(1, 2120), (1, 2121), (1, 2122), (1, 2123), (1, 2124), (1, 2125),
(1, 2130), (1, 2131), (1, 2132), (1, 2133), (1, 2134), (1, 2135), (1, 2136), (1, 2137), (1, 2138);

-- 站长(role_id=100)：拥有全部功能权限，但不能管理流程定义
INSERT INTO `sys_role_menu` (role_id, menu_id) VALUES 
(100, 2120), (100, 2121), (100, 2122), (100, 2123), (100, 2124),
(100, 2130), (100, 2131), (100, 2132), (100, 2133), (100, 2134);

-- 安检员(role_id=101)：可以发起申请、查看自己的任务，基本审批权限
INSERT INTO `sys_role_menu` (role_id, menu_id) VALUES 
(101, 2120), (101, 2121), (101, 2122), (101, 2123), (101, 2124),
(101, 2130), (101, 2131), (101, 2132), (101, 2133), (101, 2134);

-- 班组长(role_id=102)：拥有完整审批权限
INSERT INTO `sys_role_menu` (role_id, menu_id) VALUES 
(102, 2120), (102, 2121), (102, 2122), (102, 2123), (102, 2124),
(102, 2130), (102, 2131), (102, 2132), (102, 2133), (102, 2134);

-- 科长(role_id=103)：拥有完整审批权限
INSERT INTO `sys_role_menu` (role_id, menu_id) VALUES 
(103, 2120), (103, 2121), (103, 2122), (103, 2123), (103, 2124),
(103, 2130), (103, 2131), (103, 2132), (103, 2133), (103, 2134);

-- 普通角色(role_id=2)：基本查看和申请权限
INSERT INTO `sys_role_menu` (role_id, menu_id) VALUES 
(2, 2120), (2, 2121), (2, 2122), (2, 2123), (2, 2124),
(2, 2130), (2, 2133), (2, 2134);

SET FOREIGN_KEY_CHECKS = 1;