- 模型/迁移:wms_order_delivery 新增 need_oms_waybill TINYINT(4) NOT NULL DEFAULT 0,
迁移覆盖基表与全部分表(含 _history/_dispatch/_outsourced),幂等且 down 可回滚
- 写入链路:openapi 请求根节点 need_oms_waybill(兼容 camelCase needOmsWaybill)→
openapiMethods/deliveryorder.js 透传;delivery_order.js 仅 API 来源可能为 1,
QM/MANUAL/STOCKOUT 一律强制 0(见相邻提交)
- 取号分流:need_oms_waybill=1 的订单不参与本地自动分配快递
1. asyncProcessOrderCreated 不入本地取号队列,写 ORDER_NEED_OMS_WAYBILL_WAIT 操作日志
2. express.createWaybillCodePipeline 按订单级标记过滤(同订单全部 business_key 一并跳过),
返回值新增 skipped_need_oms_waybill_order_ids
3. schedule/consume_waybill_allocate_queue 将对应队列行置终态 waiting_oms
(不再走 pending 重试 → failed)
- waybill_allocate_queue.status 注释补充 waiting_oms 语义(STRING(20),无需迁移)
- test: delivery_order.asyncProcessOrderCreated.test.js 新增分流/保持本地取号用例,
express.createWaybillCodePipeline.skipCancelled.test.js 补齐返回字段断言
103 lines
2.7 KiB
JavaScript
103 lines
2.7 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 订单创建后自动分配快递的消费队列模型。
|
||
*
|
||
* 订单创建后的异步流程只入队(截单/未审核不入队),由定时任务
|
||
* app/schedule/consume_waybill_allocate_queue.js 按仓库+货主串行批量消费,
|
||
* 避免高并发逐单取号时的 InnoDB AB-BA 死锁。
|
||
*
|
||
* @param {import('egg').Application} app Egg 应用实例。
|
||
* @return {import('sequelize').ModelCtor<import('sequelize').Model>} Sequelize 模型。
|
||
*/
|
||
module.exports = app => {
|
||
const { BIGINT, INTEGER, STRING, DATE } = app.Sequelize;
|
||
|
||
const WaybillAllocateQueue = app.model.define('waybill_allocate_queue', {
|
||
id: {
|
||
type: BIGINT(20).UNSIGNED,
|
||
primaryKey: true,
|
||
autoIncrement: true,
|
||
allowNull: false,
|
||
comment: '主键',
|
||
},
|
||
order_id: {
|
||
type: BIGINT(20).UNSIGNED,
|
||
allowNull: false,
|
||
comment: '订单ID(关联订单分表)',
|
||
},
|
||
business_key: {
|
||
type: INTEGER(3),
|
||
allowNull: false,
|
||
defaultValue: 1,
|
||
comment: '业务键(与 wms_order_express.business_key 一致)',
|
||
},
|
||
warehouse_id: {
|
||
type: BIGINT(20).UNSIGNED,
|
||
allowNull: false,
|
||
comment: '仓库ID(消费分组与数据隔离维度)',
|
||
},
|
||
store_id: {
|
||
type: BIGINT(20).UNSIGNED,
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '货主ID(消费分组维度)',
|
||
},
|
||
status: {
|
||
type: STRING(20),
|
||
allowNull: false,
|
||
defaultValue: 'pending',
|
||
comment: '状态:pending/processing/done/failed/waiting_oms(waiting_oms=需要回 OMS 取号,等待外部接入,终态不重试)',
|
||
},
|
||
retry_count: {
|
||
type: INTEGER(3),
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '重试次数',
|
||
},
|
||
next_retry_at: {
|
||
type: DATE,
|
||
allowNull: true,
|
||
comment: '下次可消费时间(失败退避)',
|
||
},
|
||
error_message: {
|
||
type: STRING(500),
|
||
allowNull: true,
|
||
comment: '最近一次失败原因',
|
||
},
|
||
created_at: {
|
||
type: DATE,
|
||
allowNull: false,
|
||
comment: '创建时间',
|
||
},
|
||
updated_at: {
|
||
type: DATE,
|
||
allowNull: false,
|
||
comment: '更新时间',
|
||
},
|
||
}, {
|
||
tableName: 'wms_waybill_allocate_queue',
|
||
freezeTableName: true,
|
||
underscored: true,
|
||
timestamps: false,
|
||
comment: '订单创建后自动分配快递消费队列',
|
||
indexes: [
|
||
{
|
||
name: 'uk_order_id_business_key',
|
||
unique: true,
|
||
fields: [ 'order_id', 'business_key' ],
|
||
},
|
||
{
|
||
name: 'idx_status_id',
|
||
fields: [ 'status', 'id' ],
|
||
},
|
||
{
|
||
name: 'idx_status_updated_at',
|
||
fields: [ 'status', 'updated_at' ],
|
||
},
|
||
],
|
||
});
|
||
|
||
return WaybillAllocateQueue;
|
||
};
|