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

100 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';
/**
* 边界场景数据准备(v3):
* 当前今日前候选只有 ac1b 组 8 条(同结构总数 14,超 max_same_structure=12,不入选)。
* 改为:从同结构总数 2~12 的组中选 8 条改为今日前,其余候选(含 ac1b 组 8 条)全部改为今天。
*
* @return {Promise<void>}
*/
const mysql = require('mysql2/promise');
const TODAY_TIME = '2026-09-06 12:30:00';
const BEFORE_TODAY = '2026-01-13 07:26:07';
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.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 hashGroups = new Map();
for (const row of rows) {
const key = String(row.items_hash || '').trim();
if (!key) continue;
if (!hashGroups.has(key)) hashGroups.set(key, []);
hashGroups.get(key).push(row);
}
let picked = null;
for (const [ key, list ] of hashGroups.entries()) {
if (list.length >= KEEP_COUNT && list.length <= 12) {
picked = { key, list };
break;
}
}
if (!picked) {
// 选数量最小的 8~12 组,找不到则选任意 >=8 组
for (const [ key, list ] of hashGroups.entries()) {
if (list.length >= KEEP_COUNT) {
picked = { key, list };
break;
}
}
}
if (!picked) {
throw new Error('未找到可用的同结构分组');
}
const keepIds = picked.list.slice(0, KEEP_COUNT).map(row => Number(row.id));
const keepSet = new Set(keepIds);
console.log(`选中分组: hash=${picked.key.slice(0, 12)} 总数=${picked.list.length}`);
console.log(`保留为今日前的订单: [${keepIds.join(', ')}]`);
const allIds = rows.map(row => Number(row.id));
await connection.query(
`UPDATE wms_order_delivery_100000 SET create_at = ? WHERE id IN (?)`,
[ TODAY_TIME, allIds ]
);
await connection.query(
`UPDATE wms_order_delivery_100000 SET create_at = ? WHERE id IN (?)`,
[ BEFORE_TODAY, keepIds ]
);
console.log(`其余 ${allIds.length - keepIds.length} 条已改为今天 ${TODAY_TIME}`);
console.log('数据准备完成');
} finally {
await connection.end();
}
}
main().catch(error => {
console.error(`执行失败: ${error.message}`);
process.exit(1);
});