Files
ycc-proxy-server/deploy/sql/tianyuanapi_cost_migration.sql
2026-01-13 18:30:10 +08:00

64 lines
3.6 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- ============================================
-- Feature表 - 添加成本价字段
-- 说明:为 feature 表添加天远API调用成本价字段
-- 执行时间2025-01-13
-- ============================================
-- 添加成本价字段
ALTER TABLE `feature`
ADD COLUMN `cost_price` decimal(10, 2) DEFAULT 0.00 COMMENT '天远API调用成本价单位' AFTER `whitelist_price`;
-- ============================================
-- 说明:
-- 1. cost_price 默认值为 0.00表示该feature的成本价为0元
-- 2. 后台可以在"功能管理"页面配置每个feature的调用成本
-- 3. 成本价用于统计天远API的调用成本
-- ============================================
-- ============================================
-- 天远API调用记录表
-- 说明记录每次调用天远API的详细信息
-- ============================================
CREATE TABLE `tianyuanapi_call_log` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`feature_id` varchar(36) NOT NULL COMMENT '功能ID关联feature表',
`api_id` varchar(50) NOT NULL COMMENT 'API标识YYSYBE08',
`order_id` varchar(36) DEFAULT NULL COMMENT '订单ID关联order表',
`query_id` varchar(36) DEFAULT NULL COMMENT '查询ID关联query表',
`call_status` tinyint NOT NULL DEFAULT 0 COMMENT '调用状态0=失败1=成功',
`call_time` datetime NOT NULL COMMENT '调用时间',
`response_time` int DEFAULT NULL COMMENT '响应耗时(毫秒)',
`cost_price` decimal(10, 2) DEFAULT 0.00 COMMENT '本次调用成本成功时从feature.cost_price获取失败时为0',
`error_code` varchar(50) DEFAULT NULL COMMENT '错误码(失败时记录)',
`error_message` varchar(500) DEFAULT NULL COMMENT '错误信息(失败时记录)',
`request_params` text DEFAULT NULL COMMENT '请求参数JSON格式',
`response_data` text DEFAULT NULL COMMENT '响应数据JSON格式仅记录关键信息',
`transaction_id` varchar(100) DEFAULT NULL COMMENT '天远API流水号',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`delete_time` datetime DEFAULT NULL COMMENT '删除时间',
`del_state` tinyint NOT NULL DEFAULT 0 COMMENT '删除状态0=未删除1=已删除',
`version` bigint NOT NULL DEFAULT 0 COMMENT '版本号(乐观锁)',
PRIMARY KEY (`id`),
KEY `idx_feature_id` (`feature_id`),
KEY `idx_api_id` (`api_id`),
KEY `idx_order_id` (`order_id`),
KEY `idx_query_id` (`query_id`),
KEY `idx_call_status` (`call_status`),
KEY `idx_call_time` (`call_time`),
KEY `idx_feature_time` (`feature_id`, `call_time`) COMMENT '复合索引:查询某个功能在某段时间的调用记录'
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '天远API调用记录表';
-- ============================================
-- 说明:
-- 1. feature_id: 关联到feature表记录是哪个接口的调用
-- 2. api_id: 天远API的接口标识YYSYBE08
-- 3. order_id/query_id: 关联订单或查询,方便追溯
-- 4. call_status: 调用状态,成功=1失败=0
-- 5. cost_price: 成本价成功时为feature.cost_price失败时为0
-- 6. error_code/error_message: 失败时记录错误信息
-- 7. request_params/response_data: 请求和响应数据(可选择性记录)
-- 8. transaction_id: 天远API返回的流水号
-- 9. 无论成功失败都会记录,方便统计分析
-- ============================================