- 外部打单平台快递接口:按账号同步平台模板、绑定快递编码、查看模板明细;打开列表只读库,仅「从平台同步数据」时拉取 - 系统管理新增自定义快递编码字典,订单改快递 / 物流下拉合并系统与自定义编码,推送奇门沿用订单上的编码 - 新增 OpenAPI deliveryorder.getwaybill:WMS 批量回取号(单次≤100、并发4、逐单结果),快递编码只取 WMS 报文,取消/作废/归档返回失败,已取号直接复用 - 新增 openapi_request_idempotency 请求级幂等:request_id 回放、报文摘要校验、30 分钟 stale 接管、7 天定时清理 - 外部打单平台订单按平台 fetch_waybill_no 下发 need_oms_waybill,推送时实时判定并回写单据 - 店铺、打单账号平台配置与「平台+编码→模板」绑定走 Redis 缓存,绑定/账号变更主动失效,避免批量推送与取号逐单查库 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
88 lines
3.0 KiB
JavaScript
88 lines
3.0 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 对外 OpenAPI 请求幂等表。
|
||
*
|
||
* 外部系统(WMS)回调可能因超时重试,同一请求不应重复执行:
|
||
* - 以 (app_key, method, request_id) 唯一;
|
||
* - request_hash 记录 method + app_key + 请求报文摘要,防止同一 request_id 搭配不同报文;
|
||
* - status:0 处理中 / 1 成功 / 2 失败;处理完成后 response_body 保存完整响应,
|
||
* 重试时直接回放原响应(含逐单成功/失败结果)。
|
||
*
|
||
* 与 callback_logs 的区别:callback_logs 是异步、截断的排查日志;本表是可回放的幂等凭据。
|
||
*/
|
||
module.exports = {
|
||
async up(queryInterface, Sequelize) {
|
||
await queryInterface.createTable('openapi_request_idempotency', {
|
||
id: {
|
||
type: Sequelize.BIGINT.UNSIGNED,
|
||
primaryKey: true,
|
||
autoIncrement: true,
|
||
comment: '主键',
|
||
},
|
||
app_key: {
|
||
type: Sequelize.STRING(100),
|
||
allowNull: false,
|
||
comment: '请求携带的 app_key',
|
||
},
|
||
method: {
|
||
type: Sequelize.STRING(100),
|
||
allowNull: false,
|
||
comment: 'OpenAPI 方法名(模块.动作)',
|
||
},
|
||
request_id: {
|
||
type: Sequelize.STRING(100),
|
||
allowNull: false,
|
||
comment: '调用方请求ID(query request_id / header X-Request-Id / body requestId)',
|
||
},
|
||
request_hash: {
|
||
type: Sequelize.STRING(64),
|
||
allowNull: false,
|
||
comment: 'method + app_key + 请求报文摘要,防止同一 request_id 复用不同报文',
|
||
},
|
||
principal_id: {
|
||
type: Sequelize.BIGINT.UNSIGNED,
|
||
allowNull: true,
|
||
comment: '按 app_key 定位到的主体ID',
|
||
},
|
||
warehouse_id: {
|
||
type: Sequelize.BIGINT.UNSIGNED,
|
||
allowNull: true,
|
||
comment: '按 app_key 定位到的仓库ID',
|
||
},
|
||
status: {
|
||
type: Sequelize.TINYINT,
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '状态:0处理中 1成功 2失败',
|
||
},
|
||
http_status: {
|
||
type: Sequelize.INTEGER,
|
||
allowNull: true,
|
||
comment: '响应 HTTP 状态码',
|
||
},
|
||
response_body: {
|
||
type: Sequelize.TEXT('medium'),
|
||
allowNull: true,
|
||
comment: '完整响应报文(重试时原样回放)',
|
||
},
|
||
created_at: { type: Sequelize.DATE, allowNull: true, comment: '创建时间' },
|
||
updated_at: { type: Sequelize.DATE, allowNull: true, comment: '更新时间' },
|
||
});
|
||
|
||
await queryInterface.addIndex('openapi_request_idempotency', [ 'app_key', 'method', 'request_id' ], {
|
||
name: 'uk_openapi_request_id',
|
||
unique: true,
|
||
});
|
||
await queryInterface.addIndex('openapi_request_idempotency', [ 'created_at' ], {
|
||
name: 'idx_openapi_request_created',
|
||
});
|
||
},
|
||
|
||
async down(queryInterface) {
|
||
await queryInterface.removeIndex('openapi_request_idempotency', 'idx_openapi_request_created');
|
||
await queryInterface.removeIndex('openapi_request_idempotency', 'uk_openapi_request_id');
|
||
await queryInterface.dropTable('openapi_request_idempotency');
|
||
},
|
||
};
|