SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ============================================
-- 菜单名称乱码修复脚本
-- 根据权限字符(perms)和菜单类型还原正确的菜单名称
-- ============================================

-- 1. 订单管理模块
UPDATE sys_menu SET menu_name = '订单管理' WHERE perms = 'bid:order:list';
UPDATE sys_menu SET menu_name = '待发订单' WHERE perms = 'bid:order:pending';
UPDATE sys_menu SET menu_name = '在途订单' WHERE perms = 'bid:order:transit';
UPDATE sys_menu SET menu_name = '历史订单' WHERE perms = 'bid:order:history';
UPDATE sys_menu SET menu_name = '结单时间' WHERE perms = 'bid:order:closeDate';

-- 2. 甲方客户管理
UPDATE sys_menu SET menu_name = '甲方客户' WHERE perms = 'bid:client:list';

-- 3. 操作记录
UPDATE sys_menu SET menu_name = '操作记录' WHERE perms = 'bid:operationlog:list';
UPDATE sys_menu SET menu_name = '查询' WHERE perms = 'bid:operationlog:query' AND menu_type = 'F';

-- 4. 甲方报价（如果有乱码）
UPDATE sys_menu SET menu_name = '甲方报价' WHERE perms = 'bid:clientquote:list';
UPDATE sys_menu SET menu_name = '新增' WHERE perms = 'bid:clientquote:add' AND menu_type = 'F';
UPDATE sys_menu SET menu_name = '编辑' WHERE perms = 'bid:clientquote:edit' AND menu_type = 'F';
UPDATE sys_menu SET menu_name = '删除' WHERE perms = 'bid:clientquote:remove' AND menu_type = 'F';
UPDATE sys_menu SET menu_name = '导出' WHERE perms = 'bid:clientquote:export' AND menu_type = 'F';

-- 5. 报价请求（RFQ）
UPDATE sys_menu SET menu_name = '报价请求' WHERE perms = 'bid:rfq:list';

-- 6. 供应商管理
UPDATE sys_menu SET menu_name = '供应商管理' WHERE perms = 'bid:supplier:list';

-- 7. 物料管理
UPDATE sys_menu SET menu_name = '物料管理' WHERE perms = 'bid:material:list';

-- 8. 智慧比价
UPDATE sys_menu SET menu_name = '智慧比价' WHERE perms = 'bid:comparison:list';

-- 9. 统计分析
UPDATE sys_menu SET menu_name = '统计分析' WHERE perms = 'bid:report:list';

-- 10. 采购单
UPDATE sys_menu SET menu_name = '采购单' WHERE perms = 'bid:purchaseorder:list';

-- 11. 供应商评价
UPDATE sys_menu SET menu_name = '供应商评价' WHERE perms = 'bid:evaluation:list';

-- 12. 交易记录
UPDATE sys_menu SET menu_name = '交易记录' WHERE perms = 'bid:transaction:list';

-- ============================================
-- 验证修复结果
-- ============================================

SELECT 
    menu_id,
    menu_name,
    perms,
    menu_type,
    CASE menu_type
        WHEN 'M' THEN '目录'
        WHEN 'C' THEN '菜单'
        WHEN 'F' THEN '按钮'
    END AS type_name,
    order_num,
    status
FROM sys_menu 
WHERE perms LIKE 'bid:%'
ORDER BY menu_id;

SET FOREIGN_KEY_CHECKS = 1;
