-- 为科研计划与国际合作功能添加菜单权限
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为100，根据实际情况调整）
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 ('编辑', (SELECT id FROM sys_menu WHERE menu_name = '科研计划与国际合作' AND parent_id = 1), 1, '#', '', 1, 0, 'F', '0', '0', 'system:sciencePlan:edit', '', 'admin', NOW(), 'admin', NOW(), '科研计划与国际合作编辑权限');

-- 为管理员角色分配权限
INSERT IGNORE INTO sys_role_menu (role_id, menu_id)
SELECT r.role_id, m.id
FROM sys_role r, sys_menu m
WHERE r.role_key = 'admin' AND m.menu_name = '科研计划与国际合作';

-- 为管理员角色分配编辑权限
INSERT IGNORE INTO sys_role_menu (role_id, menu_id)
SELECT r.role_id, m.id
FROM sys_role r, sys_menu m
WHERE r.role_key = 'admin' AND m.menu_name = '编辑' AND m.parent_id = (SELECT id FROM sys_menu WHERE menu_name = '科研计划与国际合作' AND parent_id = 1);

-- 查看结果
SELECT * FROM sys_menu WHERE menu_name LIKE '%科研计划%' OR menu_name = '编辑';
SELECT * FROM sys_role_menu rm JOIN sys_menu m ON rm.menu_id = m.id WHERE m.menu_name LIKE '%科研计划%' OR m.menu_name = '编辑';