WMS_MAIN/database/migrations/20260905100000-add-wave-scope-to-order-delivery.js
liufumingren 95067aeb8a feat(wms): 工作台成员、波次范围、库存明细与报表修复等多项更新
- workbench: 工作台成员拆分 wms_workbench_member 表,下线 barcode 字段,新增绑定/移除成员接口

- order: 订单配送新增 wave_scope 波次范围字段与历史回填,自动分配快递排除备注与储位分配限制修复

- storage.transaction.list: 重写为 wms_storage_transaction 逐条明细查询,消除聚合慢查询

- stock.report: 分页默认生效、排序白名单扩充、where.stock_id 数组兼容修复

- storage.entry: quickInbound/commit 新增 noNeedNotice 通知开关

- storage.inventory.list: stock_query 支持数组多关键字并集匹配

- store: 手工单回传通知策略 notify_manual_sync

- docs: 同步接口文档与变更记录、路由表;test: 补充快递排除与储位分配限制测试
2026-09-05 22:43:38 +08:00

106 lines
3.5 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';
/**
* 订单表增加 wave_scope(波次范围)字段。
*
* 取值约定(与 order 工作台虚拟筛选 wave_scope 一致):
* - 0 = 未分配波次
* - 1 = 团购
* - 2 = 散单
* 默认 0。
*
* 覆盖范围:
* - 基表 wms_order_delivery;
* - 全部仓库分表 wms_order_delivery_{wh}(current)及
* _{wh}_history / _{wh}_dispatch / _{wh}_outsourced。
*
* 幂等:列已存在则跳过。分表模型由 app/model/order_delivery_factory.js
* 运行时 drift 同步兜底,本迁移提前补齐避免运行时 ALTER。
*/
const BASE_TABLE = 'wms_order_delivery';
const SHARD_PATTERN = /^wms_order_delivery_(\d+)(?:_(history|dispatch|outsourced))?$/;
const COLUMN_NAME = 'wave_scope';
/**
* 列举库内全部订单分表。
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
* @return {Promise<string[]>} 分表名列表。
*/
async function listOrderShards(queryInterface) {
const [ rows ] = await queryInterface.sequelize.query(
'SELECT TABLE_NAME AS tableName FROM INFORMATION_SCHEMA.TABLES '
+ 'WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME LIKE \'wms_order_delivery\\_%\' '
+ 'ORDER BY TABLE_NAME'
);
return (rows || [])
.map(row => String(row.tableName || row.TABLE_NAME || ''))
.filter(name => SHARD_PATTERN.test(name));
}
/**
* 判断列是否已存在。
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
* @param {string} tableName 表名。
* @param {string} columnName 列名。
* @return {Promise<boolean>} 是否存在。
*/
async function columnExists(queryInterface, tableName, columnName) {
const described = await queryInterface.describeTable(tableName);
return Boolean(described && described[columnName]);
}
module.exports = {
/**
* 执行迁移:为基表与全部分表增加 wave_scope 列。
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
* @param {import('sequelize')} Sequelize Sequelize 构造器。
* @return {Promise<void>} 无返回值。
*/
async up(queryInterface, Sequelize) {
const tables = [ BASE_TABLE, ...await listOrderShards(queryInterface) ];
const results = [];
for (const tableName of tables) {
if (await columnExists(queryInterface, tableName, COLUMN_NAME)) {
results.push({ tableName, action: 'skip', reason: 'exists' });
continue;
}
await queryInterface.addColumn(tableName, COLUMN_NAME, {
type: Sequelize.TINYINT(4),
allowNull: false,
defaultValue: 0,
comment: '波次范围:0未分配波次 1团购 2散单',
});
results.push({ tableName, action: 'added' });
}
console.log('[20260905100000-add-wave-scope-to-order-delivery] up results:', JSON.stringify(results));
},
/**
* 回滚迁移:移除 base 与全部分表的 wave_scope 列。
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
* @return {Promise<void>} 无返回值。
*/
async down(queryInterface) {
const tables = [ BASE_TABLE, ...await listOrderShards(queryInterface) ];
const results = [];
for (const tableName of tables) {
if (!await columnExists(queryInterface, tableName, COLUMN_NAME)) {
results.push({ tableName, action: 'skip', reason: 'missing' });
continue;
}
await queryInterface.removeColumn(tableName, COLUMN_NAME);
results.push({ tableName, action: 'removed' });
}
console.log('[20260905100000-add-wave-scope-to-order-delivery] down results:', JSON.stringify(results));
},
};