WMS_MAIN/database/migrations/20261107110000-add-oms-print-fields-to-order-express.js
liufumingren 25dac21b4b feat(waybill): OMS 取号与抖音打印 params 按店铺隔离
- express/express_platform: 新增 OMS 回源取号(need_oms_waybill=1)与统一失败收尾,
  失败时标记订单异常、写失败日志并清理未完成占位行;队列消费与手工分配共用同一口径
- order_print: 抖音打印按运单落库的 logistics_interface_id 精确命中取号接口配置,
  临时 key 缓存键带店铺与 token 指纹,避免多店铺串用 token;打印前按 OMS 记录换新 params
- order_express: 新增 print_history_id、cai_niao_auth_info_id 字段
- consume_waybill_allocate_queue / pendingOrder / delivery_order / order_async /
  printer_data_builder / order_delivery_table_schema: 配套调整
- migrations: 运单 wave_no 索引、OMS 打印字段

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

70 lines
2.6 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';
/**
* 为运单表新增 OMS 取号返回的打印定位字段。
*
* - `print_history_id`:OMS 返回的打印记录ID(店管家 PrintHistoryIds[0].id),
* 打印前用它回 `deliveryorder.getprintdata` 换新的抖音 params;
* - `cai_niao_auth_info_id`:菜鸟授权网点ID(每个店铺唯一),
* 打印时按它做店铺分组,一组只需一个 print_history_id 换一次 params。
*/
module.exports = {
/**
* 执行迁移:新增 print_history_id / cai_niao_auth_info_id(幂等)。
*
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
* @param {import('sequelize')} Sequelize Sequelize 实例。
* @return {Promise<void>} 无返回值。
*/
async up(queryInterface, Sequelize) {
const tableName = 'wms_order_express';
const columns = await queryInterface.describeTable(tableName);
const definitions = [];
if (!columns.print_history_id) {
definitions.push(
`ADD COLUMN \`print_history_id\` ${Sequelize.STRING(64)} NULL DEFAULT NULL COMMENT 'OMS 打印记录ID(打印前换新 params 用)' AFTER \`encryptedtoken\``
);
}
if (!columns.cai_niao_auth_info_id) {
const afterColumn = definitions.length > 0 ? 'print_history_id' : 'encryptedtoken';
definitions.push(
`ADD COLUMN \`cai_niao_auth_info_id\` ${Sequelize.BIGINT(20).UNSIGNED} NULL DEFAULT NULL COMMENT '菜鸟授权网点ID(OMS 取号返回,打印按店铺分组用)' AFTER \`${afterColumn}\``
);
}
if (definitions.length === 0) {
return;
}
// 拿不到元数据锁时快速失败:MDL 排队会把后续所有读写一起堵住,
// 30 秒内拿不到锁就报错退出(可安全重试),避免拖垮生产可用性
await queryInterface.sequelize.query('SET SESSION lock_wait_timeout = 30');
// 两条 ADD COLUMN 合并为一次 ALTER:MySQL 5.7 加列需重建表,分两次会重建两遍
await queryInterface.sequelize.query(
`ALTER TABLE \`${tableName}\` ${definitions.join(', ')}`
);
},
/**
* 回滚迁移:删除新增字段(幂等)。
*
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
* @return {Promise<void>} 无返回值。
*/
async down(queryInterface) {
const tableName = 'wms_order_express';
const columns = await queryInterface.describeTable(tableName);
if (columns.cai_niao_auth_info_id) {
await queryInterface.removeColumn(tableName, 'cai_niao_auth_info_id');
}
if (columns.print_history_id) {
await queryInterface.removeColumn(tableName, 'print_history_id');
}
},
};