-- SillyTavern Cloud / 云酒馆
-- PostgreSQL 手动初始化脚本，对应后端 PgsqlInitHandler.InitData 全量初始化数据
-- 使用方法（建议在全新空库上执行）：
--   psql -h <host> -U <user> -d <db> -f pgsql_init.sql
--
-- 注意：
-- 1. 本脚本不会自动清理旧数据，如需在已有数据上重置，请自行 TRUNCATE 相关表。
-- 2. 用户密码字段留空（''），初始化后请通过接口或 SQL 自行重置管理员密码。

BEGIN;

/* =========================
 * 1. 角色表 sys_authorities
 * ========================= */

INSERT INTO sys_authorities (authority_id, authority_name, parent_id, default_router)
VALUES
    (888,  '普通用户',       0,    'dashboard'),
    (9528, '测试角色',       0,    'dashboard'),
    (8881, '普通用户子角色', 888,  'dashboard');


/* =========================
 * 2. 用户表 sys_users
 *    对应 initUser.InitializeData
 * ========================= */

INSERT INTO sys_users (uuid, username, password, nick_name, header_img, authority_id, phone, email, enable)
VALUES
    ('00000000-0000-0000-0000-000000000001', 'admin',      '', 'Lee', 'https://qmplusimg.henrongyi.top/gva_header.jpg', 888,  '17611111111', '333333333@qq.com', 1),
    ('00000000-0000-0000-0000-000000000002', 'a303176530', '', '用户1',   'https://qmplusimg.henrongyi.top/1572075907logo.png', 9528, '17611111111', '333333333@qq.com', 1);


/* =====================================================
 * 3. 字典表 & 字典详情表
 *    sys_dictionaries, sys_dictionary_details
 * ===================================================== */

-- 3.1 字典表 sys_dictionaries
INSERT INTO sys_dictionaries (name, type, status, "desc")
VALUES
    ('性别',           'gender',   TRUE, '性别字典'),
    ('数据库int类型',  'int',      TRUE, 'int类型对应的数据库类型'),
    ('数据库时间日期类型', 'time.Time', TRUE, '数据库时间日期类型'),
    ('数据库浮点型',   'float64',  TRUE, '数据库浮点型'),
    ('数据库字符串',   'string',   TRUE, '数据库字符串'),
    ('数据库bool类型', 'bool',     TRUE, '数据库bool类型');

-- 3.2 字典详情表 sys_dictionary_details
-- 使用 INSERT ... SELECT，通过 type 反查 sys_dictionaries.id

-- 性别 gender
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT
    '男' AS label, '1' AS value, '' AS extend, TRUE AS status, 1 AS sort,
    d.id AS sys_dictionary_id, NULL::integer AS parent_id, 0 AS level, '' AS path
FROM sys_dictionaries d WHERE d.type = 'gender';

INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT
    '女', '2', '', TRUE, 2,
    d.id, NULL::integer, 0, ''
FROM sys_dictionaries d WHERE d.type = 'gender';

-- int
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'smallint', '1', 'mysql', TRUE, 1, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'int';
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'mediumint', '2', 'mysql', TRUE, 2, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'int';
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'int', '3', 'mysql', TRUE, 3, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'int';
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'bigint', '4', 'mysql', TRUE, 4, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'int';
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'int2', '5', 'pgsql', TRUE, 5, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'int';
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'int4', '6', 'pgsql', TRUE, 6, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'int';
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'int6', '7', 'pgsql', TRUE, 7, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'int';
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'int8', '8', 'pgsql', TRUE, 8, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'int';

-- time.Time
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'date', '0', 'mysql', TRUE, 0, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'time.Time';
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'time', '1', 'mysql', TRUE, 1, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'time.Time';
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'year', '2', 'mysql', TRUE, 2, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'time.Time';
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'datetime', '3', 'mysql', TRUE, 3, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'time.Time';
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'timestamp', '5', 'mysql', TRUE, 5, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'time.Time';
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'timestamptz', '6', 'pgsql', TRUE, 5, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'time.Time';

-- float64
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'float', '0', 'mysql', TRUE, 0, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'float64';
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'double', '1', 'mysql', TRUE, 1, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'float64';
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'decimal', '2', 'mysql', TRUE, 2, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'float64';
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'numeric', '3', 'pgsql', TRUE, 3, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'float64';
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'smallserial', '4', 'pgsql', TRUE, 4, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'float64';

-- string
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'char', '0', 'mysql', TRUE, 0, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'string';
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'varchar', '1', 'mysql', TRUE, 1, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'string';
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'tinyblob', '2', 'mysql', TRUE, 2, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'string';
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'tinytext', '3', 'mysql', TRUE, 3, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'string';
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'text', '4', 'mysql', TRUE, 4, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'string';
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'blob', '5', 'mysql', TRUE, 5, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'string';
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'mediumblob', '6', 'mysql', TRUE, 6, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'string';
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'mediumtext', '7', 'mysql', TRUE, 7, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'string';
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'longblob', '8', 'mysql', TRUE, 8, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'string';
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'longtext', '9', 'mysql', TRUE, 9, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'string';

-- bool
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'tinyint', '1', 'mysql', TRUE, 0, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'bool';
INSERT INTO sys_dictionary_details (label, value, extend, status, sort, sys_dictionary_id, parent_id, level, path)
SELECT 'bool', '2', 'pgsql', TRUE, 0, d.id, NULL::integer, 0, '' FROM sys_dictionaries d WHERE d.type = 'bool';


/* =========================
 * 4. API 表 sys_apis
 * ========================= */

INSERT INTO sys_apis (api_group, method, path, description)
VALUES
    ('jwt', 'POST', '/jwt/jsonInBlacklist', 'jwt加入黑名单(退出，必选)'),

    ('登录日志', 'DELETE', '/sysLoginLog/deleteLoginLog', '删除登录日志'),
    ('登录日志', 'DELETE', '/sysLoginLog/deleteLoginLogByIds', '批量删除登录日志'),
    ('登录日志', 'GET',    '/sysLoginLog/findLoginLog', '根据ID获取登录日志'),
    ('登录日志', 'GET',    '/sysLoginLog/getLoginLogList', '获取登录日志列表'),

    ('API Token', 'POST', '/sysApiToken/createApiToken', '签发API Token'),
    ('API Token', 'POST', '/sysApiToken/getApiTokenList', '获取API Token列表'),
    ('API Token', 'POST', '/sysApiToken/deleteApiToken', '作废API Token'),

    ('系统用户', 'DELETE', '/user/deleteUser', '删除用户'),
    ('系统用户', 'POST',   '/user/admin_register', '用户注册'),
    ('系统用户', 'POST',   '/user/getUserList', '获取用户列表'),
    ('系统用户', 'PUT',    '/user/setUserInfo', '设置用户信息'),
    ('系统用户', 'PUT',    '/user/setSelfInfo', '设置自身信息(必选)'),
    ('系统用户', 'GET',    '/user/getUserInfo', '获取自身信息(必选)'),
    ('系统用户', 'POST',   '/user/setUserAuthorities', '设置权限组'),
    ('系统用户', 'POST',   '/user/changePassword', '修改密码（建议选择)'),
    ('系统用户', 'POST',   '/user/setUserAuthority', '修改用户角色(必选)'),
    ('系统用户', 'POST',   '/user/resetPassword', '重置用户密码'),
    ('系统用户', 'PUT',    '/user/setSelfSetting', '用户界面配置'),

    ('api', 'POST', '/api/createApi', '创建api'),
    ('api', 'POST', '/api/deleteApi', '删除Api'),
    ('api', 'POST', '/api/updateApi', '更新Api'),
    ('api', 'POST', '/api/getApiList', '获取api列表'),
    ('api', 'POST', '/api/getAllApis', '获取所有api'),
    ('api', 'POST', '/api/getApiById', '获取api详细信息'),
    ('api', 'DELETE', '/api/deleteApisByIds', '批量删除api'),
    ('api', 'GET', '/api/syncApi', '获取待同步API'),
    ('api', 'GET', '/api/getApiGroups', '获取路由组'),
    ('api', 'POST', '/api/enterSyncApi', '确认同步API'),
    ('api', 'POST', '/api/ignoreApi', '忽略API'),

    ('角色', 'POST', '/authority/copyAuthority', '拷贝角色'),
    ('角色', 'POST', '/authority/createAuthority', '创建角色'),
    ('角色', 'POST', '/authority/deleteAuthority', '删除角色'),
    ('角色', 'PUT',  '/authority/updateAuthority', '更新角色信息'),
    ('角色', 'POST', '/authority/getAuthorityList', '获取角色列表'),
    ('角色', 'POST', '/authority/setDataAuthority', '设置角色资源权限'),

    ('casbin', 'POST', '/casbin/updateCasbin', '更改角色api权限'),
    ('casbin', 'POST', '/casbin/getPolicyPathByAuthorityId', '获取权限列表'),

    ('菜单', 'POST', '/menu/addBaseMenu', '新增菜单'),
    ('菜单', 'POST', '/menu/getMenu', '获取菜单树(必选)'),
    ('菜单', 'POST', '/menu/deleteBaseMenu', '删除菜单'),
    ('菜单', 'POST', '/menu/updateBaseMenu', '更新菜单'),
    ('菜单', 'POST', '/menu/getBaseMenuById', '根据id获取菜单'),
    ('菜单', 'POST', '/menu/getMenuList', '分页获取基础menu列表'),
    ('菜单', 'POST', '/menu/getBaseMenuTree', '获取用户动态路由'),
    ('菜单', 'POST', '/menu/getMenuAuthority', '获取指定角色menu'),
    ('菜单', 'POST', '/menu/addMenuAuthority', '增加menu和角色关联关系'),

    ('分片上传', 'GET',  '/fileUploadAndDownload/findFile', '寻找目标文件（秒传）'),
    ('分片上传', 'POST', '/fileUploadAndDownload/breakpointContinue', '断点续传'),
    ('分片上传', 'POST', '/fileUploadAndDownload/breakpointContinueFinish', '断点续传完成'),
    ('分片上传', 'POST', '/fileUploadAndDownload/removeChunk', '上传完成移除文件'),

    ('文件上传与下载', 'POST', '/fileUploadAndDownload/upload', '文件上传（建议选择）'),
    ('文件上传与下载', 'POST', '/fileUploadAndDownload/deleteFile', '删除文件'),
    ('文件上传与下载', 'POST', '/fileUploadAndDownload/editFileName', '文件名或者备注编辑'),
    ('文件上传与下载', 'POST', '/fileUploadAndDownload/getFileList', '获取上传文件列表'),
    ('文件上传与下载', 'POST', '/fileUploadAndDownload/importURL', '导入URL'),

    ('系统服务', 'POST', '/system/getServerInfo', '获取服务器信息'),
    ('系统服务', 'POST', '/system/getSystemConfig', '获取配置文件内容'),
    ('系统服务', 'POST', '/system/setSystemConfig', '设置配置文件内容'),

    ('skills', 'GET',  '/skills/getTools', '获取技能工具列表'),
    ('skills', 'POST', '/skills/getSkillList', '获取技能列表'),
    ('skills', 'POST', '/skills/getSkillDetail', '获取技能详情'),
    ('skills', 'POST', '/skills/saveSkill', '保存技能定义'),
    ('skills', 'POST', '/skills/createScript', '创建技能脚本'),
    ('skills', 'POST', '/skills/getScript', '读取技能脚本'),
    ('skills', 'POST', '/skills/saveScript', '保存技能脚本'),
    ('skills', 'POST', '/skills/createResource', '创建技能资源'),
    ('skills', 'POST', '/skills/getResource', '读取技能资源'),
    ('skills', 'POST', '/skills/saveResource', '保存技能资源'),
    ('skills', 'POST', '/skills/createReference', '创建技能参考'),
    ('skills', 'POST', '/skills/getReference', '读取技能参考'),
    ('skills', 'POST', '/skills/saveReference', '保存技能参考'),
    ('skills', 'POST', '/skills/createTemplate', '创建技能模板'),
    ('skills', 'POST', '/skills/getTemplate', '读取技能模板'),
    ('skills', 'POST', '/skills/saveTemplate', '保存技能模板'),
    ('skills', 'POST', '/skills/getGlobalConstraint', '读取全局约束'),
    ('skills', 'POST', '/skills/saveGlobalConstraint', '保存全局约束'),

    ('客户', 'PUT',   '/customer/customer', '更新客户'),
    ('客户', 'POST',  '/customer/customer', '创建客户'),
    ('客户', 'DELETE','/customer/customer', '删除客户'),
    ('客户', 'GET',   '/customer/customer', '获取单一客户'),
    ('客户', 'GET',   '/customer/customerList', '获取客户列表'),

    ('代码生成器', 'GET',  '/autoCode/getDB', '获取所有数据库'),
    ('代码生成器', 'GET',  '/autoCode/getTables', '获取数据库表'),
    ('代码生成器', 'POST', '/autoCode/createTemp', '自动化代码'),
    ('代码生成器', 'POST', '/autoCode/preview', '预览自动化代码'),
    ('代码生成器', 'GET',  '/autoCode/getColumn', '获取所选table的所有字段'),
    ('代码生成器', 'POST', '/autoCode/installPlugin', '安装插件'),
    ('代码生成器', 'POST', '/autoCode/pubPlug', '打包插件'),
    ('代码生成器', 'POST', '/autoCode/removePlugin', '卸载插件'),
    ('代码生成器', 'GET',  '/autoCode/getPluginList', '获取已安装插件'),
    ('代码生成器', 'POST', '/autoCode/mcp', '自动生成 MCP Tool 模板'),
    ('代码生成器', 'POST', '/autoCode/mcpTest', 'MCP Tool 测试'),
    ('代码生成器', 'POST', '/autoCode/mcpList', '获取 MCP ToolList'),

    ('模板配置', 'POST', '/autoCode/createPackage', '配置模板'),
    ('模板配置', 'GET',  '/autoCode/getTemplates', '获取模板文件'),
    ('模板配置', 'POST', '/autoCode/getPackage', '获取所有模板'),
    ('模板配置', 'POST', '/autoCode/delPackage', '删除模板'),

    ('代码生成器历史', 'POST', '/autoCode/getMeta', '获取meta信息'),
    ('代码生成器历史', 'POST', '/autoCode/rollback', '回滚自动生成代码'),
    ('代码生成器历史', 'POST', '/autoCode/getSysHistory', '查询回滚记录'),
    ('代码生成器历史', 'POST', '/autoCode/delSysHistory', '删除回滚记录'),
    ('代码生成器历史', 'POST', '/autoCode/addFunc', '增加模板方法'),

    ('系统字典详情', 'PUT',   '/sysDictionaryDetail/updateSysDictionaryDetail', '更新字典内容'),
    ('系统字典详情', 'POST',  '/sysDictionaryDetail/createSysDictionaryDetail', '新增字典内容'),
    ('系统字典详情', 'DELETE','/sysDictionaryDetail/deleteSysDictionaryDetail', '删除字典内容'),
    ('系统字典详情', 'GET',   '/sysDictionaryDetail/findSysDictionaryDetail', '根据ID获取字典内容'),
    ('系统字典详情', 'GET',   '/sysDictionaryDetail/getSysDictionaryDetailList', '获取字典内容列表'),
    ('系统字典详情', 'GET',   '/sysDictionaryDetail/getDictionaryTreeList', '获取字典数列表'),
    ('系统字典详情', 'GET',   '/sysDictionaryDetail/getDictionaryTreeListByType', '根据分类获取字典数列表'),
    ('系统字典详情', 'GET',   '/sysDictionaryDetail/getDictionaryDetailsByParent', '根据父级ID获取字典详情'),
    ('系统字典详情', 'GET',   '/sysDictionaryDetail/getDictionaryPath', '获取字典详情的完整路径'),

    ('系统字典', 'POST',  '/sysDictionary/createSysDictionary', '新增字典'),
    ('系统字典', 'DELETE','/sysDictionary/deleteSysDictionary', '删除字典'),
    ('系统字典', 'PUT',   '/sysDictionary/updateSysDictionary', '更新字典'),
    ('系统字典', 'GET',   '/sysDictionary/findSysDictionary', '根据ID获取字典（建议选择）'),
    ('系统字典', 'GET',   '/sysDictionary/getSysDictionaryList', '获取字典列表'),
    ('系统字典', 'POST',  '/sysDictionary/importSysDictionary', '导入字典JSON'),
    ('系统字典', 'GET',   '/sysDictionary/exportSysDictionary', '导出字典JSON'),

    ('操作记录', 'POST',  '/sysOperationRecord/createSysOperationRecord', '新增操作记录'),
    ('操作记录', 'GET',   '/sysOperationRecord/findSysOperationRecord', '根据ID获取操作记录'),
    ('操作记录', 'GET',   '/sysOperationRecord/getSysOperationRecordList', '获取操作记录列表'),
    ('操作记录', 'DELETE','/sysOperationRecord/deleteSysOperationRecord', '删除操作记录'),
    ('操作记录', 'DELETE','/sysOperationRecord/deleteSysOperationRecordByIds', '批量删除操作历史'),

    ('断点续传(插件版)', 'POST', '/simpleUploader/upload', '插件版分片上传'),
    ('断点续传(插件版)', 'GET',  '/simpleUploader/checkFileMd5', '文件完整度验证'),
    ('断点续传(插件版)', 'GET',  '/simpleUploader/mergeFileMd5', '上传完成合并文件'),

    ('email', 'POST', '/email/emailTest', '发送测试邮件'),
    ('email', 'POST', '/email/sendEmail', '发送邮件'),

    ('按钮权限', 'POST', '/authorityBtn/setAuthorityBtn', '设置按钮权限'),
    ('按钮权限', 'POST', '/authorityBtn/getAuthorityBtn', '获取已有按钮权限'),
    ('按钮权限', 'POST', '/authorityBtn/canRemoveAuthorityBtn', '删除按钮'),

    ('导出模板', 'POST',  '/sysExportTemplate/createSysExportTemplate', '新增导出模板'),
    ('导出模板', 'DELETE','/sysExportTemplate/deleteSysExportTemplate', '删除导出模板'),
    ('导出模板', 'DELETE','/sysExportTemplate/deleteSysExportTemplateByIds', '批量删除导出模板'),
    ('导出模板', 'PUT',   '/sysExportTemplate/updateSysExportTemplate', '更新导出模板'),
    ('导出模板', 'GET',   '/sysExportTemplate/findSysExportTemplate', '根据ID获取导出模板'),
    ('导出模板', 'GET',   '/sysExportTemplate/getSysExportTemplateList', '获取导出模板列表'),
    ('导出模板', 'GET',   '/sysExportTemplate/exportExcel', '导出Excel'),
    ('导出模板', 'GET',   '/sysExportTemplate/exportTemplate', '下载模板'),
    ('导出模板', 'GET',   '/sysExportTemplate/previewSQL', '预览SQL'),
    ('导出模板', 'POST',  '/sysExportTemplate/importExcel', '导入Excel'),

    ('错误日志', 'POST',  '/sysError/createSysError', '新建错误日志'),
    ('错误日志', 'DELETE','/sysError/deleteSysError', '删除错误日志'),
    ('错误日志', 'DELETE','/sysError/deleteSysErrorByIds', '批量删除错误日志'),
    ('错误日志', 'PUT',   '/sysError/updateSysError', '更新错误日志'),
    ('错误日志', 'GET',   '/sysError/findSysError', '根据ID获取错误日志'),
    ('错误日志', 'GET',   '/sysError/getSysErrorList', '获取错误日志列表'),
    ('错误日志', 'GET',   '/sysError/getSysErrorSolution', '触发错误处理(异步)'),

    ('公告', 'POST',  '/info/createInfo', '新建公告'),
    ('公告', 'DELETE','/info/deleteInfo', '删除公告'),
    ('公告', 'DELETE','/info/deleteInfoByIds', '批量删除公告'),
    ('公告', 'PUT',   '/info/updateInfo', '更新公告'),
    ('公告', 'GET',   '/info/findInfo', '根据ID获取公告'),
    ('公告', 'GET',   '/info/getInfoList', '获取公告列表'),

    ('参数管理', 'POST',  '/sysParams/createSysParams', '新建参数'),
    ('参数管理', 'DELETE','/sysParams/deleteSysParams', '删除参数'),
    ('参数管理', 'DELETE','/sysParams/deleteSysParamsByIds', '批量删除参数'),
    ('参数管理', 'PUT',   '/sysParams/updateSysParams', '更新参数'),
    ('参数管理', 'GET',   '/sysParams/findSysParams', '根据ID获取参数'),
    ('参数管理', 'GET',   '/sysParams/getSysParamsList', '获取参数列表'),
    ('参数管理', 'GET',   '/sysParams/getSysParam', '获取参数列表'),

    ('媒体库分类', 'GET',  '/attachmentCategory/getCategoryList', '分类列表'),
    ('媒体库分类', 'POST', '/attachmentCategory/addCategory', '添加/编辑分类'),
    ('媒体库分类', 'POST', '/attachmentCategory/deleteCategory', '删除分类'),

    ('版本控制', 'GET',   '/sysVersion/findSysVersion', '获取单一版本'),
    ('版本控制', 'GET',   '/sysVersion/getSysVersionList', '获取版本列表'),
    ('版本控制', 'GET',   '/sysVersion/downloadVersionJson', '下载版本json'),
    ('版本控制', 'POST',  '/sysVersion/exportVersion', '创建版本'),
    ('版本控制', 'POST',  '/sysVersion/importVersion', '同步版本'),
    ('版本控制', 'DELETE','/sysVersion/deleteSysVersion', '删除版本'),
    ('版本控制', 'DELETE','/sysVersion/deleteSysVersionByIds', '批量删除版本');


/* =========================
 * 5. 忽略 API 表 sys_ignore_apis
 * ========================= */

INSERT INTO sys_ignore_apis (method, path)
VALUES
    ('GET',  '/swagger/*any'),
    ('GET',  '/api/freshCasbin'),
    ('GET',  '/uploads/file/*filepath'),
    ('GET',  '/health'),
    ('HEAD', '/uploads/file/*filepath'),
    ('POST', '/autoCode/llmAuto'),
    ('POST', '/system/reloadSystem'),
    ('POST', '/base/login'),
    ('POST', '/base/captcha'),
    ('POST', '/init/initdb'),
    ('POST', '/init/checkdb'),
    ('GET',  '/info/getInfoDataSource'),
    ('GET',  '/info/getInfoPublic');


/* =========================
 * 6. Casbin 规则表 casbin_rules
 * ========================= */

INSERT INTO casbin_rules (ptype, v0, v1, v2)
VALUES
    -- 888
    ('p', '888', '/user/admin_register', 'POST'),

    ('p', '888', '/sysLoginLog/deleteLoginLog', 'DELETE'),
    ('p', '888', '/sysLoginLog/deleteLoginLogByIds', 'DELETE'),
    ('p', '888', '/sysLoginLog/findLoginLog', 'GET'),
    ('p', '888', '/sysLoginLog/getLoginLogList', 'GET'),

    ('p', '888', '/sysApiToken/createApiToken', 'POST'),
    ('p', '888', '/sysApiToken/getApiTokenList', 'POST'),
    ('p', '888', '/sysApiToken/deleteApiToken', 'POST'),

    ('p', '888', '/api/createApi', 'POST'),
    ('p', '888', '/api/getApiList', 'POST'),
    ('p', '888', '/api/getApiById', 'POST'),
    ('p', '888', '/api/deleteApi', 'POST'),
    ('p', '888', '/api/updateApi', 'POST'),
    ('p', '888', '/api/getAllApis', 'POST'),
    ('p', '888', '/api/deleteApisByIds', 'DELETE'),
    ('p', '888', '/api/syncApi', 'GET'),
    ('p', '888', '/api/getApiGroups', 'GET'),
    ('p', '888', '/api/enterSyncApi', 'POST'),
    ('p', '888', '/api/ignoreApi', 'POST'),

    ('p', '888', '/authority/copyAuthority', 'POST'),
    ('p', '888', '/authority/updateAuthority', 'PUT'),
    ('p', '888', '/authority/createAuthority', 'POST'),
    ('p', '888', '/authority/deleteAuthority', 'POST'),
    ('p', '888', '/authority/getAuthorityList', 'POST'),
    ('p', '888', '/authority/setDataAuthority', 'POST'),

    ('p', '888', '/menu/getMenu', 'POST'),
    ('p', '888', '/menu/getMenuList', 'POST'),
    ('p', '888', '/menu/addBaseMenu', 'POST'),
    ('p', '888', '/menu/getBaseMenuTree', 'POST'),
    ('p', '888', '/menu/addMenuAuthority', 'POST'),
    ('p', '888', '/menu/getMenuAuthority', 'POST'),
    ('p', '888', '/menu/deleteBaseMenu', 'POST'),
    ('p', '888', '/menu/updateBaseMenu', 'POST'),
    ('p', '888', '/menu/getBaseMenuById', 'POST'),

    ('p', '888', '/user/getUserInfo', 'GET'),
    ('p', '888', '/user/setUserInfo', 'PUT'),
    ('p', '888', '/user/setSelfInfo', 'PUT'),
    ('p', '888', '/user/getUserList', 'POST'),
    ('p', '888', '/user/deleteUser', 'DELETE'),
    ('p', '888', '/user/changePassword', 'POST'),
    ('p', '888', '/user/setUserAuthority', 'POST'),
    ('p', '888', '/user/setUserAuthorities', 'POST'),
    ('p', '888', '/user/resetPassword', 'POST'),
    ('p', '888', '/user/setSelfSetting', 'PUT'),

    ('p', '888', '/fileUploadAndDownload/findFile', 'GET'),
    ('p', '888', '/fileUploadAndDownload/breakpointContinueFinish', 'POST'),
    ('p', '888', '/fileUploadAndDownload/breakpointContinue', 'POST'),
    ('p', '888', '/fileUploadAndDownload/removeChunk', 'POST'),

    ('p', '888', '/fileUploadAndDownload/upload', 'POST'),
    ('p', '888', '/fileUploadAndDownload/deleteFile', 'POST'),
    ('p', '888', '/fileUploadAndDownload/editFileName', 'POST'),
    ('p', '888', '/fileUploadAndDownload/getFileList', 'POST'),
    ('p', '888', '/fileUploadAndDownload/importURL', 'POST'),

    ('p', '888', '/casbin/updateCasbin', 'POST'),
    ('p', '888', '/casbin/getPolicyPathByAuthorityId', 'POST'),

    ('p', '888', '/jwt/jsonInBlacklist', 'POST'),

    ('p', '888', '/system/getSystemConfig', 'POST'),
    ('p', '888', '/system/setSystemConfig', 'POST'),
    ('p', '888', '/system/getServerInfo', 'POST'),

    ('p', '888', '/skills/getTools', 'GET'),
    ('p', '888', '/skills/getSkillList', 'POST'),
    ('p', '888', '/skills/getSkillDetail', 'POST'),
    ('p', '888', '/skills/saveSkill', 'POST'),
    ('p', '888', '/skills/createScript', 'POST'),
    ('p', '888', '/skills/getScript', 'POST'),
    ('p', '888', '/skills/saveScript', 'POST'),
    ('p', '888', '/skills/createResource', 'POST'),
    ('p', '888', '/skills/getResource', 'POST'),
    ('p', '888', '/skills/saveResource', 'POST'),
    ('p', '888', '/skills/createReference', 'POST'),
    ('p', '888', '/skills/getReference', 'POST'),
    ('p', '888', '/skills/saveReference', 'POST'),
    ('p', '888', '/skills/createTemplate', 'POST'),
    ('p', '888', '/skills/getTemplate', 'POST'),
    ('p', '888', '/skills/saveTemplate', 'POST'),
    ('p', '888', '/skills/getGlobalConstraint', 'POST'),
    ('p', '888', '/skills/saveGlobalConstraint', 'POST'),

    ('p', '888', '/customer/customer', 'GET'),
    ('p', '888', '/customer/customer', 'PUT'),
    ('p', '888', '/customer/customer', 'POST'),
    ('p', '888', '/customer/customer', 'DELETE'),
    ('p', '888', '/customer/customerList', 'GET'),

    ('p', '888', '/autoCode/getDB', 'GET'),
    ('p', '888', '/autoCode/getMeta', 'POST'),
    ('p', '888', '/autoCode/preview', 'POST'),
    ('p', '888', '/autoCode/getTables', 'GET'),
    ('p', '888', '/autoCode/getColumn', 'GET'),
    ('p', '888', '/autoCode/rollback', 'POST'),
    ('p', '888', '/autoCode/createTemp', 'POST'),
    ('p', '888', '/autoCode/delSysHistory', 'POST'),
    ('p', '888', '/autoCode/getSysHistory', 'POST'),
    ('p', '888', '/autoCode/createPackage', 'POST'),
    ('p', '888', '/autoCode/getTemplates', 'GET'),
    ('p', '888', '/autoCode/getPackage', 'POST'),
    ('p', '888', '/autoCode/delPackage', 'POST'),
    ('p', '888', '/autoCode/createPlug', 'POST'),
    ('p', '888', '/autoCode/installPlugin', 'POST'),
    ('p', '888', '/autoCode/pubPlug', 'POST'),
    ('p', '888', '/autoCode/removePlugin', 'POST'),
    ('p', '888', '/autoCode/getPluginList', 'GET'),
    ('p', '888', '/autoCode/addFunc', 'POST'),
    ('p', '888', '/autoCode/mcp', 'POST'),
    ('p', '888', '/autoCode/mcpTest', 'POST'),
    ('p', '888', '/autoCode/mcpList', 'POST'),

    ('p', '888', '/sysDictionaryDetail/findSysDictionaryDetail', 'GET'),
    ('p', '888', '/sysDictionaryDetail/updateSysDictionaryDetail', 'PUT'),
    ('p', '888', '/sysDictionaryDetail/createSysDictionaryDetail', 'POST'),
    ('p', '888', '/sysDictionaryDetail/getSysDictionaryDetailList', 'GET'),
    ('p', '888', '/sysDictionaryDetail/deleteSysDictionaryDetail', 'DELETE'),
    ('p', '888', '/sysDictionaryDetail/getDictionaryTreeList', 'GET'),
    ('p', '888', '/sysDictionaryDetail/getDictionaryTreeListByType', 'GET'),
    ('p', '888', '/sysDictionaryDetail/getDictionaryDetailsByParent', 'GET'),
    ('p', '888', '/sysDictionaryDetail/getDictionaryPath', 'GET'),

    ('p', '888', '/sysDictionary/findSysDictionary', 'GET'),
    ('p', '888', '/sysDictionary/updateSysDictionary', 'PUT'),
    ('p', '888', '/sysDictionary/getSysDictionaryList', 'GET'),
    ('p', '888', '/sysDictionary/createSysDictionary', 'POST'),
    ('p', '888', '/sysDictionary/deleteSysDictionary', 'DELETE'),
    ('p', '888', '/sysDictionary/importSysDictionary', 'POST'),
    ('p', '888', '/sysDictionary/exportSysDictionary', 'GET'),

    ('p', '888', '/sysOperationRecord/findSysOperationRecord', 'GET'),
    ('p', '888', '/sysOperationRecord/updateSysOperationRecord', 'PUT'),
    ('p', '888', '/sysOperationRecord/createSysOperationRecord', 'POST'),
    ('p', '888', '/sysOperationRecord/getSysOperationRecordList', 'GET'),
    ('p', '888', '/sysOperationRecord/deleteSysOperationRecord', 'DELETE'),
    ('p', '888', '/sysOperationRecord/deleteSysOperationRecordByIds', 'DELETE'),

    ('p', '888', '/email/emailTest', 'POST'),
    ('p', '888', '/email/sendEmail', 'POST'),

    ('p', '888', '/simpleUploader/upload', 'POST'),
    ('p', '888', '/simpleUploader/checkFileMd5', 'GET'),
    ('p', '888', '/simpleUploader/mergeFileMd5', 'GET'),

    ('p', '888', '/authorityBtn/setAuthorityBtn', 'POST'),
    ('p', '888', '/authorityBtn/getAuthorityBtn', 'POST'),
    ('p', '888', '/authorityBtn/canRemoveAuthorityBtn', 'POST'),

    ('p', '888', '/sysExportTemplate/createSysExportTemplate', 'POST'),
    ('p', '888', '/sysExportTemplate/deleteSysExportTemplate', 'DELETE'),
    ('p', '888', '/sysExportTemplate/deleteSysExportTemplateByIds', 'DELETE'),
    ('p', '888', '/sysExportTemplate/updateSysExportTemplate', 'PUT'),
    ('p', '888', '/sysExportTemplate/findSysExportTemplate', 'GET'),
    ('p', '888', '/sysExportTemplate/getSysExportTemplateList', 'GET'),
    ('p', '888', '/sysExportTemplate/exportExcel', 'GET'),
    ('p', '888', '/sysExportTemplate/exportTemplate', 'GET'),
    ('p', '888', '/sysExportTemplate/previewSQL', 'GET'),
    ('p', '888', '/sysExportTemplate/importExcel', 'POST'),

    ('p', '888', '/sysError/createSysError', 'POST'),
    ('p', '888', '/sysError/deleteSysError', 'DELETE'),
    ('p', '888', '/sysError/deleteSysErrorByIds', 'DELETE'),
    ('p', '888', '/sysError/updateSysError', 'PUT'),
    ('p', '888', '/sysError/findSysError', 'GET'),
    ('p', '888', '/sysError/getSysErrorList', 'GET'),
    ('p', '888', '/sysError/getSysErrorSolution', 'GET'),

    ('p', '888', '/info/createInfo', 'POST'),
    ('p', '888', '/info/deleteInfo', 'DELETE'),
    ('p', '888', '/info/deleteInfoByIds', 'DELETE'),
    ('p', '888', '/info/updateInfo', 'PUT'),
    ('p', '888', '/info/findInfo', 'GET'),
    ('p', '888', '/info/getInfoList', 'GET'),

    ('p', '888', '/sysParams/createSysParams', 'POST'),
    ('p', '888', '/sysParams/deleteSysParams', 'DELETE'),
    ('p', '888', '/sysParams/deleteSysParamsByIds', 'DELETE'),
    ('p', '888', '/sysParams/updateSysParams', 'PUT'),
    ('p', '888', '/sysParams/findSysParams', 'GET'),
    ('p', '888', '/sysParams/getSysParamsList', 'GET'),
    ('p', '888', '/sysParams/getSysParam', 'GET'),
    ('p', '888', '/attachmentCategory/getCategoryList', 'GET'),
    ('p', '888', '/attachmentCategory/addCategory', 'POST'),
    ('p', '888', '/attachmentCategory/deleteCategory', 'POST'),

    ('p', '888', '/sysVersion/findSysVersion', 'GET'),
    ('p', '888', '/sysVersion/getSysVersionList', 'GET'),
    ('p', '888', '/sysVersion/downloadVersionJson', 'GET'),
    ('p', '888', '/sysVersion/exportVersion', 'POST'),
    ('p', '888', '/sysVersion/importVersion', 'POST'),
    ('p', '888', '/sysVersion/deleteSysVersion', 'DELETE'),
    ('p', '888', '/sysVersion/deleteSysVersionByIds', 'DELETE'),

    -- 8881
    ('p', '8881', '/user/admin_register', 'POST'),
    ('p', '8881', '/api/createApi', 'POST'),
    ('p', '8881', '/api/getApiList', 'POST'),
    ('p', '8881', '/api/getApiById', 'POST'),
    ('p', '8881', '/api/deleteApi', 'POST'),
    ('p', '8881', '/api/updateApi', 'POST'),
    ('p', '8881', '/api/getAllApis', 'POST'),
    ('p', '8881', '/authority/createAuthority', 'POST'),
    ('p', '8881', '/authority/deleteAuthority', 'POST'),
    ('p', '8881', '/authority/getAuthorityList', 'POST'),
    ('p', '8881', '/authority/setDataAuthority', 'POST'),
    ('p', '8881', '/menu/getMenu', 'POST'),
    ('p', '8881', '/menu/getMenuList', 'POST'),
    ('p', '8881', '/menu/addBaseMenu', 'POST'),
    ('p', '8881', '/menu/getBaseMenuTree', 'POST'),
    ('p', '8881', '/menu/addMenuAuthority', 'POST'),
    ('p', '8881', '/menu/getMenuAuthority', 'POST'),
    ('p', '8881', '/menu/deleteBaseMenu', 'POST'),
    ('p', '8881', '/menu/updateBaseMenu', 'POST'),
    ('p', '8881', '/menu/getBaseMenuById', 'POST'),
    ('p', '8881', '/user/changePassword', 'POST'),
    ('p', '8881', '/user/getUserList', 'POST'),
    ('p', '8881', '/user/setUserAuthority', 'POST'),
    ('p', '8881', '/fileUploadAndDownload/upload', 'POST'),
    ('p', '8881', '/fileUploadAndDownload/getFileList', 'POST'),
    ('p', '8881', '/fileUploadAndDownload/deleteFile', 'POST'),
    ('p', '8881', '/fileUploadAndDownload/editFileName', 'POST'),
    ('p', '8881', '/fileUploadAndDownload/importURL', 'POST'),
    ('p', '8881', '/casbin/updateCasbin', 'POST'),
    ('p', '8881', '/casbin/getPolicyPathByAuthorityId', 'POST'),
    ('p', '8881', '/jwt/jsonInBlacklist', 'POST'),
    ('p', '8881', '/system/getSystemConfig', 'POST'),
    ('p', '8881', '/system/setSystemConfig', 'POST'),
    ('p', '8881', '/customer/customer', 'POST'),
    ('p', '8881', '/customer/customer', 'PUT'),
    ('p', '8881', '/customer/customer', 'DELETE'),
    ('p', '8881', '/customer/customer', 'GET'),
    ('p', '8881', '/customer/customerList', 'GET'),
    ('p', '8881', '/user/getUserInfo', 'GET'),

    -- 9528
    ('p', '9528', '/user/admin_register', 'POST'),
    ('p', '9528', '/api/createApi', 'POST'),
    ('p', '9528', '/api/getApiList', 'POST'),
    ('p', '9528', '/api/getApiById', 'POST'),
    ('p', '9528', '/api/deleteApi', 'POST'),
    ('p', '9528', '/api/updateApi', 'POST'),
    ('p', '9528', '/api/getAllApis', 'POST'),

    ('p', '9528', '/authority/createAuthority', 'POST'),
    ('p', '9528', '/authority/deleteAuthority', 'POST'),
    ('p', '9528', '/authority/getAuthorityList', 'POST'),
    ('p', '9528', '/authority/setDataAuthority', 'POST'),

    ('p', '9528', '/menu/getMenu', 'POST'),
    ('p', '9528', '/menu/getMenuList', 'POST'),
    ('p', '9528', '/menu/addBaseMenu', 'POST'),
    ('p', '9528', '/menu/getBaseMenuTree', 'POST'),
    ('p', '9528', '/menu/addMenuAuthority', 'POST'),
    ('p', '9528', '/menu/getMenuAuthority', 'POST'),
    ('p', '9528', '/menu/deleteBaseMenu', 'POST'),
    ('p', '9528', '/menu/updateBaseMenu', 'POST'),
    ('p', '9528', '/menu/getBaseMenuById', 'POST'),
    ('p', '9528', '/user/changePassword', 'POST'),
    ('p', '9528', '/user/getUserList', 'POST'),
    ('p', '9528', '/user/setUserAuthority', 'POST'),
    ('p', '9528', '/fileUploadAndDownload/upload', 'POST'),
    ('p', '9528', '/fileUploadAndDownload/getFileList', 'POST'),
    ('p', '9528', '/fileUploadAndDownload/deleteFile', 'POST'),
    ('p', '9528', '/fileUploadAndDownload/editFileName', 'POST'),
    ('p', '9528', '/fileUploadAndDownload/importURL', 'POST'),
    ('p', '9528', '/casbin/updateCasbin', 'POST'),
    ('p', '9528', '/casbin/getPolicyPathByAuthorityId', 'POST'),
    ('p', '9528', '/jwt/jsonInBlacklist', 'POST'),
    ('p', '9528', '/system/getSystemConfig', 'POST'),
    ('p', '9528', '/system/setSystemConfig', 'POST'),
    ('p', '9528', '/customer/customer', 'PUT'),
    ('p', '9528', '/customer/customer', 'GET'),
    ('p', '9528', '/customer/customer', 'POST'),
    ('p', '9528', '/customer/customer', 'DELETE'),
    ('p', '9528', '/customer/customerList', 'GET'),
    ('p', '9528', '/autoCode/createTemp', 'POST'),
    ('p', '9528', '/user/getUserInfo', 'GET');


/* =========================
 * 7. 菜单表 sys_base_menus
 * ========================= */

-- 7.1 顶级菜单
INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon)
VALUES
    (0, FALSE, 0, 'dashboard', 'dashboard', 'view/dashboard/index.vue', 1, '仪表盘', 'odometer'),
    (0, FALSE, 0, 'about', 'about', 'view/about/index.vue', 9, '关于我们', 'info-filled'),
    (0, FALSE, 0, 'admin', 'superAdmin', 'view/superAdmin/index.vue', 3, '超级管理员', 'user'),
    (0, TRUE,  0, 'person', 'person', 'view/person/person.vue', 4, '个人信息', 'message'),
    (0, FALSE, 0, 'example', 'example', 'view/example/index.vue', 7, '示例文件', 'management'),
    (0, FALSE, 0, 'systemTools', 'systemTools', 'view/systemTools/index.vue', 5, '系统工具', 'tools'),
    (0, FALSE, 0, 'https://www.gin-vue-admin.com', 'https://www.gin-vue-admin.com', '/', 0, '官方网站', 'customer-gva'),
    (0, FALSE, 0, 'state', 'state', 'view/system/state.vue', 8, '服务器状态', 'cloudy'),
    (0, FALSE, 0, 'plugin', 'plugin', 'view/routerHolder.vue', 6, '插件系统', 'cherry');

-- 7.2 子菜单（通过名称反查父级 ID）

-- superAdmin 子菜单
INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon, meta_keep_alive)
SELECT
    1, FALSE, m.id, 'authority', 'authority', 'view/superAdmin/authority/authority.vue', 1, '角色管理', 'avatar', FALSE
FROM sys_base_menus m WHERE m.name = 'superAdmin';

INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon, meta_keep_alive)
SELECT
    1, FALSE, m.id, 'menu', 'menu', 'view/superAdmin/menu/menu.vue', 2, '菜单管理', 'tickets', TRUE
FROM sys_base_menus m WHERE m.name = 'superAdmin';

INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon, meta_keep_alive)
SELECT
    1, FALSE, m.id, 'api', 'api', 'view/superAdmin/api/api.vue', 3, 'api管理', 'platform', TRUE
FROM sys_base_menus m WHERE m.name = 'superAdmin';

INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon)
SELECT
    1, FALSE, m.id, 'user', 'user', 'view/superAdmin/user/user.vue', 4, '用户管理', 'coordinate'
FROM sys_base_menus m WHERE m.name = 'superAdmin';

INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon)
SELECT
    1, FALSE, m.id, 'dictionary', 'dictionary', 'view/superAdmin/dictionary/sysDictionary.vue', 5, '字典管理', 'notebook'
FROM sys_base_menus m WHERE m.name = 'superAdmin';

INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon)
SELECT
    1, FALSE, m.id, 'operation', 'operation', 'view/superAdmin/operation/sysOperationRecord.vue', 6, '操作历史', 'pie-chart'
FROM sys_base_menus m WHERE m.name = 'superAdmin';

INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon)
SELECT
    1, FALSE, m.id, 'sysParams', 'sysParams', 'view/superAdmin/params/sysParams.vue', 7, '参数管理', 'compass'
FROM sys_base_menus m WHERE m.name = 'superAdmin';

-- example 子菜单
INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon)
SELECT
    1, FALSE, m.id, 'upload', 'upload', 'view/example/upload/upload.vue', 5, '媒体库（上传下载）', 'upload'
FROM sys_base_menus m WHERE m.name = 'example';

INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon)
SELECT
    1, FALSE, m.id, 'breakpoint', 'breakpoint', 'view/example/breakpoint/breakpoint.vue', 6, '断点续传', 'upload-filled'
FROM sys_base_menus m WHERE m.name = 'example';

INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon)
SELECT
    1, FALSE, m.id, 'customer', 'customer', 'view/example/customer/customer.vue', 7, '客户列表（资源示例）', 'avatar'
FROM sys_base_menus m WHERE m.name = 'example';

-- systemTools 子菜单
INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon, meta_keep_alive)
SELECT
    1, FALSE, m.id, 'autoCode', 'autoCode', 'view/systemTools/autoCode/index.vue', 1, '代码生成器', 'cpu', TRUE
FROM sys_base_menus m WHERE m.name = 'systemTools';

INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon, meta_keep_alive)
SELECT
    1, FALSE, m.id, 'formCreate', 'formCreate', 'view/systemTools/formCreate/index.vue', 3, '表单生成器', 'magic-stick', TRUE
FROM sys_base_menus m WHERE m.name = 'systemTools';

INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon)
SELECT
    1, FALSE, m.id, 'system', 'system', 'view/systemTools/system/system.vue', 4, '系统配置', 'operation'
FROM sys_base_menus m WHERE m.name = 'systemTools';

INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon)
SELECT
    1, FALSE, m.id, 'autoCodeAdmin', 'autoCodeAdmin', 'view/systemTools/autoCodeAdmin/index.vue', 2, '自动化代码管理', 'magic-stick'
FROM sys_base_menus m WHERE m.name = 'systemTools';

INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon)
SELECT
    1, FALSE, m.id, 'loginLog', 'loginLog', 'view/systemTools/loginLog/index.vue', 5, '登录日志', 'monitor'
FROM sys_base_menus m WHERE m.name = 'systemTools';

INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon)
SELECT
    1, FALSE, m.id, 'apiToken', 'apiToken', 'view/systemTools/apiToken/index.vue', 6, 'API Token', 'key'
FROM sys_base_menus m WHERE m.name = 'systemTools';

INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, hidden, meta_title, meta_icon)
SELECT
    1, TRUE, m.id, 'autoCodeEdit/:id', 'autoCodeEdit', 'view/systemTools/autoCode/index.vue', 0, TRUE, '自动化代码-${id}', 'magic-stick'
FROM sys_base_menus m WHERE m.name = 'systemTools';

INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon)
SELECT
    1, FALSE, m.id, 'autoPkg', 'autoPkg', 'view/systemTools/autoPkg/autoPkg.vue', 0, '模板配置', 'folder'
FROM sys_base_menus m WHERE m.name = 'systemTools';

INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon)
SELECT
    1, FALSE, m.id, 'exportTemplate', 'exportTemplate', 'view/systemTools/exportTemplate/exportTemplate.vue', 5, '导出模板', 'reading'
FROM sys_base_menus m WHERE m.name = 'systemTools';

INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon)
SELECT
    1, FALSE, m.id, 'skills', 'skills', 'view/systemTools/skills/index.vue', 6, 'Skills管理', 'document'
FROM sys_base_menus m WHERE m.name = 'systemTools';

INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon)
SELECT
    1, FALSE, m.id, 'picture', 'picture', 'view/systemTools/autoCode/picture.vue', 6, 'AI页面绘制', 'picture-filled'
FROM sys_base_menus m WHERE m.name = 'systemTools';

INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon)
SELECT
    1, FALSE, m.id, 'mcpTool', 'mcpTool', 'view/systemTools/autoCode/mcp.vue', 7, 'Mcp Tools模板', 'magnet'
FROM sys_base_menus m WHERE m.name = 'systemTools';

INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon)
SELECT
    1, FALSE, m.id, 'mcpTest', 'mcpTest', 'view/systemTools/autoCode/mcpTest.vue', 7, 'Mcp Tools测试', 'partly-cloudy'
FROM sys_base_menus m WHERE m.name = 'systemTools';

INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon)
SELECT
    1, FALSE, m.id, 'sysVersion', 'sysVersion', 'view/systemTools/version/version.vue', 8, '版本管理', 'server'
FROM sys_base_menus m WHERE m.name = 'systemTools';

INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon)
SELECT
    1, FALSE, m.id, 'sysError', 'sysError', 'view/systemTools/sysError/sysError.vue', 9, '错误日志', 'warn'
FROM sys_base_menus m WHERE m.name = 'systemTools';

-- plugin 子菜单
INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon)
SELECT
    1, FALSE, m.id, 'https://plugin.gin-vue-admin.com/', 'https://plugin.gin-vue-admin.com/', 'https://plugin.gin-vue-admin.com/', 0, '插件市场', 'shop'
FROM sys_base_menus m WHERE m.name = 'plugin';

INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon)
SELECT
    1, FALSE, m.id, 'installPlugin', 'installPlugin', 'view/systemTools/installPlugin/index.vue', 1, '插件安装', 'box'
FROM sys_base_menus m WHERE m.name = 'plugin';

INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon)
SELECT
    1, FALSE, m.id, 'pubPlug', 'pubPlug', 'view/systemTools/pubPlug/pubPlug.vue', 3, '打包插件', 'files'
FROM sys_base_menus m WHERE m.name = 'plugin';

INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon)
SELECT
    1, FALSE, m.id, 'plugin-email', 'plugin-email', 'plugin/email/view/index.vue', 4, '邮件插件', 'message'
FROM sys_base_menus m WHERE m.name = 'plugin';

INSERT INTO sys_base_menus (menu_level, hidden, parent_id, path, name, component, sort, meta_title, meta_icon)
SELECT
    1, FALSE, m.id, 'anInfo', 'anInfo', 'plugin/announcement/view/info.vue', 5, '公告管理[示例]', 'scaleToOriginal'
FROM sys_base_menus m WHERE m.name = 'plugin';


/* =========================
 * 8. 示例文件表 exa_file_upload_and_downloads
 * ========================= */

INSERT INTO exa_file_upload_and_downloads (name, class_id, url, tag, key)
VALUES
    ('10.png', '0', 'https://qmplusimg.henrongyi.top/gvalogo.png', 'png', '158787308910.png'),
    ('logo.png', '0', 'https://qmplusimg.henrongyi.top/1576554439myAvatar.png', 'png', '1587973709logo.png');


/* =========================
 * 9. 导出模板表 sys_export_templates
 * ========================= */

INSERT INTO sys_export_templates (db_name, name, table_name, template_id, template_info)
VALUES
    ('', 'api', 'sys_apis', 'api',
     '{
"path":"路径",
"method":"方法（大写）",
"description":"方法介绍",
"api_group":"方法分组"
}');


/* =========================
 * 10. 多对多关联表
 *     sys_data_authority_id, sys_user_authority, sys_authority_menus
 * ========================= */

-- 10.1 数据权限表 sys_data_authority_id
INSERT INTO sys_data_authority_id (sys_authority_authority_id, data_authority_id)
VALUES
    (888,  888),
    (888,  9528),
    (888,  8881),
    (9528, 9528),
    (9528, 8881);


-- 10.2 用户-角色表 sys_user_authority
INSERT INTO sys_user_authority (sys_user_id, sys_authority_authority_id)
SELECT u.id, a.authority_id
FROM sys_users u
JOIN sys_authorities a ON a.authority_id IN (888, 9528, 8881)
WHERE u.username = 'admin';

INSERT INTO sys_user_authority (sys_user_id, sys_authority_authority_id)
SELECT u.id, a.authority_id
FROM sys_users u
JOIN sys_authorities a ON a.authority_id = 888
WHERE u.username = 'a303176530';


-- 10.3 角色-菜单表 sys_authority_menus

-- 888: 拥有所有菜单
INSERT INTO sys_authority_menus (sys_authority_authority_id, sys_base_menu_id)
SELECT 888, id FROM sys_base_menus;

-- 8881: 仅拥有 dashboard / about / person / state 顶级菜单
INSERT INTO sys_authority_menus (sys_authority_authority_id, sys_base_menu_id)
SELECT 8881, id
FROM sys_base_menus
WHERE parent_id = 0 AND name IN ('dashboard', 'about', 'person', 'state');

-- 9528: 所有顶级菜单 + systemTools/example 下的子菜单
INSERT INTO sys_authority_menus (sys_authority_authority_id, sys_base_menu_id)
SELECT 9528, id
FROM sys_base_menus
WHERE parent_id = 0;

INSERT INTO sys_authority_menus (sys_authority_authority_id, sys_base_menu_id)
SELECT 9528, id
FROM sys_base_menus
WHERE parent_id IN (
    SELECT id FROM sys_base_menus WHERE name IN ('systemTools', 'example')
);

COMMIT;

