USE cattletrade;

-- 检查 sys_menu 表的字段长度
-- 用于诊断字段值被截断的问题

-- ============================================
-- 1. 检查 page_url 和 authority 字段的定义
-- ============================================
-- 执行以下查询查看字段定义：
SHOW COLUMNS FROM sys_menu WHERE Field IN ('page_url', 'authority');

-- 或者使用以下查询：
SELECT 
    COLUMN_NAME,
    DATA_TYPE,
    CHARACTER_MAXIMUM_LENGTH,
    COLUMN_COMMENT
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'cattletrade'
  AND TABLE_NAME = 'sys_menu'
  AND COLUMN_NAME IN ('page_url', 'authority');

-- ============================================
-- 2. 检查当前菜单数据的字段长度
-- ============================================
SELECT 
    id,
    parent_id,
    type,
    name,
    route_url,
    page_url,
    LENGTH(page_url) as page_url_length,
    authority,
    LENGTH(authority) as authority_length
FROM sys_menu 
WHERE (id = 82 OR parent_id = 82) 
  AND is_delete = 0 
ORDER BY id, sort;

-- ============================================
-- 3. 检查是否有被截断的字段值
-- ============================================
-- 检查进仓管理菜单
SELECT 
    id,
    name,
    page_url,
    LENGTH(page_url) as page_url_length,
    'warehouse/warehouseIn' as expected_value,
    LENGTH('warehouse/warehouseIn') as expected_length
FROM sys_menu 
WHERE id = 88 
  AND is_delete = 0;

-- 检查出仓管理菜单
SELECT 
    id,
    name,
    page_url,
    LENGTH(page_url) as page_url_length,
    authority,
    LENGTH(authority) as authority_length,
    'warehouse/warehouseOut' as expected_page_url,
    LENGTH('warehouse/warehouseOut') as expected_page_url_length,
    'warehouseout:list' as expected_authority,
    LENGTH('warehouseout:list') as expected_authority_length
FROM sys_menu 
WHERE id = 93 
  AND is_delete = 0;

-- ============================================
-- 4. 如果需要扩展字段长度，执行以下语句（取消注释）
-- ============================================
-- 注意：执行前请先备份数据库！

-- 扩展 page_url 字段长度到 255
-- ALTER TABLE sys_menu MODIFY COLUMN page_url VARCHAR(255) COMMENT '前端路由地址';

-- 扩展 authority 字段长度到 100
-- ALTER TABLE sys_menu MODIFY COLUMN authority VARCHAR(100) COMMENT '权限字符串';

