USE cattletrade;

-- 修复中转仓管理菜单中被截断的字段值
-- 该脚本专门用于修复字段值被截断的问题

-- ============================================
-- 修复进仓管理菜单（id=88）的 page_url
-- ============================================
-- 修复：warehouse/warehouselr -> warehouse/warehouseIn
UPDATE sys_menu 
SET 
    page_url = 'warehouse/warehouseIn',
    update_time = NOW()
WHERE id = 88
  AND name = '进仓管理'
  AND type = 1
  AND parent_id = 82
  AND page_url != 'warehouse/warehouseIn'
  AND is_delete = 0;

-- 如果上面的更新没有生效，尝试更宽泛的条件
UPDATE sys_menu 
SET 
    page_url = 'warehouse/warehouseIn',
    update_time = NOW()
WHERE name = '进仓管理' 
  AND type = 1
  AND parent_id = 82
  AND (page_url LIKE 'warehouse/warehouselr%'
       OR page_url = 'warehouse/warehouselr'
       OR page_url LIKE 'warehouse/warehouseIn%' AND page_url != 'warehouse/warehouseIn'
       OR LENGTH(page_url) < 20)
  AND is_delete = 0;

-- ============================================
-- 修复出仓管理菜单（id=93）的 page_url 和 authority
-- ============================================
-- 修复：warehouse/warehouseO -> warehouse/warehouseOut
-- 修复：warehouseout:li -> warehouseout:list
UPDATE sys_menu 
SET 
    page_url = 'warehouse/warehouseOut',
    authority = 'warehouseout:list',
    update_time = NOW()
WHERE id = 93
  AND name = '出仓管理'
  AND type = 1
  AND parent_id = 82
  AND (page_url != 'warehouse/warehouseOut' OR authority != 'warehouseout:list')
  AND is_delete = 0;

-- 如果上面的更新没有生效，尝试更宽泛的条件
UPDATE sys_menu 
SET 
    page_url = 'warehouse/warehouseOut',
    authority = 'warehouseout:list',
    update_time = NOW()
WHERE name = '出仓管理' 
  AND type = 1
  AND parent_id = 82
  AND (page_url LIKE 'warehouse/warehouseO%' AND page_url != 'warehouse/warehouseOut'
       OR page_url = 'warehouse/warehouseO'
       OR page_url LIKE 'warehouse/warehouseOut%' AND page_url != 'warehouse/warehouseOut'
       OR LENGTH(page_url) < 20
       OR authority LIKE 'warehouseout:li%' AND authority != 'warehouseout:list'
       OR authority = 'warehouseout:li'
       OR LENGTH(authority) < 15)
  AND is_delete = 0;

-- ============================================
-- 验证修复结果
-- ============================================
-- 执行以下查询验证数据是否正确：
-- SELECT id, parent_id, type, name, route_url, page_url, authority 
-- FROM sys_menu 
-- WHERE (id = 82 OR parent_id = 82) 
--   AND is_delete = 0 
-- ORDER BY id, sort;
--
-- 预期结果：
-- id=88: page_url = 'warehouse/warehouseIn'
-- id=93: page_url = 'warehouse/warehouseOut', authority = 'warehouseout:list'

