'use strict'; /** * 对外回调日志模型,对应 callback_logs 表 * 记录外部系统调用 POST /openapi 的请求与返回(含未通过校验的请求),用于排查回调链路 * @param {Egg.Application} app egg application * @return {object} callbackLog model */ module.exports = app => { const { BIGINT, STRING, INTEGER, TINYINT, TEXT, DATE } = app.Sequelize; const CallbackLog = app.model.define('callback_log', { id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' }, principal_id: { type: BIGINT.UNSIGNED, comment: '所属主体ID(app_key 未定位到时为空)' }, warehouse_id: { type: BIGINT.UNSIGNED, comment: '关联仓库ID(app_key 未定位到时为空)' }, warehouse_api_id: { type: BIGINT.UNSIGNED, comment: '命中的仓库接口配置ID' }, method: { type: STRING(100), allowNull: false, defaultValue: '', comment: '回调方法名,如 index.ping / entryorder.confirm' }, app_key: { type: STRING(100), comment: '请求携带的 app_key' }, ip: { type: STRING(64), comment: '调用方 IP' }, http_status: { type: INTEGER, comment: '响应 HTTP 状态码' }, flag: { type: STRING(20), comment: '结果标记:success / failure' }, business_code: { type: STRING(32), comment: '业务码(成功1,失败见 code)' }, message: { type: STRING(500), comment: '提示信息 / 失败原因' }, request_query: { type: TEXT, comment: '请求 query JSON(sign 已脱敏)' }, request_body: { type: TEXT, comment: '请求报文 JSON(敏感字段已脱敏,超长截断)' }, response_body: { type: TEXT, comment: '返回报文 JSON(超长截断)' }, is_success: { type: TINYINT, defaultValue: 0, comment: '业务是否成功:1是 0否' }, error: { type: TEXT, comment: '失败信息(未注册方法 / 验签失败 / 单据处理失败等)' }, duration: { type: INTEGER, comment: '耗时(毫秒)' }, created_at: { type: DATE, comment: '创建时间' }, updated_at: { type: DATE, comment: '更新时间' }, }); return CallbackLog; };