- 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)
59 lines
3.4 KiB
JavaScript
59 lines
3.4 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 对外回调日志表(外部系统 → OMS 的 POST /openapi 请求与返回)
|
||
* 与 api_outbound_logs(OMS → 外部)方向相反,覆盖回调链路的排查
|
||
*/
|
||
module.exports = {
|
||
async up(queryInterface, Sequelize) {
|
||
await queryInterface.createTable(
|
||
'callback_logs',
|
||
{
|
||
id: {
|
||
type: Sequelize.BIGINT.UNSIGNED,
|
||
allowNull: false,
|
||
autoIncrement: true,
|
||
primaryKey: true,
|
||
},
|
||
principal_id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: true, comment: '所属主体ID(app_key 未定位到时为空)' },
|
||
warehouse_id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: true, comment: '关联仓库ID(app_key 未定位到时为空)' },
|
||
warehouse_api_id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: true, comment: '命中的仓库接口配置ID' },
|
||
method: { type: Sequelize.STRING(100), allowNull: false, defaultValue: '', comment: '回调方法名,如 index.ping / entryorder.confirm' },
|
||
app_key: { type: Sequelize.STRING(100), allowNull: true, comment: '请求携带的 app_key' },
|
||
ip: { type: Sequelize.STRING(64), allowNull: true, comment: '调用方 IP' },
|
||
http_status: { type: Sequelize.INTEGER, allowNull: true, comment: '响应 HTTP 状态码' },
|
||
flag: { type: Sequelize.STRING(20), allowNull: true, comment: '结果标记:success / failure' },
|
||
business_code: { type: Sequelize.STRING(32), allowNull: true, comment: '业务码(成功1,失败见 code)' },
|
||
message: { type: Sequelize.STRING(500), allowNull: true, comment: '提示信息 / 失败原因' },
|
||
request_query: { type: Sequelize.TEXT, allowNull: true, comment: '请求 query JSON(sign 已脱敏)' },
|
||
request_body: { type: Sequelize.TEXT, allowNull: true, comment: '请求报文 JSON(敏感字段已脱敏,超长截断)' },
|
||
response_body: { type: Sequelize.TEXT, allowNull: true, comment: '返回报文 JSON(超长截断)' },
|
||
is_success: { type: Sequelize.TINYINT, defaultValue: 0, comment: '业务是否成功(1是 0否)' },
|
||
error: { type: Sequelize.TEXT, allowNull: true, comment: '失败信息(未注册方法 / 验签失败 / 单据处理失败等)' },
|
||
duration: { type: Sequelize.INTEGER, allowNull: true, comment: '耗时(毫秒)' },
|
||
created_at: {
|
||
type: Sequelize.DATE,
|
||
allowNull: false,
|
||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
|
||
},
|
||
updated_at: {
|
||
type: Sequelize.DATE,
|
||
allowNull: false,
|
||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
|
||
},
|
||
},
|
||
{ charset: 'utf8mb4', collate: 'utf8mb4_unicode_ci', comment: '对外回调日志表' }
|
||
);
|
||
|
||
await queryInterface.addIndex('callback_logs', { fields: [ 'principal_id' ], name: 'idx_cb_log_principal' });
|
||
await queryInterface.addIndex('callback_logs', { fields: [ 'warehouse_id' ], name: 'idx_cb_log_warehouse' });
|
||
await queryInterface.addIndex('callback_logs', { fields: [ 'warehouse_api_id' ], name: 'idx_cb_log_api' });
|
||
await queryInterface.addIndex('callback_logs', { fields: [ 'method' ], name: 'idx_cb_log_method' });
|
||
await queryInterface.addIndex('callback_logs', { fields: [ 'created_at' ], name: 'idx_cb_log_created' });
|
||
},
|
||
|
||
async down(queryInterface) {
|
||
await queryInterface.dropTable('callback_logs');
|
||
},
|
||
};
|