WMS_MAIN/app/model/order_express_trace.js
liufumingren 89e4cd22c0 feat(waybill): 运单物流轨迹表与 waybill.getTrace 批量更新
- 新增 wms_order_express_trace(1 运单 : N 轨迹):express_id 关联主表,
  冗余 waybill_code / order_id,warehouse_id 隔离,raw_data 存原始报文;
  uk_express_op_scan(express_id, op_time, scan_type) 幂等;字符集与主表一致
- 新增出站回调 waybill.getTrace(注册到 callback_functions,管理端可勾选):
  入参与 waybill.getreceive 一致({ request: { waybill_codes: [...] } },单批 10 单,
  signMode=simple);响应 [{ waybillNo, trace: {...} }],兼容 trace 数组与 {code,data} 包装
- 新增 waybill.warehouse.updateTrace / updateTraceTaskProgress:
  复用导出任务的异步任务ID与进度模式(前缀 waybill_trace_),
  支持 waybillCodes 或与 waybill.warehouse.list 一致的 where 条件圈选(上限 5000);
  轨迹按 (express_id, op_time, scan_type) upsert,未匹配运单计入 not_found
- 文档:methods/system.json(0.3.325)、变更记录、设计文档 2.2.1/3.9、出站回调说明 3.7

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-11 19:53:29 +08:00

96 lines
2.7 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';
/**
* 运单物流轨迹模型。
* 一个运单(express_id)对应多条轨迹,由外部快递/轨迹接口回传。
* @param {import('egg').Application} app Egg 应用实例。
* @return {import('sequelize').ModelCtor<import('sequelize').Model>} Sequelize 模型。
*/
module.exports = app => {
const { BIGINT, STRING, INTEGER, DATE, JSON: JSON_TYPE } = app.Sequelize;
const OrderExpressTrace = app.model.define('order_express_trace', {
id: {
type: BIGINT(20).UNSIGNED,
primaryKey: true,
autoIncrement: true,
allowNull: false,
comment: '主键ID',
},
express_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '运单ID(wms_order_express.id)',
},
waybill_code: {
type: STRING(50),
allowNull: false,
comment: '运单号(冗余,便于按运单号直查)',
},
order_id: {
type: BIGINT(20).UNSIGNED,
allowNull: true,
comment: '订单ID(冗余,便于按订单查轨迹)',
},
warehouse_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '仓库ID(数据隔离维度)',
},
op_time: {
type: DATE,
allowNull: true,
comment: '操作时间(opTime)',
},
out_biz_code: {
type: STRING(191),
allowNull: true,
comment: '外部业务码(outBizCode)',
},
memo: {
type: STRING(500),
allowNull: true,
comment: '轨迹描述(memo)',
},
op_org_city_name: {
type: STRING(100),
allowNull: true,
comment: '操作机构所在城市(opOrgCityName)',
},
weight: {
type: INTEGER(11),
allowNull: true,
defaultValue: 0,
comment: '重量(weight,来源原值)',
},
scan_type: {
type: STRING(50),
allowNull: true,
comment: '扫描类型(scanType),如 发件/到件/派件/签收',
},
raw_data: {
type: JSON_TYPE,
allowNull: true,
comment: '原始轨迹报文(未落库字段的兜底存储)',
},
}, {
tableName: 'wms_order_express_trace',
freezeTableName: true,
underscored: true,
timestamps: true,
createdAt: 'created_at',
updatedAt: 'updated_at',
deletedAt: 'deleted_at',
paranoid: true,
comment: '运单物流轨迹表(1 运单 : N 轨迹)',
indexes: [
{ name: 'uk_express_op_scan', unique: true, fields: [ 'express_id', 'op_time', 'scan_type' ] },
{ name: 'idx_waybill_code', fields: [ 'waybill_code', 'op_time' ] },
{ name: 'idx_order_id', fields: [ 'order_id' ] },
{ name: 'idx_warehouse_op_time', fields: [ 'warehouse_id', 'op_time' ] },
],
});
return OrderExpressTrace;
};