115 lines
4.7 KiB
JavaScript
115 lines
4.7 KiB
JavaScript
'use strict';
|
|
// 开发环境集成测试:验证 wms_stock_warehouse + wms_stock_transaction 修改
|
|
const mysql = require('mysql2/promise');
|
|
const DB_CONFIG = { host: '127.0.0.1', port: 3307, user: 'wms', password: 'dspxmRwRdRbWtbm7', database: 'wms' };
|
|
const BASE_URL = 'http://127.0.0.1:6060';
|
|
const TEST_WAREHOUSE_ID = 100000;
|
|
const TEST_STORE_ID = 1000000;
|
|
|
|
async function main() {
|
|
const conn = await mysql.createConnection(DB_CONFIG);
|
|
|
|
try {
|
|
console.log('='.repeat(70));
|
|
console.log('WMS 拣货/复核完成 - stock_warehouse + stock_transaction 集成验证');
|
|
console.log(`测试时间: ${new Date().toISOString()}`);
|
|
console.log(`测试仓库: ${TEST_WAREHOUSE_ID}`);
|
|
console.log(`测试货主: ${TEST_STORE_ID}`);
|
|
console.log('='.repeat(70));
|
|
|
|
// === 步骤1: 检查订单分表 ===
|
|
console.log('\n--- 步骤1: 检查订单分表 ---');
|
|
const [ tables ] = await conn.query("SHOW TABLES LIKE 'wms_order_delivery_%'");
|
|
console.log(` 订单分表数量: ${tables.length}`);
|
|
tables.forEach(t => console.log(` - ${Object.values(t)[0]}`));
|
|
|
|
// === 步骤2: 查看订单状态分布 ===
|
|
console.log('\n--- 步骤2: 订单状态分布 (wms_order_delivery_100000) ---');
|
|
const [ statusDist ] = await conn.query(`
|
|
SELECT pick_status, recheck_status, storage_status, status, COUNT(*) as cnt
|
|
FROM wms_order_delivery_100000
|
|
GROUP BY pick_status, recheck_status, storage_status, status
|
|
ORDER BY cnt DESC
|
|
LIMIT 15
|
|
`);
|
|
console.table(statusDist);
|
|
|
|
// === 步骤3: 查找最近有库存变更的 stock_warehouse ===
|
|
console.log('\n--- 步骤3: wms_stock_warehouse 状态 (warehouse=100000) ---');
|
|
const [ swRows ] = await conn.query(`
|
|
SELECT id, item_code, item_name, quantity, locked_quantity, store_id
|
|
FROM wms_stock_warehouse
|
|
WHERE warehouse_id = 100000 AND quantity > 0
|
|
ORDER BY id DESC
|
|
LIMIT 10
|
|
`);
|
|
console.table(swRows);
|
|
|
|
// === 步骤4: wms_stock_transaction 最近记录 ===
|
|
console.log('\n--- 步骤4: wms_stock_transaction 最近记录 ---');
|
|
const [ recentTx ] = await conn.query(`
|
|
SELECT id, transaction_type, order_type, stock_id, quantity,
|
|
before_quantity, after_quantity,
|
|
before_locked_quantity, after_locked_quantity,
|
|
remark, created_at
|
|
FROM wms_stock_transaction
|
|
ORDER BY id DESC
|
|
LIMIT 15
|
|
`);
|
|
console.table(recentTx);
|
|
|
|
// 检查是否有 PICK_OUTBOUND 类型的记录
|
|
const pickOutboundTx = recentTx.filter(r => r.order_type === 'PICK_OUTBOUND');
|
|
console.log(`\n PICK_OUTBOUND 类型 stock_transaction 记录数: ${pickOutboundTx.length}`);
|
|
if (pickOutboundTx.length > 0) {
|
|
console.log(' ✅ 已有拣货出库 stock_transaction 记录,说明 pick.js 修改生效');
|
|
for (const tx of pickOutboundTx) {
|
|
console.log(` id=${tx.id} stock_id=${tx.stock_id} qty=${tx.quantity} locked: ${tx.before_locked_quantity}→${tx.after_locked_quantity}`);
|
|
}
|
|
} else {
|
|
console.log(' ⚠️ 尚无 PICK_OUTBOUND stock_transaction 记录,需触发拣货流程验证');
|
|
}
|
|
|
|
// === 步骤5: 统计 stock_transaction 的 before_locked/after_locked 非零记录 ===
|
|
console.log('\n--- 步骤5: stock_transaction locked_quantity 变更统计 ---');
|
|
const [ lockedStats ] = await conn.query(`
|
|
SELECT
|
|
COUNT(*) as total,
|
|
SUM(CASE WHEN before_locked_quantity > 0 OR after_locked_quantity > 0 THEN 1 ELSE 0 END) as with_locked,
|
|
SUM(CASE WHEN before_locked_quantity != after_locked_quantity THEN 1 ELSE 0 END) as locked_changed
|
|
FROM wms_stock_transaction
|
|
`);
|
|
console.table(lockedStats);
|
|
|
|
// === 步骤6: 检查 wms_stock_transaction 中 remark 包含"货主库存释放"的记录 ===
|
|
console.log('\n--- 步骤6: 货主库存释放 stock_transaction 记录 ---');
|
|
const [ releaseTx ] = await conn.query(`
|
|
SELECT id, transaction_type, order_type, stock_id, quantity,
|
|
before_locked_quantity, after_locked_quantity, remark, created_at
|
|
FROM wms_stock_transaction
|
|
WHERE remark LIKE '%货主库存释放%'
|
|
ORDER BY id DESC
|
|
LIMIT 10
|
|
`);
|
|
console.log(` 货主库存释放记录数: ${releaseTx.length}`);
|
|
if (releaseTx.length > 0) {
|
|
console.table(releaseTx);
|
|
console.log(' ✅ stock_warehouse locked_quantity 释放 + stock_transaction 写入已验证');
|
|
} else {
|
|
console.log(' ⚠️ 尚无"货主库存释放"remark 记录');
|
|
}
|
|
|
|
console.log('\n' + '='.repeat(70));
|
|
console.log('集成验证完成');
|
|
console.log('='.repeat(70));
|
|
|
|
} finally {
|
|
await conn.end();
|
|
}
|
|
}
|
|
|
|
main().catch(err => {
|
|
console.error('测试失败:', err);
|
|
process.exit(1);
|
|
});
|