-- =====================================================
-- 管理端侧边导航栏优化 - 菜单更新SQL
-- 执行前请备份 eb_system_menu 表
-- =====================================================

-- 备份原表（可选）
-- CREATE TABLE eb_system_menu_backup AS SELECT * FROM eb_system_menu;

-- =====================================================
-- 第一步：添加新的一级菜单（目录）
-- =====================================================

-- 1. 数据监控
INSERT INTO eb_system_menu (pid, name, icon, perms, component, menu_type, sort, is_show, is_delte, path)
SELECT 0, '数据监控', 'el-icon-monitor', 'admin:monitor', '', 'M', 100, 1, 0, '/monitor'
WHERE NOT EXISTS (SELECT 1 FROM eb_system_menu WHERE name = '数据监控' AND pid = 0);

-- 2. 用户管理（如果不存在）
INSERT INTO eb_system_menu (pid, name, icon, perms, component, menu_type, sort, is_show, is_delte, path)
SELECT 0, '用户管理', 'el-icon-user', 'admin:user:manage', '', 'M', 99, 1, 0, '/userManage'
WHERE NOT EXISTS (SELECT 1 FROM eb_system_menu WHERE name = '用户管理' AND pid = 0);

-- 3. 直播管理
INSERT INTO eb_system_menu (pid, name, icon, perms, component, menu_type, sort, is_show, is_delte, path)
SELECT 0, '直播管理', 'el-icon-video-camera', 'admin:live:manage', '', 'M', 98, 1, 0, '/liveManage'
WHERE NOT EXISTS (SELECT 1 FROM eb_system_menu WHERE name = '直播管理' AND pid = 0);

-- 4. 社交互动
INSERT INTO eb_system_menu (pid, name, icon, perms, component, menu_type, sort, is_show, is_delte, path)
SELECT 0, '社交互动', 'el-icon-chat-dot-round', 'admin:social:manage', '', 'M', 97, 1, 0, '/socialManage'
WHERE NOT EXISTS (SELECT 1 FROM eb_system_menu WHERE name = '社交互动' AND pid = 0);

-- 5. 礼物打赏
INSERT INTO eb_system_menu (pid, name, icon, perms, component, menu_type, sort, is_show, is_delte, path)
SELECT 0, '礼物打赏', 'el-icon-present', 'admin:gift:manage', '', 'M', 96, 1, 0, '/giftManage'
WHERE NOT EXISTS (SELECT 1 FROM eb_system_menu WHERE name = '礼物打赏' AND pid = 0);

-- 6. 虚拟道具
INSERT INTO eb_system_menu (pid, name, icon, perms, component, menu_type, sort, is_show, is_delte, path)
SELECT 0, '虚拟道具', 'el-icon-magic-stick', 'admin:virtual:manage', '', 'M', 95, 1, 0, '/virtualProps'
WHERE NOT EXISTS (SELECT 1 FROM eb_system_menu WHERE name = '虚拟道具' AND pid = 0);

-- 7. 营销活动
INSERT INTO eb_system_menu (pid, name, icon, perms, component, menu_type, sort, is_show, is_delte, path)
SELECT 0, '营销活动', 'el-icon-s-flag', 'admin:activity:manage', '', 'M', 94, 1, 0, '/activityManage'
WHERE NOT EXISTS (SELECT 1 FROM eb_system_menu WHERE name = '营销活动' AND pid = 0);

-- 8. 任务系统
INSERT INTO eb_system_menu (pid, name, icon, perms, component, menu_type, sort, is_show, is_delte, path)
SELECT 0, '任务系统', 'el-icon-s-claim', 'admin:task:manage', '', 'M', 93, 1, 0, '/taskManage'
WHERE NOT EXISTS (SELECT 1 FROM eb_system_menu WHERE name = '任务系统' AND pid = 0);

-- 9. 财务管理
INSERT INTO eb_system_menu (pid, name, icon, perms, component, menu_type, sort, is_show, is_delte, path)
SELECT 0, '财务管理', 'el-icon-money', 'admin:finance:manage', '', 'M', 92, 1, 0, '/financeManage'
WHERE NOT EXISTS (SELECT 1 FROM eb_system_menu WHERE name = '财务管理' AND pid = 0);

-- 10. 订单商城
INSERT INTO eb_system_menu (pid, name, icon, perms, component, menu_type, sort, is_show, is_delte, path)
SELECT 0, '订单商城', 'el-icon-shopping-cart-2', 'admin:shop:manage', '', 'M', 91, 1, 0, '/shopManage'
WHERE NOT EXISTS (SELECT 1 FROM eb_system_menu WHERE name = '订单商城' AND pid = 0);

-- 11. 内容管理
INSERT INTO eb_system_menu (pid, name, icon, perms, component, menu_type, sort, is_show, is_delte, path)
SELECT 0, '内容管理', 'el-icon-document', 'admin:content:manage', '', 'M', 90, 1, 0, '/contentManage'
WHERE NOT EXISTS (SELECT 1 FROM eb_system_menu WHERE name = '内容管理' AND pid = 0);

-- 12. 用户反馈
INSERT INTO eb_system_menu (pid, name, icon, perms, component, menu_type, sort, is_show, is_delte, path)
SELECT 0, '用户反馈', 'el-icon-warning', 'admin:feedback:manage', '', 'M', 89, 1, 0, '/feedbackManage'
WHERE NOT EXISTS (SELECT 1 FROM eb_system_menu WHERE name = '用户反馈' AND pid = 0);

-- 13. 代理管理
INSERT INTO eb_system_menu (pid, name, icon, perms, component, menu_type, sort, is_show, is_delte, path)
SELECT 0, '代理管理', 'el-icon-s-custom', 'admin:agent:manage', '', 'M', 88, 1, 0, '/agentManage'
WHERE NOT EXISTS (SELECT 1 FROM eb_system_menu WHERE name = '代理管理' AND pid = 0);

-- 14. 系统设置
INSERT INTO eb_system_menu (pid, name, icon, perms, component, menu_type, sort, is_show, is_delte, path)
SELECT 0, '系统设置', 'el-icon-setting', 'admin:system:manage', '', 'M', 87, 1, 0, '/systemSetting'
WHERE NOT EXISTS (SELECT 1 FROM eb_system_menu WHERE name = '系统设置' AND pid = 0);

-- =====================================================
-- 第二步：隐藏旧的一级菜单
-- =====================================================

UPDATE eb_system_menu SET is_show = 0 WHERE pid = 0 AND name IN (
    '商品', '用户', '房间管理', '礼物管理', '礼物数量管理', '关注管理',
    '互动管理', '任务管理', '帮助中心', '平台活动管理', '抽奖管理',
    '内容管理', '系统消息管理', '头饰管理', '财务管理', '坐骑管理',
    '邀请管理', '举报反馈管理', '家族管理', '夫妻相管理', '代理管理',
    '聊天付费配置', '金币钻石配置', '聊天常用语', '动态管理',
    '礼物打赏管理', '轮播图管理', '黑名单管理', '魅力值管理',
    '会员管理', '提现管理', '评论管理', '配置管理', '客户端版本管理',
    '兑换管理', '新手任务管理', '订单管理', '购买坐骑管理',
    '敏感词管理', '粉丝团管理', '明细管理', '会话管理', '认证管理',
    '申诉管理', '通话管理', '好友管理', '实时监控', '验证码管理',
    '贵族等级管理', '社会动态', '设置', '应用', '维护', '装修',
    '移动端', '分销', '营销', '订单'
);

-- =====================================================
-- 第三步：添加二级菜单（需要根据实际的父菜单ID调整）
-- 注意：以下SQL中的 @parent_id 需要替换为实际查询到的父菜单ID
-- =====================================================

-- 示例：为"数据监控"添加子菜单
-- 先获取父菜单ID
SET @monitor_pid = (SELECT id FROM eb_system_menu WHERE name = '数据监控' AND pid = 0 LIMIT 1);

INSERT INTO eb_system_menu (pid, name, icon, perms, component, menu_type, sort, is_show, is_delte, path)
SELECT @monitor_pid, '监控概览', '', 'admin:monitor:overview', 'monitor/overview/index', 'C', 100, 1, 0, 'overview'
WHERE @monitor_pid IS NOT NULL AND NOT EXISTS (SELECT 1 FROM eb_system_menu WHERE name = '监控概览' AND pid = @monitor_pid);

INSERT INTO eb_system_menu (pid, name, icon, perms, component, menu_type, sort, is_show, is_delte, path)
SELECT @monitor_pid, '在线用户', '', 'admin:monitor:users', 'monitor/users/index', 'C', 99, 1, 0, 'users'
WHERE @monitor_pid IS NOT NULL AND NOT EXISTS (SELECT 1 FROM eb_system_menu WHERE name = '在线用户' AND pid = @monitor_pid);

INSERT INTO eb_system_menu (pid, name, icon, perms, component, menu_type, sort, is_show, is_delte, path)
SELECT @monitor_pid, '活跃房间', '', 'admin:monitor:rooms', 'monitor/rooms/index', 'C', 98, 1, 0, 'rooms'
WHERE @monitor_pid IS NOT NULL AND NOT EXISTS (SELECT 1 FROM eb_system_menu WHERE name = '活跃房间' AND pid = @monitor_pid);

INSERT INTO eb_system_menu (pid, name, icon, perms, component, menu_type, sort, is_show, is_delte, path)
SELECT @monitor_pid, '系统状态', '', 'admin:monitor:system', 'monitor/system/index', 'C', 97, 1, 0, 'system'
WHERE @monitor_pid IS NOT NULL AND NOT EXISTS (SELECT 1 FROM eb_system_menu WHERE name = '系统状态' AND pid = @monitor_pid);

-- =====================================================
-- 清除菜单缓存（需要在应用中执行或重启服务）
-- =====================================================
-- 执行完SQL后，需要清除Redis中的菜单缓存：
-- 删除 key: menuList
-- 或者重启后端服务

-- =====================================================
-- 完成后请：
-- 1. 清除浏览器缓存
-- 2. 重新登录管理后台
-- 3. 或者清除Redis中的 menuList 缓存
-- =====================================================
