oms/backend/app/model/callbackLog.js
liufumingren 0a9ee3c593 feat(backend): 对外通用回调接口 /openapi 与回调日志
- POST /openapi 入口(controller/openapi.js),协议与 WMS openapi 对齐(method/app_key/sign)
- 方法注册表 lib/openapiMethods.js:index.ping、entryorder.confirm/match、deliveryorder.confirm、stockout.confirm、order.cancel
- 单据处理公共逻辑 lib/orderCallback.js;请求/响应封装 lib/apiResponse.js、lib/openapiCallback.js
- WMS 回调入口 controller/wmsNotify.js 改为复用公共模块
- 回调日志:callback_logs 表 + lib/callbackLog.js(脱敏、fire-and-forget)
2026-09-13 02:23:49 +08:00

36 lines
2.1 KiB
JavaScript
Raw 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.

'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;
};