|
|
@@ -85,56 +85,32 @@ CREATE TABLE `kku_openapi_logs` (
|
|
|
KEY `idx_created_at` (`created_at`)
|
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='API调用日志表';
|
|
|
|
|
|
--- OpenAPI模块 - API调用日志表
|
|
|
--- 用于记录所有API调用的详细信息
|
|
|
|
|
|
-CREATE TABLE `kku_openapi_logs` (
|
|
|
- `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
|
|
- `app_id` varchar(64) NOT NULL DEFAULT '' COMMENT '应用ID',
|
|
|
- `user_id` int(11) DEFAULT NULL COMMENT '用户ID',
|
|
|
- `method` varchar(10) NOT NULL DEFAULT '' COMMENT '请求方法',
|
|
|
- `uri` varchar(500) NOT NULL DEFAULT '' COMMENT '请求URI',
|
|
|
- `params` json COMMENT '请求参数',
|
|
|
- `headers` json COMMENT '请求头',
|
|
|
- `ip_address` varchar(45) NOT NULL DEFAULT '' COMMENT 'IP地址',
|
|
|
- `user_agent` text COMMENT '用户代理',
|
|
|
- `response_code` int(11) NOT NULL DEFAULT 0 COMMENT '响应状态码',
|
|
|
- `response_time` int(11) NOT NULL DEFAULT 0 COMMENT '响应时间(毫秒)',
|
|
|
- `response_size` int(11) NOT NULL DEFAULT 0 COMMENT '响应大小(字节)',
|
|
|
- `error_message` text COMMENT '错误信息',
|
|
|
- `scope` varchar(50) NOT NULL DEFAULT '' COMMENT '使用的权限范围',
|
|
|
- `rate_limit_hit` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否触发限流',
|
|
|
- `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
|
|
- PRIMARY KEY (`id`),
|
|
|
- KEY `idx_app_id` (`app_id`),
|
|
|
- KEY `idx_user_id` (`user_id`),
|
|
|
- KEY `idx_method` (`method`),
|
|
|
- KEY `idx_response_code` (`response_code`),
|
|
|
- KEY `idx_scope` (`scope`),
|
|
|
- KEY `idx_created_at` (`created_at`),
|
|
|
- KEY `idx_ip_address` (`ip_address`)
|
|
|
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='API调用日志表';
|
|
|
-
|
|
|
--- OpenAPI模块 - API权限范围表
|
|
|
--- 用于定义和管理API权限范围
|
|
|
|
|
|
+-- 4. API权限范围表
|
|
|
CREATE TABLE `kku_openapi_scopes` (
|
|
|
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
|
|
- `scope_name` varchar(50) NOT NULL DEFAULT '' COMMENT '权限范围名称',
|
|
|
- `scope_label` varchar(100) NOT NULL DEFAULT '' COMMENT '权限范围标签',
|
|
|
+ `app_id` varchar(64) NOT NULL DEFAULT '' COMMENT '应用ID',
|
|
|
+ `scope` varchar(50) NOT NULL DEFAULT '' COMMENT '权限范围',
|
|
|
+ `name` varchar(100) NOT NULL DEFAULT '' COMMENT '权限名称',
|
|
|
`description` text COMMENT '权限描述',
|
|
|
`category` varchar(50) NOT NULL DEFAULT '' COMMENT '权限分类',
|
|
|
- `risk_level` tinyint(4) NOT NULL DEFAULT 1 COMMENT '风险级别(1-5)',
|
|
|
- `is_default` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否默认权限',
|
|
|
- `is_enabled` tinyint(1) NOT NULL DEFAULT 1 COMMENT '是否启用',
|
|
|
- `dependencies` json COMMENT '依赖的权限',
|
|
|
+ `risk_level` varchar(20) NOT NULL DEFAULT 'LOW' COMMENT '风险级别',
|
|
|
+ `is_active` tinyint(1) NOT NULL DEFAULT 1 COMMENT '是否激活',
|
|
|
+ `granted_at` timestamp NULL DEFAULT NULL COMMENT '授权时间',
|
|
|
+ `expires_at` timestamp NULL DEFAULT NULL COMMENT '过期时间',
|
|
|
+ `granted_by` varchar(100) DEFAULT NULL COMMENT '授权人',
|
|
|
+ `notes` text COMMENT '备注',
|
|
|
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
|
|
`updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
|
|
PRIMARY KEY (`id`),
|
|
|
- UNIQUE KEY `uk_scope_name` (`scope_name`),
|
|
|
+ UNIQUE KEY `uk_app_scope` (`app_id`, `scope`),
|
|
|
+ KEY `idx_app_id` (`app_id`),
|
|
|
+ KEY `idx_scope` (`scope`),
|
|
|
KEY `idx_category` (`category`),
|
|
|
KEY `idx_risk_level` (`risk_level`),
|
|
|
- KEY `idx_is_enabled` (`is_enabled`)
|
|
|
+ KEY `idx_is_active` (`is_active`),
|
|
|
+ KEY `idx_expires_at` (`expires_at`)
|
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='API权限范围表';
|
|
|
|
|
|
-- 插入默认权限范围数据
|
|
|
@@ -159,69 +135,77 @@ INSERT INTO `kku_openapi_scopes` (`scope_name`, `scope_label`, `description`, `c
|
|
|
('SYSTEM_READ', '读取系统信息', '允许读取系统状态和配置信息', '系统管理', 2, 0),
|
|
|
('SYSTEM_ADMIN', '系统管理权限', '允许执行系统管理操作', '系统管理', 5, 0);
|
|
|
|
|
|
--- OpenAPI模块 - API统计表
|
|
|
--- 用于存储API调用统计数据
|
|
|
-
|
|
|
+-- 5. API统计表
|
|
|
CREATE TABLE `kku_openapi_stats` (
|
|
|
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
|
|
`app_id` varchar(64) NOT NULL DEFAULT '' COMMENT '应用ID',
|
|
|
`date` date NOT NULL COMMENT '统计日期',
|
|
|
`hour` tinyint(4) DEFAULT NULL COMMENT '统计小时(0-23)',
|
|
|
- `total_requests` int(11) NOT NULL DEFAULT 0 COMMENT '总请求数',
|
|
|
- `successful_requests` int(11) NOT NULL DEFAULT 0 COMMENT '成功请求数',
|
|
|
- `failed_requests` int(11) NOT NULL DEFAULT 0 COMMENT '失败请求数',
|
|
|
- `rate_limited_requests` int(11) NOT NULL DEFAULT 0 COMMENT '被限流请求数',
|
|
|
- `average_response_time` int(11) NOT NULL DEFAULT 0 COMMENT '平均响应时间(毫秒)',
|
|
|
- `total_response_size` bigint(20) NOT NULL DEFAULT 0 COMMENT '总响应大小(字节)',
|
|
|
+ `endpoint` varchar(500) NOT NULL DEFAULT '' COMMENT '接口端点',
|
|
|
+ `request_count` int(11) NOT NULL DEFAULT 0 COMMENT '请求次数',
|
|
|
+ `success_count` int(11) NOT NULL DEFAULT 0 COMMENT '成功次数',
|
|
|
+ `error_count` int(11) NOT NULL DEFAULT 0 COMMENT '错误次数',
|
|
|
+ `avg_response_time` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT '平均响应时间(毫秒)',
|
|
|
+ `max_response_time` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT '最大响应时间(毫秒)',
|
|
|
+ `min_response_time` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT '最小响应时间(毫秒)',
|
|
|
+ `rate_limit_hits` int(11) NOT NULL DEFAULT 0 COMMENT '限流命中次数',
|
|
|
`unique_ips` int(11) NOT NULL DEFAULT 0 COMMENT '唯一IP数量',
|
|
|
+ `error_details` json COMMENT '错误详情',
|
|
|
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
|
|
`updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
|
|
PRIMARY KEY (`id`),
|
|
|
- UNIQUE KEY `uk_app_date_hour` (`app_id`, `date`, `hour`),
|
|
|
+ UNIQUE KEY `uk_app_date_hour_endpoint` (`app_id`, `date`, `hour`, `endpoint`),
|
|
|
+ KEY `idx_app_id` (`app_id`),
|
|
|
KEY `idx_date` (`date`),
|
|
|
- KEY `idx_hour` (`hour`)
|
|
|
+ KEY `idx_hour` (`hour`),
|
|
|
+ KEY `idx_endpoint` (`endpoint`)
|
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='API统计表';
|
|
|
|
|
|
--- OpenAPI模块 - Webhook配置表
|
|
|
--- 用于管理应用的回调配置
|
|
|
-
|
|
|
+-- 6. Webhook配置表
|
|
|
CREATE TABLE `kku_openapi_webhooks` (
|
|
|
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
|
|
`app_id` varchar(64) NOT NULL DEFAULT '' COMMENT '应用ID',
|
|
|
- `event_type` varchar(50) NOT NULL DEFAULT '' COMMENT '事件类型',
|
|
|
- `webhook_url` varchar(500) NOT NULL DEFAULT '' COMMENT '回调URL',
|
|
|
+ `name` varchar(255) NOT NULL DEFAULT '' COMMENT 'Webhook名称',
|
|
|
+ `url` varchar(500) NOT NULL DEFAULT '' COMMENT '回调URL',
|
|
|
+ `events` json COMMENT '监听的事件类型',
|
|
|
`secret` varchar(255) NOT NULL DEFAULT '' COMMENT '签名密钥',
|
|
|
- `is_enabled` tinyint(1) NOT NULL DEFAULT 1 COMMENT '是否启用',
|
|
|
- `retry_times` tinyint(4) NOT NULL DEFAULT 3 COMMENT '重试次数',
|
|
|
- `timeout` int(11) NOT NULL DEFAULT 10 COMMENT '超时时间(秒)',
|
|
|
- `last_triggered_at` timestamp NULL DEFAULT NULL COMMENT '最后触发时间',
|
|
|
+ `status` varchar(20) NOT NULL DEFAULT 'ACTIVE' COMMENT '状态',
|
|
|
+ `timeout` int(11) NOT NULL DEFAULT 30 COMMENT '超时时间(秒)',
|
|
|
+ `retry_count` int(11) NOT NULL DEFAULT 3 COMMENT '重试次数',
|
|
|
+ `current_retry_count` int(11) NOT NULL DEFAULT 0 COMMENT '当前重试次数',
|
|
|
+ `total_deliveries` int(11) NOT NULL DEFAULT 0 COMMENT '总投递次数',
|
|
|
+ `successful_deliveries` int(11) NOT NULL DEFAULT 0 COMMENT '成功投递次数',
|
|
|
+ `failed_deliveries` int(11) NOT NULL DEFAULT 0 COMMENT '失败投递次数',
|
|
|
`last_success_at` timestamp NULL DEFAULT NULL COMMENT '最后成功时间',
|
|
|
- `failure_count` int(11) NOT NULL DEFAULT 0 COMMENT '连续失败次数',
|
|
|
+ `last_failure_at` timestamp NULL DEFAULT NULL COMMENT '最后失败时间',
|
|
|
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
|
|
`updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
|
|
PRIMARY KEY (`id`),
|
|
|
KEY `idx_app_id` (`app_id`),
|
|
|
- KEY `idx_event_type` (`event_type`),
|
|
|
- KEY `idx_is_enabled` (`is_enabled`)
|
|
|
+ KEY `idx_status` (`status`),
|
|
|
+ KEY `idx_last_success_at` (`last_success_at`),
|
|
|
+ KEY `idx_last_failure_at` (`last_failure_at`)
|
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Webhook配置表';
|
|
|
|
|
|
--- OpenAPI模块 - 限流记录表
|
|
|
--- 用于记录限流状态和统计
|
|
|
-
|
|
|
+-- 7. 限流记录表
|
|
|
CREATE TABLE `kku_openapi_rate_limits` (
|
|
|
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
|
|
`app_id` varchar(64) NOT NULL DEFAULT '' COMMENT '应用ID',
|
|
|
- `scope` varchar(50) NOT NULL DEFAULT '' COMMENT '权限范围',
|
|
|
`ip_address` varchar(45) NOT NULL DEFAULT '' COMMENT 'IP地址',
|
|
|
+ `endpoint` varchar(500) NOT NULL DEFAULT '' COMMENT '接口端点',
|
|
|
+ `limit_type` varchar(50) NOT NULL DEFAULT '' COMMENT '限制类型',
|
|
|
`window_start` timestamp NOT NULL COMMENT '时间窗口开始',
|
|
|
- `window_end` timestamp NOT NULL COMMENT '时间窗口结束',
|
|
|
`request_count` int(11) NOT NULL DEFAULT 0 COMMENT '请求次数',
|
|
|
- `limit_count` int(11) NOT NULL DEFAULT 0 COMMENT '限制次数',
|
|
|
`is_blocked` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否被阻止',
|
|
|
+ `user_agent` text COMMENT '用户代理',
|
|
|
+ `headers` json COMMENT '请求头信息',
|
|
|
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
|
|
`updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
|
|
PRIMARY KEY (`id`),
|
|
|
- UNIQUE KEY `uk_app_scope_ip_window` (`app_id`, `scope`, `ip_address`, `window_start`),
|
|
|
- KEY `idx_window_end` (`window_end`),
|
|
|
+ KEY `idx_app_id` (`app_id`),
|
|
|
+ KEY `idx_ip_address` (`ip_address`),
|
|
|
+ KEY `idx_endpoint` (`endpoint`),
|
|
|
+ KEY `idx_limit_type` (`limit_type`),
|
|
|
+ KEY `idx_window_start` (`window_start`),
|
|
|
KEY `idx_is_blocked` (`is_blocked`)
|
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='限流记录表';
|