-- 删除工单管理下的错误子菜单
-- 这些子菜单导致路由跳转到错误的URL

-- 步骤1：先查看要删除的菜单（确认后再执行删除）
SELECT 
    menu_id,
    menu_name,
    parent_id,
    path,
    component,
    query,
    menu_type,
    perms
FROM sys_menu
WHERE parent_id = 2098  -- 工单管理的直接子菜单
  AND menu_type = 'C'   -- 菜单类型
  AND path IN ('testOrder01', 'testWorkOrder02', 'test_work_order')
  AND menu_name IN ('进行中', '已完成', '测试中', '待领取', '一审中', '二审中', '三审中', '全部工单');

-- 步骤2：删除错误的状态子菜单
-- 注意：请先执行步骤1确认要删除的菜单，再执行此步骤
DELETE FROM sys_menu
WHERE parent_id = 2098  -- 工单管理的直接子菜单
  AND menu_type = 'C'   -- 菜单类型
  AND menu_name IN ('进行中', '已完成', '测试中', '待领取', '一审中', '二审中', '三审中', '全部工单');

-- 步骤3：删除所有包含错误路径的菜单
DELETE FROM sys_menu
WHERE parent_id = 2098
  AND path IN ('testOrder01', 'testWorkOrder02');

-- 步骤4：验证删除结果
SELECT 
    menu_id,
    menu_name,
    parent_id,
    path,
    component,
    menu_type
FROM sys_menu
WHERE parent_id = 2098
ORDER BY order_num;

-- 步骤5：确保工单管理父菜单的路径正确
UPDATE sys_menu
SET 
    path = 'test_work_order',
    update_time = NOW()
WHERE menu_id = 2098
  AND path != 'test_work_order';

-- 步骤6：最终验证 - 应该只有"测试工单"(menu_id=2092)这一个子菜单
SELECT 
    m1.menu_id as parent_id,
    m1.menu_name as parent_name,
    m1.path as parent_path,
    m2.menu_id as child_id,
    m2.menu_name as child_name,
    m2.path as child_path,
    m2.component as child_component,
    m2.menu_type as child_type
FROM sys_menu m1
LEFT JOIN sys_menu m2 ON m1.menu_id = m2.parent_id
WHERE m1.menu_id = 2098
ORDER BY m2.order_num;
