-- 为科研计划与国际合作功能添加菜单权限
USE `ry-vue`;

-- 插入菜单
INSERT IGNORE INTO sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
VALUES ('科研计划与国际合作', 1, 100, 'sciencePlan', 'system/sciencePlan/index', 1, 0, 'C', '0', '0', 'system:sciencePlan:view', 'education', 'admin', NOW(), 'admin', NOW(), '科研计划与国际合作管理');

-- 获取菜单ID
SELECT id INTO @menu_id FROM sys_menu WHERE menu_name = '科研计划与国际合作' AND parent_id = 1;

-- 插入编辑权限
INSERT IGNORE INTO sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
VALUES ('编辑', @menu_id, 1, '#', '', 1, 0, 'F', '0', '0', 'system:sciencePlan:edit', '', 'admin', NOW(), 'admin', NOW(), '科研计划与国际合作编辑权限');

-- 获取编辑权限ID
SELECT id INTO @edit_perm_id FROM sys_menu WHERE menu_name = '编辑' AND parent_id = @menu_id;

-- 获取管理员角色ID
SELECT role_id INTO @admin_role_id FROM sys_role WHERE role_key = 'admin';

-- 分配菜单权限
INSERT IGNORE INTO sys_role_menu (role_id, menu_id) VALUES (@admin_role_id, @menu_id);

-- 分配编辑权限
INSERT IGNORE INTO sys_role_menu (role_id, menu_id) VALUES (@admin_role_id, @edit_perm_id);

-- 查看结果
SELECT '菜单ID:', @menu_id, '编辑权限ID:', @edit_perm_id, '管理员角色ID:', @admin_role_id;