test(storage): directPutaway 与 quickPutaway 链路对比测试脚本
- tmp-test-putaway-full-compare.cjs:全链路真实接口对比(A 两步 quickPutaway→addItem→commit / B 一步 directPutaway),支持 A|B 参数单独跑 - tmp-test-putaway-batch-compare.cjs:批次维度对比(不同批次建行 / 同批次累加) - tmp-verify-all-tables.cjs:15 张表逐表核对输出 - tmp-check-*:条码、请求日志、通知失败表、权限、库存行/流水等定点核对 - tmp-clear-user-cache.cjs:清 Redis 用户缓存(权限变更后刷新) - 测试数据保留不清理(收货单 1521-1535、入库单 381-392 等)
This commit is contained in:
parent
0fe7b724ed
commit
3352fbaff6
23
script/tmp-check-barcodes.cjs
Normal file
23
script/tmp-check-barcodes.cjs
Normal file
@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
const mysql = require('mysql2/promise');
|
||||
(async () => {
|
||||
const c = await mysql.createConnection({ host: '127.0.0.1', port: 3307, user: 'wms', password: 'dspxmRwRdRbWtbm7', database: 'wms' });
|
||||
|
||||
// bindDetailProduct 自动写入的条码(本次测试的 TMPBC/FULLBC 前缀)
|
||||
const [barcodes] = await c.query(`
|
||||
SELECT id, stock_id, warehouse_id, barcode
|
||||
FROM wms_stock_barcodes
|
||||
WHERE barcode LIKE 'TMPBC%' OR barcode LIKE 'FULLBC%'
|
||||
ORDER BY id`);
|
||||
console.log('== wms_stock_barcodes 测试写入的条码(共 ' + barcodes.length + ' 行) ==');
|
||||
console.log(JSON.stringify(barcodes, null, 2));
|
||||
|
||||
// 商品 159061/159064 上的全部条码
|
||||
const [all] = await c.query(
|
||||
`SELECT id, stock_id, barcode FROM wms_stock_barcodes WHERE stock_id IN (159061, 159064) ORDER BY id`
|
||||
);
|
||||
console.log('== 两商品全部条码 ==');
|
||||
console.log(JSON.stringify(all, null, 2));
|
||||
await c.end();
|
||||
process.exit(0);
|
||||
})().catch(e => { console.error(e); process.exit(1); });
|
||||
42
script/tmp-check-hidden-tables.cjs
Normal file
42
script/tmp-check-hidden-tables.cjs
Normal file
@ -0,0 +1,42 @@
|
||||
'use strict';
|
||||
const mysql = require('mysql2/promise');
|
||||
(async () => {
|
||||
const c = await mysql.createConnection({ host: '127.0.0.1', port: 3307, user: 'wms', password: 'dspxmRwRdRbWtbm7', database: 'wms' });
|
||||
|
||||
// 1. 请求日志表:本次重测 A(1530)/B(1531) 相关的接口调用日志
|
||||
const [sysLogs] = await c.query(`
|
||||
SELECT id, method, v, store_id, use_time, LEFT(body, 120) AS body_snip, created_at
|
||||
FROM wms_system_log
|
||||
WHERE body LIKE '%R20688012%' OR body LIKE '%R20688013%'
|
||||
OR body LIKE '%"receiving_id":1530%' OR body LIKE '%"receiving_id":1531%'
|
||||
OR body LIKE '%"ids":[1530%' OR body LIKE '%"ids":[1531%'
|
||||
OR body LIKE '%"entry_order_id":387%' OR body LIKE '%"entry_order_id":388%'
|
||||
ORDER BY id`);
|
||||
console.log('== wms_system_log 请求日志(本次重测相关,共 ' + sysLogs.length + ' 条) ==');
|
||||
console.log(JSON.stringify(sysLogs, null, 2));
|
||||
|
||||
// 2. 通知发送日志表(失败才写)
|
||||
const [notiLogs] = await c.query(`
|
||||
SELECT id, trace_id, store_id, warehouse_id, business_name, event, status, http_status, created_at
|
||||
FROM wms_notification_send_log
|
||||
WHERE created_at >= DATE_SUB(NOW(), INTERVAL 2 DAY)
|
||||
ORDER BY id DESC LIMIT 10`);
|
||||
console.log('== wms_notification_send_log 最近两天(共 ' + notiLogs.length + ' 条) ==');
|
||||
console.log(JSON.stringify(notiLogs, null, 2));
|
||||
|
||||
// 3. 商品资料异步补全相关(无图片/无重量时应无写入)
|
||||
const [stockRow] = await c.query(
|
||||
`SELECT id, is_images, gross_weight FROM wms_stock_warehouse WHERE id IN (159061, 159064)`
|
||||
);
|
||||
console.log('== 商品资料快照(is_images/gross_weight,验证异步补全未触发) ==');
|
||||
console.log(JSON.stringify(stockRow, null, 2));
|
||||
|
||||
const [fileRefs] = await c.query(
|
||||
`SELECT id, business_type, business_id, file_id FROM wms_file_reference WHERE business_type='stock' AND business_id IN ('159061','159064')`
|
||||
);
|
||||
console.log('== wms_file_reference(stock 类型,共 ' + fileRefs.length + ' 行) ==');
|
||||
console.log(JSON.stringify(fileRefs, null, 2));
|
||||
|
||||
await c.end();
|
||||
process.exit(0);
|
||||
})().catch(e => { console.error(e); process.exit(1); });
|
||||
15
script/tmp-check-policy.cjs
Normal file
15
script/tmp-check-policy.cjs
Normal file
@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
const mysql = require('mysql2/promise');
|
||||
(async () => {
|
||||
const c = await mysql.createConnection({ host: '127.0.0.1', port: 3307, user: 'wms', password: 'dspxmRwRdRbWtbm7', database: 'wms' });
|
||||
const [r] = await c.query(
|
||||
`SELECT id, store_id, warehouse_id, warehouse_use_status,
|
||||
JSON_EXTRACT(policy_config, '$.allow_receiving_direct_putaway') AS direct,
|
||||
JSON_EXTRACT(policy_config, '$.allow_receiving_quick_putaway') AS quick
|
||||
FROM wms_store_warehouse WHERE store_id = 1000000 AND warehouse_id = 100000`
|
||||
);
|
||||
console.log('store_warehouse:', JSON.stringify(r, null, 2));
|
||||
const [r2] = await c.query('SELECT id, store_id, warehouse_id, status, is_review, storage_status FROM wms_receiving WHERE id IN (1521,1522,1523,1524)');
|
||||
console.log('receivings:', JSON.stringify(r2, null, 2));
|
||||
await c.end();
|
||||
})().catch(e => { console.error(e); process.exit(1); });
|
||||
12
script/tmp-check-role-permission.cjs
Normal file
12
script/tmp-check-role-permission.cjs
Normal file
@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
const mysql = require('mysql2/promise');
|
||||
(async () => {
|
||||
const c = await mysql.createConnection({ host: '127.0.0.1', port: 3307, user: 'wms', password: 'dspxmRwRdRbWtbm7', database: 'wms' });
|
||||
const [p] = await c.query("SELECT id, path, meta_title FROM wms_permission WHERE path LIKE 'storage.inventory%' AND type='api'");
|
||||
console.log('perms:', JSON.stringify(p));
|
||||
const [r] = await c.query('SELECT id, permissions FROM wms_role WHERE id IN (7)');
|
||||
console.log('roles:', JSON.stringify(r));
|
||||
const [col] = await c.query('SHOW COLUMNS FROM wms_role');
|
||||
console.log('cols:', col.map(x => x.Field + ':' + x.Type).join(', '));
|
||||
await c.end();
|
||||
})().catch(e => { console.error(e); process.exit(1); });
|
||||
28
script/tmp-check-storage-rows.cjs
Normal file
28
script/tmp-check-storage-rows.cjs
Normal file
@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
const mysql = require('mysql2/promise');
|
||||
(async () => {
|
||||
const c = await mysql.createConnection({ host: '127.0.0.1', port: 3307, user: 'wms', password: 'dspxmRwRdRbWtbm7', database: 'wms' });
|
||||
|
||||
// 两个测试商品在 wms_storage 中的全部行
|
||||
const [rows] = await c.query(`
|
||||
SELECT id, warehouse_id, store_id, space_id, stock_id, batch_no, inventory_type,
|
||||
quantity, locked_quantity, available_quantity,
|
||||
inbound_order_no, receiving_id, entry_order_id, inbound_time
|
||||
FROM wms_storage
|
||||
WHERE stock_id IN (159061, 159064)
|
||||
ORDER BY id`);
|
||||
console.log('== wms_storage 中两个测试商品的全部行(共 ' + rows.length + ' 行) ==');
|
||||
console.log(JSON.stringify(rows, null, 2));
|
||||
|
||||
// 两商品的库位流水(逐笔证据)
|
||||
const [txns] = await c.query(`
|
||||
SELECT id, order_no, transaction_type, stock_id, storage_id, space_id, quantity, before_quantity, after_quantity, batch_no
|
||||
FROM wms_storage_transaction
|
||||
WHERE stock_id IN (159061, 159064)
|
||||
ORDER BY id`);
|
||||
console.log('== wms_storage_transaction 两商品逐笔流水(共 ' + txns.length + ' 条) ==');
|
||||
console.log(JSON.stringify(txns, null, 2));
|
||||
|
||||
await c.end();
|
||||
process.exit(0);
|
||||
})().catch(e => { console.error(e); process.exit(1); });
|
||||
41
script/tmp-check-storage-stock.cjs
Normal file
41
script/tmp-check-storage-stock.cjs
Normal file
@ -0,0 +1,41 @@
|
||||
'use strict';
|
||||
const mysql = require('mysql2/promise');
|
||||
(async () => {
|
||||
const c = await mysql.createConnection({ host: '127.0.0.1', port: 3307, user: 'wms', password: 'dspxmRwRdRbWtbm7', database: 'wms' });
|
||||
|
||||
// 1. wms_storage 当前状态(A/B 共用的累加行)
|
||||
const [storages] = await c.query(`
|
||||
SELECT id, space_id, stock_id, batch_no, quantity, locked_quantity, available_quantity,
|
||||
inbound_order_no, receiving_id, entry_order_id, inbound_time
|
||||
FROM wms_storage WHERE id IN (408, 409)`);
|
||||
console.log('== wms_storage 当前行(408/409) ==');
|
||||
console.log(JSON.stringify(storages, null, 2));
|
||||
|
||||
// 2. wms_stock_warehouse 当前数量
|
||||
const [stocks] = await c.query(`
|
||||
SELECT id, item_code, quantity, locked_quantity, is_valid
|
||||
FROM wms_stock_warehouse WHERE id IN (159061, 159064)`);
|
||||
console.log('== wms_stock_warehouse 当前数量 ==');
|
||||
console.log(JSON.stringify(stocks, null, 2));
|
||||
|
||||
// 3. A(入库单 387)与 B(入库单 388)各自的库位流水(证明 storage 写入)
|
||||
const [storageTxns] = await c.query(`
|
||||
SELECT order_no, transaction_type, stock_id, storage_id, space_id, quantity, before_quantity, after_quantity, batch_no
|
||||
FROM wms_storage_transaction
|
||||
WHERE order_id IN (387, 388) OR order_no IN ('SCRK202608240007','SCRK202608240008')
|
||||
ORDER BY id`);
|
||||
console.log('== wms_storage_transaction:A(387)/B(388) 的库位流水 ==');
|
||||
console.log(JSON.stringify(storageTxns, null, 2));
|
||||
|
||||
// 4. A/B 各自的商品流水(证明 stock_warehouse 数量变更)
|
||||
const [stockTxns] = await c.query(`
|
||||
SELECT order_no, transaction_type, stock_id, quantity, before_quantity, after_quantity, entry_order_id
|
||||
FROM wms_stock_transaction
|
||||
WHERE entry_order_id IN (387, 388) OR order_no IN ('SCRK202608240007','SCRK202608240008')
|
||||
ORDER BY id`);
|
||||
console.log('== wms_stock_transaction:A(387)/B(388) 的商品流水 ==');
|
||||
console.log(JSON.stringify(stockTxns, null, 2));
|
||||
|
||||
await c.end();
|
||||
process.exit(0);
|
||||
})().catch(e => { console.error(e); process.exit(1); });
|
||||
13
script/tmp-clear-user-cache.cjs
Normal file
13
script/tmp-clear-user-cache.cjs
Normal file
@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
const Redis = require('ioredis');
|
||||
(async () => {
|
||||
const r = new Redis({ host: '127.0.0.1', port: 6379, password: 'qwe2019', db: 10 });
|
||||
const keys = await r.keys('user:info:*');
|
||||
console.log('matched keys:', keys);
|
||||
for (const k of keys) {
|
||||
await r.del(k);
|
||||
console.log('deleted:', k);
|
||||
}
|
||||
r.disconnect();
|
||||
process.exit(0);
|
||||
})().catch(e => { console.error(e); process.exit(1); });
|
||||
58
script/tmp-explore-putaway-test-data.cjs
Normal file
58
script/tmp-explore-putaway-test-data.cjs
Normal file
@ -0,0 +1,58 @@
|
||||
'use strict';
|
||||
/* 临时探索脚本:查询直入/转入库单对比测试所需数据(只读) */
|
||||
const mysql = require('mysql2/promise');
|
||||
|
||||
(async () => {
|
||||
const conn = await mysql.createConnection({
|
||||
host: '127.0.0.1', port: 3307, user: 'wms', password: 'dspxmRwRdRbWtbm7', database: 'wms',
|
||||
});
|
||||
|
||||
const [cols] = await conn.query('SHOW COLUMNS FROM wms_employee_role');
|
||||
console.log('== wms_employee_role columns ==');
|
||||
console.log(cols.map(c => c.Field).join(','));
|
||||
|
||||
const [whUsers] = await conn.query(`
|
||||
SELECT a.id account_id, a.username, a.status, e.id employee_id, e.store_id warehouse_id, r.id role_id, r.role_type
|
||||
FROM wms_account a
|
||||
JOIN wms_account_store_employee e ON e.account_id = a.id AND e.deleted_at IS NULL
|
||||
LEFT JOIN wms_employee_role er ON er.employee_id = e.id
|
||||
LEFT JOIN wms_role r ON r.id = er.role_id
|
||||
WHERE a.status = 1
|
||||
ORDER BY e.id ASC LIMIT 8`);
|
||||
console.log('== accounts ==');
|
||||
console.log(JSON.stringify(whUsers, null, 2));
|
||||
|
||||
if (whUsers.length === 0) { await conn.end(); return; }
|
||||
const whId = whUsers[0].warehouse_id;
|
||||
console.log('== using warehouse_id = ' + whId + ' ==');
|
||||
|
||||
const [stores] = await conn.query(`
|
||||
SELECT sw.store_id, sw.warehouse_use_status, sw.policy_config, s.company_name
|
||||
FROM wms_store_warehouse sw JOIN wms_store s ON s.id = sw.store_id
|
||||
WHERE sw.warehouse_id = ? AND sw.warehouse_use_status = 1
|
||||
ORDER BY sw.id DESC LIMIT 5`, [ whId ]);
|
||||
console.log('== store_warehouse contracts (warehouse=' + whId + ') ==');
|
||||
console.log(JSON.stringify(stores, null, 2));
|
||||
|
||||
const [stocks] = await conn.query(`
|
||||
SELECT sw.id, sw.item_code, sw.item_name, sw.is_batch_mgmt, sw.is_shelf_life_mgmt, sw.is_valid, sw.quantity, sw.store_id
|
||||
FROM wms_stock_warehouse sw
|
||||
WHERE sw.warehouse_id = ? AND sw.is_valid = 'Y' AND sw.deleted_at IS NULL
|
||||
ORDER BY sw.id DESC LIMIT 8`, [ whId ]);
|
||||
console.log('== stock_warehouse products ==');
|
||||
console.log(JSON.stringify(stocks, null, 2));
|
||||
|
||||
const [spacesCols] = await conn.query('SHOW COLUMNS FROM wms_location_space');
|
||||
console.log('== wms_location_space columns ==');
|
||||
console.log(spacesCols.map(c => c.Field).join(','));
|
||||
|
||||
const [spaces] = await conn.query(`
|
||||
SELECT id, space_code, custom_name, is_enabled, current_quantity
|
||||
FROM wms_location_space
|
||||
WHERE warehouse_id = ? AND is_enabled = 1 AND deleted_at IS NULL
|
||||
ORDER BY id LIMIT 8`, [ whId ]);
|
||||
console.log('== location spaces ==');
|
||||
console.log(JSON.stringify(spaces, null, 2));
|
||||
|
||||
await conn.end();
|
||||
})().catch(e => { console.error(e); process.exit(1); });
|
||||
136
script/tmp-test-putaway-batch-compare.cjs
Normal file
136
script/tmp-test-putaway-batch-compare.cjs
Normal file
@ -0,0 +1,136 @@
|
||||
'use strict';
|
||||
/**
|
||||
* 批次维度对比测试(真实接口):
|
||||
* 1. A 两步:批次 B-A-1 入库 10 件 → storage 建行
|
||||
* 2. B 一步:批次 B-B-1 入库 10 件 → storage 建行(不同批次不互相影响)
|
||||
* 3. A 两步:批次 B-A-1 再入库 5 件 → 同批次累加到 15
|
||||
* 4. B 一步:批次 B-B-1 再入库 5 件 → 同批次累加到 15
|
||||
* 商品 159061 / 库位 5918。测试数据不清理。
|
||||
*/
|
||||
const mysql = require('mysql2/promise');
|
||||
const jwt = require('jsonwebtoken');
|
||||
|
||||
const BASE = 'http://127.0.0.1:6060';
|
||||
const JWT_SECRET = 'E5#ex.g@,GfL_8?';
|
||||
const ACCOUNT_ID = 1;
|
||||
const STORE_ID = 1000000;
|
||||
const STOCK_ID = 159061;
|
||||
const SPACE_ID = 5918;
|
||||
|
||||
const token = jwt.sign({ id: ACCOUNT_ID }, JWT_SECRET, { expiresIn: 14400 });
|
||||
|
||||
async function db() {
|
||||
return mysql.createConnection({ host: '127.0.0.1', port: 3307, user: 'wms', password: 'dspxmRwRdRbWtbm7', database: 'wms' });
|
||||
}
|
||||
|
||||
async function call(method, data) {
|
||||
const res = await fetch(`${BASE}/system?method=${method}&v=1×tamp=${Date.now()}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
platform: 'web',
|
||||
project: 'all',
|
||||
authorization: `Bearer ${token}`,
|
||||
},
|
||||
body: JSON.stringify(data || {}),
|
||||
});
|
||||
const text = await res.text();
|
||||
let parsed;
|
||||
try { parsed = JSON.parse(text); } catch { parsed = text; }
|
||||
return { http: res.status, body: parsed };
|
||||
}
|
||||
|
||||
function step(name, res) {
|
||||
const code = res.body && res.body.code;
|
||||
const ok = res.http === 200 && res.body && res.body.flag === 'success' && (code === 200 || code === 1);
|
||||
console.log(` [${ok ? 'OK' : 'FAIL'}] ${name} http=${res.http} code=${code} msg=${res.body && res.body.message}`);
|
||||
if (!ok) console.log(' 响应:', JSON.stringify(res.body).slice(0, 600));
|
||||
return ok;
|
||||
}
|
||||
|
||||
async function runFlow(tag, mode, batchNo, qty) {
|
||||
console.log(`\n===== ${tag}:批次=${batchNo} 数量=${qty} =====`);
|
||||
const conn = await db();
|
||||
const [before] = await conn.query(
|
||||
`SELECT quantity FROM wms_stock_warehouse WHERE id = ?`, [ STOCK_ID ]
|
||||
);
|
||||
|
||||
// 收货单全链路
|
||||
const createRes = await call('storage.receiving.create', {
|
||||
store_id: STORE_ID, delivery_method: 'other', loading_method: 'with_pallet',
|
||||
remark: `[批次对比-${tag}-${batchNo}]`, status: 'receiving',
|
||||
});
|
||||
const b = createRes.body || {};
|
||||
const receivingId = (b.data && b.data.id) || b.id;
|
||||
if (!step('创建收货单', createRes)) { await conn.end(); return null; }
|
||||
|
||||
const addRes = await call('storage.receiving.addDetail', {
|
||||
receiving_id: receivingId,
|
||||
item: { product_name: '批次对比测试商品', barcode: `B${Date.now()}`, actual_quantity: qty, batch_number: batchNo, space_id: SPACE_ID },
|
||||
});
|
||||
const addBody = addRes.body || {};
|
||||
const addData = addBody.data || addBody;
|
||||
const detailId = addData.selectId || (addData.details && addData.details[0] && addData.details[0].id);
|
||||
if (!step('添加明细', addRes)) { await conn.end(); return null; }
|
||||
|
||||
if (!step('绑定商品', await call('storage.receiving.bindDetailProduct', { detail_id: detailId, system_product_id: STOCK_ID }))) { await conn.end(); return null; }
|
||||
if (!step('完成收货', await call('storage.receiving.completeReceiving', { id: receivingId }))) { await conn.end(); return null; }
|
||||
if (!step('审核', await call('storage.receiving.reviewReceiving', { ids: [ receivingId ] }))) { await conn.end(); return null; }
|
||||
|
||||
let entryOrderId;
|
||||
if (mode === 'A') {
|
||||
const pRes = await call('storage.inventory.quickPutaway', { receiving_id: receivingId });
|
||||
if (!step('quickPutaway', pRes)) { await conn.end(); return null; }
|
||||
entryOrderId = pRes.body.data.entry_order_id;
|
||||
if (!step('addItem(绑定收货明细)', await call('storage.entry.addItem', {
|
||||
entry_order_id: entryOrderId,
|
||||
items: [{ stock_id: STOCK_ID, quantity: qty, space_id: SPACE_ID, receiving_detail_id: detailId, allocated_quantity: qty, inbound_type: 'pda' }],
|
||||
}))) { await conn.end(); return null; }
|
||||
if (!step('commit', await call('storage.entry.commit', { entry_order_id: entryOrderId }))) { await conn.end(); return null; }
|
||||
} else {
|
||||
const dRes = await call('storage.inventory.directPutaway', { receiving_id: receivingId });
|
||||
if (!step('directPutaway', dRes)) { await conn.end(); return null; }
|
||||
entryOrderId = dRes.body.data.entry_order_id;
|
||||
}
|
||||
|
||||
const [after] = await conn.query(
|
||||
`SELECT quantity FROM wms_stock_warehouse WHERE id = ?`, [ STOCK_ID ]
|
||||
);
|
||||
console.log(` ── wms_stock_warehouse ${STOCK_ID}: ${before[0].quantity} → ${after[0].quantity}(+${qty})`);
|
||||
|
||||
const [storages] = await conn.query(
|
||||
`SELECT id, space_id, stock_id, batch_no, inventory_type, quantity, available_quantity, inbound_order_no, entry_order_id
|
||||
FROM wms_storage WHERE stock_id = ? AND space_id = ? ORDER BY batch_no`, [ STOCK_ID, SPACE_ID ]
|
||||
);
|
||||
console.log(' ── wms_storage(商品 159061 / 库位 5918 全部行)──');
|
||||
console.log(' ', JSON.stringify(storages));
|
||||
|
||||
await conn.end();
|
||||
return { receivingId, entryOrderId };
|
||||
}
|
||||
|
||||
async function main() {
|
||||
await runFlow('① A-两步', 'A', 'B-A-1', 10);
|
||||
await runFlow('② B-一步', 'B', 'B-B-1', 10);
|
||||
await runFlow('③ A-两步(同批次累加)', 'A', 'B-A-1', 5);
|
||||
await runFlow('④ B-一步(同批次累加)', 'B', 'B-B-1', 5);
|
||||
|
||||
const conn = await db();
|
||||
const [storages] = await conn.query(
|
||||
`SELECT id, space_id, stock_id, batch_no, inventory_type, quantity, locked_quantity, available_quantity, inbound_order_no, receiving_id, entry_order_id
|
||||
FROM wms_storage WHERE stock_id = 159061 AND space_id = 5918 ORDER BY batch_no`
|
||||
);
|
||||
console.log('\n========== 最终 wms_storage 对比(商品 159061 / 库位 5918) ==========');
|
||||
console.log(JSON.stringify(storages, null, 2));
|
||||
|
||||
const [txns] = await conn.query(
|
||||
`SELECT order_no, transaction_type, stock_id, storage_id, space_id, quantity, before_quantity, after_quantity, batch_no, order_type
|
||||
FROM wms_storage_transaction WHERE stock_id = 159061 AND space_id = 5918 AND batch_no IN ('B-A-1','B-B-1') ORDER BY id`
|
||||
);
|
||||
console.log('\n========== 库位流水(批次 B-A-1 / B-B-1) ==========');
|
||||
console.log(JSON.stringify(txns, null, 2));
|
||||
await conn.end();
|
||||
console.log('\n================ 批次对比测试结束 ================');
|
||||
}
|
||||
|
||||
main().then(() => process.exit(0)).catch(e => { console.error(e); process.exit(1); });
|
||||
261
script/tmp-test-putaway-compare.cjs
Normal file
261
script/tmp-test-putaway-compare.cjs
Normal file
@ -0,0 +1,261 @@
|
||||
'use strict';
|
||||
/**
|
||||
* 临时对比测试:quickPutaway(转入库单) vs directPutaway(直入库存)
|
||||
* 全链路走真实接口:创建收货单 → 添加明细 → 绑定商品 → 完成收货 → 审核 → 上架。
|
||||
* 测试数据不清理,保留以便核对。
|
||||
* 用法:node script/tmp-test-putaway-compare.cjs
|
||||
*/
|
||||
const mysql = require('mysql2/promise');
|
||||
const jwt = require('jsonwebtoken');
|
||||
|
||||
const BASE = 'http://127.0.0.1:6060';
|
||||
const JWT_SECRET = 'E5#ex.g@,GfL_8?';
|
||||
const ACCOUNT_ID = 1;
|
||||
const WAREHOUSE_ID = 100000;
|
||||
const STORE_ID = 1000000;
|
||||
|
||||
// 商品:159061 非批次非效期;159064 效期管理(非批次)
|
||||
const PRODUCTS = [
|
||||
{ stock_id: 159061, item_code: '20260703', qty: 30, batch_number: 'TQB1', space_id: null },
|
||||
{ stock_id: 159064, item_code: '544354', qty: 7, batch_number: 'TQB2', production_date: '2026-01-01', expiry_date: '2027-01-01', space_id: null },
|
||||
];
|
||||
|
||||
const token = jwt.sign({ id: ACCOUNT_ID }, JWT_SECRET, { expiresIn: 14400 });
|
||||
|
||||
async function db() {
|
||||
return mysql.createConnection({
|
||||
host: '127.0.0.1', port: 3307, user: 'wms', password: 'dspxmRwRdRbWtbm7', database: 'wms',
|
||||
});
|
||||
}
|
||||
|
||||
async function call(method, data) {
|
||||
const res = await fetch(`${BASE}/system?method=${method}&v=1×tamp=${Date.now()}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
platform: 'web',
|
||||
project: 'all',
|
||||
authorization: `Bearer ${token}`,
|
||||
},
|
||||
body: JSON.stringify(data || {}),
|
||||
});
|
||||
const text = await res.text();
|
||||
let parsed;
|
||||
try { parsed = JSON.parse(text); } catch { parsed = text; }
|
||||
return { http: res.status, body: parsed };
|
||||
}
|
||||
|
||||
function step(name, res, extract) {
|
||||
const bodyCode = res.body && res.body.code;
|
||||
const ok = res.http === 200 && res.body && res.body.flag === 'success' && (bodyCode === 200 || bodyCode === 1);
|
||||
let extra = '';
|
||||
if (extract && res.body && res.body.data) {
|
||||
try { extra = JSON.stringify(extract(res.body.data)); } catch (e) { /* ignore */ }
|
||||
}
|
||||
console.log(` [${ok ? 'OK' : 'FAIL'}] ${name} http=${res.http} code=${bodyCode} msg=${res.body && res.body.message} ${extra}`);
|
||||
return ok;
|
||||
}
|
||||
|
||||
async function runFlow(tag, putawayMethod) {
|
||||
console.log(`\n================ 流程 ${tag}(${putawayMethod}) ================`);
|
||||
const conn = await db();
|
||||
|
||||
// 快照入库前商品总库存
|
||||
const stockIds = PRODUCTS.map(p => p.stock_id);
|
||||
const [beforeStock] = await conn.query(
|
||||
`SELECT id, quantity, locked_quantity FROM wms_stock_warehouse WHERE id IN (?)`, [ stockIds ]
|
||||
);
|
||||
|
||||
// 1. 创建收货单
|
||||
const createRes = await call('storage.receiving.create', {
|
||||
store_id: STORE_ID,
|
||||
delivery_method: 'other',
|
||||
loading_method: 'with_pallet',
|
||||
remark: `[自动对比测试-${tag}]`,
|
||||
status: 'receiving',
|
||||
});
|
||||
const createBody = createRes.body || {};
|
||||
const receivingId = createBody.data && createBody.data.id ? createBody.data.id : createBody.id;
|
||||
const receivingNumber = (createBody.data && createBody.data.receiving_number) || createBody.receiving_number;
|
||||
if (!step('创建收货单', createRes, () => ({ id: receivingId, receiving_number: receivingNumber }))) {
|
||||
console.log(' create 响应:', JSON.stringify(createBody).slice(0, 600));
|
||||
return { conn, receivingId: 0 };
|
||||
}
|
||||
console.log(` receiving_id=${receivingId} receiving_number=${receivingNumber}`);
|
||||
|
||||
// 2. 添加明细(含库位)
|
||||
const detailIds = [];
|
||||
for (let i = 0; i < PRODUCTS.length; i++) {
|
||||
const p = PRODUCTS[i];
|
||||
const addRes = await call('storage.receiving.addDetail', {
|
||||
receiving_id: receivingId,
|
||||
item: {
|
||||
product_name: `对比测试商品${i + 1}`,
|
||||
barcode: `TMPBC${Date.now()}${i}`,
|
||||
actual_quantity: p.qty,
|
||||
batch_number: p.batch_number,
|
||||
production_date: p.production_date || null,
|
||||
expiry_date: p.expiry_date || null,
|
||||
space_id: p.space_id,
|
||||
},
|
||||
});
|
||||
const addBody = addRes.body || {};
|
||||
const addData = addBody.data || addBody;
|
||||
const newDetailId = addData.selectId
|
||||
|| (addData.details && Array.isArray(addData.details) && addData.details[0] && addData.details[0].id);
|
||||
if (!step(`添加明细#${i + 1}`, addRes, () => ({ detail_id: newDetailId }))) {
|
||||
console.log(' addDetail 响应:', JSON.stringify(addBody).slice(0, 600));
|
||||
return { conn, receivingId };
|
||||
}
|
||||
detailIds.push(newDetailId);
|
||||
}
|
||||
|
||||
// 3. 绑定系统商品
|
||||
for (let i = 0; i < PRODUCTS.length; i++) {
|
||||
const bindRes = await call('storage.receiving.bindDetailProduct', {
|
||||
detail_id: detailIds[i],
|
||||
system_product_id: PRODUCTS[i].stock_id,
|
||||
});
|
||||
if (!step(`绑定商品#${i + 1}`, bindRes, d => ({ detail_id: d.detail_id, system_product_id: d.system_product_id }))) return { conn, receivingId };
|
||||
}
|
||||
|
||||
// 4. 完成收货
|
||||
const completeRes = await call('storage.receiving.completeReceiving', { id: receivingId });
|
||||
if (!step('完成收货', completeRes, d => ({ status: d.status || d.receiving_status }))) {
|
||||
console.log(' completeReceiving 响应:', JSON.stringify(completeRes.body).slice(0, 500));
|
||||
return { conn, receivingId };
|
||||
}
|
||||
|
||||
// 5. 审核
|
||||
const reviewRes = await call('storage.receiving.reviewReceiving', { ids: [ receivingId ] });
|
||||
if (!step('审核收货单', reviewRes)) {
|
||||
console.log(' reviewReceiving 响应:', JSON.stringify(reviewRes.body).slice(0, 500));
|
||||
return { conn, receivingId };
|
||||
}
|
||||
|
||||
// 6. 上架
|
||||
const putawayRes = await call(putawayMethod, { receiving_id: receivingId });
|
||||
if (!step(`上架(${putawayMethod})`, putawayRes, d => ({ entry_order_id: d.entry_order_id, entry_order_code: d.entry_order_code, order_status: d.order_status }))) {
|
||||
console.log(' 上架响应:', JSON.stringify(putawayRes.body).slice(0, 800));
|
||||
return { conn, receivingId };
|
||||
}
|
||||
|
||||
// 7. 对比验证数据
|
||||
const entryOrderId = putawayRes.body.data.entry_order_id;
|
||||
const entryOrderCode = putawayRes.body.data.entry_order_code;
|
||||
|
||||
const [afterStock] = await conn.query(
|
||||
`SELECT id, quantity, locked_quantity FROM wms_stock_warehouse WHERE id IN (?)`, [ stockIds ]
|
||||
);
|
||||
console.log(' ── 商品总库存(wms_stock_warehouse)──');
|
||||
for (const b of beforeStock) {
|
||||
const a = afterStock.find(x => String(x.id) === String(b.id)) || { quantity: '?', locked_quantity: '?' };
|
||||
console.log(` stock_id=${b.id} before=${b.quantity} after=${a.quantity} locked=${a.locked_quantity}`);
|
||||
}
|
||||
|
||||
const [entryOrder] = await conn.query(
|
||||
`SELECT id, entry_order_code, order_type, order_status, sync_status, total_order_lines FROM wms_entry_order WHERE id = ?`, [ entryOrderId ]
|
||||
);
|
||||
console.log(' ── 入库单(wms_entry_order)──');
|
||||
console.log(' ', JSON.stringify(entryOrder[0] || null));
|
||||
|
||||
const [entryItems] = await conn.query(
|
||||
`SELECT order_line_no, item_code, stock_id, count, received_quantity, inventory_type FROM wms_entry_items WHERE order_id = ? ORDER BY order_line_no`, [ entryOrderId ]
|
||||
);
|
||||
console.log(' ── 入库单明细(wms_entry_items,共 ' + entryItems.length + ' 行)──');
|
||||
console.log(' ', JSON.stringify(entryItems));
|
||||
|
||||
const [orderReceiving] = await conn.query(
|
||||
`SELECT entry_order_id, receiving_id FROM wms_entry_order_receiving WHERE entry_order_id = ?`, [ entryOrderId ]
|
||||
);
|
||||
console.log(' ── 绑定(wms_entry_order_receiving)──');
|
||||
console.log(' ', JSON.stringify(orderReceiving));
|
||||
|
||||
const [receivingRow] = await conn.query(
|
||||
`SELECT id, status, is_review, storage_status, detail_status FROM wms_receiving WHERE id = ?`, [ receivingId ]
|
||||
);
|
||||
console.log(' ── 收货单主表(wms_receiving)──');
|
||||
console.log(' ', JSON.stringify(receivingRow[0] || null));
|
||||
|
||||
const [receivingDetails] = await conn.query(
|
||||
`SELECT id, system_product_id, actual_quantity, stored_quantity, storage_status, space_id, batch_number FROM wms_receiving_detail WHERE receiving_id = ? ORDER BY id`, [ receivingId ]
|
||||
);
|
||||
console.log(' ── 收货明细(wms_receiving_detail)──');
|
||||
console.log(' ', JSON.stringify(receivingDetails));
|
||||
|
||||
const [storages] = await conn.query(
|
||||
`SELECT id, space_id, stock_id, batch_no, inventory_type, quantity, locked_quantity, available_quantity,
|
||||
inbound_order_no, receiving_id, entry_order_id, production_date, expiry_date
|
||||
FROM wms_storage
|
||||
WHERE entry_order_id = ? OR (inbound_order_no = ? AND receiving_id = ?)
|
||||
ORDER BY id`, [ entryOrderId, entryOrderCode, receivingId ]
|
||||
);
|
||||
console.log(' ── 库位库存(wms_storage,共 ' + storages.length + ' 行)──');
|
||||
console.log(' ', JSON.stringify(storages));
|
||||
|
||||
const [stockTxns] = await conn.query(
|
||||
`SELECT transaction_type, stock_id, quantity, before_quantity, after_quantity, batch_no, order_type, order_no, receiving_id, entry_order_id
|
||||
FROM wms_stock_transaction WHERE order_no = ? OR entry_order_id = ? ORDER BY id`, [ entryOrderCode, entryOrderId ]
|
||||
);
|
||||
console.log(' ── 商品流水(wms_stock_transaction,共 ' + stockTxns.length + ' 行)──');
|
||||
console.log(' ', JSON.stringify(stockTxns));
|
||||
|
||||
const [storageTxns] = await conn.query(
|
||||
`SELECT transaction_type, stock_id, storage_id, space_id, quantity, before_quantity, after_quantity, batch_no, order_type, order_no
|
||||
FROM wms_storage_transaction WHERE order_no = ? OR order_id = ? ORDER BY id`, [ entryOrderCode, entryOrderId ]
|
||||
);
|
||||
console.log(' ── 库位流水(wms_storage_transaction,共 ' + storageTxns.length + ' 行)──');
|
||||
console.log(' ', JSON.stringify(storageTxns));
|
||||
|
||||
const [opLogs] = await conn.query(
|
||||
`SELECT business_type, operation_code, business_id, operator_name, message
|
||||
FROM wms_operation_log WHERE business_id = ? ORDER BY id`, [ String(entryOrderId) ]
|
||||
);
|
||||
console.log(' ── 操作日志(wms_operation_log,共 ' + opLogs.length + ' 行)──');
|
||||
console.log(' ', JSON.stringify(opLogs));
|
||||
|
||||
await conn.end();
|
||||
return { receivingId, entryOrderId, entryOrderCode };
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const conn = await db();
|
||||
// 取两个真实库位
|
||||
const [spaces] = await conn.query(
|
||||
`SELECT id, space_code FROM wms_location_space WHERE warehouse_id = ? AND is_enabled = 1 AND deleted_at IS NULL ORDER BY id LIMIT 3`,
|
||||
[ WAREHOUSE_ID ]
|
||||
);
|
||||
console.log('使用库位:', JSON.stringify(spaces));
|
||||
PRODUCTS[0].space_id = spaces[0].id;
|
||||
PRODUCTS[1].space_id = spaces[1] ? spaces[1].id : spaces[0].id;
|
||||
|
||||
// 开关状态:quick 已开(货主 1000000 配置为 1);direct 需开启
|
||||
const [beforePolicy] = await conn.query(
|
||||
`SELECT policy_config FROM wms_store_warehouse WHERE store_id = ? AND warehouse_id = ?`, [ STORE_ID, WAREHOUSE_ID ]
|
||||
);
|
||||
console.log('货主 policy_config:', JSON.stringify(beforePolicy[0] && beforePolicy[0].policy_config));
|
||||
await conn.end();
|
||||
|
||||
// 流程 A:转入库单(可用 node script/tmp-test-putaway-compare.cjs A 单独跑)
|
||||
if (!process.argv[2] || process.argv[2] === 'A') {
|
||||
await runFlow('A-quickPutaway', 'storage.inventory.quickPutaway');
|
||||
}
|
||||
|
||||
// 开启直入开关(测试准备,SQL 直接配置)
|
||||
const conn2 = await db();
|
||||
await conn2.query(
|
||||
`UPDATE wms_store_warehouse SET policy_config = JSON_SET(COALESCE(policy_config,'{}'), '$.allow_receiving_direct_putaway', 1)
|
||||
WHERE store_id = ? AND warehouse_id = ?`, [ STORE_ID, WAREHOUSE_ID ]
|
||||
);
|
||||
await conn2.end();
|
||||
console.log('\n已开启 allow_receiving_direct_putaway=1(store=1000000, warehouse=100000)');
|
||||
|
||||
// 流程 B:直入库存
|
||||
if (!process.argv[2] || process.argv[2] === 'B') {
|
||||
await runFlow('B-directPutaway', 'storage.inventory.directPutaway');
|
||||
}
|
||||
|
||||
console.log('\n================ 测试结束 ================');
|
||||
}
|
||||
|
||||
main().then(() => process.exit(0)).catch(e => { console.error(e); process.exit(1); });
|
||||
281
script/tmp-test-putaway-full-compare.cjs
Normal file
281
script/tmp-test-putaway-full-compare.cjs
Normal file
@ -0,0 +1,281 @@
|
||||
'use strict';
|
||||
/**
|
||||
* 临时完整对比测试:
|
||||
* 流程 A(两步):storage.inventory.quickPutaway(转入库单)
|
||||
* → storage.entry.addItem(导入入库,绑定收货明细)
|
||||
* → storage.entry.commit(提交确认写库存)
|
||||
* 流程 B(一步):storage.inventory.directPutaway(直入库存)
|
||||
* 收货单链路全部走真实接口。测试数据不清理。
|
||||
* 用法:node script/tmp-test-putaway-full-compare.cjs [A|B]
|
||||
*/
|
||||
const mysql = require('mysql2/promise');
|
||||
const jwt = require('jsonwebtoken');
|
||||
|
||||
const BASE = 'http://127.0.0.1:6060';
|
||||
const JWT_SECRET = 'E5#ex.g@,GfL_8?';
|
||||
const ACCOUNT_ID = 1;
|
||||
const WAREHOUSE_ID = 100000;
|
||||
const STORE_ID = 1000000;
|
||||
|
||||
const PRODUCTS = [
|
||||
{ stock_id: 159061, item_code: '20260703', qty: 30, batch_number: 'TQB1', space_id: null },
|
||||
{ stock_id: 159064, item_code: '544354', qty: 7, batch_number: 'TQB2', production_date: '2026-01-01', expiry_date: '2027-01-01', space_id: null },
|
||||
];
|
||||
|
||||
const token = jwt.sign({ id: ACCOUNT_ID }, JWT_SECRET, { expiresIn: 14400 });
|
||||
|
||||
async function db() {
|
||||
return mysql.createConnection({
|
||||
host: '127.0.0.1', port: 3307, user: 'wms', password: 'dspxmRwRdRbWtbm7', database: 'wms',
|
||||
});
|
||||
}
|
||||
|
||||
async function call(method, data) {
|
||||
const res = await fetch(`${BASE}/system?method=${method}&v=1×tamp=${Date.now()}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
platform: 'web',
|
||||
project: 'all',
|
||||
authorization: `Bearer ${token}`,
|
||||
},
|
||||
body: JSON.stringify(data || {}),
|
||||
});
|
||||
const text = await res.text();
|
||||
let parsed;
|
||||
try { parsed = JSON.parse(text); } catch { parsed = text; }
|
||||
return { http: res.status, body: parsed };
|
||||
}
|
||||
|
||||
function step(name, res, extract) {
|
||||
const bodyCode = res.body && res.body.code;
|
||||
const ok = res.http === 200 && res.body && res.body.flag === 'success' && (bodyCode === 200 || bodyCode === 1);
|
||||
let extra = '';
|
||||
if (extract && res.body && res.body.data) {
|
||||
try { extra = JSON.stringify(extract(res.body.data)); } catch (e) { /* ignore */ }
|
||||
}
|
||||
console.log(` [${ok ? 'OK' : 'FAIL'}] ${name} http=${res.http} code=${bodyCode} msg=${res.body && res.body.message} ${extra}`);
|
||||
return ok;
|
||||
}
|
||||
|
||||
async function verifyFlow(conn, tag, receivingId, entryOrderId, entryOrderCode, beforeStock) {
|
||||
const stockIds = PRODUCTS.map(p => p.stock_id);
|
||||
const [afterStock] = await conn.query(
|
||||
`SELECT id, quantity, locked_quantity FROM wms_stock_warehouse WHERE id IN (?)`, [ stockIds ]
|
||||
);
|
||||
console.log(` ── [${tag}] 商品总库存(wms_stock_warehouse)──`);
|
||||
for (const b of beforeStock) {
|
||||
const a = afterStock.find(x => String(x.id) === String(b.id)) || { quantity: '?', locked_quantity: '?' };
|
||||
console.log(` stock_id=${b.id} before=${b.quantity} after=${a.quantity} locked=${a.locked_quantity}`);
|
||||
}
|
||||
|
||||
const [entryOrder] = await conn.query(
|
||||
`SELECT id, entry_order_code, order_type, order_status, sync_status, total_order_lines FROM wms_entry_order WHERE id = ?`, [ entryOrderId ]
|
||||
);
|
||||
console.log(` ── [${tag}] 入库单(wms_entry_order)──`);
|
||||
console.log(' ', JSON.stringify(entryOrder[0] || null));
|
||||
|
||||
const [entryItems] = await conn.query(
|
||||
`SELECT order_line_no, item_code, stock_id, count, received_quantity, inventory_type FROM wms_entry_items WHERE order_id = ? ORDER BY order_line_no`, [ entryOrderId ]
|
||||
);
|
||||
console.log(` ── [${tag}] 入库单明细(wms_entry_items,共 ${entryItems.length} 行)──`);
|
||||
console.log(' ', JSON.stringify(entryItems));
|
||||
|
||||
const [orderReceiving] = await conn.query(
|
||||
`SELECT entry_order_id, receiving_id FROM wms_entry_order_receiving WHERE entry_order_id = ?`, [ entryOrderId ]
|
||||
);
|
||||
console.log(` ── [${tag}] 绑定(wms_entry_order_receiving)──`);
|
||||
console.log(' ', JSON.stringify(orderReceiving));
|
||||
|
||||
const [receivingRow] = await conn.query(
|
||||
`SELECT id, status, is_review, storage_status, detail_status FROM wms_receiving WHERE id = ?`, [ receivingId ]
|
||||
);
|
||||
console.log(` ── [${tag}] 收货单主表(wms_receiving)──`);
|
||||
console.log(' ', JSON.stringify(receivingRow[0] || null));
|
||||
|
||||
const [receivingDetails] = await conn.query(
|
||||
`SELECT id, system_product_id, actual_quantity, stored_quantity, storage_status, space_id, batch_number FROM wms_receiving_detail WHERE receiving_id = ? ORDER BY id`, [ receivingId ]
|
||||
);
|
||||
console.log(` ── [${tag}] 收货明细(wms_receiving_detail)──`);
|
||||
console.log(' ', JSON.stringify(receivingDetails));
|
||||
|
||||
const [storages] = await conn.query(
|
||||
`SELECT id, space_id, stock_id, batch_no, inventory_type, quantity, locked_quantity, available_quantity,
|
||||
inbound_order_no, receiving_id, entry_order_id, production_date, expiry_date
|
||||
FROM wms_storage
|
||||
WHERE entry_order_id = ? OR (inbound_order_no = ? AND receiving_id = ?)
|
||||
ORDER BY id`, [ entryOrderId, entryOrderCode, receivingId ]
|
||||
);
|
||||
console.log(` ── [${tag}] 库位库存(wms_storage,共 ${storages.length} 行)──`);
|
||||
console.log(' ', JSON.stringify(storages));
|
||||
|
||||
const [stockTxns] = await conn.query(
|
||||
`SELECT transaction_type, stock_id, quantity, before_quantity, after_quantity, batch_no, order_type, order_no, receiving_id, entry_order_id
|
||||
FROM wms_stock_transaction WHERE order_no = ? OR entry_order_id = ? ORDER BY id`, [ entryOrderCode, entryOrderId ]
|
||||
);
|
||||
console.log(` ── [${tag}] 商品流水(wms_stock_transaction,共 ${stockTxns.length} 行)──`);
|
||||
console.log(' ', JSON.stringify(stockTxns));
|
||||
|
||||
const [storageTxns] = await conn.query(
|
||||
`SELECT transaction_type, stock_id, storage_id, space_id, quantity, before_quantity, after_quantity, batch_no, order_type, order_no
|
||||
FROM wms_storage_transaction WHERE order_no = ? OR order_id = ? ORDER BY id`, [ entryOrderCode, entryOrderId ]
|
||||
);
|
||||
console.log(` ── [${tag}] 库位流水(wms_storage_transaction,共 ${storageTxns.length} 行)──`);
|
||||
console.log(' ', JSON.stringify(storageTxns));
|
||||
|
||||
const [directLogs] = await conn.query(
|
||||
`SELECT id, stock_id, quantity, entry_item_id, receiving_detail_id, space_id, status, inbound_type
|
||||
FROM wms_inbound_direct_log WHERE entry_order_id = ? ORDER BY id`, [ entryOrderId ]
|
||||
);
|
||||
console.log(` ── [${tag}] 导入入库记录(wms_inbound_direct_log,共 ${directLogs.length} 行)──`);
|
||||
console.log(' ', JSON.stringify(directLogs));
|
||||
|
||||
const [opLogs] = await conn.query(
|
||||
`SELECT business_type, operation_code, operator_name, message
|
||||
FROM wms_operation_log WHERE business_id = ? AND operation_code IN
|
||||
('ENTRY_ORDER_QUICK_PUTAWAY','ENTRY_ORDER_DIRECT_PUTAWAY','STORAGE_DIRECT_PUTAWAY','STOCK_DIRECT_PUTAWAY','DIRECT_INBOUND_ADD','DIRECT_INBOUND_COMMIT')
|
||||
ORDER BY id`, [ String(entryOrderId) ]
|
||||
);
|
||||
console.log(` ── [${tag}] 本流程操作日志(wms_operation_log,共 ${opLogs.length} 行)──`);
|
||||
console.log(' ', JSON.stringify(opLogs));
|
||||
}
|
||||
|
||||
async function runFlow(tag, mode) {
|
||||
console.log(`\n================ 流程 ${tag}(${mode}) ================`);
|
||||
const conn = await db();
|
||||
|
||||
const stockIds = PRODUCTS.map(p => p.stock_id);
|
||||
const [beforeStock] = await conn.query(
|
||||
`SELECT id, quantity, locked_quantity FROM wms_stock_warehouse WHERE id IN (?)`, [ stockIds ]
|
||||
);
|
||||
|
||||
// 收货单全链路
|
||||
const createRes = await call('storage.receiving.create', {
|
||||
store_id: STORE_ID,
|
||||
delivery_method: 'other',
|
||||
loading_method: 'with_pallet',
|
||||
remark: `[完整对比测试-${tag}]`,
|
||||
status: 'receiving',
|
||||
});
|
||||
const createBody = createRes.body || {};
|
||||
const receivingId = createBody.data && createBody.data.id ? createBody.data.id : createBody.id;
|
||||
const receivingNumber = (createBody.data && createBody.data.receiving_number) || createBody.receiving_number;
|
||||
if (!step('创建收货单', createRes, () => ({ id: receivingId, receiving_number: receivingNumber }))) {
|
||||
await conn.end(); return;
|
||||
}
|
||||
console.log(` receiving_id=${receivingId} receiving_number=${receivingNumber}`);
|
||||
|
||||
const detailIds = [];
|
||||
for (let i = 0; i < PRODUCTS.length; i++) {
|
||||
const p = PRODUCTS[i];
|
||||
const addRes = await call('storage.receiving.addDetail', {
|
||||
receiving_id: receivingId,
|
||||
item: {
|
||||
product_name: `完整对比测试商品${i + 1}`,
|
||||
barcode: `FULLBC${Date.now()}${i}`,
|
||||
actual_quantity: p.qty,
|
||||
batch_number: p.batch_number,
|
||||
production_date: p.production_date || null,
|
||||
expiry_date: p.expiry_date || null,
|
||||
space_id: p.space_id,
|
||||
},
|
||||
});
|
||||
const addBody = addRes.body || {};
|
||||
const addData = addBody.data || addBody;
|
||||
const newDetailId = addData.selectId
|
||||
|| (addData.details && Array.isArray(addData.details) && addData.details[0] && addData.details[0].id);
|
||||
if (!step(`添加明细#${i + 1}`, addRes, () => ({ detail_id: newDetailId }))) { await conn.end(); return; }
|
||||
detailIds.push(newDetailId);
|
||||
}
|
||||
|
||||
for (let i = 0; i < PRODUCTS.length; i++) {
|
||||
const bindRes = await call('storage.receiving.bindDetailProduct', {
|
||||
detail_id: detailIds[i],
|
||||
system_product_id: PRODUCTS[i].stock_id,
|
||||
});
|
||||
if (!step(`绑定商品#${i + 1}`, bindRes, d => ({ detail_id: d.detail_id, system_product_id: d.system_product_id }))) { await conn.end(); return; }
|
||||
}
|
||||
|
||||
const completeRes = await call('storage.receiving.completeReceiving', { id: receivingId });
|
||||
if (!step('完成收货', completeRes)) {
|
||||
console.log(' completeReceiving 响应:', JSON.stringify(completeRes.body).slice(0, 500));
|
||||
await conn.end(); return;
|
||||
}
|
||||
|
||||
const reviewRes = await call('storage.receiving.reviewReceiving', { ids: [ receivingId ] });
|
||||
if (!step('审核收货单', reviewRes)) {
|
||||
console.log(' reviewReceiving 响应:', JSON.stringify(reviewRes.body).slice(0, 500));
|
||||
await conn.end(); return;
|
||||
}
|
||||
|
||||
let entryOrderId;
|
||||
let entryOrderCode;
|
||||
|
||||
if (mode === 'A') {
|
||||
// 两步流程第一步:转入库单
|
||||
const putawayRes = await call('storage.inventory.quickPutaway', { receiving_id: receivingId });
|
||||
if (!step('① quickPutaway(转入库单)', putawayRes, d => ({ entry_order_id: d.entry_order_id, entry_order_code: d.entry_order_code, order_status: d.order_status }))) {
|
||||
console.log(' 响应:', JSON.stringify(putawayRes.body).slice(0, 600));
|
||||
await conn.end(); return;
|
||||
}
|
||||
entryOrderId = putawayRes.body.data.entry_order_id;
|
||||
entryOrderCode = putawayRes.body.data.entry_order_code;
|
||||
|
||||
// 两步流程第二步:导入入库(绑定收货明细 + 收货明细库位)
|
||||
const addItemRes = await call('storage.entry.addItem', {
|
||||
entry_order_id: entryOrderId,
|
||||
items: [
|
||||
{ stock_id: PRODUCTS[0].stock_id, quantity: PRODUCTS[0].qty, space_id: PRODUCTS[0].space_id, receiving_detail_id: detailIds[0], allocated_quantity: PRODUCTS[0].qty, inbound_type: 'pda' },
|
||||
{ stock_id: PRODUCTS[1].stock_id, quantity: PRODUCTS[1].qty, space_id: PRODUCTS[1].space_id, receiving_detail_id: detailIds[1], allocated_quantity: PRODUCTS[1].qty, inbound_type: 'pda' },
|
||||
],
|
||||
});
|
||||
if (!step('② storage.entry.addItem(导入入库,绑定收货明细)', addItemRes, d => ({ count: d.count, total_quantity: d.total_quantity }))) {
|
||||
console.log(' 响应:', JSON.stringify(addItemRes.body).slice(0, 800));
|
||||
await conn.end(); return;
|
||||
}
|
||||
|
||||
// 两步流程第三步:提交确认写库存
|
||||
const commitRes = await call('storage.entry.commit', { entry_order_id: entryOrderId });
|
||||
if (!step('③ storage.entry.commit(提交确认入库)', commitRes, d => ({ success: d.success, message: d.message }))) {
|
||||
console.log(' 响应:', JSON.stringify(commitRes.body).slice(0, 800));
|
||||
await conn.end(); return;
|
||||
}
|
||||
} else {
|
||||
// 一步直入
|
||||
const directRes = await call('storage.inventory.directPutaway', { receiving_id: receivingId });
|
||||
if (!step('① directPutaway(一步直入)', directRes, d => ({ entry_order_id: d.entry_order_id, entry_order_code: d.entry_order_code, order_status: d.order_status }))) {
|
||||
console.log(' 响应:', JSON.stringify(directRes.body).slice(0, 600));
|
||||
await conn.end(); return;
|
||||
}
|
||||
entryOrderId = directRes.body.data.entry_order_id;
|
||||
entryOrderCode = directRes.body.data.entry_order_code;
|
||||
}
|
||||
|
||||
await verifyFlow(conn, tag, receivingId, entryOrderId, entryOrderCode, beforeStock);
|
||||
await conn.end();
|
||||
console.log(`================ 流程 ${tag} 完成:receiving=${receivingId} entry_order=${entryOrderId} ================`);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const conn = await db();
|
||||
const [spaces] = await conn.query(
|
||||
`SELECT id, space_code FROM wms_location_space WHERE warehouse_id = ? AND is_enabled = 1 AND deleted_at IS NULL ORDER BY id LIMIT 2`,
|
||||
[ WAREHOUSE_ID ]
|
||||
);
|
||||
console.log('使用库位:', JSON.stringify(spaces));
|
||||
PRODUCTS[0].space_id = spaces[0].id;
|
||||
PRODUCTS[1].space_id = spaces[1] ? spaces[1].id : spaces[0].id;
|
||||
await conn.end();
|
||||
|
||||
const only = (process.argv[2] || '').toUpperCase();
|
||||
if (!only || only === 'A') {
|
||||
await runFlow('A-两步', 'A');
|
||||
}
|
||||
if (!only || only === 'B') {
|
||||
await runFlow('B-一步', 'B');
|
||||
}
|
||||
|
||||
console.log('\n================ 测试结束 ================');
|
||||
}
|
||||
|
||||
main().then(() => process.exit(0)).catch(e => { console.error(e); process.exit(1); });
|
||||
103
script/tmp-verify-all-tables.cjs
Normal file
103
script/tmp-verify-all-tables.cjs
Normal file
@ -0,0 +1,103 @@
|
||||
'use strict';
|
||||
/**
|
||||
* 全表核对:A 两步链路(收货单 1526 / 入库单 383) vs B 一步直入(收货单 1528 / 入库单 385)
|
||||
* 覆盖 A 链路涉及的所有表(收货单阶段 + 转入库单 + 导入入库 + 提交确认)。
|
||||
* 只读,不产生数据。
|
||||
*/
|
||||
const mysql = require('mysql2/promise');
|
||||
|
||||
const A = { receiving: 1526, entryOrder: 383, code: 'SCRK202608240003', detailIds: [ 2711, 2712 ] };
|
||||
const B = { receiving: 1528, entryOrder: 385, code: 'SCRK202608240005', detailIds: [ 2715, 2716 ] };
|
||||
|
||||
(async () => {
|
||||
const conn = await mysql.createConnection({
|
||||
host: '127.0.0.1', port: 3307, user: 'wms', password: 'dspxmRwRdRbWtbm7', database: 'wms',
|
||||
});
|
||||
|
||||
const show = async (title, sql, params) => {
|
||||
const [rows] = await conn.query(sql, params);
|
||||
console.log(`\n===== ${title} =====`);
|
||||
console.log(JSON.stringify(rows, null, 2));
|
||||
};
|
||||
|
||||
for (const [ tag, t ] of [ [ 'A-两步', A ], [ 'B-一步', B ] ]) {
|
||||
console.log(`\n########## ${tag}(receiving=${t.receiving}, entry_order=${t.entryOrder}) ##########`);
|
||||
|
||||
await show('1. wms_receiving 收货单主表', `
|
||||
SELECT id, receiving_number, status, is_review, storage_status, detail_status, store_id, warehouse_id, total_items, total_quantity
|
||||
FROM wms_receiving WHERE id = ?`, [ t.receiving ]);
|
||||
|
||||
await show('2. wms_receiving_detail 收货明细', `
|
||||
SELECT id, receiving_id, system_product_id, actual_quantity, stored_quantity, storage_status,
|
||||
space_id, batch_number, production_date, expiry_date, barcode, receiving_status
|
||||
FROM wms_receiving_detail WHERE receiving_id = ? ORDER BY id`, [ t.receiving ]);
|
||||
|
||||
await show('3. wms_entry_order 入库单', `
|
||||
SELECT id, entry_order_code, order_type, order_status, sync_status, sync_message, source_type,
|
||||
total_order_lines, warehouse_id, store_id, store_name, warehouse_name, remark
|
||||
FROM wms_entry_order WHERE id = ?`, [ t.entryOrder ]);
|
||||
|
||||
await show('4. wms_entry_items 入库明细', `
|
||||
SELECT id, order_id, order_line_no, item_code, stock_id, count, received_quantity, confirm_quantity, inventory_type
|
||||
FROM wms_entry_items WHERE order_id = ? ORDER BY order_line_no`, [ t.entryOrder ]);
|
||||
|
||||
await show('5. wms_entry_order_receiving 主表绑定', `
|
||||
SELECT id, entry_order_id, receiving_id, created_at FROM wms_entry_order_receiving WHERE entry_order_id = ?`, [ t.entryOrder ]);
|
||||
|
||||
await show('6. wms_inbound_direct_log 导入入库记录(两步中间态)', `
|
||||
SELECT id, entry_order_id, entry_order_code, stock_id, quantity, entry_item_id, receiving_detail_id, space_id, status, inbound_type, remark
|
||||
FROM wms_inbound_direct_log WHERE entry_order_id = ? ORDER BY id`, [ t.entryOrder ]);
|
||||
|
||||
await show('7. wms_stock_warehouse 商品总库存', `
|
||||
SELECT id, item_code, quantity, locked_quantity, is_valid FROM wms_stock_warehouse WHERE id IN (159061, 159064) ORDER BY id`);
|
||||
|
||||
await show('8. wms_storage 库位库存', `
|
||||
SELECT id, space_id, stock_id, batch_no, inventory_type, quantity, locked_quantity, available_quantity,
|
||||
inbound_order_no, receiving_id, entry_order_id, production_date, expiry_date, inbound_time
|
||||
FROM wms_storage WHERE entry_order_id = ? OR (inbound_order_no = ? AND receiving_id = ?) ORDER BY id`,
|
||||
[ t.entryOrder, t.code, t.receiving ]);
|
||||
|
||||
await show('9. wms_stock_transaction 商品流水', `
|
||||
SELECT id, transaction_type, stock_id, quantity, before_quantity, after_quantity,
|
||||
before_locked_quantity, after_locked_quantity, batch_no, order_type, order_no, receiving_id, entry_order_id, remark
|
||||
FROM wms_stock_transaction WHERE order_no = ? OR entry_order_id = ? ORDER BY id`, [ t.code, t.entryOrder ]);
|
||||
|
||||
await show('10. wms_storage_transaction 库位流水', `
|
||||
SELECT id, transaction_type, stock_id, storage_id, space_id, quantity, before_quantity, after_quantity,
|
||||
before_locked_quantity, after_locked_quantity, batch_no, inventory_type, order_type, order_no, order_id
|
||||
FROM wms_storage_transaction WHERE order_no = ? OR order_id = ? ORDER BY id`, [ t.code, t.entryOrder ]);
|
||||
|
||||
await show('11. wms_operation_log 本流程操作日志', `
|
||||
SELECT id, business_type, business_id, operation_code, operator_name, warehouse_id, message
|
||||
FROM wms_operation_log
|
||||
WHERE business_id = ? AND operation_code IN
|
||||
('RECEIVING_CREATE','RECEIVING_ADD_DETAIL','RECEIVING_BIND_PRODUCT','RECEIVING_COMPLETE','RECEIVING_REVIEW',
|
||||
'ENTRY_ORDER_QUICK_PUTAWAY','DIRECT_INBOUND_ADD','DIRECT_INBOUND_COMMIT',
|
||||
'ENTRY_ORDER_DIRECT_PUTAWAY','STORAGE_DIRECT_PUTAWAY','STOCK_DIRECT_PUTAWAY')
|
||||
ORDER BY id`, [ String(t.entryOrder) ]);
|
||||
|
||||
await show('12. wms_operation_log 收货单维度操作日志', `
|
||||
SELECT id, business_type, business_id, operation_code, operator_name, warehouse_id, message
|
||||
FROM wms_operation_log WHERE business_id = ? ORDER BY id`, [ String(t.receiving) ]);
|
||||
|
||||
await show('13. wms_store_warehouse 货主签约与开关', `
|
||||
SELECT id, store_id, warehouse_id, warehouse_use_status,
|
||||
JSON_EXTRACT(policy_config, '$.allow_receiving_quick_putaway') AS quick,
|
||||
JSON_EXTRACT(policy_config, '$.allow_receiving_direct_putaway') AS direct
|
||||
FROM wms_store_warehouse WHERE store_id = 1000000 AND warehouse_id = 100000`);
|
||||
|
||||
await show('14. wms_stock_barcodes 本次绑定的条码', `
|
||||
SELECT id, stock_id, warehouse_id, barcode
|
||||
FROM wms_stock_barcodes
|
||||
WHERE stock_id IN (159061, 159064)
|
||||
AND barcode IN (SELECT barcode FROM wms_receiving_detail WHERE receiving_id = ?)
|
||||
ORDER BY id`, [ t.receiving ]);
|
||||
|
||||
await show('15. wms_location_space 库位统计快照(入库链路不维护该统计)', `
|
||||
SELECT id, space_code, current_quantity, current_sku_count, is_enabled
|
||||
FROM wms_location_space WHERE id IN (5918, 5919)`);
|
||||
}
|
||||
|
||||
await conn.end();
|
||||
process.exit(0);
|
||||
})().catch(e => { console.error(e); process.exit(1); });
|
||||
Loading…
x
Reference in New Issue
Block a user