USE cattletrade;

-- 诊断和修复脚本：检查问题并强制修复
-- ============================================

-- ============================================
-- 步骤1：诊断当前状态
-- ============================================
SELECT 
    '=== 当前状态 ===' as info,
    id, 
    name, 
    page_url, 
    CHAR_LENGTH(page_url) as page_url_len,
    HEX(page_url) as page_url_hex,
    authority,
    CHAR_LENGTH(authority) as authority_len,
    HEX(authority) as authority_hex
FROM sys_menu 
WHERE id IN (88, 93);

-- ============================================
-- 步骤2：检查是否有触发器
-- ============================================
SHOW TRIGGERS FROM cattletrade LIKE 'sys_menu';

-- ============================================
-- 步骤3：检查字段定义和约束
-- ============================================
SHOW COLUMNS FROM sys_menu WHERE Field IN ('page_url', 'authority');

-- ============================================
-- 步骤4：尝试强制更新（使用不同的方法）
-- ============================================

-- 方法1：直接UPDATE，不检查任何条件
UPDATE sys_menu 
SET page_url = 'warehouse/warehouseIn'
WHERE id = 88;

-- 检查是否成功
SELECT 
    '=== 更新 id=88 后 ===' as info,
    id, 
    name, 
    page_url, 
    CHAR_LENGTH(page_url) as page_url_len
FROM sys_menu 
WHERE id = 88;

-- 方法2：更新 id=93
UPDATE sys_menu 
SET 
    page_url = 'warehouse/warehouseOut',
    authority = 'warehouseout:list'
WHERE id = 93;

-- 检查是否成功
SELECT 
    '=== 更新 id=93 后 ===' as info,
    id, 
    name, 
    page_url, 
    CHAR_LENGTH(page_url) as page_url_len,
    authority,
    CHAR_LENGTH(authority) as authority_len
FROM sys_menu 
WHERE id = 93;

-- ============================================
-- 步骤5：如果上述方法失败，尝试使用 REPLACE
-- ============================================
-- 注意：REPLACE 会删除并重新插入，需要所有字段值

-- 先查询完整记录
SELECT * FROM sys_menu WHERE id = 88;
SELECT * FROM sys_menu WHERE id = 93;

-- 如果 UPDATE 失败，可以使用以下方法（需要根据实际字段值调整）：
-- REPLACE INTO sys_menu (id, parent_id, type, icon, name, sort, route_url, page_url, org_type, authority, create_time, update_time, is_delete)
-- SELECT id, parent_id, type, icon, name, sort, route_url, 'warehouse/warehouseIn', org_type, authority, create_time, NOW(), is_delete
-- FROM sys_menu WHERE id = 88;

-- ============================================
-- 步骤6：最终验证
-- ============================================
SELECT 
    '=== 最终验证 ===' as info,
    id, 
    name, 
    page_url, 
    CHAR_LENGTH(page_url) as page_url_len,
    CASE 
        WHEN page_url = 'warehouse/warehouseIn' THEN '✓ 正确'
        ELSE '✗ 错误'
    END as page_url_status,
    authority,
    CHAR_LENGTH(authority) as authority_len,
    CASE 
        WHEN authority = 'warehouseout:list' THEN '✓ 正确'
        ELSE '✗ 错误'
    END as authority_status
FROM sys_menu 
WHERE id IN (88, 93);

