-- 完整修复403权限问题
USE soybean_admin;

-- 1. 显示当前配置
SELECT '=== 修复前的角色配置 ===' AS info;
SELECT role_code, role_name, menus FROM sys_role;

-- 2. 修复所有角色的菜单配置
-- 注意：父路由使用连字符（如 user-manage, my-device），子路由使用下划线（如 user-manage_list, my-device_status）

-- 超级管理员：拥有所有权限
UPDATE sys_role 
SET menus = 'home,device,device_list,device_online,device_power,device_monitor,device_group,screen,screen_wall,screen_control,screen_record,user-manage,user-manage_list,user-manage_role,user-manage_permission,application,application_approval,application_history,system,system_amt,system_agent,system_log,my-device,my-device_status,my-device_remote-control,my-device_power-control,my-application,my-application_apply,my-application_my-list'
WHERE role_code = 'R_SUPER';

-- 管理员：除了系统设置和权限管理外的所有功能
UPDATE sys_role 
SET menus = 'home,device,device_list,device_online,device_power,device_monitor,device_group,screen,screen_wall,screen_control,screen_record,user-manage,user-manage_list,user-manage_role,application,application_approval,application_history'
WHERE role_code = 'R_ADMIN';

-- 普通用户：只能访问自己的设备和申请
UPDATE sys_role 
SET menus = 'home,my-device,my-device_status,my-device_remote-control,my-device_power-control,my-application,my-application_apply,my-application_my-list'
WHERE role_code = 'R_USER';

-- 学生：只能访问首页（如果需要更多权限可以添加）
UPDATE sys_role 
SET menus = 'home'
WHERE role_code = 'R_STU';

-- 3. 显示修复后的配置
SELECT '=== 修复后的角色配置 ===' AS info;
SELECT role_code, role_name, menus FROM sys_role;

-- 4. 验证路由表中的路由名称
SELECT '=== 数据库中的路由名称 ===' AS info;
SELECT name, path, component FROM sys_route WHERE status = 1 ORDER BY order_num;

-- 5. 检查用户的角色配置
SELECT '=== 用户角色配置 ===' AS info;
SELECT user_id, user_name, roles, status FROM sys_user;
