-- =============================================
-- PMS系统配置管理模块菜单SQL (修复版)
-- 版本: v1.2 (解决menu_id自增问题)
-- 创建日期: 2024-12-19
-- 说明: 包含系统配置管理相关的菜单和权限定义
-- =============================================
-- 设置字符集
SET NAMES utf8mb4;
-- =============================================
-- 0. 获取当前最大菜单ID
-- =============================================
SET @max_menu_id = (
        SELECT COALESCE(MAX(menu_id), 0)
        FROM sys_menu
    );
-- =============================================
-- 1. 系统配置管理主菜单
-- =============================================
SET @system_menu_id = @max_menu_id + 1;
INSERT INTO sys_menu (
        menu_id,
        menu_name,
        parent_id,
        order_num,
        path,
        component,
        query_param,
        is_frame,
        is_cache,
        menu_type,
        visible,
        status,
        perms,
        icon,
        create_dept,
        create_by,
        create_time,
        update_by,
        update_time,
        remark
    )
VALUES (
        @system_menu_id,
        '系统配置管理',
        0,
        7,
        'pms-system',
        NULL,
        NULL,
        1,
        0,
        'M',
        '0',
        '0',
        NULL,
        'system',
        103,
        1,
        NOW(),
        1,
        NOW(),
        'PMS系统配置管理主菜单'
    );
-- =============================================
-- 2. 租户配置管理菜单
-- =============================================
SET @tenant_settings_menu_id = @max_menu_id + 2;
INSERT INTO sys_menu (
        menu_id,
        menu_name,
        parent_id,
        order_num,
        path,
        component,
        query_param,
        is_frame,
        is_cache,
        menu_type,
        visible,
        status,
        perms,
        icon,
        create_dept,
        create_by,
        create_time,
        update_by,
        update_time,
        remark
    )
VALUES (
        @tenant_settings_menu_id,
        '租户配置管理',
        @system_menu_id,
        1,
        'tenant-settings',
        'pms/system/tenant-settings/index',
        NULL,
        1,
        0,
        'C',
        '0',
        '0',
        'pms:tenantSettings:list',
        'setting',
        103,
        1,
        NOW(),
        1,
        NOW(),
        '租户配置管理菜单'
    );
-- 租户配置管理权限按钮
INSERT INTO sys_menu (
        menu_id,
        menu_name,
        parent_id,
        order_num,
        path,
        component,
        query_param,
        is_frame,
        is_cache,
        menu_type,
        visible,
        status,
        perms,
        icon,
        create_dept,
        create_by,
        create_time,
        update_by,
        update_time,
        remark
    )
VALUES (
        @max_menu_id + 3,
        '租户配置查询',
        @tenant_settings_menu_id,
        1,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:tenantSettings:query',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 4,
        '租户配置新增',
        @tenant_settings_menu_id,
        2,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:tenantSettings:add',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 5,
        '租户配置修改',
        @tenant_settings_menu_id,
        3,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:tenantSettings:edit',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 6,
        '租户配置删除',
        @tenant_settings_menu_id,
        4,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:tenantSettings:remove',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 7,
        '租户配置导出',
        @tenant_settings_menu_id,
        5,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:tenantSettings:export',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 8,
        '租户配置导入',
        @tenant_settings_menu_id,
        6,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:tenantSettings:import',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 9,
        '租户配置批量操作',
        @tenant_settings_menu_id,
        7,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:tenantSettings:batch',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 10,
        '租户配置重置',
        @tenant_settings_menu_id,
        8,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:tenantSettings:reset',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    );
-- =============================================
-- 3. 门店配置管理菜单
-- =============================================
SET @dept_settings_menu_id = @max_menu_id + 11;
INSERT INTO sys_menu (
        menu_id,
        menu_name,
        parent_id,
        order_num,
        path,
        component,
        query_param,
        is_frame,
        is_cache,
        menu_type,
        visible,
        status,
        perms,
        icon,
        create_dept,
        create_by,
        create_time,
        update_by,
        update_time,
        remark
    )
VALUES (
        @dept_settings_menu_id,
        '门店配置管理',
        @system_menu_id,
        2,
        'dept-settings',
        'pms/system/dept-settings/index',
        NULL,
        1,
        0,
        'C',
        '0',
        '0',
        'pms:deptSettings:list',
        'tree',
        103,
        1,
        NOW(),
        1,
        NOW(),
        '门店配置管理菜单'
    );
-- 门店配置管理权限按钮
INSERT INTO sys_menu (
        menu_id,
        menu_name,
        parent_id,
        order_num,
        path,
        component,
        query_param,
        is_frame,
        is_cache,
        menu_type,
        visible,
        status,
        perms,
        icon,
        create_dept,
        create_by,
        create_time,
        update_by,
        update_time,
        remark
    )
VALUES (
        @max_menu_id + 12,
        '门店配置查询',
        @dept_settings_menu_id,
        1,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:deptSettings:query',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 13,
        '门店配置新增',
        @dept_settings_menu_id,
        2,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:deptSettings:add',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 14,
        '门店配置修改',
        @dept_settings_menu_id,
        3,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:deptSettings:edit',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 15,
        '门店配置删除',
        @dept_settings_menu_id,
        4,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:deptSettings:remove',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 16,
        '门店配置继承',
        @dept_settings_menu_id,
        5,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:deptSettings:inherit',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 17,
        '门店配置覆盖',
        @dept_settings_menu_id,
        6,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:deptSettings:override',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    );
-- =============================================
-- 4. 小程序配置管理菜单
-- =============================================
SET @mp_settings_menu_id = @max_menu_id + 18;
INSERT INTO sys_menu (
        menu_id,
        menu_name,
        parent_id,
        order_num,
        path,
        component,
        query_param,
        is_frame,
        is_cache,
        menu_type,
        visible,
        status,
        perms,
        icon,
        create_dept,
        create_by,
        create_time,
        update_by,
        update_time,
        remark
    )
VALUES (
        @mp_settings_menu_id,
        '小程序配置',
        @system_menu_id,
        3,
        'mp-settings',
        'pms/system/mp-settings/index',
        NULL,
        1,
        0,
        'C',
        '0',
        '0',
        'pms:mpSettings:list',
        'wechat',
        103,
        1,
        NOW(),
        1,
        NOW(),
        '小程序配置管理菜单'
    );
-- 小程序配置管理权限按钮
INSERT INTO sys_menu (
        menu_id,
        menu_name,
        parent_id,
        order_num,
        path,
        component,
        query_param,
        is_frame,
        is_cache,
        menu_type,
        visible,
        status,
        perms,
        icon,
        create_dept,
        create_by,
        create_time,
        update_by,
        update_time,
        remark
    )
VALUES (
        @max_menu_id + 19,
        '小程序配置查询',
        @mp_settings_menu_id,
        1,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:mpSettings:query',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 20,
        '小程序配置新增',
        @mp_settings_menu_id,
        2,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:mpSettings:add',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 21,
        '小程序配置修改',
        @mp_settings_menu_id,
        3,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:mpSettings:edit',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 22,
        '小程序配置删除',
        @mp_settings_menu_id,
        4,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:mpSettings:remove',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 23,
        '主题配置',
        @mp_settings_menu_id,
        5,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:mpSettings:theme',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 24,
        '功能开关',
        @mp_settings_menu_id,
        6,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:mpSettings:function',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 25,
        '支付配置',
        @mp_settings_menu_id,
        7,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:mpSettings:payment',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 26,
        '通知配置',
        @mp_settings_menu_id,
        8,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:mpSettings:notification',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    );
-- =============================================
-- 5. 用户设备管理菜单
-- =============================================
SET @user_devices_menu_id = @max_menu_id + 27;
INSERT INTO sys_menu (
        menu_id,
        menu_name,
        parent_id,
        order_num,
        path,
        component,
        query_param,
        is_frame,
        is_cache,
        menu_type,
        visible,
        status,
        perms,
        icon,
        create_dept,
        create_by,
        create_time,
        update_by,
        update_time,
        remark
    )
VALUES (
        @user_devices_menu_id,
        '用户设备管理',
        @system_menu_id,
        4,
        'user-devices',
        'pms/system/user-devices/index',
        NULL,
        1,
        0,
        'C',
        '0',
        '0',
        'pms:userDevices:list',
        'phone',
        103,
        1,
        NOW(),
        1,
        NOW(),
        '用户设备管理菜单'
    );
-- 用户设备管理权限按钮
INSERT INTO sys_menu (
        menu_id,
        menu_name,
        parent_id,
        order_num,
        path,
        component,
        query_param,
        is_frame,
        is_cache,
        menu_type,
        visible,
        status,
        perms,
        icon,
        create_dept,
        create_by,
        create_time,
        update_by,
        update_time,
        remark
    )
VALUES (
        @max_menu_id + 28,
        '设备查询',
        @user_devices_menu_id,
        1,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:userDevices:query',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 29,
        '设备详情',
        @user_devices_menu_id,
        2,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:userDevices:detail',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 30,
        '设备状态管理',
        @user_devices_menu_id,
        3,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:userDevices:status',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 31,
        '设备删除',
        @user_devices_menu_id,
        4,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:userDevices:remove',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 32,
        '推送管理',
        @user_devices_menu_id,
        5,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:userDevices:push',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 33,
        '登录历史',
        @user_devices_menu_id,
        6,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:userDevices:history',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 34,
        '安全审计',
        @user_devices_menu_id,
        7,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:userDevices:audit',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    );
-- =============================================
-- 6. 配置模板管理菜单
-- =============================================
SET @config_templates_menu_id = @max_menu_id + 35;
INSERT INTO sys_menu (
        menu_id,
        menu_name,
        parent_id,
        order_num,
        path,
        component,
        query_param,
        is_frame,
        is_cache,
        menu_type,
        visible,
        status,
        perms,
        icon,
        create_dept,
        create_by,
        create_time,
        update_by,
        update_time,
        remark
    )
VALUES (
        @config_templates_menu_id,
        '配置模板管理',
        @system_menu_id,
        5,
        'config-templates',
        'pms/system/config-templates/index',
        NULL,
        1,
        0,
        'C',
        '0',
        '0',
        'pms:configTemplates:list',
        'clipboard',
        103,
        1,
        NOW(),
        1,
        NOW(),
        '配置模板管理菜单'
    );
-- 配置模板管理权限按钮
INSERT INTO sys_menu (
        menu_id,
        menu_name,
        parent_id,
        order_num,
        path,
        component,
        query_param,
        is_frame,
        is_cache,
        menu_type,
        visible,
        status,
        perms,
        icon,
        create_dept,
        create_by,
        create_time,
        update_by,
        update_time,
        remark
    )
VALUES (
        @max_menu_id + 36,
        '模板查询',
        @config_templates_menu_id,
        1,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:configTemplates:query',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 37,
        '模板新增',
        @config_templates_menu_id,
        2,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:configTemplates:add',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 38,
        '模板修改',
        @config_templates_menu_id,
        3,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:configTemplates:edit',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 39,
        '模板删除',
        @config_templates_menu_id,
        4,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:configTemplates:remove',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 40,
        '模板应用',
        @config_templates_menu_id,
        5,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:configTemplates:apply',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 41,
        '模板导出',
        @config_templates_menu_id,
        6,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:configTemplates:export',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 42,
        '模板导入',
        @config_templates_menu_id,
        7,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:configTemplates:import',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    );
-- =============================================
-- 7. 系统监控菜单
-- =============================================
SET @system_monitor_menu_id = @max_menu_id + 43;
INSERT INTO sys_menu (
        menu_id,
        menu_name,
        parent_id,
        order_num,
        path,
        component,
        query_param,
        is_frame,
        is_cache,
        menu_type,
        visible,
        status,
        perms,
        icon,
        create_dept,
        create_by,
        create_time,
        update_by,
        update_time,
        remark
    )
VALUES (
        @system_monitor_menu_id,
        '系统监控',
        @system_menu_id,
        6,
        'system-monitor',
        'pms/system/monitor/index',
        NULL,
        1,
        0,
        'C',
        '0',
        '0',
        'pms:systemMonitor:list',
        'monitor',
        103,
        1,
        NOW(),
        1,
        NOW(),
        '系统监控菜单'
    );
-- 系统监控权限按钮
INSERT INTO sys_menu (
        menu_id,
        menu_name,
        parent_id,
        order_num,
        path,
        component,
        query_param,
        is_frame,
        is_cache,
        menu_type,
        visible,
        status,
        perms,
        icon,
        create_dept,
        create_by,
        create_time,
        update_by,
        update_time,
        remark
    )
VALUES (
        @max_menu_id + 44,
        '监控查询',
        @system_monitor_menu_id,
        1,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:systemMonitor:query',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 45,
        '性能监控',
        @system_monitor_menu_id,
        2,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:systemMonitor:performance',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 46,
        '配置变更监控',
        @system_monitor_menu_id,
        3,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:systemMonitor:configChange',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 47,
        '用户行为监控',
        @system_monitor_menu_id,
        4,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:systemMonitor:userBehavior',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 48,
        '系统日志',
        @system_monitor_menu_id,
        5,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:systemMonitor:logs',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    ),
    (
        @max_menu_id + 49,
        '报警管理',
        @system_monitor_menu_id,
        6,
        '#',
        '',
        NULL,
        1,
        0,
        'F',
        '0',
        '0',
        'pms:systemMonitor:alert',
        '#',
        103,
        1,
        NOW(),
        1,
        NOW(),
        ''
    );
-- =============================================
-- 8. 输出菜单ID信息
-- =============================================
SELECT '系统配置管理主菜单ID' AS menu_type,
    @system_menu_id AS menu_id
UNION ALL
SELECT '租户配置管理菜单ID' AS menu_type,
    @tenant_settings_menu_id AS menu_id
UNION ALL
SELECT '门店配置管理菜单ID' AS menu_type,
    @dept_settings_menu_id AS menu_id
UNION ALL
SELECT '小程序配置管理菜单ID' AS menu_type,
    @mp_settings_menu_id AS menu_id
UNION ALL
SELECT '用户设备管理菜单ID' AS menu_type,
    @user_devices_menu_id AS menu_id
UNION ALL
SELECT '配置模板管理菜单ID' AS menu_type,
    @config_templates_menu_id AS menu_id
UNION ALL
SELECT '系统监控菜单ID' AS menu_type,
    @system_monitor_menu_id AS menu_id;