'use strict'; /** * 统计策略 7(边拣边分)候选订单池: * 命中匹配表、未分配波次、状态满足抓取口径的订单,按同结构与创建时间分布统计。 * * @return {Promise} */ const mysql = require('mysql2/promise'); 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, o.create_at, o.step, o.post_status, o.storage_status, o.print_status, o.status, o.outbound_status, o.intercept_status, o.lock_status, o.wave_id 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 ORDER BY o.id DESC` ); console.log(`===== 命中策略7订单总数: ${rows.length} =====`); const todayStartUtc = Date.UTC(2026, 8, 5, 16, 0, 0); // 2026-09-06 00:00 +08:00 const beforeToday = rows.filter(row => row.create_at && new Date(row.create_at).getTime() < todayStartUtc); const today = rows.filter(row => row.create_at && new Date(row.create_at).getTime() >= todayStartUtc); console.log(`今日前订单数: ${beforeToday.length}`); console.log(`今日订单数: ${today.length}`); const eligible = rows.filter(row => Number(row.wave_id) === 0 && Number(row.step) !== 0 && String(row.post_status) === 'fin' && String(row.storage_status) === 'fin' && String(row.print_status) !== 'fin' && String(row.status) !== 'cancel' && String(row.outbound_status) !== 'padding' && String(row.intercept_status) === 'none' && String(row.lock_status) === 'none' ); console.log(`===== 满足抓取口径订单数: ${eligible.length} =====`); const eligibleBeforeToday = eligible.filter(row => new Date(row.create_at).getTime() < todayStartUtc); const eligibleToday = eligible.filter(row => new Date(row.create_at).getTime() >= todayStartUtc); console.log(` 其中今日前: ${eligibleBeforeToday.length}`); console.log(` 其中今天: ${eligibleToday.length}`); const hashGroups = new Map(); for (const row of eligible) { const key = String(row.items_hash || '').trim(); if (!key) continue; if (!hashGroups.has(key)) hashGroups.set(key, []); hashGroups.get(key).push(row); } console.log('===== 同结构分组(仅数量>=2) ====='); for (const [ key, list ] of hashGroups.entries()) { if (list.length < 2) continue; const beforeCount = list.filter(row => new Date(row.create_at).getTime() < todayStartUtc).length; console.log(`hash=${key.slice(0, 12)} 总数=${list.length} 今日前=${beforeCount} 今天=${list.length - beforeCount}`); } } finally { await connection.end(); } } main().catch(error => { console.error(`查询失败: ${error.message}`); process.exit(1); });