-- 主播管理菜单配置
-- 请在数据库中执行此脚本

-- 1. 首先查找直播管理的菜单ID
SELECT id, pid, name, component FROM eb_system_menu WHERE name = '直播管理' OR component LIKE '%liveManage%';

-- 2. 查找直播管理下的子菜单，确认结构
SELECT id, pid, name, component, sort FROM eb_system_menu WHERE pid IN (
    SELECT id FROM eb_system_menu WHERE name = '直播管理' OR component LIKE '%liveManage%'
) ORDER BY sort DESC;

-- 3. 添加主播管理菜单（需要根据上面查询结果修改 pid 值）
-- 假设直播管理的菜单ID是 @live_manage_id，请根据实际查询结果替换

-- 方式一：如果知道直播管理的ID（例如是 XXX），直接插入
-- INSERT INTO `eb_system_menu` (`pid`, `name`, `icon`, `perms`, `component`, `menu_type`, `sort`, `is_show`, `is_delte`, `create_time`, `update_time`) 
-- VALUES (XXX, '主播管理', '', 'admin:streamer:list', '/liveManage/streamer/list', 'C', 10, 1, 0, NOW(), NOW());

-- 方式二：使用变量（推荐）
SET @live_manage_id = (SELECT id FROM eb_system_menu WHERE name = '直播管理' LIMIT 1);

-- 检查是否已存在主播管理菜单
SELECT * FROM eb_system_menu WHERE name = '主播管理' AND pid = @live_manage_id;

-- 如果不存在，插入主播管理菜单
INSERT INTO `eb_system_menu` (`pid`, `name`, `icon`, `perms`, `component`, `menu_type`, `sort`, `is_show`, `is_delte`, `create_time`, `update_time`) 
SELECT @live_manage_id, '主播管理', '', 'admin:streamer:list', '/liveManage/streamer/list', 'C', 5, 1, 0, NOW(), NOW()
FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM eb_system_menu WHERE name = '主播管理' AND pid = @live_manage_id);

-- 4. 获取新插入的菜单ID
SET @streamer_menu_id = (SELECT id FROM eb_system_menu WHERE name = '主播管理' AND pid = @live_manage_id LIMIT 1);

-- 5. 添加主播管理的权限按钮（可选）
INSERT INTO `eb_system_menu` (`pid`, `name`, `icon`, `perms`, `component`, `menu_type`, `sort`, `is_show`, `is_delte`, `create_time`, `update_time`) 
SELECT @streamer_menu_id, '主播列表', '', 'admin:streamer:list', '', 'A', 1, 1, 0, NOW(), NOW()
FROM DUAL
WHERE @streamer_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM eb_system_menu WHERE perms = 'admin:streamer:list' AND menu_type = 'A');

INSERT INTO `eb_system_menu` (`pid`, `name`, `icon`, `perms`, `component`, `menu_type`, `sort`, `is_show`, `is_delte`, `create_time`, `update_time`) 
SELECT @streamer_menu_id, '主播详情', '', 'admin:streamer:detail', '', 'A', 2, 1, 0, NOW(), NOW()
FROM DUAL
WHERE @streamer_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM eb_system_menu WHERE perms = 'admin:streamer:detail');

INSERT INTO `eb_system_menu` (`pid`, `name`, `icon`, `perms`, `component`, `menu_type`, `sort`, `is_show`, `is_delte`, `create_time`, `update_time`) 
SELECT @streamer_menu_id, '封禁主播', '', 'admin:streamer:ban', '', 'A', 3, 1, 0, NOW(), NOW()
FROM DUAL
WHERE @streamer_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM eb_system_menu WHERE perms = 'admin:streamer:ban');

INSERT INTO `eb_system_menu` (`pid`, `name`, `icon`, `perms`, `component`, `menu_type`, `sort`, `is_show`, `is_delte`, `create_time`, `update_time`) 
SELECT @streamer_menu_id, '解封主播', '', 'admin:streamer:unban', '', 'A', 4, 1, 0, NOW(), NOW()
FROM DUAL
WHERE @streamer_menu_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM eb_system_menu WHERE perms = 'admin:streamer:unban');

-- 6. 给超级管理员角色分配权限（角色ID通常是1）
-- 先查询角色菜单关联表
SELECT * FROM eb_system_role_menu WHERE rid = 1 ORDER BY menu_id DESC LIMIT 10;

-- 添加菜单权限到超级管理员角色
INSERT IGNORE INTO eb_system_role_menu (rid, menu_id) 
SELECT 1, id FROM eb_system_menu WHERE name = '主播管理' OR perms LIKE 'admin:streamer:%';

-- 7. 验证结果
SELECT m.id, m.pid, m.name, m.perms, m.component, m.menu_type 
FROM eb_system_menu m 
WHERE m.name = '主播管理' OR m.perms LIKE 'admin:streamer:%'
ORDER BY m.id;

-- 8. 清除Redis缓存（需要在Redis中执行）
-- DEL menuList

-- 提示：执行完SQL后，需要清除Redis缓存才能看到新菜单
-- 可以在Redis中执行: DEL menuList
-- 或者重启后端服务
