-- ============================================================
-- 系统路由表 (sys_routes) 剩余更新脚本
-- 说明：部分更新已完成（废弃路由删除、settings创建等）
--       此脚本仅包含剩余需要执行的步骤
-- 生成时间: 2025-11-17
-- ============================================================

-- ============================================================
-- 第 1 步：添加缺失的路由
-- ============================================================

-- 1.1 添加 /rules/list 列表页（作为 rules 的子级）
INSERT INTO sys_routes (
    route_path, route_name, route_title,
    parent_id, icon, sort_order,
    is_hidden, is_cache, component, meta
) VALUES (
    '/rules/list', 'RulesList', '评查点列表',
    41, NULL, 2,
    false, true, 'views/rules/List.vue', '{}'
);

-- 1.2 添加 /rules-files（作为 rules 的子级）
INSERT INTO sys_routes (
    route_path, route_name, route_title,
    parent_id, icon, sort_order,
    is_hidden, is_cache, component, meta
) VALUES (
    '/rules-files', 'RulesFiles', '评查文件列表',
    41, NULL, 3,
    false, true, 'views/rules/Files.vue', '{}'
);

-- 1.3 添加 /contract-template/list（作为 contract-template 的子级）
INSERT INTO sys_routes (
    route_path, route_name, route_title,
    parent_id, icon, sort_order,
    is_hidden, is_cache, component, meta
) VALUES (
    '/contract-template/list', 'ContractTemplateList', '合同列表',
    38, NULL, 2,
    false, true, 'views/contract-template/List.vue', '{}'
);

-- 1.4 添加 /reviews 评查详情页（隐藏路由）
INSERT INTO sys_routes (
    route_path, route_name, route_title,
    parent_id, icon, sort_order,
    is_hidden, is_cache, component, meta
) VALUES (
    '/reviews', 'Reviews', '评查详情',
    NULL, NULL, 99,
    true, true, 'views/reviews/Index.vue', '{}'
);

-- ============================================================
-- 第 2 步：调整排序顺序
-- ============================================================

-- 期望的一级菜单顺序：
-- 1. 系统概览
-- 2. 文档管理
-- 3. 评查规则库
-- 4. 合同模板
-- 5. 系统设置
-- 6. 交叉评查
-- 7. AI法务助手
-- 8. 文件管理
-- 9. 配置列表

UPDATE sys_routes SET sort_order = 1 WHERE id = 31;  -- /home (系统概览)
UPDATE sys_routes SET sort_order = 2 WHERE id = 2;   -- /documents (文档管理)
UPDATE sys_routes SET sort_order = 3 WHERE id = 41;  -- /rules (评查规则库)
UPDATE sys_routes SET sort_order = 4 WHERE id = 38;  -- /contract-template (合同模板)
UPDATE sys_routes SET sort_order = 5 WHERE id = 53;  -- /settings (系统设置)
UPDATE sys_routes SET sort_order = 6 WHERE id = 35;  -- /cross-checking (交叉评查)
UPDATE sys_routes SET sort_order = 7 WHERE id = 40;  -- /chat-with-llm (AI法务助手)
UPDATE sys_routes SET sort_order = 8 WHERE id = 51;  -- /files (文件管理)
UPDATE sys_routes SET sort_order = 9 WHERE id = 49;  -- /config-lists (配置列表)

-- ============================================================
-- 第 3 步：隐藏入口页
-- ============================================================

UPDATE sys_routes SET is_hidden = true WHERE id = 30;  -- /

-- ============================================================
-- 第 4 步：验证更新结果
-- ============================================================

-- 查看更新后的一级菜单
SELECT id, route_path, route_name, route_title, parent_id, icon, sort_order, is_hidden
FROM sys_routes
WHERE parent_id IS NULL
ORDER BY sort_order;

-- 查看 /rules 的子菜单
SELECT id, route_path, route_name, route_title, parent_id, sort_order, is_hidden
FROM sys_routes
WHERE parent_id = 41
ORDER BY sort_order;

-- 查看 /contract-template 的子菜单
SELECT id, route_path, route_name, route_title, parent_id, sort_order, is_hidden
FROM sys_routes
WHERE parent_id = 38
ORDER BY sort_order;

-- 查看 /settings 的子菜单
SELECT id, route_path, route_name, route_title, parent_id, sort_order, is_hidden
FROM sys_routes
WHERE parent_id = 53
ORDER BY sort_order;

-- ============================================================
-- 完成！
-- ============================================================

-- 提示：执行此脚本后，请重新登录系统以刷新路由权限
