-- =============================================
-- 知识库管理菜单 - 简化版（一键执行）
-- =============================================
-- 说明：此脚本假设"心理测评管理"的menu_id为2000
-- 如果不是，请先查询：SELECT menu_id FROM sys_menu WHERE menu_name LIKE '%心理%';
-- =============================================

-- 添加知识库管理主菜单
INSERT INTO sys_menu (
    menu_name, parent_id, order_num, path, component, 
    is_frame, is_cache, menu_type, visible, status, 
    perms, icon, create_by, create_time, remark
) VALUES (
    '知识库管理', 2000, 8, 'knowledge', 'psychology/knowledge/index',
    1, 0, 'C', '0', '0',
    'psychology:knowledge:list', 'documentation', 'admin', NOW(), 'AI知识库文档管理'
);

-- 获取刚插入的菜单ID
SET @menu_id = LAST_INSERT_ID();

-- 添加按钮权限
INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time)
VALUES 
('知识库查询', @menu_id, 1, '#', '', 1, 0, 'F', '0', '0', 'psychology:knowledge:query', '#', 'admin', NOW()),
('知识库上传', @menu_id, 2, '#', '', 1, 0, 'F', '0', '0', 'psychology:knowledge:upload', '#', 'admin', NOW()),
('知识库删除', @menu_id, 3, '#', '', 1, 0, 'F', '0', '0', 'psychology:knowledge:remove', '#', 'admin', NOW()),
('知识库重建', @menu_id, 4, '#', '', 1, 0, 'F', '0', '0', 'psychology:knowledge:rebuild', '#', 'admin', NOW());

-- 为管理员角色分配权限（角色ID=1）
INSERT INTO sys_role_menu (role_id, menu_id)
SELECT 1, menu_id FROM sys_menu 
WHERE menu_name IN ('知识库管理', '知识库查询', '知识库上传', '知识库删除', '知识库重建')
AND NOT EXISTS (
    SELECT 1 FROM sys_role_menu WHERE role_id = 1 AND sys_role_menu.menu_id = sys_menu.menu_id
);

-- 完成！刷新页面查看
SELECT '菜单添加完成！请刷新浏览器页面' AS message;
