-- ═══════════════════════════════════════════════════════════
-- 菜单重组：订单履约 → 供应商履约（子目录）+ 甲方履约
-- 目标结构：
--   订单履约 (2120)
--     ├── 供应商履约 (新目录)
--     │   ├── 待发订单
--     │   ├── 在途订单
--     │   ├── 历史订单
--     │   ├── 结单时间管理
--     │   └── 订单异议
--     └── 甲方履约 (2044)
--         ├── 甲方待发
--         ├── 甲方在途
--         └── 甲方历史
-- ═══════════════════════════════════════════════════════════

SET NAMES utf8mb4;

-- 1. 创建「供应商履约」目录菜单（M = 目录），挂在订单履约(2120)下
INSERT IGNORE INTO sys_menu(menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time)
VALUES (2121, '供应商履约', 2120, 1, 'supplierFulfill', NULL, 1, 0, 'M', '0', '0', '', 'user', 'admin', NOW());

-- 2. 将 5 个子菜单移到「供应商履约」下
UPDATE sys_menu SET parent_id = 2121, order_num = 1 WHERE perms = 'bid:order:pending';
UPDATE sys_menu SET parent_id = 2121, order_num = 2 WHERE perms = 'bid:order:transit';
UPDATE sys_menu SET parent_id = 2121, order_num = 3 WHERE perms = 'bid:order:history';
UPDATE sys_menu SET parent_id = 2121, order_num = 4 WHERE perms = 'bid:order:closeDate';
UPDATE sys_menu SET parent_id = 2121, order_num = 5 WHERE perms = 'bid:objection:list';

-- 3. 甲方履约保持直接挂在订单履约下，排序调整到 2
UPDATE sys_menu SET parent_id = 2120, order_num = 2 WHERE perms = 'bid:clientDelivery:list';

-- 4. 给 admin 角色授权新菜单
INSERT IGNORE INTO sys_role_menu(role_id, menu_id)
SELECT 1, menu_id FROM sys_menu WHERE menu_id = 2121;

-- 5. 验证结果
SELECT m.menu_id, m.menu_name, m.parent_id, p.menu_name AS parent_name, m.order_num, m.perms
FROM sys_menu m
LEFT JOIN sys_menu p ON m.parent_id = p.menu_id
WHERE m.parent_id IN (2120, 2121)
   OR m.menu_id IN (2120, 2121)
ORDER BY m.parent_id, m.order_num;
