-- =====================================================
-- 添加封禁管理菜单（替换原有的拉黑菜单）
-- eb_system_menu 表结构：id, pid, name, icon, perms, component, menu_type, sort, is_show, is_delte
-- =====================================================

-- 1. 查找用户管理的父菜单ID
SET @userManagePid = (SELECT id FROM eb_system_menu WHERE `name` = '用户管理' AND pid = 0 LIMIT 1);

-- 如果没有找到用户管理，尝试查找"用户"菜单
SET @userManagePid = IFNULL(@userManagePid, (SELECT id FROM eb_system_menu WHERE `name` = '用户' AND pid = 0 LIMIT 1));

-- 如果还是没有找到，使用默认值4（通常是用户菜单的ID）
SET @userManagePid = IFNULL(@userManagePid, 4);

SELECT CONCAT('用户管理菜单ID: ', @userManagePid) as info;

-- 2. 删除旧的拉黑菜单（如果存在）
DELETE FROM eb_system_menu WHERE `name` IN ('房间拉黑', '用户拉黑') AND pid = @userManagePid;

-- 3. 添加新的封禁菜单
-- 用户封禁
INSERT INTO eb_system_menu (`pid`, `name`, `icon`, `perms`, `component`, `menu_type`, `sort`, `is_show`, `is_delte`, `create_time`, `update_time`)
SELECT @userManagePid, '用户封禁', '', 'admin:ban:user', '/user/ban/userBan', 'C', 92, 1, 0, NOW(), NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM eb_system_menu WHERE `name` = '用户封禁' AND pid = @userManagePid);

-- 房间封禁
INSERT INTO eb_system_menu (`pid`, `name`, `icon`, `perms`, `component`, `menu_type`, `sort`, `is_show`, `is_delte`, `create_time`, `update_time`)
SELECT @userManagePid, '房间封禁', '', 'admin:ban:room', '/user/ban/roomBan', 'C', 91, 1, 0, NOW(), NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM eb_system_menu WHERE `name` = '房间封禁' AND pid = @userManagePid);

-- 4. 验证菜单
SELECT '=== 封禁管理菜单 ===' as info;
SELECT id, pid, `name`, perms, component, sort, is_show
FROM eb_system_menu 
WHERE pid = @userManagePid AND (`name` LIKE '%封禁%' OR `name` LIKE '%黑名单%' OR `name` LIKE '%拉黑%')
ORDER BY sort DESC;

-- 5. 显示所有用户管理子菜单
SELECT '=== 用户管理所有子菜单 ===' as info;
SELECT id, pid, `name`, perms, component, sort, is_show
FROM eb_system_menu 
WHERE pid = @userManagePid
ORDER BY sort DESC;
