-- 将「设备补货单」模块添加到「库存管理」下
-- ============================================
-- 菜单 (已执行成功则跳过)
-- ============================================
INSERT IGNORE INTO t_menu (id, parent_id, menu_type, title, name, path, component, `rank`, icon, show_link, show_parent, `redirect`, keep_alive)
VALUES (505, 500, 0, '设备补货单', 'ReplenishmentOrder', '/inventory/replenishment-order', '', 4, 'ep:shopping-cart', 1, 0, '/inventory/replenishment-order/list', 1);

INSERT IGNORE INTO t_menu (id, parent_id, menu_type, title, name, path, component, `rank`, show_link, show_parent)
VALUES (506, 505, 0, '补货单列表', 'ReplenishmentOrderList', '/inventory/replenishment-order/list', 'replenishment-order/index', 1, 1, 0);

INSERT IGNORE INTO t_menu (id, parent_id, menu_type, title, name, path, component, `rank`, show_link, show_parent)
VALUES (507, 505, 0, '补货单详情', 'ReplenishmentOrderDetail', '/inventory/replenishment-order/detail', 'replenishment-order/detail', 2, 0, 0);

-- ============================================
-- 角色菜单关联 (自动生成不冲突的 ID)
-- ============================================
INSERT INTO t_role_menu (id, role_id, menu_id, create_time)
SELECT t.max_id + (@rn := @rn + 1), 1, src.menu_id, NOW()
FROM (SELECT 505 AS menu_id UNION ALL SELECT 506 UNION ALL SELECT 507) src
CROSS JOIN (SELECT @rn := 0) r
CROSS JOIN (SELECT COALESCE(MAX(id), 0) AS max_id FROM t_role_menu) t
WHERE NOT EXISTS (SELECT 1 FROM t_role_menu rm WHERE rm.role_id = 1 AND rm.menu_id = src.menu_id);
