SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- 修复服务管理菜单（完整版）
-- ----------------------------
BEGIN;

-- 删除可能存在的错误数据
DELETE FROM system_menu WHERE id IN (2065, 2066, 2067, 2068, 2069) AND deleted = 0;

-- 重新插入服务管理菜单
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 
(2065, '服务管理', '', 1, 33, 0, '/service', 'ep:service', NULL, NULL, 0, b'1', b'1', b'1', 'admin', NOW(), 'admin', NOW(), b'0'),
(2066, 'APP意见反馈', 'service:feedback:query', 2, 1, 2065, 'feedback', 'ep:chat-line-round', 'service/feedback/index', 'ServiceFeedback', 0, b'1', b'1', b'1', 'admin', NOW(), 'admin', NOW(), b'0'),
(2067, '服务评价管理', 'service:evaluation:query', 2, 2, 2065, 'evaluation', 'ep:star', 'service/evaluation/index', 'ServiceEvaluation', 0, b'1', b'1', b'1', 'admin', NOW(), 'admin', NOW(), b'0'),
(2068, '维保管理', 'service:maintenance:query', 2, 3, 2065, 'maintenance', 'ep:tools', 'service/maintenance/index', 'ServiceMaintenance', 0, b'1', b'1', b'1', 'admin', NOW(), 'admin', NOW(), b'0'),
(2069, '消息管理', 'service:message:query', 2, 4, 2065, 'message', 'ep:message', 'service/message/index', 'ServiceMessage', 0, b'1', b'1', b'1', 'admin', NOW(), 'admin', NOW(), b'0')
ON DUPLICATE KEY UPDATE
    `name` = VALUES(`name`),
    `permission` = VALUES(`permission`),
    `type` = VALUES(`type`),
    `sort` = VALUES(`sort`),
    `parent_id` = VALUES(`parent_id`),
    `path` = VALUES(`path`),
    `icon` = VALUES(`icon`),
    `component` = VALUES(`component`),
    `component_name` = VALUES(`component_name`),
    `status` = VALUES(`status`),
    `visible` = VALUES(`visible`),
    `keep_alive` = VALUES(`keep_alive`),
    `always_show` = VALUES(`always_show`),
    `updater` = 'admin',
    `update_time` = NOW(),
    `deleted` = b'0';

-- 确保权限分配给超级管理员角色
INSERT INTO system_role_menu (role_id, menu_id) 
SELECT 1, id FROM system_menu WHERE id IN (2065, 2066, 2067, 2068, 2069)
AND id NOT IN (SELECT menu_id FROM system_role_menu WHERE role_id = 1);

COMMIT;
SET FOREIGN_KEY_CHECKS = 1;

