-- ========================================
-- 检查重复菜单查询脚本
-- 用途：在执行清理前查看数据库中的重复菜单
-- ========================================
USE ry_news;
SET NAMES utf8mb4;

-- ========================================
-- 1. 查找所有重复的菜单（基于menu_name和path组合）
-- ========================================
SELECT 
    menu_name AS '菜单名称',
    path AS '路由路径',
    component AS '组件路径',
    parent_id AS '父菜单ID',
    COUNT(*) AS '重复数量',
    GROUP_CONCAT(menu_id ORDER BY menu_id SEPARATOR ', ') AS '菜单ID列表'
FROM sys_menu
WHERE menu_name LIKE '%心理%' 
   OR menu_name LIKE '%量表%' 
   OR menu_name LIKE '%题目%'
   OR menu_name LIKE '%因子%'
   OR menu_name LIKE '%测评%'
   OR menu_name LIKE '%报告%'
   OR menu_name LIKE '%解释%'
   OR menu_name LIKE '%档案%'
   OR menu_name LIKE '%问卷%'
   OR menu_name LIKE '%网站%'
   OR menu_name LIKE '%栏目%'
   OR menu_name LIKE '%评论%'
   OR menu_name LIKE '%预警%'
GROUP BY menu_name, path, component, parent_id
HAVING COUNT(*) > 1
ORDER BY COUNT(*) DESC, menu_name;

-- ========================================
-- 2. 统计心理学相关菜单总数
-- ========================================
SELECT 
    '心理学相关菜单总数' AS '统计项',
    COUNT(*) AS '数量'
FROM sys_menu
WHERE menu_name LIKE '%心理%' 
   OR menu_name LIKE '%量表%' 
   OR menu_name LIKE '%题目%'
   OR menu_name LIKE '%因子%'
   OR menu_name LIKE '%测评%'
   OR menu_name LIKE '%报告%'
   OR menu_name LIKE '%解释%'
   OR menu_name LIKE '%档案%'
   OR menu_name LIKE '%问卷%'
   OR menu_name LIKE '%网站%'
   OR menu_name LIKE '%栏目%'
   OR menu_name LIKE '%评论%'
   OR menu_name LIKE '%预警%';

-- ========================================
-- 3. 查找重复的父菜单（目录）
-- ========================================
SELECT 
    menu_name AS '目录名称',
    COUNT(*) AS '重复数量',
    GROUP_CONCAT(menu_id ORDER BY menu_id SEPARATOR ', ') AS '菜单ID列表'
FROM sys_menu
WHERE parent_id = 0
  AND (menu_name LIKE '%心理%' OR menu_name LIKE '%网站%')
GROUP BY menu_name
HAVING COUNT(*) > 1;

-- ========================================
-- 4. 列出所有心理学相关菜单（按层级）
-- ========================================
SELECT 
    menu_id,
    menu_name AS '菜单名称',
    parent_id AS '父菜单ID',
    path AS '路由路径',
    component AS '组件路径',
    menu_type AS '类型',
    visible AS '是否显示',
    order_num AS '排序'
FROM sys_menu
WHERE menu_name LIKE '%心理%' 
   OR menu_name LIKE '%量表%' 
   OR menu_name LIKE '%题目%'
   OR menu_name LIKE '%因子%'
   OR menu_name LIKE '%测评%'
   OR menu_name LIKE '%报告%'
   OR menu_name LIKE '%解释%'
   OR menu_name LIKE '%档案%'
   OR menu_name LIKE '%问卷%'
   OR menu_name LIKE '%网站%'
   OR menu_name LIKE '%栏目%'
   OR menu_name LIKE '%评论%'
   OR menu_name LIKE '%预警%'
ORDER BY parent_id, order_num, menu_id;
