-- =====================================================
-- 中介黑名单管理菜单SQL
-- 功能: 为中介黑名单管理模块创建菜单和权限配置
-- 版本: 2.0
-- 日期: 2026-02-04
-- =====================================================

-- 1. 创建主菜单 (中介黑名单)
-- 父级菜单: 2000 (业务管理, 请根据实际情况调整)
-- 菜单类型: M (目录)
INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, query, perms, icon, menu_type, status, visible, create_by, create_time, update_by, update_time, remark)
VALUES (
    '中介黑名单',
    2000,
    5,
    'intermediary',
    NULL,
    NULL,
    NULL,
    'peoples',
    'M',
    '0',
    '0',
    'admin',
    NOW(),
    '',
    NULL,
    '中介黑名单管理目录'
);

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

-- 2. 创建子菜单 (中介黑名单管理)
-- 菜单类型: C (菜单)
INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, query, perms, icon, menu_type, status, visible, create_by, create_time, update_by, update_time, remark)
VALUES (
    '中介管理',
    @menu_id,
    1,
    'intermediaryIndex',
    'ccdi/intermediary/index',
    NULL,
    NULL,
    'user',
    'C',
    '0',
    '0',
    'admin',
    NOW(),
    '',
    NULL,
    '中介黑名单管理菜单'
);

SET @intermediary_menu_id = LAST_INSERT_ID();

-- 3. 创建按钮权限
-- 查询权限
INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, query, perms, icon, menu_type, status, visible, create_by, create_time, update_by, update_time, remark)
VALUES (
    '中介查询',
    @intermediary_menu_id,
    1,
    '',
    NULL,
    NULL,
    'ccdi:intermediary:query',
    '#',
    'F',
    '0',
    '0',
    'admin',
    NOW(),
    '',
    NULL,
    ''
);

-- 列表权限
INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, query, perms, icon, menu_type, status, visible, create_by, create_time, update_by, update_time, remark)
VALUES (
    '中介列表',
    @intermediary_menu_id,
    2,
    '',
    NULL,
    NULL,
    'ccdi:intermediary:list',
    '#',
    'F',
    '0',
    '0',
    'admin',
    NOW(),
    '',
    NULL,
    ''
);

-- 新增权限
INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, query, perms, icon, menu_type, status, visible, create_by, create_time, update_by, update_time, remark)
VALUES (
    '中介新增',
    @intermediary_menu_id,
    3,
    '',
    NULL,
    NULL,
    'ccdi:intermediary:add',
    '#',
    'F',
    '0',
    '0',
    'admin',
    NOW(),
    '',
    NULL,
    ''
);

-- 修改权限
INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, query, perms, icon, menu_type, status, visible, create_by, create_time, update_by, update_time, remark)
VALUES (
    '中介修改',
    @intermediary_menu_id,
    4,
    '',
    NULL,
    NULL,
    'ccdi:intermediary:edit',
    '#',
    'F',
    '0',
    '0',
    'admin',
    NOW(),
    '',
    NULL,
    ''
);

-- 删除权限
INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, query, perms, icon, menu_type, status, visible, create_by, create_time, update_by, update_time, remark)
VALUES (
    '中介删除',
    @intermediary_menu_id,
    5,
    '',
    NULL,
    NULL,
    'ccdi:intermediary:remove',
    '#',
    'F',
    '0',
    '0',
    'admin',
    NOW(),
    '',
    NULL,
    ''
);

-- 导出权限
INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, query, perms, icon, menu_type, status, visible, create_by, create_time, update_by, update_time, remark)
VALUES (
    '中介导出',
    @intermediary_menu_id,
    6,
    '',
    NULL,
    NULL,
    'ccdi:intermediary:export',
    '#',
    'F',
    '0',
    '0',
    'admin',
    NOW(),
    '',
    NULL,
    ''
);

-- 导入权限
INSERT INTO sys_menu (menu_name, parent_id, order_num, path, component, query, perms, icon, menu_type, status, visible, create_by, create_time, update_by, update_time, remark)
VALUES (
    '中介导入',
    @intermediary_menu_id,
    7,
    '',
    NULL,
    NULL,
    'ccdi:intermediary:import',
    '#',
    'F',
    '0',
    '0',
    'admin',
    NOW(),
    '',
    NULL,
    ''
);

-- =====================================================
-- 说明:
-- 1. 本SQL创建了完整的菜单结构:
--    - 一级菜单: 中介黑名单 (目录)
--    - 二级菜单: 中介管理 (菜单页面)
--    - 三级菜单: 各种按钮权限
--
-- 2. 权限标识:
--    - ccdi:intermediary:query (查询)
--    - ccdi:intermediary:list (列表)
--    - ccdi:intermediary:add (新增)
--    - ccdi:intermediary:edit (修改)
--    - ccdi:intermediary:remove (删除)
--    - ccdi:intermediary:export (导出)
--    - ccdi:intermediary:import (导入)
--
-- 3. 使用说明:
--    - 执行本SQL后,需要在角色管理中为相应角色分配权限
--    - 建议为admin角色分配所有权限
--    - 前端路由会根据权限自动显示菜单
--
-- 4. 注意事项:
--    - parent_id=2000 是业务管理的父级菜单,请根据实际情况调整
--    - 组件路径 'ccdi/intermediary/index' 需要与前端Vue组件路径一致
--    - 如果父级菜单不存在,需要先创建父级菜单或修改parent_id
-- =====================================================

-- 查询创建的菜单 (用于验证)
SELECT
    menu_id AS '菜单ID',
    menu_name AS '菜单名称',
    parent_id AS '父级菜单ID',
    order_num AS '显示顺序',
    perms AS '权限标识',
    menu_type AS '菜单类型',
    status AS '状态',
    visible AS '可见',
    create_time AS '创建时间'
FROM sys_menu
WHERE menu_name LIKE '%中介%' OR perms LIKE '%intermediary%'
ORDER BY parent_id, order_num;
