WMS_MAIN/script/tmp-prepare-wave-pool-boundary.cjs
liufumingren c3f1c67592 chore(script): 沉淀波次池/报表/库存/订单本地排查脚本
新增一批一次性排查脚本(script/tmp-*.cjs),与仓库既有 script/tmp- 约定保持一致,
覆盖波次池边界与优先级核对、库位/出库报表核对、订单状态与更新范围核验等场景
2026-09-13 15:31:27 +08:00

96 lines
3.0 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';
/**
* 边界场景数据准备:让策略 7 的第一订单池(今日前)仅剩 8 条同结构订单,
* 其余满足抓取口径的候选订单全部改为今天,用于验证:
* - 第一池不足 20 时不会用第二池填充;
* - 第一池抓取完毕后,第二轮才开始抓第二池(今天订单)并抓满 20。
*
* @return {Promise<void>}
*/
const mysql = require('mysql2/promise');
const TODAY_TIME = '2026-09-06 11:00:00';
const KEEP_COUNT = 8;
async function main() {
const connection = await mysql.createConnection({
host: '127.0.0.1',
port: 3307,
user: 'wms',
password: 'dspxmRwRdRbWtbm7',
database: 'wms',
});
try {
const [ rows ] = await connection.query(
`SELECT o.id, o.create_at, o.items_hash
FROM wms_order_wave_strategy_match m
INNER JOIN wms_order_delivery_100000 o
ON o.id = m.order_id
WHERE m.warehouse_id = 100000
AND m.strategy_id = 7
AND o.wave_id = 0
AND o.step != 0
AND o.post_status = 'fin'
AND o.storage_status = 'fin'
AND o.print_status != 'fin'
AND o.status != 'cancel'
AND o.outbound_status != 'padding'
AND o.intercept_status = 'none'
AND o.lock_status = 'none'
ORDER BY o.id ASC`
);
console.log(`满足口径且未分配波次的候选总数: ${rows.length}`);
const todayStart = Date.UTC(2026, 8, 5, 16, 0, 0); // 2026-09-06 00:00 +08:00
const beforeToday = rows.filter(row => new Date(row.create_at).getTime() < todayStart);
console.log(`其中今日前候选: ${beforeToday.length}`);
// 选择同一 hash 的 8 条今日前订单保留
const hashGroups = new Map();
for (const row of beforeToday) {
const key = String(row.items_hash || '').trim();
if (!key) continue;
if (!hashGroups.has(key)) hashGroups.set(key, []);
hashGroups.get(key).push(row);
}
let keepGroup = null;
for (const list of hashGroups.values()) {
if (list.length >= KEEP_COUNT) {
keepGroup = list;
break;
}
}
if (!keepGroup) {
console.log('未找到同结构数量>=8的今日前分组,改用任意8条');
keepGroup = beforeToday.slice(0, KEEP_COUNT);
}
const keepIds = keepGroup.slice(0, KEEP_COUNT).map(row => Number(row.id));
const keepSet = new Set(keepIds);
const moveIds = rows.map(row => Number(row.id)).filter(id => !keepSet.has(id));
console.log(`保留为今日前的订单(将不足20): [${keepIds.join(', ')}]`);
console.log(`改为今天的订单数: ${moveIds.length}`);
if (moveIds.length > 0) {
const [ result ] = await connection.query(
`UPDATE wms_order_delivery_100000
SET create_at = ?
WHERE id IN (?)`,
[ TODAY_TIME, moveIds ]
);
console.log(`已更新行数: ${result.affectedRows}`);
}
console.log('数据准备完成');
} finally {
await connection.end();
}
}
main().catch(error => {
console.error(`执行失败: ${error.message}`);
process.exit(1);
});