USE cattletrade;

-- 修复中转仓管理菜单的组件路径
-- 该脚本用于修复已存在的菜单记录，确保组件路径正确

-- ============================================
-- 1. 修复中转仓管理菜单（list）
-- ============================================
UPDATE sys_menu 
SET 
    route_url = 'list',
    page_url = 'warehouse/warehouse',
    update_time = NOW()
WHERE name = '中转仓管理' 
  AND parent_id IN (SELECT id FROM (SELECT id FROM sys_menu WHERE name = '中转仓管理' AND type = 0 AND is_delete = 0) AS temp)
  AND type = 1 
  AND is_delete = 0
  AND page_url != 'warehouse/warehouse';

-- ============================================
-- 2. 修复进仓管理菜单（in）
-- ============================================
UPDATE sys_menu 
SET 
    route_url = 'in',
    page_url = 'warehouse/warehouseIn',
    update_time = NOW()
WHERE name = '进仓管理' 
  AND parent_id IN (SELECT id FROM (SELECT id FROM sys_menu WHERE name = '中转仓管理' AND type = 0 AND is_delete = 0) AS temp)
  AND type = 1 
  AND is_delete = 0
  AND page_url != 'warehouse/warehouseIn';

-- ============================================
-- 3. 修复出仓管理菜单（out）
-- ============================================
UPDATE sys_menu 
SET 
    route_url = 'out',
    page_url = 'warehouse/warehouseOut',
    update_time = NOW()
WHERE name = '出仓管理' 
  AND parent_id IN (SELECT id FROM (SELECT id FROM sys_menu WHERE name = '中转仓管理' AND type = 0 AND is_delete = 0) AS temp)
  AND type = 1 
  AND is_delete = 0
  AND page_url != 'warehouse/warehouseOut';

-- ============================================
-- 4. 修复运输管理菜单中的shippingList（如果存在）
-- ============================================
-- 注意：如果数据库中存在 shipping/shippinglist 的菜单，需要手动修复
-- 实际文件是 shipping/shippingList.vue（注意大小写）
-- 修复所有可能的变体：shipping/shippinglist, shipping/ShippingList, shipping/SHIPPINGLIST 等
-- 使用 LOWER() 函数进行大小写不敏感匹配
UPDATE sys_menu 
SET 
    page_url = 'shipping/shippingList',
    update_time = NOW()
WHERE LOWER(page_url) = 'shipping/shippinglist'
  AND page_url != 'shipping/shippingList'
  AND is_delete = 0;

-- 修复其他可能的变体（包含路径的情况，包括带前导斜杠的情况）
UPDATE sys_menu 
SET 
    page_url = 'shipping/shippingList',
    update_time = NOW()
WHERE (LOWER(page_url) LIKE '%shipping/shippinglist%'
   OR LOWER(page_url) LIKE '%/shipping/shippinglist%'
   OR page_url LIKE '%shipping/ShippingList%'
   OR page_url LIKE '%shipping/SHIPPINGLIST%')
  AND page_url != 'shipping/shippingList'
  AND page_url != '/shipping/shippingList'
  AND is_delete = 0;

-- 修复带前导斜杠的情况（如 /shipping/shippinglist -> shipping/shippingList）
UPDATE sys_menu 
SET 
    page_url = 'shipping/shippingList',
    update_time = NOW()
WHERE LOWER(page_url) = '/shipping/shippinglist'
  AND is_delete = 0;

