-- 修复用户管理菜单问题
USE soybean_admin;

-- ============================================
-- 修复用户管理路由的 name 字段
-- 必须与前端 routeMap 和角色配置完全一致
-- ============================================

-- 父路由：user-manage（使用连字符）
UPDATE sys_route 
SET name = 'user-manage' 
WHERE route_id = 'user_manage';

-- 子路由：user-manage_list, user-manage_role, user-manage_permission
UPDATE sys_route 
SET name = 'user-manage_list' 
WHERE route_id = 'user_manage_list';

UPDATE sys_route 
SET name = 'user-manage_role' 
WHERE route_id = 'user_manage_role';

UPDATE sys_route 
SET name = 'user-manage_permission' 
WHERE route_id = 'user_manage_permission';

-- ============================================
-- 修复组件路径
-- 父路由用 layout.base，子路由用 view.xxx
-- ============================================

-- 父路由
UPDATE sys_route 
SET component = 'layout.base' 
WHERE route_id = 'user_manage';

-- 子路由
UPDATE sys_route 
SET component = 'view.user-manage_list' 
WHERE route_id = 'user_manage_list';

UPDATE sys_route 
SET component = 'view.user-manage_role' 
WHERE route_id = 'user_manage_role';

UPDATE sys_route 
SET component = 'view.user-manage_permission' 
WHERE route_id = 'user_manage_permission';

-- ============================================
-- 验证修复结果
-- ============================================

SELECT '========================================' AS '';
SELECT '修复后的用户管理路由' AS '';
SELECT '========================================' AS '';
SELECT route_id, name, path, component 
FROM sys_route 
WHERE route_id LIKE 'user%'
ORDER BY order_num;

SELECT '' AS '';
SELECT '========================================' AS '';
SELECT '检查是否匹配角色配置' AS '';
SELECT '========================================' AS '';
SELECT 
    r.route_id,
    r.name AS route_name,
    CASE 
        WHEN role.menus LIKE CONCAT('%', r.name, '%') THEN '✓ 匹配'
        ELSE '✗ 不匹配'
    END AS matches_role_config
FROM sys_route r
CROSS JOIN sys_role role
WHERE role.role_code = 'R_SUPER'
  AND r.route_id LIKE 'user%'
ORDER BY r.order_num;
