- 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: 补充快递排除与储位分配限制测试
103 lines
3.6 KiB
JavaScript
103 lines
3.6 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 存量订单回填 wave_scope(波次范围)字段。
|
||
*
|
||
* 口径(与波次生成写入逻辑 resolveWaveScopeByWaveMeta 一致):
|
||
* - 0 = 未分配波次(wave_id = 0,默认值无需更新);
|
||
* - 1 = 大团购:wms_wave_batch.wave_type = 1 且 source = 0;
|
||
* - 3 = 小团购:wms_wave_batch.wave_type = 1 且 source = 2;
|
||
* - 2 = 散单:其余有波次的订单(wave_type = 2,或 wave_type = 1 且 source = 1,
|
||
* 或 wave_id 指向的波次已不存在)。
|
||
*
|
||
* 覆盖范围:基表 wms_order_delivery 与全部仓库分表
|
||
* (current/history/dispatch/outsourced)。
|
||
*
|
||
* 幂等:按 CASE 规则全量覆盖写入,重复执行结果一致。
|
||
*/
|
||
|
||
const BASE_TABLE = 'wms_order_delivery';
|
||
|
||
const SHARD_PATTERN = /^wms_order_delivery_(\d+)(?:_(history|dispatch|outsourced))?$/;
|
||
|
||
/**
|
||
* 列举库内全部订单分表。
|
||
* @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 {*} updateResult query 返回结果。
|
||
* @return {number} 受影响行数。
|
||
*/
|
||
function extractAffectedRows(updateResult) {
|
||
if (Array.isArray(updateResult)) {
|
||
const meta = updateResult[1];
|
||
return Number(meta && (meta.affectedRows || meta.affectedCount || meta.rowCount) || 0);
|
||
}
|
||
if (updateResult && typeof updateResult === 'object') {
|
||
return Number(updateResult.affectedRows || updateResult.affectedCount || updateResult.rowCount || 0);
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
module.exports = {
|
||
/**
|
||
* 执行迁移:按波次类型/来源回填 wave_scope。
|
||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||
* @return {Promise<void>} 无返回值。
|
||
*/
|
||
async up(queryInterface) {
|
||
const tables = [ BASE_TABLE, ...await listOrderShards(queryInterface) ];
|
||
const results = [];
|
||
|
||
for (const tableName of tables) {
|
||
const updateResult = await queryInterface.sequelize.query(`
|
||
UPDATE \`${tableName}\` o
|
||
LEFT JOIN wms_wave_batch wb ON wb.wave_id = o.wave_id
|
||
SET o.wave_scope = CASE
|
||
WHEN wb.wave_type = 1 AND wb.source = 0 THEN 1
|
||
WHEN wb.wave_type = 1 AND wb.source = 2 THEN 3
|
||
ELSE 2
|
||
END
|
||
WHERE o.wave_id > 0
|
||
`);
|
||
results.push({ tableName, affectedRows: extractAffectedRows(updateResult) });
|
||
}
|
||
|
||
console.log('[20260905130000-backfill-order-wave-scope] up results:', JSON.stringify(results));
|
||
},
|
||
|
||
/**
|
||
* 回滚迁移:将已分配波次订单的 wave_scope 重置为 0(未回填状态)。
|
||
* @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) {
|
||
const updateResult = await queryInterface.sequelize.query(`
|
||
UPDATE \`${tableName}\`
|
||
SET wave_scope = 0
|
||
WHERE wave_id > 0
|
||
`);
|
||
results.push({ tableName, affectedRows: extractAffectedRows(updateResult) });
|
||
}
|
||
|
||
console.log('[20260905130000-backfill-order-wave-scope] down results:', JSON.stringify(results));
|
||
},
|
||
};
|