-- =====================================================
-- 修复拉黑菜单 - 最终版
-- =====================================================

-- 1. 查看表结构
DESC eb_system_menu;

-- 2. 查看社交互动菜单
SELECT id, pid, `name`, component, menu_type, sort, is_show FROM eb_system_menu WHERE `name` = '社交互动';

-- 3. 查看群组管理作为参考（它能正常显示）
SELECT * FROM eb_system_menu WHERE `name` = '群组管理';

-- 4. 查看现有的拉黑菜单
SELECT * FROM eb_system_menu WHERE `name` IN ('用户拉黑', '房间拉黑');

-- 5. 删除旧的拉黑菜单记录
DELETE FROM eb_system_menu WHERE `name` = '用户拉黑';
DELETE FROM eb_system_menu WHERE `name` = '房间拉黑';

-- 6. 获取社交互动的ID
SET @social_id = (SELECT id FROM eb_system_menu WHERE `name` = '社交互动' AND menu_type = 'M' LIMIT 1);
SELECT @social_id as '社交互动ID';

-- 7. 获取群组管理的sort值，在其后面添加
SET @group_sort = (SELECT sort FROM eb_system_menu WHERE `name` = '群组管理' LIMIT 1);
SELECT @group_sort as '群组管理排序';

-- 8. 插入用户拉黑菜单（参考群组管理的格式）
INSERT INTO eb_system_menu (`pid`, `name`, `icon`, `perms`, `component`, `menu_type`, `sort`, `is_show`)
VALUES (@social_id, '用户拉黑', '', 'admin:blacklist:user:list', '/socialManage/blacklist/user', 'C', IFNULL(@group_sort, 0) + 1, 1);

SET @user_blacklist_id = LAST_INSERT_ID();
SELECT @user_blacklist_id as '用户拉黑菜单ID';

-- 9. 插入房间拉黑菜单
INSERT INTO eb_system_menu (`pid`, `name`, `icon`, `perms`, `component`, `menu_type`, `sort`, `is_show`)
VALUES (@social_id, '房间拉黑', '', 'admin:blacklist:room:list', '/socialManage/blacklist/room', 'C', IFNULL(@group_sort, 0) + 2, 1);

SET @room_blacklist_id = LAST_INSERT_ID();
SELECT @room_blacklist_id as '房间拉黑菜单ID';

-- 10. 为管理员角色添加权限（rid=1是超级管理员）
INSERT IGNORE INTO eb_system_role_menu (rid, menu_id) VALUES (1, @user_blacklist_id);
INSERT IGNORE INTO eb_system_role_menu (rid, menu_id) VALUES (1, @room_blacklist_id);

-- 11. 验证结果
SELECT '=== 社交互动下所有子菜单 ===' as info;
SELECT id, pid, `name`, component, sort, is_show, menu_type
FROM eb_system_menu 
WHERE pid = @social_id
ORDER BY sort;

-- 12. 验证权限
SELECT '=== 拉黑菜单权限 ===' as info;
SELECT rm.rid, rm.menu_id, m.`name`, m.component
FROM eb_system_role_menu rm 
JOIN eb_system_menu m ON rm.menu_id = m.id 
WHERE m.`name` IN ('用户拉黑', '房间拉黑');
