SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- 更新社区管理菜单
-- ----------------------------
BEGIN;

-- 1. 删除不需要的菜单（话题管理、评论管理）
DELETE FROM `system_menu` WHERE `id` IN (2010, 2020);

-- 2. 更新社区管理主菜单（如果存在）
UPDATE `system_menu` SET 
  `name` = '社区管理',
  `sort` = 29,
  `path` = '/community',
  `icon` = 'ep:chat-dot-round',
  `updater` = 'admin',
  `update_time` = NOW()
WHERE `id` = 2000;

-- 3. 删除旧的"帖子管理"，准备创建新的"文章管理"
DELETE FROM `system_menu` WHERE `id` = 2001;

-- 4. 插入或更新文章管理
INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES 
(2075, '文章管理', 'community:post:query', 2, 1, 2000, 'post', 'ep:document', 'community/post/index', 'CommunityPost', 0, b'1', b'1', b'1', 'admin', NOW(), 'admin', NOW(), b'0')
ON DUPLICATE KEY UPDATE 
  `name` = '文章管理',
  `permission` = 'community:post:query',
  `sort` = 1,
  `path` = 'post',
  `icon` = 'ep:document',
  `component` = 'community/post/index',
  `component_name` = 'CommunityPost',
  `updater` = 'admin',
  `update_time` = NOW();

-- 5. 更新活动管理
UPDATE `system_menu` SET 
  `sort` = 2,
  `updater` = 'admin',
  `update_time` = NOW()
WHERE `id` = 2062;

-- 6. 更新Banner管理
UPDATE `system_menu` SET 
  `sort` = 3,
  `updater` = 'admin',
  `update_time` = NOW()
WHERE `id` = 2063;

-- 7. 更新敏感词管理（如果ID是2030，需要更新为2076，或者直接更新2030）
-- 先检查是否存在2030
UPDATE `system_menu` SET 
  `id` = 2076,
  `sort` = 4,
  `path` = 'sensitive',
  `icon` = 'ep:warning',
  `component` = 'community/sensitive/index',
  `component_name` = 'CommunitySensitiveWord',
  `updater` = 'admin',
  `update_time` = NOW()
WHERE `id` = 2030;

-- 如果2030不存在，则插入新的敏感词管理
INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES 
(2076, '敏感词管理', 'community:sensitive-word:query', 2, 4, 2000, 'sensitive', 'ep:warning', 'community/sensitive/index', 'CommunitySensitiveWord', 0, b'1', b'1', b'1', 'admin', NOW(), 'admin', NOW(), b'0')
ON DUPLICATE KEY UPDATE 
  `name` = '敏感词管理',
  `permission` = 'community:sensitive-word:query',
  `sort` = 4,
  `path` = 'sensitive',
  `icon` = 'ep:warning',
  `component` = 'community/sensitive/index',
  `component_name` = 'CommunitySensitiveWord',
  `updater` = 'admin',
  `update_time` = NOW();

-- 8. 更新封禁管理
UPDATE `system_menu` SET 
  `sort` = 5,
  `updater` = 'admin',
  `update_time` = NOW()
WHERE `id` = 2060;

-- 9. 更新举报管理
UPDATE `system_menu` SET 
  `sort` = 6,
  `icon` = 'ep:warning-filled',
  `updater` = 'admin',
  `update_time` = NOW()
WHERE `id` = 2061;

COMMIT;
SET FOREIGN_KEY_CHECKS = 1;

