-- ============================================================================
-- 系统监控模块权限菜单配置 SQL 脚本
-- 作者: Leocoder
-- 创建时间: 2025-09-27
-- 描述: 为系统监控功能配置完整的菜单权限系统
-- ============================================================================

-- ----------------------------
-- 系统监控菜单结构
-- ----------------------------

-- 1. 系统监控顶级菜单（如果不存在）
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`) 
SELECT 2000, '系统监控', 'System Monitor', 0, '1', '/monitor', 'monitorPage', '', 'Monitor', 'monitor:auth', '0', NULL, '1', '', '0', '1', '1', '1', 8, 'system', NOW(), 'system', NOW()
WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `menu_id` = 2000);

-- 2. 服务器监控菜单
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`) 
VALUES (2010, '服务器监控', 'Server Monitor', 2000, '2', '/monitor/server', 'serverMonitorPage', 'monitor/server/index', 'Platform', 'monitor:server:list', '0', NULL, '1', '', '1', '1', '1', '1', 1, 'system', NOW(), 'system', NOW());

-- 3. Redis监控菜单
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`) 
VALUES (2011, 'Redis监控', 'Redis Monitor', 2000, '2', '/monitor/redis', 'redisMonitorPage', 'monitor/redis/index', 'Connection', 'monitor:redis:list', '0', NULL, '1', '', '1', '1', '1', '1', 2, 'system', NOW(), 'system', NOW());

-- 4. 缓存管理菜单
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`) 
VALUES (2012, '缓存管理', 'Cache Management', 2000, '2', '/monitor/cache', 'cacheManagePage', 'monitor/cache/index', 'Coin', 'monitor:cache:list', '0', NULL, '1', '', '1', '1', '1', '1', 3, 'system', NOW(), 'system', NOW());

-- 5. 操作日志菜单（如果需要）
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`) 
SELECT 2013, '操作日志', 'Operation Logs', 2000, '2', '/monitor/operlog', 'operLogPage', 'monitor/operlog/index', 'Document', 'monitor:operlog:list', '0', NULL, '1', '', '1', '1', '1', '1', 4, 'system', NOW(), 'system', NOW()
WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `menu_id` = 2013);

-- 6. 登录日志菜单（如果需要）
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`) 
SELECT 2014, '登录日志', 'Login Logs', 2000, '2', '/monitor/loginlog', 'loginLogPage', 'monitor/loginlog/index', 'Key', 'monitor:loginlog:list', '0', NULL, '1', '', '1', '1', '1', '1', 5, 'system', NOW(), 'system', NOW()
WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `menu_id` = 2014);

-- 7. 定时任务菜单（如果需要）
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`) 
SELECT 2015, '定时任务', 'Scheduled Jobs', 2000, '2', '/monitor/job', 'jobPage', 'monitor/job/index', 'Timer', 'monitor:job:list', '0', NULL, '1', '', '1', '1', '1', '1', 6, 'system', NOW(), 'system', NOW()
WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `menu_id` = 2015);

-- ----------------------------
-- 服务器监控按钮权限
-- ----------------------------
-- 服务器监控-查看
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`) 
VALUES (2101, '查看', 'View', 2010, '3', '', NULL, NULL, '', 'monitor:server:list', '0', NULL, '0', '', '0', '1', '1', '1', 1, 'system', NOW(), 'system', NOW());

-- ----------------------------
-- Redis监控按钮权限
-- ----------------------------
-- Redis监控-查看
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`) 
VALUES (2102, '查看', 'View', 2011, '3', '', NULL, NULL, '', 'monitor:redis:list', '0', NULL, '0', '', '0', '1', '1', '1', 1, 'system', NOW(), 'system', NOW());

-- ----------------------------
-- 缓存管理按钮权限
-- ----------------------------
-- 缓存管理-查看
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`) 
VALUES (2103, '查看', 'View', 2012, '3', '', NULL, NULL, '', 'monitor:cache:list', '0', NULL, '0', '', '0', '1', '1', '1', 1, 'system', NOW(), 'system', NOW());

-- 缓存管理-删除
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`) 
VALUES (2104, '删除', 'Delete', 2012, '3', '', NULL, NULL, '', 'monitor:cache:delete', '0', NULL, '0', '', '0', '1', '1', '1', 2, 'system', NOW(), 'system', NOW());

-- 缓存管理-清空
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`) 
VALUES (2105, '清空', 'Clear', 2012, '3', '', NULL, NULL, '', 'monitor:cache:clear', '0', NULL, '0', '', '0', '1', '1', '1', 3, 'system', NOW(), 'system', NOW());

-- ----------------------------
-- 操作日志按钮权限（如果需要）
-- ----------------------------
-- 操作日志-查看
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`) 
SELECT 2106, '查看', 'View', 2013, '3', '', NULL, NULL, '', 'monitor:operlog:list', '0', NULL, '0', '', '0', '1', '1', '1', 1, 'system', NOW(), 'system', NOW()
WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `menu_id` = 2106);

-- 操作日志-删除
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`) 
SELECT 2107, '删除', 'Delete', 2013, '3', '', NULL, NULL, '', 'monitor:operlog:delete', '0', NULL, '0', '', '0', '1', '1', '1', 2, 'system', NOW(), 'system', NOW()
WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `menu_id` = 2107);

-- 操作日志-清空
INSERT INTO `sys_menu` (`menu_id`, `menu_name`, `en_name`, `parent_id`, `menu_type`, `path`, `name`, `component`, `icon`, `auth`, `menu_status`, `active_menu`, `is_hide`, `is_link`, `is_keep_alive`, `is_full`, `is_affix`, `is_spread`, `sorted`, `create_by`, `create_time`, `update_by`, `update_time`) 
SELECT 2108, '清空', 'Clear', 2013, '3', '', NULL, NULL, '', 'monitor:operlog:clear', '0', NULL, '0', '', '0', '1', '1', '1', 3, 'system', NOW(), 'system', NOW()
WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `menu_id` = 2108);

-- ----------------------------
-- 角色权限关联（管理员角色拥有监控权限）
-- ----------------------------

-- 给管理员角色分配监控菜单权限
-- 注意：这里假设管理员角色ID为1，请根据实际情况调整

-- 系统监控顶级菜单
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`) 
SELECT 1, 2000 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2000);

-- 服务器监控
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`) 
SELECT 1, 2010 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2010);
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`) 
SELECT 1, 2101 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2101);

-- Redis监控
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`) 
SELECT 1, 2011 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2011);
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`) 
SELECT 1, 2102 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2102);

-- 缓存管理
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`) 
SELECT 1, 2012 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2012);
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`) 
SELECT 1, 2103 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2103);
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`) 
SELECT 1, 2104 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2104);
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`) 
SELECT 1, 2105 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2105);

-- 操作日志
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`) 
SELECT 1, 2013 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2013);
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`) 
SELECT 1, 2106 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2106);
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`) 
SELECT 1, 2107 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2107);
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`) 
SELECT 1, 2108 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2108);

-- 登录日志
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`) 
SELECT 1, 2014 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2014);

-- 定时任务
INSERT INTO `sys_role_menu` (`role_id`, `menu_id`) 
SELECT 1, 2015 WHERE NOT EXISTS (SELECT 1 FROM `sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2015);

-- ----------------------------
-- 执行说明
-- ----------------------------

/*
执行此脚本后，系统将具备以下监控菜单结构：

📊 系统监控 (/monitor)
├── 🖥️  服务器监控 (/monitor/server) 
│   └── 👀 查看 [monitor:server:list]
├── 🔗 Redis监控 (/monitor/redis)
│   └── 👀 查看 [monitor:redis:list]  
├── 💾 缓存管理 (/monitor/cache)
│   ├── 👀 查看 [monitor:cache:list]
│   ├── 🗑️  删除 [monitor:cache:delete]
│   └── 🧹 清空 [monitor:cache:clear]
├── 📋 操作日志 (/monitor/operlog)
│   ├── 👀 查看 [monitor:operlog:list]
│   ├── 🗑️  删除 [monitor:operlog:delete]  
│   └── 🧹 清空 [monitor:operlog:clear]
├── 🔑 登录日志 (/monitor/loginlog)
│   └── 👀 查看 [monitor:loginlog:list]
└── ⏰ 定时任务 (/monitor/job)
    └── 👀 查看 [monitor:job:list]

🔐 权限说明：
- 所有菜单默认分配给管理员角色（role_id=1）
- 使用Sa-Token权限验证
- 支持细粒度按钮权限控制

📝 注意事项：
- 菜单ID范围：2000-2999（避免冲突）
- 所有SQL使用防重复执行机制
- 可根据实际需要调整管理员角色ID
- 执行前请备份相关表数据
*/

-- ============================================================================
-- SQL 脚本执行完成
-- ============================================================================