chore: ESLint auto-fix formatting (JSDoc, spacing, quotes, line endings)
This commit is contained in:
parent
7f05b26db2
commit
7854057244
@ -130,7 +130,7 @@ module.exports = appInfo => {
|
||||
'audio/x-m4a': 'audio',
|
||||
};
|
||||
config.cors = {
|
||||
origin: (ctx) => ctx.get('Origin'), // 动态返回请求源,配合 credentials: true 使用
|
||||
origin: ctx => ctx.get('Origin'), // 动态返回请求源,配合 credentials: true 使用
|
||||
allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS',
|
||||
exposeHeaders: 'Authorization',
|
||||
credentials: true, // 允许携带 cookie
|
||||
|
||||
@ -10,10 +10,10 @@ const FK_NAME = 'wms_express_setting_ibfk_1';
|
||||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||||
* @param {string} tableName 表名。
|
||||
* @param {string} indexName 索引名。
|
||||
* @returns {Promise<boolean>} 索引是否存在。
|
||||
* @return {Promise<boolean>} 索引是否存在。
|
||||
*/
|
||||
const hasIndex = async (queryInterface, tableName, indexName) => {
|
||||
const [rows] = await queryInterface.sequelize.query(
|
||||
const [ rows ] = await queryInterface.sequelize.query(
|
||||
`SHOW INDEX FROM \`${tableName}\` WHERE Key_name = :indexName`,
|
||||
{ replacements: { indexName } }
|
||||
);
|
||||
@ -25,10 +25,10 @@ const hasIndex = async (queryInterface, tableName, indexName) => {
|
||||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||||
* @param {string} tableName 表名。
|
||||
* @param {string} constraintName 约束名。
|
||||
* @returns {Promise<boolean>} 外键是否存在。
|
||||
* @return {Promise<boolean>} 外键是否存在。
|
||||
*/
|
||||
const hasForeignKey = async (queryInterface, tableName, constraintName) => {
|
||||
const [rows] = await queryInterface.sequelize.query(
|
||||
const [ rows ] = await queryInterface.sequelize.query(
|
||||
`SELECT CONSTRAINT_NAME
|
||||
FROM information_schema.TABLE_CONSTRAINTS
|
||||
WHERE CONSTRAINT_SCHEMA = DATABASE()
|
||||
@ -47,7 +47,7 @@ module.exports = {
|
||||
* 原 UNIQUE KEY `platform_code` ON (`express_code`, `warehouse_id`) 约束过紧,
|
||||
* 且该索引被外键 `wms_express_setting_ibfk_1`(express_code → wms_express.code)依赖。
|
||||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||||
* @returns {Promise<void>} 无返回值。
|
||||
* @return {Promise<void>} 无返回值。
|
||||
*/
|
||||
async up(queryInterface) {
|
||||
// 1. 先删除依赖该索引的外键约束
|
||||
@ -75,7 +75,7 @@ module.exports = {
|
||||
/**
|
||||
* 回滚迁移:恢复唯一索引与外键约束。
|
||||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||||
* @returns {Promise<void>} 无返回值。
|
||||
* @return {Promise<void>} 无返回值。
|
||||
*/
|
||||
async down(queryInterface) {
|
||||
// 1. 删除替代的普通索引
|
||||
|
||||
@ -9,10 +9,10 @@ const PLAIN_INDEX_NAME = 'idx_warehouse_platform_shop_name';
|
||||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||||
* @param {string} tableName 表名。
|
||||
* @param {string} indexName 索引名。
|
||||
* @returns {Promise<boolean>} 索引是否存在。
|
||||
* @return {Promise<boolean>} 索引是否存在。
|
||||
*/
|
||||
const hasIndex = async (queryInterface, tableName, indexName) => {
|
||||
const [rows] = await queryInterface.sequelize.query(
|
||||
const [ rows ] = await queryInterface.sequelize.query(
|
||||
`SHOW INDEX FROM \`${tableName}\` WHERE Key_name = :indexName`,
|
||||
{ replacements: { indexName } }
|
||||
);
|
||||
@ -26,7 +26,7 @@ module.exports = {
|
||||
* 触发 UNIQUE KEY `uk_warehouse_platform_shop_name` 约束冲突,导致 MySQL UPDATE 失败。
|
||||
* 故将此唯一约束降为普通索引,仅保留查询性能。
|
||||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||||
* @returns {Promise<void>} 无返回值。
|
||||
* @return {Promise<void>} 无返回值。
|
||||
*/
|
||||
async up(queryInterface) {
|
||||
// 1. 删除唯一索引
|
||||
@ -47,7 +47,7 @@ module.exports = {
|
||||
/**
|
||||
* 回滚迁移:恢复唯一约束。
|
||||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||||
* @returns {Promise<void>} 无返回值。
|
||||
* @return {Promise<void>} 无返回值。
|
||||
*/
|
||||
async down(queryInterface) {
|
||||
// 1. 删除普通索引
|
||||
|
||||
@ -117,7 +117,7 @@ const ROLE_UPDATES = [
|
||||
// 其他普工:排除设置模块(4-9,40,41,80,81,336,366,375)、财务、数据、测试、系统、敏感API、仓库管理API、视频
|
||||
permissions: '[1,11,12,13,14,15,17,18,19,20,21,22,24,25,26,27,29,30,38,39,43,44,45,46,48,49,50,54,55,57,58,61,62,63,64,65,66,67,68,69,70,71,72,74,75,76,77,78,79,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,108,244,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,281,283,290,291,292,293,294,295,296,297,298,299,300,303,304,305,306,307,309,333,334,335,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,357,358,361,364,365,370,373,374,376,377,379,380,381,382,383,384]',
|
||||
old: '[4-121]',
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@ -5,6 +5,7 @@ module.exports = {
|
||||
* 将 CREATED 状态合并到 PENDING:
|
||||
* 1. 先把现有 CREATED 行更新为 PENDING
|
||||
* 2. 再 ALTER TABLE 去掉 CREATED 枚举值
|
||||
* @param queryInterface
|
||||
*/
|
||||
up: async queryInterface => {
|
||||
// 先更新现有 CREATED 行
|
||||
@ -19,6 +20,7 @@ module.exports = {
|
||||
|
||||
/**
|
||||
* 回滚:将 CREATED 加回 ENUM(数据不回退,因为无法区分哪些行原本是 CREATED)
|
||||
* @param queryInterface
|
||||
*/
|
||||
down: async queryInterface => {
|
||||
await queryInterface.sequelize.query(
|
||||
|
||||
@ -134,17 +134,17 @@ module.exports = {
|
||||
},
|
||||
});
|
||||
|
||||
await queryInterface.addIndex(TABLE_NAME, ['warehouse_id', 'items_hash', 'items_crc', 'package_material_id'], {
|
||||
await queryInterface.addIndex(TABLE_NAME, [ 'warehouse_id', 'items_hash', 'items_crc', 'package_material_id' ], {
|
||||
unique: true,
|
||||
name: 'uk_item_material',
|
||||
});
|
||||
|
||||
await queryInterface.addIndex(TABLE_NAME, ['warehouse_id', 'is_active', 'items_hash', 'bind_count'], {
|
||||
await queryInterface.addIndex(TABLE_NAME, [ 'warehouse_id', 'is_active', 'items_hash', 'bind_count' ], {
|
||||
name: 'idx_lookup',
|
||||
});
|
||||
},
|
||||
|
||||
down: async (queryInterface) => {
|
||||
down: async queryInterface => {
|
||||
await queryInterface.dropTable(TABLE_NAME);
|
||||
},
|
||||
};
|
||||
|
||||
@ -4,29 +4,31 @@ module.exports = {
|
||||
/**
|
||||
* 修改 wms_api_app 表的唯一键 uk_interface_warehouse:
|
||||
* 从 (qimen_app_key, qimen_customer_id) 改为 (qimen_app_key, qimen_warehouse_code)
|
||||
* @param queryInterface
|
||||
*/
|
||||
up: async queryInterface => {
|
||||
// 1. 删除旧唯一键
|
||||
await queryInterface.sequelize.query(
|
||||
"ALTER TABLE wms_api_app DROP INDEX uk_interface_warehouse"
|
||||
'ALTER TABLE wms_api_app DROP INDEX uk_interface_warehouse'
|
||||
);
|
||||
// 2. 创建新唯一键
|
||||
await queryInterface.sequelize.query(
|
||||
"ALTER TABLE wms_api_app ADD UNIQUE INDEX uk_interface_warehouse (qimen_app_key, qimen_warehouse_code)"
|
||||
'ALTER TABLE wms_api_app ADD UNIQUE INDEX uk_interface_warehouse (qimen_app_key, qimen_warehouse_code)'
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* 回滚:恢复为 (qimen_app_key, qimen_customer_id)
|
||||
* @param queryInterface
|
||||
*/
|
||||
down: async queryInterface => {
|
||||
// 1. 删除新唯一键
|
||||
await queryInterface.sequelize.query(
|
||||
"ALTER TABLE wms_api_app DROP INDEX uk_interface_warehouse"
|
||||
'ALTER TABLE wms_api_app DROP INDEX uk_interface_warehouse'
|
||||
);
|
||||
// 2. 恢复旧唯一键
|
||||
await queryInterface.sequelize.query(
|
||||
"ALTER TABLE wms_api_app ADD UNIQUE INDEX uk_interface_warehouse (qimen_app_key, qimen_customer_id)"
|
||||
'ALTER TABLE wms_api_app ADD UNIQUE INDEX uk_interface_warehouse (qimen_app_key, qimen_customer_id)'
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
@ -5,6 +5,7 @@ module.exports = {
|
||||
* 为 wms_entry_order 增加 CREATED 状态:
|
||||
* ENUM 顺序: CREATING → CREATED → PENDING → CONFIRMED → PARTIAL_RECEIVED → COMPLETED → CANCELLED
|
||||
* 默认值改为 CREATED
|
||||
* @param queryInterface
|
||||
*/
|
||||
up: async queryInterface => {
|
||||
await queryInterface.sequelize.query(
|
||||
@ -16,6 +17,7 @@ module.exports = {
|
||||
* 回滚:
|
||||
* 1. 先将 CREATED 行更新为 PENDING
|
||||
* 2. 再移除 CREATED 枚举值,恢复默认值 PENDING
|
||||
* @param queryInterface
|
||||
*/
|
||||
down: async queryInterface => {
|
||||
await queryInterface.sequelize.query(
|
||||
|
||||
@ -8,6 +8,7 @@ module.exports = {
|
||||
* 前置条件:
|
||||
* - CONFIRMED 行数为 0,无需迁移
|
||||
* - PARTIAL_RECEIVED 的 11 行改为 PENDING
|
||||
* @param queryInterface
|
||||
*/
|
||||
up: async queryInterface => {
|
||||
// 将 PARTIAL_RECEIVED 和 CONFIRMED 记录统一刷成 PENDING
|
||||
@ -22,6 +23,7 @@ module.exports = {
|
||||
|
||||
/**
|
||||
* 回滚:恢复 CONFIRMED 和 PARTIAL_RECEIVED 到 ENUM 中(不回滚数据)
|
||||
* @param queryInterface
|
||||
*/
|
||||
down: async queryInterface => {
|
||||
await queryInterface.sequelize.query(
|
||||
|
||||
@ -46,21 +46,21 @@ module.exports = {
|
||||
},
|
||||
});
|
||||
|
||||
await queryInterface.addIndex(TABLE_NAME, ['entry_order_id'], {
|
||||
await queryInterface.addIndex(TABLE_NAME, [ 'entry_order_id' ], {
|
||||
name: 'idx_entry_order_id',
|
||||
});
|
||||
|
||||
await queryInterface.addIndex(TABLE_NAME, ['receiving_id'], {
|
||||
await queryInterface.addIndex(TABLE_NAME, [ 'receiving_id' ], {
|
||||
name: 'idx_receiving_id',
|
||||
});
|
||||
|
||||
await queryInterface.addIndex(TABLE_NAME, ['entry_order_id', 'receiving_id'], {
|
||||
await queryInterface.addIndex(TABLE_NAME, [ 'entry_order_id', 'receiving_id' ], {
|
||||
unique: true,
|
||||
name: 'uk_entry_order_receiving',
|
||||
});
|
||||
},
|
||||
|
||||
down: async (queryInterface) => {
|
||||
down: async queryInterface => {
|
||||
await queryInterface.dropTable(TABLE_NAME);
|
||||
},
|
||||
};
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
*/
|
||||
const logMigrationDbContext = async (queryInterface, phase, table) => {
|
||||
try {
|
||||
const [rows] = await queryInterface.sequelize.query(
|
||||
const [ rows ] = await queryInterface.sequelize.query(
|
||||
'SELECT DATABASE() AS db_name, @@hostname AS db_host, @@port AS db_port, CURRENT_USER() AS db_user'
|
||||
);
|
||||
const dbContext = Array.isArray(rows) && rows.length > 0 ? rows[0] : {};
|
||||
@ -35,11 +35,11 @@ const logMigrationDbContext = async (queryInterface, phase, table) => {
|
||||
* ALTER TABLE wms_receiving_detail MODIFY COLUMN storage_status ENUM('none','partial','all') NOT NULL DEFAULT 'none' COMMENT '入库状态:none-未入库, partial-部分入库, all-全部入库';
|
||||
*/
|
||||
|
||||
const UP_SQL_RECEIVING = `ALTER TABLE wms_receiving MODIFY COLUMN storage_status ENUM('none','waiting','partial','all') NOT NULL DEFAULT 'none' COMMENT '入库状态:none-未入库, waiting-等待入库, partial-部分入库, all-全部入库'`;
|
||||
const DOWN_SQL_RECEIVING = `ALTER TABLE wms_receiving MODIFY COLUMN storage_status ENUM('none','partial','all') NOT NULL DEFAULT 'none' COMMENT '入库状态:none-未入库, partial-部分入库, all-全部入库'`;
|
||||
const UP_SQL_RECEIVING = 'ALTER TABLE wms_receiving MODIFY COLUMN storage_status ENUM(\'none\',\'waiting\',\'partial\',\'all\') NOT NULL DEFAULT \'none\' COMMENT \'入库状态:none-未入库, waiting-等待入库, partial-部分入库, all-全部入库\'';
|
||||
const DOWN_SQL_RECEIVING = 'ALTER TABLE wms_receiving MODIFY COLUMN storage_status ENUM(\'none\',\'partial\',\'all\') NOT NULL DEFAULT \'none\' COMMENT \'入库状态:none-未入库, partial-部分入库, all-全部入库\'';
|
||||
|
||||
const UP_SQL_DETAIL = `ALTER TABLE wms_receiving_detail MODIFY COLUMN storage_status ENUM('none','waiting','partial','all') NOT NULL DEFAULT 'none' COMMENT '入库状态:none-未入库, waiting-等待入库, partial-部分入库, all-全部入库'`;
|
||||
const DOWN_SQL_DETAIL = `ALTER TABLE wms_receiving_detail MODIFY COLUMN storage_status ENUM('none','partial','all') NOT NULL DEFAULT 'none' COMMENT '入库状态:none-未入库, partial-部分入库, all-全部入库'`;
|
||||
const UP_SQL_DETAIL = 'ALTER TABLE wms_receiving_detail MODIFY COLUMN storage_status ENUM(\'none\',\'waiting\',\'partial\',\'all\') NOT NULL DEFAULT \'none\' COMMENT \'入库状态:none-未入库, waiting-等待入库, partial-部分入库, all-全部入库\'';
|
||||
const DOWN_SQL_DETAIL = 'ALTER TABLE wms_receiving_detail MODIFY COLUMN storage_status ENUM(\'none\',\'partial\',\'all\') NOT NULL DEFAULT \'none\' COMMENT \'入库状态:none-未入库, partial-部分入库, all-全部入库\'';
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
|
||||
@ -6,17 +6,17 @@ const reqBody = process.argv[4] || '{}';
|
||||
const options = {
|
||||
hostname: 'localhost',
|
||||
port: 6060,
|
||||
path: `/system?method=${method}&v=1×tamp=${Math.floor(Date.now()/1000)}`,
|
||||
path: `/system?method=${method}&v=1×tamp=${Math.floor(Date.now() / 1000)}`,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'platform': 'web',
|
||||
'project': 'wms',
|
||||
'Authorization': `Bearer ${token}`,
|
||||
platform: 'web',
|
||||
project: 'wms',
|
||||
Authorization: `Bearer ${token}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
};
|
||||
|
||||
const req = http.request(options, (res) => {
|
||||
const req = http.request(options, res => {
|
||||
let data = '';
|
||||
res.on('data', chunk => data += chunk);
|
||||
res.on('end', () => {
|
||||
@ -29,6 +29,6 @@ const req = http.request(options, (res) => {
|
||||
}
|
||||
});
|
||||
});
|
||||
req.on('error', (e) => console.error('ERROR:', e.message));
|
||||
req.on('error', e => console.error('ERROR:', e.message));
|
||||
req.write(reqBody);
|
||||
req.end();
|
||||
|
||||
@ -14,17 +14,17 @@ if (reqBodyFile && reqBodyFile.endsWith('.json')) {
|
||||
const options = {
|
||||
hostname: 'localhost',
|
||||
port: 6060,
|
||||
path: `/system?method=${method}&v=1×tamp=${Math.floor(Date.now()/1000)}`,
|
||||
path: `/system?method=${method}&v=1×tamp=${Math.floor(Date.now() / 1000)}`,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'platform': 'web',
|
||||
'project': 'wms',
|
||||
'Authorization': `Bearer ${token}`,
|
||||
platform: 'web',
|
||||
project: 'wms',
|
||||
Authorization: `Bearer ${token}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
};
|
||||
|
||||
const req = http.request(options, (res) => {
|
||||
const req = http.request(options, res => {
|
||||
let data = '';
|
||||
res.on('data', chunk => data += chunk);
|
||||
res.on('end', () => {
|
||||
@ -42,6 +42,6 @@ const req = http.request(options, (res) => {
|
||||
}
|
||||
});
|
||||
});
|
||||
req.on('error', (e) => console.error('REQUEST ERROR:', e.message));
|
||||
req.on('error', e => console.error('REQUEST ERROR:', e.message));
|
||||
req.write(reqBody);
|
||||
req.end();
|
||||
|
||||
@ -30,7 +30,7 @@ async function main() {
|
||||
|
||||
try {
|
||||
// 先查影响行数
|
||||
const [previewRows] = await sequelize.query(`
|
||||
const [ previewRows ] = await sequelize.query(`
|
||||
SELECT COUNT(1) AS count
|
||||
FROM wms_wave_pick_task_wave w
|
||||
INNER JOIN wms_wave_pick_task t ON t.id = w.task_id AND t.warehouse_id = w.warehouse_id
|
||||
@ -47,7 +47,7 @@ async function main() {
|
||||
}
|
||||
|
||||
// 执行更新
|
||||
const [result] = await sequelize.query(`
|
||||
const [ result ] = await sequelize.query(`
|
||||
UPDATE wms_wave_pick_task_wave w
|
||||
INNER JOIN wms_wave_pick_task t ON t.id = w.task_id AND t.warehouse_id = w.warehouse_id
|
||||
SET w.status = 1,
|
||||
|
||||
@ -9,21 +9,21 @@ async function main() {
|
||||
});
|
||||
|
||||
const key = 'store_warehouse:contract_config:1000028:1000241';
|
||||
|
||||
|
||||
try {
|
||||
const val = await redis.get(key);
|
||||
console.log('Current cache value:', val ? val.substring(0, 200) : 'NULL');
|
||||
|
||||
|
||||
await redis.del(key);
|
||||
console.log('✅ Cache key deleted:', key);
|
||||
|
||||
|
||||
// Verify
|
||||
const after = await redis.get(key);
|
||||
console.log('After delete:', after);
|
||||
} catch (e) {
|
||||
console.error('Error:', e.message);
|
||||
}
|
||||
|
||||
|
||||
redis.disconnect();
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* 截单时间逻辑真实 API 集成测试 (v2)
|
||||
*
|
||||
*
|
||||
* 测试目标: 验证 asyncProcessOrderCreated 中的截单时间兜底逻辑
|
||||
* 策略: 通过 SQL 直接更新 policy_config (绕过 API 权限问题),通过 API 创建订单并验证结果
|
||||
*/
|
||||
@ -32,17 +32,16 @@ function api(method, body) {
|
||||
const bodyStr = typeof body === 'string' ? body : JSON.stringify(body);
|
||||
const opts = {
|
||||
hostname: 'localhost', port: 6060,
|
||||
path: `/system?method=${method}&v=1×tamp=${Math.floor(Date.now()/1000)}`,
|
||||
path: `/system?method=${method}&v=1×tamp=${Math.floor(Date.now() / 1000)}`,
|
||||
method: 'POST',
|
||||
headers: { 'platform': 'web', 'project': 'wms', 'Authorization': `Bearer ${TOKEN}`, 'Content-Type': 'application/json' },
|
||||
headers: { platform: 'web', project: 'wms', Authorization: `Bearer ${TOKEN}`, 'Content-Type': 'application/json' },
|
||||
timeout: 60000,
|
||||
};
|
||||
const req = http.request(opts, res => {
|
||||
let d = '';
|
||||
res.on('data', c => d += c);
|
||||
res.on('end', () => {
|
||||
try { resolve({ status: res.statusCode, body: JSON.parse(d) }); }
|
||||
catch (e) { resolve({ status: res.statusCode, body: { _raw: d.substring(0, 300) } }); }
|
||||
try { resolve({ status: res.statusCode, body: JSON.parse(d) }); } catch (e) { resolve({ status: res.statusCode, body: { _raw: d.substring(0, 300) } }); }
|
||||
});
|
||||
});
|
||||
req.on('error', e => reject(e));
|
||||
@ -57,13 +56,13 @@ function sleep(ms) { return new Promise(r => setTimeout(r, ms)); }
|
||||
async function setPolicy(policyCfg) {
|
||||
const conn = await mysql.createConnection(DB_CONFIG);
|
||||
await conn.execute('UPDATE wms_store_warehouse SET policy_config = ? WHERE id = ?',
|
||||
[JSON.stringify(policyCfg), TEST.contractId]);
|
||||
[ JSON.stringify(policyCfg), TEST.contractId ]);
|
||||
await conn.end();
|
||||
}
|
||||
|
||||
async function dbQuery(sql, params = []) {
|
||||
const conn = await mysql.createConnection(DB_CONFIG);
|
||||
const [rows] = await conn.execute(sql, params);
|
||||
const [ rows ] = await conn.execute(sql, params);
|
||||
await conn.end();
|
||||
return rows;
|
||||
}
|
||||
@ -84,14 +83,14 @@ async function createOrder() {
|
||||
async function checkExpressAssignment(orderId) {
|
||||
const rows = await dbQuery(
|
||||
'SELECT id, order_id, warehouse_id FROM wms_order_express WHERE order_id = ? AND warehouse_id = ? LIMIT 1',
|
||||
[orderId, TEST.warehouseId]
|
||||
[ orderId, TEST.warehouseId ]
|
||||
);
|
||||
return rows.length > 0;
|
||||
}
|
||||
|
||||
async function runScene(label, sceneKey, expectedStep, expectedExpress) {
|
||||
console.log(`\n=== ${label} ===`);
|
||||
|
||||
|
||||
// 1. Set policy
|
||||
console.log(' [1] 设置 policy_config...');
|
||||
await setPolicy(POLICY[sceneKey]);
|
||||
@ -104,13 +103,13 @@ async function runScene(label, sceneKey, expectedStep, expectedExpress) {
|
||||
console.log(' [2] 创建订单...');
|
||||
const r = await createOrder();
|
||||
console.log(` status: ${r.status}`);
|
||||
|
||||
|
||||
const success = r.status === 200 && r.body && r.body.flag === 'success';
|
||||
if (!success) {
|
||||
console.log(` ❌ 创建失败: ${JSON.stringify(r.body).substring(0, 200)}`);
|
||||
return { pass: false, reason: 'create_failed', detail: r.body };
|
||||
}
|
||||
|
||||
|
||||
const orderId = r.body.order_id || r.body.data?.order_id;
|
||||
const step = r.body.step || r.body.data?.step;
|
||||
console.log(` order_id: ${orderId}, step: ${step} (预期=${expectedStep})`);
|
||||
@ -171,8 +170,8 @@ async function main() {
|
||||
console.log('============================================');
|
||||
const total = Object.keys(results).length;
|
||||
const passing = Object.values(results).filter(r => r.pass).length;
|
||||
|
||||
for (const [key, r] of Object.entries(results)) {
|
||||
|
||||
for (const [ key, r ] of Object.entries(results)) {
|
||||
const icon = r.pass ? '✅' : '❌';
|
||||
console.log(` ${icon} 场景 ${key}: step=${r.step}(预期${r.expectedStep}) express=${r.hasExpress}(预期${r.expectedExpress})`);
|
||||
}
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
/**
|
||||
* 截单时间逻辑真实 API 集成测试 (v3 - Final)
|
||||
*
|
||||
*
|
||||
* 测试 asyncProcessOrderCreated 的截单兜底逻辑
|
||||
*
|
||||
*
|
||||
* 场景 A: 免审核 + 未截单(23:59) → 应触发自动分配快递
|
||||
* 场景 B: 免审核 + 已截单(00:01) → 应跳过
|
||||
* 场景 C: 需要审核 → 应跳过 (step=0)
|
||||
@ -34,14 +34,13 @@ function api(method, body) {
|
||||
const bodyStr = JSON.stringify(body);
|
||||
const req = http.request({
|
||||
hostname: 'localhost', port: 6060,
|
||||
path: `/system?method=${method}&v=1×tamp=${Math.floor(Date.now()/1000)}`,
|
||||
path: `/system?method=${method}&v=1×tamp=${Math.floor(Date.now() / 1000)}`,
|
||||
method: 'POST',
|
||||
headers: { platform: 'web', project: 'wms', Authorization: `Bearer ${TOKEN}`, 'Content-Type': 'application/json' },
|
||||
timeout: 60000,
|
||||
}, res => {
|
||||
let d = ''; res.on('data', c => d += c); res.on('end', () => {
|
||||
try { resolve({ status: res.statusCode, body: JSON.parse(d) }); }
|
||||
catch (e) { resolve({ status: res.statusCode, body: { _raw: d.substring(0, 300) } }); }
|
||||
try { resolve({ status: res.statusCode, body: JSON.parse(d) }); } catch (e) { resolve({ status: res.statusCode, body: { _raw: d.substring(0, 300) } }); }
|
||||
});
|
||||
});
|
||||
req.on('error', e => reject(e));
|
||||
@ -53,7 +52,7 @@ function sleep(ms) { return new Promise(r => setTimeout(r, ms)); }
|
||||
|
||||
async function dbQuery(sql, params = []) {
|
||||
const conn = await mysql.createConnection(DB);
|
||||
const [rows] = await conn.execute(sql, params);
|
||||
const [ rows ] = await conn.execute(sql, params);
|
||||
await conn.end();
|
||||
return rows;
|
||||
}
|
||||
@ -64,9 +63,9 @@ async function setPolicy(sceneKey) {
|
||||
const policyObj = POLICY[sceneKey];
|
||||
const conn = await mysql.createConnection(DB);
|
||||
await conn.execute('UPDATE wms_store_warehouse SET policy_config = ? WHERE id = ?',
|
||||
[JSON.stringify(policyObj), CONTRACT_ID]);
|
||||
[ JSON.stringify(policyObj), CONTRACT_ID ]);
|
||||
await conn.end();
|
||||
|
||||
|
||||
// 通过 API 调用 savePolicyConfig 清除缓存
|
||||
console.log(' 调用 savePolicyConfig API 清除缓存...');
|
||||
const apiRes = await api('storeWarehouse.store.savePolicyConfig', { id: CONTRACT_ID, policy_config: policyObj });
|
||||
@ -112,13 +111,13 @@ async function runScene(label, sceneKey, expectedStep, checkExpressExpected) {
|
||||
console.log(` [1] 更新 policy_config → scene ${sceneKey}`);
|
||||
console.log(` ${JSON.stringify(POLICY[sceneKey])}`);
|
||||
await setPolicy(sceneKey);
|
||||
|
||||
|
||||
// 2. Wait for cache invalidation
|
||||
console.log(` [2] 等待缓存... (10秒让 600s cache 有机会清除)`);
|
||||
console.log(' [2] 等待缓存... (10秒让 600s cache 有机会清除)');
|
||||
await sleep(10000);
|
||||
|
||||
// 3. Create order via API
|
||||
console.log(` [3] API 创建订单...`);
|
||||
console.log(' [3] API 创建订单...');
|
||||
const r = await createOrder();
|
||||
console.log(` HTTP ${r.status}`);
|
||||
|
||||
@ -133,7 +132,7 @@ async function runScene(label, sceneKey, expectedStep, checkExpressExpected) {
|
||||
console.log(` order_id=${orderId}, api_step=${apiStep}, api_step_label="${r.body.step_label}"`);
|
||||
|
||||
// 4. Wait async processing
|
||||
console.log(` [4] 等待异步处理 (8秒)...`);
|
||||
console.log(' [4] 等待异步处理 (8秒)...');
|
||||
await sleep(8000);
|
||||
|
||||
// 5. Check DB
|
||||
@ -141,7 +140,7 @@ async function runScene(label, sceneKey, expectedStep, checkExpressExpected) {
|
||||
if (order) {
|
||||
console.log(` [5] DB 订单状态: step=${order.step}, status=${order.status}, wave_id=${order.wave_id}, logistics=${order.sys_logistics_code}`);
|
||||
} else {
|
||||
console.log(` [5] ⚠️ 数据库中未找到订单!`);
|
||||
console.log(' [5] ⚠️ 数据库中未找到订单!');
|
||||
return { pass: false, reason: 'DB中找不到订单' };
|
||||
}
|
||||
|
||||
@ -190,7 +189,7 @@ async function main() {
|
||||
console.log(' 测试结果汇总');
|
||||
console.log(`${'='.repeat(60)}`);
|
||||
let passCount = 0;
|
||||
for (const [key, r] of Object.entries(results)) {
|
||||
for (const [ key, r ] of Object.entries(results)) {
|
||||
const icon = r.pass ? '✅' : '❌';
|
||||
const detail = r.pass ? '' : ` | step=${r.step}≠${r.expectedStep} express=${r.hasExpress}≠${r.checkExpressExpected}`;
|
||||
console.log(` ${icon} 场景 ${key}${detail}`);
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
/**
|
||||
* 截单时间逻辑真实 API 集成测试
|
||||
*
|
||||
*
|
||||
* 测试目标: 验证 asyncProcessOrderCreated 中的截单时间兜底逻辑
|
||||
*
|
||||
*
|
||||
* 测试环境:
|
||||
* - Dev Server: http://localhost:6060
|
||||
* - Warehouse ID: 1000028 (天豹云仓)
|
||||
* - Store ID: 1000241
|
||||
* - Store-Warehouse ID: 100213
|
||||
*
|
||||
*
|
||||
* 测试步骤:
|
||||
* A) 免审核 + 未截单 → 应触发自动分配快递
|
||||
* B) 免审核 + 已截单 → 应跳过
|
||||
@ -40,14 +40,14 @@ function apiRequest(method, body) {
|
||||
path: `/system?method=${method}&v=1×tamp=${Math.floor(Date.now() / 1000)}`,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'platform': 'web',
|
||||
'project': 'wms',
|
||||
'Authorization': `Bearer ${TOKEN}`,
|
||||
platform: 'web',
|
||||
project: 'wms',
|
||||
Authorization: `Bearer ${TOKEN}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
timeout: 60000,
|
||||
};
|
||||
const req = http.request(options, (res) => {
|
||||
const req = http.request(options, res => {
|
||||
let data = '';
|
||||
res.on('data', chunk => data += chunk);
|
||||
res.on('end', () => {
|
||||
@ -60,7 +60,7 @@ function apiRequest(method, body) {
|
||||
resolve({ status: res.statusCode, body: parsed });
|
||||
});
|
||||
});
|
||||
req.on('error', (e) => reject(e));
|
||||
req.on('error', e => reject(e));
|
||||
req.on('timeout', () => { req.destroy(); reject(new Error('Request timeout')); });
|
||||
req.write(bodyStr);
|
||||
req.end();
|
||||
@ -73,6 +73,7 @@ function sleep(ms) {
|
||||
|
||||
/**
|
||||
* 更新 store_warehouse 的 policy_config
|
||||
* @param policyConfig
|
||||
*/
|
||||
async function updatePolicyConfig(policyConfig) {
|
||||
return await apiRequest('storeWarehouse.store.savePolicyConfig', {
|
||||
|
||||
@ -16,13 +16,13 @@ function apiRequest(method, body) {
|
||||
path: `/system?method=${method}&v=1×tamp=${Math.floor(Date.now() / 1000)}`,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'platform': 'web',
|
||||
'project': 'wms',
|
||||
'Authorization': `Bearer ${TOKEN}`,
|
||||
platform: 'web',
|
||||
project: 'wms',
|
||||
Authorization: `Bearer ${TOKEN}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
};
|
||||
const req = http.request(options, (res) => {
|
||||
const req = http.request(options, res => {
|
||||
let data = '';
|
||||
res.on('data', chunk => data += chunk);
|
||||
res.on('end', () => {
|
||||
@ -35,7 +35,7 @@ function apiRequest(method, body) {
|
||||
resolve({ status: res.statusCode, headers: res.headers, body, _rawLength: data.length });
|
||||
});
|
||||
});
|
||||
req.on('error', (e) => reject(e));
|
||||
req.on('error', e => reject(e));
|
||||
req.write(bodyStr);
|
||||
req.end();
|
||||
});
|
||||
|
||||
@ -46,15 +46,15 @@ async function main() {
|
||||
database: 'wms',
|
||||
});
|
||||
|
||||
const [result] = await conn.execute(
|
||||
const [ result ] = await conn.execute(
|
||||
'UPDATE wms_store_warehouse SET policy_config = ? WHERE id = ?',
|
||||
[policyStr, contractId]
|
||||
[ policyStr, contractId ]
|
||||
);
|
||||
console.log('Update result:', JSON.stringify(result));
|
||||
|
||||
const [rows] = await conn.execute(
|
||||
const [ rows ] = await conn.execute(
|
||||
'SELECT id, store_id, warehouse_id, policy_config FROM wms_store_warehouse WHERE id = ?',
|
||||
[contractId]
|
||||
[ contractId ]
|
||||
);
|
||||
console.log('Current record:', JSON.stringify(rows[0], null, 2));
|
||||
|
||||
|
||||
@ -2,28 +2,28 @@
|
||||
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 conn = await mysql.createConnection({ host: '127.0.0.1', port: 3307, user: 'wms', password: 'dspxmRwRdRbWtbm7', database: 'wms' });
|
||||
|
||||
const [tables] = await conn.query("SHOW TABLES LIKE 'wms_order_delivery%'");
|
||||
const [ tables ] = await conn.query("SHOW TABLES LIKE 'wms_order_delivery%'");
|
||||
console.log('order_delivery tables:');
|
||||
tables.forEach(t => console.log(' ', Object.values(t)[0]));
|
||||
|
||||
const [tables2] = await conn.query("SHOW TABLES LIKE '%recheck%'");
|
||||
const [ tables2 ] = await conn.query("SHOW TABLES LIKE '%recheck%'");
|
||||
console.log('recheck tables:');
|
||||
tables2.forEach(t => console.log(' ', Object.values(t)[0]));
|
||||
|
||||
const [tables3] = await conn.query("SHOW TABLES LIKE '%wave%'");
|
||||
const [ tables3 ] = await conn.query("SHOW TABLES LIKE '%wave%'");
|
||||
console.log('wave tables:');
|
||||
tables3.forEach(t => console.log(' ', Object.values(t)[0]));
|
||||
|
||||
// Check the current model table for warehouse 100000
|
||||
console.log('\nChecking wms_order_delivery for recheck_status:');
|
||||
try {
|
||||
const [rows] = await conn.query("SELECT * FROM wms_order_delivery WHERE warehouse_id = 100000 LIMIT 1");
|
||||
const [ rows ] = await conn.query('SELECT * FROM wms_order_delivery WHERE warehouse_id = 100000 LIMIT 1');
|
||||
if (rows.length > 0) {
|
||||
console.log('Keys:', Object.keys(rows[0]).join(', '));
|
||||
}
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
console.log('Error:', e.message);
|
||||
}
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@ 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 集成验证');
|
||||
@ -19,13 +19,13 @@ async function main() {
|
||||
|
||||
// === 步骤1: 检查订单分表 ===
|
||||
console.log('\n--- 步骤1: 检查订单分表 ---');
|
||||
const [tables] = await conn.query("SHOW TABLES LIKE 'wms_order_delivery_%'");
|
||||
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(`
|
||||
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
|
||||
@ -36,7 +36,7 @@ async function main() {
|
||||
|
||||
// === 步骤3: 查找最近有库存变更的 stock_warehouse ===
|
||||
console.log('\n--- 步骤3: wms_stock_warehouse 状态 (warehouse=100000) ---');
|
||||
const [swRows] = await conn.query(`
|
||||
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
|
||||
@ -47,7 +47,7 @@ async function main() {
|
||||
|
||||
// === 步骤4: wms_stock_transaction 最近记录 ===
|
||||
console.log('\n--- 步骤4: wms_stock_transaction 最近记录 ---');
|
||||
const [recentTx] = await conn.query(`
|
||||
const [ recentTx ] = await conn.query(`
|
||||
SELECT id, transaction_type, order_type, stock_id, quantity,
|
||||
before_quantity, after_quantity,
|
||||
before_locked_quantity, after_locked_quantity,
|
||||
@ -72,7 +72,7 @@ async function main() {
|
||||
|
||||
// === 步骤5: 统计 stock_transaction 的 before_locked/after_locked 非零记录 ===
|
||||
console.log('\n--- 步骤5: stock_transaction locked_quantity 变更统计 ---');
|
||||
const [lockedStats] = await conn.query(`
|
||||
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,
|
||||
@ -83,7 +83,7 @@ async function main() {
|
||||
|
||||
// === 步骤6: 检查 wms_stock_transaction 中 remark 包含"货主库存释放"的记录 ===
|
||||
console.log('\n--- 步骤6: 货主库存释放 stock_transaction 记录 ---');
|
||||
const [releaseTx] = await conn.query(`
|
||||
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
|
||||
@ -102,7 +102,7 @@ async function main() {
|
||||
console.log('\n' + '='.repeat(70));
|
||||
console.log('集成验证完成');
|
||||
console.log('='.repeat(70));
|
||||
|
||||
|
||||
} finally {
|
||||
await conn.end();
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
const mysql = require('mysql2/promise');
|
||||
const DB_CONFIG = {host:'127.0.0.1',port:3307,user:'wms',password:'dspxmRwRdRbWtbm7',database:'wms'};
|
||||
const DB_CONFIG = { host: '127.0.0.1', port: 3307, user: 'wms', password: 'dspxmRwRdRbWtbm7', database: 'wms' };
|
||||
const TABLE = 'wms_order_delivery_100000';
|
||||
|
||||
(async () => {
|
||||
@ -8,7 +8,7 @@ const TABLE = 'wms_order_delivery_100000';
|
||||
try {
|
||||
// More success candidates: pick_status = 'fin' AND recheck_status != 'fin'
|
||||
console.log('=== 已拣货未复核 ===');
|
||||
const [r1] = await conn.query(
|
||||
const [ r1 ] = await conn.query(
|
||||
`SELECT id, delivery_order_code, pick_status, recheck_status, wave_id
|
||||
FROM ${TABLE}
|
||||
WHERE storage_status='fin' AND post_status='fin' AND status='created'
|
||||
@ -21,7 +21,7 @@ const TABLE = 'wms_order_delivery_100000';
|
||||
|
||||
// Also check: pick_status='none' (未拣货未复核)
|
||||
console.log('=== 未拣货未复核 (pick_status=none) ===');
|
||||
const [r2] = await conn.query(
|
||||
const [ r2 ] = await conn.query(
|
||||
`SELECT id, delivery_order_code, pick_status, recheck_status
|
||||
FROM ${TABLE}
|
||||
WHERE storage_status='fin' AND post_status='fin' AND status='created'
|
||||
@ -34,7 +34,7 @@ const TABLE = 'wms_order_delivery_100000';
|
||||
|
||||
// Other pick statuses
|
||||
console.log('=== 其他拣货状态未复核 ===');
|
||||
const [r3] = await conn.query(
|
||||
const [ r3 ] = await conn.query(
|
||||
`SELECT id, delivery_order_code, pick_status, recheck_status
|
||||
FROM ${TABLE}
|
||||
WHERE storage_status='fin' AND post_status='fin' AND status='created'
|
||||
@ -46,5 +46,5 @@ const TABLE = 'wms_order_delivery_100000';
|
||||
console.log(` 共 ${r3.length} 条\n`);
|
||||
|
||||
await conn.end();
|
||||
} catch(e) { console.error(e.message); await conn.end(); }
|
||||
} catch (e) { console.error(e.message); await conn.end(); }
|
||||
})();
|
||||
|
||||
@ -21,7 +21,7 @@ async function queryTestOrders() {
|
||||
console.log('【成功用例候选】满足所有前置条件的订单(未复核):');
|
||||
console.log('-'.repeat(80));
|
||||
|
||||
const [successRows] = await conn.query(
|
||||
const [ successRows ] = await conn.query(
|
||||
`SELECT id, delivery_order_code, pre_delivery_order_code,
|
||||
storage_status, post_status, status, intercept_status,
|
||||
pick_status, recheck_status, wave_id, wave_no
|
||||
@ -34,7 +34,7 @@ async function queryTestOrders() {
|
||||
AND recheck_status != 'fin'
|
||||
ORDER BY pick_status ASC, id DESC
|
||||
LIMIT 10`,
|
||||
[WAREHOUSE_ID]
|
||||
[ WAREHOUSE_ID ]
|
||||
);
|
||||
|
||||
for (const row of successRows) {
|
||||
@ -52,7 +52,7 @@ async function queryTestOrders() {
|
||||
console.log('【失败用例候选 - storage_status != fin】未分配储位:');
|
||||
console.log('-'.repeat(80));
|
||||
|
||||
const [noStorageRows] = await conn.query(
|
||||
const [ noStorageRows ] = await conn.query(
|
||||
`SELECT id, delivery_order_code, pre_delivery_order_code,
|
||||
storage_status, post_status, status, intercept_status,
|
||||
pick_status, recheck_status
|
||||
@ -62,7 +62,7 @@ async function queryTestOrders() {
|
||||
AND (post_status = 'fin' OR 1=1)
|
||||
ORDER BY id DESC
|
||||
LIMIT 3`,
|
||||
[WAREHOUSE_ID]
|
||||
[ WAREHOUSE_ID ]
|
||||
);
|
||||
|
||||
for (const row of noStorageRows) {
|
||||
@ -75,7 +75,7 @@ async function queryTestOrders() {
|
||||
console.log('【失败用例候选 - post_status != fin】未分配快递:');
|
||||
console.log('-'.repeat(80));
|
||||
|
||||
const [noPostRows] = await conn.query(
|
||||
const [ noPostRows ] = await conn.query(
|
||||
`SELECT id, delivery_order_code, pre_delivery_order_code,
|
||||
storage_status, post_status, status, intercept_status,
|
||||
pick_status, recheck_status
|
||||
@ -85,7 +85,7 @@ async function queryTestOrders() {
|
||||
AND storage_status = 'fin'
|
||||
ORDER BY id DESC
|
||||
LIMIT 3`,
|
||||
[WAREHOUSE_ID]
|
||||
[ WAREHOUSE_ID ]
|
||||
);
|
||||
|
||||
for (const row of noPostRows) {
|
||||
@ -98,7 +98,7 @@ async function queryTestOrders() {
|
||||
console.log('【失败用例候选 - status != created】未同步:');
|
||||
console.log('-'.repeat(80));
|
||||
|
||||
const [noSyncRows] = await conn.query(
|
||||
const [ noSyncRows ] = await conn.query(
|
||||
`SELECT id, delivery_order_code, pre_delivery_order_code,
|
||||
storage_status, post_status, status, intercept_status,
|
||||
pick_status, recheck_status
|
||||
@ -109,7 +109,7 @@ async function queryTestOrders() {
|
||||
AND post_status = 'fin'
|
||||
ORDER BY id DESC
|
||||
LIMIT 3`,
|
||||
[WAREHOUSE_ID]
|
||||
[ WAREHOUSE_ID ]
|
||||
);
|
||||
|
||||
for (const row of noSyncRows) {
|
||||
@ -122,7 +122,7 @@ async function queryTestOrders() {
|
||||
console.log('【失败用例候选 - 已拦截】:');
|
||||
console.log('-'.repeat(80));
|
||||
|
||||
const [interceptedRows] = await conn.query(
|
||||
const [ interceptedRows ] = await conn.query(
|
||||
`SELECT id, delivery_order_code, pre_delivery_order_code,
|
||||
storage_status, post_status, status, intercept_status,
|
||||
pick_status, recheck_status
|
||||
@ -131,7 +131,7 @@ async function queryTestOrders() {
|
||||
AND intercept_status IN ('intercepted', 'intercepted_at_warehouse')
|
||||
ORDER BY id DESC
|
||||
LIMIT 3`,
|
||||
[WAREHOUSE_ID]
|
||||
[ WAREHOUSE_ID ]
|
||||
);
|
||||
|
||||
for (const row of interceptedRows) {
|
||||
|
||||
@ -15,7 +15,7 @@ async function main() {
|
||||
console.log('【成功用例候选】满足所有前置条件的订单(未复核):');
|
||||
console.log('-'.repeat(80));
|
||||
|
||||
const [successRows] = await conn.query(
|
||||
const [ successRows ] = await conn.query(
|
||||
`SELECT id, delivery_order_code, pre_delivery_order_code,
|
||||
storage_status, post_status, status, intercept_status,
|
||||
pick_status, recheck_status, wave_id, wave_no
|
||||
@ -39,7 +39,7 @@ async function main() {
|
||||
|
||||
console.log('='.repeat(80));
|
||||
console.log('【失败用例候选 - storage_status != fin】');
|
||||
const [noStorageRows] = await conn.query(
|
||||
const [ noStorageRows ] = await conn.query(
|
||||
`SELECT id, delivery_order_code, storage_status FROM ${TABLE} WHERE storage_status != 'fin' ORDER BY id DESC LIMIT 3`
|
||||
);
|
||||
noStorageRows.forEach(r => console.log(` ID: ${r.id} storage_status="${r.storage_status}"`));
|
||||
@ -48,7 +48,7 @@ async function main() {
|
||||
|
||||
console.log('='.repeat(80));
|
||||
console.log('【失败用例候选 - post_status != fin】');
|
||||
const [noPostRows] = await conn.query(
|
||||
const [ noPostRows ] = await conn.query(
|
||||
`SELECT id, delivery_order_code, post_status FROM ${TABLE} WHERE post_status != 'fin' AND storage_status = 'fin' ORDER BY id DESC LIMIT 3`
|
||||
);
|
||||
noPostRows.forEach(r => console.log(` ID: ${r.id} post_status="${r.post_status}"`));
|
||||
@ -57,7 +57,7 @@ async function main() {
|
||||
|
||||
console.log('='.repeat(80));
|
||||
console.log('【失败用例候选 - status != created】');
|
||||
const [noSyncRows] = await conn.query(
|
||||
const [ noSyncRows ] = await conn.query(
|
||||
`SELECT id, delivery_order_code, status FROM ${TABLE} WHERE status != 'created' AND storage_status = 'fin' AND post_status = 'fin' ORDER BY id DESC LIMIT 3`
|
||||
);
|
||||
noSyncRows.forEach(r => console.log(` ID: ${r.id} status="${r.status}"`));
|
||||
@ -66,7 +66,7 @@ async function main() {
|
||||
|
||||
console.log('='.repeat(80));
|
||||
console.log('【失败用例候选 - 已拦截】');
|
||||
const [interceptedRows] = await conn.query(
|
||||
const [ interceptedRows ] = await conn.query(
|
||||
`SELECT id, delivery_order_code, intercept_status FROM ${TABLE} WHERE intercept_status IN ('intercepted','intercepted_at_warehouse') ORDER BY id DESC LIMIT 3`
|
||||
);
|
||||
interceptedRows.forEach(r => console.log(` ID: ${r.id} intercept_status="${r.intercept_status}"`));
|
||||
|
||||
@ -4,13 +4,13 @@ const TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwidXNlcm5hbWUiOiJs
|
||||
const BASE_URL = 'http://127.0.0.1:6060';
|
||||
const TABLE = 'wms_order_delivery_100000';
|
||||
const mysql = require('mysql2/promise');
|
||||
const DB_CONFIG = {host:'127.0.0.1',port:3307,user:'wms',password:'dspxmRwRdRbWtbm7',database:'wms'};
|
||||
const DB_CONFIG = { host: '127.0.0.1', port: 3307, user: 'wms', password: 'dspxmRwRdRbWtbm7', database: 'wms' };
|
||||
|
||||
async function getOrderSnapshot(conn, ids) {
|
||||
if (!ids.length) return {};
|
||||
const [rows] = await conn.query(
|
||||
const [ rows ] = await conn.query(
|
||||
`SELECT id, pick_status, recheck_status, storage_status, post_status, status, intercept_status
|
||||
FROM ${TABLE} WHERE id IN (?)`, [ids]
|
||||
FROM ${TABLE} WHERE id IN (?)`, [ ids ]
|
||||
);
|
||||
const map = {};
|
||||
rows.forEach(r => { map[r.id] = r; });
|
||||
@ -21,10 +21,10 @@ async function callApi(ids) {
|
||||
const ts = Math.floor(Date.now() / 1000);
|
||||
const url = `${BASE_URL}/system?method=order.recheckOrder.batchQuickRecheck&v=1.0×tamp=${ts}`;
|
||||
const headers = {
|
||||
'platform': 'web',
|
||||
'project': 'wms',
|
||||
platform: 'web',
|
||||
project: 'wms',
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
'Authorization': `Bearer ${TOKEN}`,
|
||||
Authorization: `Bearer ${TOKEN}`,
|
||||
};
|
||||
const body = JSON.stringify({
|
||||
module: 'order.recheckOrder',
|
||||
@ -53,7 +53,7 @@ async function runTestCase(name, ids, expectedDesc) {
|
||||
// 测试前快照
|
||||
beforeSnapshot = await getOrderSnapshot(conn, ids);
|
||||
console.log(' 测试前状态:');
|
||||
for (const [id, snap] of Object.entries(beforeSnapshot)) {
|
||||
for (const [ id, snap ] of Object.entries(beforeSnapshot)) {
|
||||
console.log(` ID ${id}: pick="${snap.pick_status}" recheck="${snap.recheck_status}" storage="${snap.storage_status}" post="${snap.post_status}" status="${snap.status}" intercept="${snap.intercept_status}"`);
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ async function runTestCase(name, ids, expectedDesc) {
|
||||
// 测试后快照
|
||||
afterSnapshot = await getOrderSnapshot(conn, ids);
|
||||
console.log(' 测试后状态:');
|
||||
for (const [id, snap] of Object.entries(afterSnapshot)) {
|
||||
for (const [ id, snap ] of Object.entries(afterSnapshot)) {
|
||||
const before = beforeSnapshot[id] || {};
|
||||
const changes = [];
|
||||
if (snap.pick_status !== before.pick_status) changes.push(`pick: ${before.pick_status}→${snap.pick_status}`);
|
||||
@ -98,42 +98,42 @@ async function main() {
|
||||
// 用例1: 全成功-含未拣货(1个有效订单)
|
||||
results.push(await runTestCase(
|
||||
'用例1: 全成功-含未拣货',
|
||||
[120946],
|
||||
[ 120946 ],
|
||||
'pick_status=none → 自动完成拣货+复核, 全部 success'
|
||||
));
|
||||
|
||||
// 用例2: 全失败-无储位
|
||||
results.push(await runTestCase(
|
||||
'用例2: 全失败-无储位',
|
||||
[120947, 120939],
|
||||
[ 120947, 120939 ],
|
||||
'全部 failed, reason="未分配储位"'
|
||||
));
|
||||
|
||||
// 用例3: 全失败-无快递
|
||||
results.push(await runTestCase(
|
||||
'用例3: 全失败-无快递',
|
||||
[120944, 120943],
|
||||
[ 120944, 120943 ],
|
||||
'全部 failed, reason="没有分配快递"'
|
||||
));
|
||||
|
||||
// 用例4: 全失败-未同步
|
||||
results.push(await runTestCase(
|
||||
'用例4: 全失败-未同步',
|
||||
[120858, 120857],
|
||||
[ 120858, 120857 ],
|
||||
'全部 failed, reason="没有同步"'
|
||||
));
|
||||
|
||||
// 用例5: 全失败-已拦截
|
||||
results.push(await runTestCase(
|
||||
'用例5: 全失败-已拦截',
|
||||
[120945],
|
||||
[ 120945 ],
|
||||
'全部 failed, reason="已拦截"'
|
||||
));
|
||||
|
||||
// 用例6: 部分失败-混合
|
||||
results.push(await runTestCase(
|
||||
'用例6: 部分失败-混合',
|
||||
[120946, 120947, 999999999],
|
||||
[ 120946, 120947, 999999999 ],
|
||||
'success 和 failed 各有'
|
||||
));
|
||||
|
||||
@ -147,7 +147,7 @@ async function main() {
|
||||
// 用例8: 不存在ID
|
||||
results.push(await runTestCase(
|
||||
'用例8: 不存在ID',
|
||||
[999999999],
|
||||
[ 999999999 ],
|
||||
'全部 failed, reason="未找到对应订单"'
|
||||
));
|
||||
|
||||
|
||||
@ -29,10 +29,10 @@ async function closeConn() {
|
||||
async function getOrderSnapshot(ids) {
|
||||
const c = await getConn();
|
||||
if (!ids.length) return {};
|
||||
const [rows] = await c.query(
|
||||
const [ rows ] = await c.query(
|
||||
`SELECT id, delivery_order_code, pre_delivery_order_code,
|
||||
pick_status, recheck_status, storage_status, post_status, status, intercept_status
|
||||
FROM ${TABLE} WHERE id IN (?)`, [ids]
|
||||
FROM ${TABLE} WHERE id IN (?)`, [ ids ]
|
||||
);
|
||||
const map = {};
|
||||
rows.forEach(r => { map[r.id] = r; });
|
||||
@ -42,8 +42,8 @@ async function getOrderSnapshot(ids) {
|
||||
async function getStorageSnapshot(ids) {
|
||||
const c = await getConn();
|
||||
if (!ids.length) return {};
|
||||
const [rows] = await c.query(
|
||||
'SELECT id, quantity, locked_quantity FROM wms_storage WHERE id IN (?) AND warehouse_id = 100000', [ids]
|
||||
const [ rows ] = await c.query(
|
||||
'SELECT id, quantity, locked_quantity FROM wms_storage WHERE id IN (?) AND warehouse_id = 100000', [ ids ]
|
||||
);
|
||||
const map = {};
|
||||
rows.forEach(r => { map[r.id] = r; });
|
||||
@ -54,10 +54,10 @@ async function callApi(ids) {
|
||||
const ts = Math.floor(Date.now() / 1000);
|
||||
const url = `${BASE_URL}/system?method=order.recheckOrder.batchQuickRecheck&v=1.0×tamp=${ts}`;
|
||||
const headers = {
|
||||
'platform': 'web',
|
||||
'project': 'wms',
|
||||
platform: 'web',
|
||||
project: 'wms',
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
'Authorization': `Bearer ${TOKEN}`,
|
||||
Authorization: `Bearer ${TOKEN}`,
|
||||
};
|
||||
const body = JSON.stringify({ ids });
|
||||
|
||||
@ -76,7 +76,10 @@ async function runTestCase(name, ids, expectedDesc, preSetup, postVerify, postCl
|
||||
console.log(` 输入IDs: [${ids.join(', ')}]`);
|
||||
console.log(` 预期: ${expectedDesc}`);
|
||||
|
||||
let beforeOrder = {}, beforeStorage = {}, afterOrder = {}, afterStorage = {};
|
||||
let beforeOrder = {},
|
||||
beforeStorage = {},
|
||||
afterOrder = {},
|
||||
afterStorage = {};
|
||||
let passed = false;
|
||||
let failReason = '';
|
||||
|
||||
@ -91,7 +94,7 @@ async function runTestCase(name, ids, expectedDesc, preSetup, postVerify, postCl
|
||||
// 测试前快照
|
||||
beforeOrder = await getOrderSnapshot(ids);
|
||||
console.log(' 测试前订单状态:');
|
||||
for (const [id, snap] of Object.entries(beforeOrder)) {
|
||||
for (const [ id, snap ] of Object.entries(beforeOrder)) {
|
||||
console.log(` ID ${id}: storage="${snap.storage_status}" post="${snap.post_status}" status="${snap.status}" intercept="${snap.intercept_status}" pick="${snap.pick_status}" recheck="${snap.recheck_status}" code="${snap.delivery_order_code || snap.pre_delivery_order_code || ''}"`);
|
||||
}
|
||||
|
||||
@ -104,7 +107,7 @@ async function runTestCase(name, ids, expectedDesc, preSetup, postVerify, postCl
|
||||
// 测试后快照
|
||||
afterOrder = await getOrderSnapshot(ids);
|
||||
console.log(' 测试后订单状态:');
|
||||
for (const [id, snap] of Object.entries(afterOrder)) {
|
||||
for (const [ id, snap ] of Object.entries(afterOrder)) {
|
||||
const before = beforeOrder[id] || {};
|
||||
const changes = [];
|
||||
if (snap.pick_status !== before.pick_status) changes.push(`pick: ${before.pick_status}→${snap.pick_status}`);
|
||||
@ -155,7 +158,7 @@ async function main() {
|
||||
console.log(`测试时间: ${new Date().toISOString()}`);
|
||||
console.log(`目标表: ${TABLE}`);
|
||||
console.log(`Base URL: ${BASE_URL}`);
|
||||
console.log(`测试仓库ID: 100000 | 测试货主ID: 1000000`);
|
||||
console.log('测试仓库ID: 100000 | 测试货主ID: 1000000');
|
||||
console.log('='.repeat(60));
|
||||
|
||||
const results = [];
|
||||
@ -164,7 +167,7 @@ async function main() {
|
||||
console.log('\n── 全局前置:恢复 120946 关联库存 locked_quantity ──');
|
||||
const c = await getConn();
|
||||
// 记录 storage 184 原始状态
|
||||
const [origStorage] = await c.query('SELECT id, quantity, locked_quantity FROM wms_storage WHERE id = 184 AND warehouse_id = 100000');
|
||||
const [ origStorage ] = await c.query('SELECT id, quantity, locked_quantity FROM wms_storage WHERE id = 184 AND warehouse_id = 100000');
|
||||
console.log(` storage 184 原始: quantity=${origStorage[0].quantity}, locked=${origStorage[0].locked_quantity}`);
|
||||
// 恢复 locked_quantity 以便测试成功扣减
|
||||
if (origStorage[0].locked_quantity < 1) {
|
||||
@ -187,7 +190,7 @@ async function main() {
|
||||
[],
|
||||
'返回错误 "订单ID列表不能为空"',
|
||||
null,
|
||||
async (result) => {
|
||||
async result => {
|
||||
// batchQuickRecheck 返回 500 而非 400(内部 throw(400) 被框架包装为 500)
|
||||
// 检查是否包含错误消息
|
||||
const msg = result.body && (result.body.message || '');
|
||||
@ -200,10 +203,10 @@ async function main() {
|
||||
// ── 用例 8: 不存在的订单ID ──
|
||||
results.push(await runTestCase(
|
||||
'用例8: 不存在的订单ID',
|
||||
[999999999],
|
||||
[ 999999999 ],
|
||||
'全部 failed, reason="未找到对应订单"',
|
||||
null,
|
||||
async (result) => {
|
||||
async result => {
|
||||
const data = result.body && (result.body.data !== undefined ? result.body.data : result.body);
|
||||
if (!data || typeof data !== 'object') return `返回数据格式异常: ${JSON.stringify(result.body)}`;
|
||||
if (data.success_count === 0 && data.failed_count >= 1) {
|
||||
@ -218,10 +221,10 @@ async function main() {
|
||||
// ── 用例 5: 失败-未同步(120858: status='pedding') ──
|
||||
results.push(await runTestCase(
|
||||
'用例5: 失败-未同步',
|
||||
[120858, 120857],
|
||||
[ 120858, 120857 ],
|
||||
'全部 failed, reason="没有同步"',
|
||||
null,
|
||||
async (result) => {
|
||||
async result => {
|
||||
const data = result.body && (result.body.data !== undefined ? result.body.data : result.body);
|
||||
if (!data || data.success_count !== 0) return `期望 success_count=0,实际: ${JSON.stringify(data)}`;
|
||||
const allNoSync = (data.failed || []).every(f => f.reason === '没有同步');
|
||||
@ -233,10 +236,10 @@ async function main() {
|
||||
// ── 用例 4: 失败-无快递(120944: post_status='none') ──
|
||||
results.push(await runTestCase(
|
||||
'用例4: 失败-无快递',
|
||||
[120944, 120943],
|
||||
[ 120944, 120943 ],
|
||||
'全部 failed, reason="没有分配快递"',
|
||||
null,
|
||||
async (result) => {
|
||||
async result => {
|
||||
const data = result.body && (result.body.data !== undefined ? result.body.data : result.body);
|
||||
if (!data || data.success_count !== 0) return `期望 success_count=0,实际: ${JSON.stringify(data)}`;
|
||||
const allNoPost = (data.failed || []).every(f => f.reason === '没有分配快递');
|
||||
@ -248,10 +251,10 @@ async function main() {
|
||||
// ── 用例 3: 失败-未分配储位(120947: storage_status='none') ──
|
||||
results.push(await runTestCase(
|
||||
'用例3: 失败-未分配储位',
|
||||
[120947, 120939],
|
||||
[ 120947, 120939 ],
|
||||
'全部 failed, reason="未分配储位"',
|
||||
null,
|
||||
async (result) => {
|
||||
async result => {
|
||||
const data = result.body && (result.body.data !== undefined ? result.body.data : result.body);
|
||||
if (!data || data.success_count !== 0) return `期望 success_count=0,实际: ${JSON.stringify(data)}`;
|
||||
const allNoStorage = (data.failed || []).every(f => f.reason === '未分配储位');
|
||||
@ -263,10 +266,10 @@ async function main() {
|
||||
// ── 用例 2: 失败-已拦截(120945: intercept_status='intercepted_at_warehouse') ──
|
||||
results.push(await runTestCase(
|
||||
'用例2: 失败-已拦截',
|
||||
[120945],
|
||||
[ 120945 ],
|
||||
'全部 failed, reason="已拦截"',
|
||||
null,
|
||||
async (result) => {
|
||||
async result => {
|
||||
const data = result.body && (result.body.data !== undefined ? result.body.data : result.body);
|
||||
if (!data || data.success_count !== 0) return `期望 success_count=0,实际: ${JSON.stringify(data)}`;
|
||||
const allIntercepted = (data.failed || []).every(f => f.reason === '已拦截');
|
||||
@ -280,23 +283,23 @@ async function main() {
|
||||
let case1Cleanup = null;
|
||||
results.push(await runTestCase(
|
||||
'用例1: 成功-含未拣货',
|
||||
[120946],
|
||||
[ 120946 ],
|
||||
'success_count >= 1, 订单 recheck_status=fin, pick_status=fin',
|
||||
async () => {
|
||||
// 再次确认前置条件
|
||||
const c2 = await getConn();
|
||||
const [st] = await c2.query('SELECT locked_quantity FROM wms_storage WHERE id = 184 AND warehouse_id = 100000');
|
||||
const [ st ] = await c2.query('SELECT locked_quantity FROM wms_storage WHERE id = 184 AND warehouse_id = 100000');
|
||||
console.log(` [前置确认] storage 184 locked_quantity=${st[0].locked_quantity}`);
|
||||
const [pk] = await c2.query('SELECT status FROM wms_picking WHERE id = 87425 AND warehouse_id = 100000');
|
||||
const [ pk ] = await c2.query('SELECT status FROM wms_picking WHERE id = 87425 AND warehouse_id = 100000');
|
||||
console.log(` [前置确认] picking 87425 status=${pk[0].status}`);
|
||||
},
|
||||
async (result) => {
|
||||
async result => {
|
||||
const data = result.body && (result.body.data !== undefined ? result.body.data : result.body);
|
||||
if (!data || data.success_count < 1) return `期望 success_count >= 1,实际: ${JSON.stringify(data)}`;
|
||||
|
||||
// 验证 120946 的状态
|
||||
const c3 = await getConn();
|
||||
const [order] = await c3.query(
|
||||
const [ order ] = await c3.query(
|
||||
'SELECT pick_status, recheck_status FROM wms_order_delivery_100000 WHERE id = 120946 AND warehouse_id = 100000'
|
||||
);
|
||||
console.log(` [验证] 120946 pick_status="${order[0].pick_status}" recheck_status="${order[0].recheck_status}"`);
|
||||
@ -304,7 +307,7 @@ async function main() {
|
||||
if (order[0].recheck_status !== 'fin') return `期望 recheck_status='fin',实际="${order[0].recheck_status}"`;
|
||||
|
||||
// 验证库存已扣减
|
||||
const [stAfter] = await c3.query('SELECT locked_quantity, quantity FROM wms_storage WHERE id = 184 AND warehouse_id = 100000');
|
||||
const [ stAfter ] = await c3.query('SELECT locked_quantity, quantity FROM wms_storage WHERE id = 184 AND warehouse_id = 100000');
|
||||
console.log(` [验证] storage 184 扣减后: locked=${stAfter[0].locked_quantity}, quantity=${stAfter[0].quantity}`);
|
||||
|
||||
// 记录清理函数
|
||||
@ -329,12 +332,12 @@ async function main() {
|
||||
// 需要先确保 120946 恢复到可测试状态
|
||||
results.push(await runTestCase(
|
||||
'用例6: 部分失败-混合',
|
||||
[120946, 120947, 999999999],
|
||||
[ 120946, 120947, 999999999 ],
|
||||
'success_count >= 1 且 failed_count >= 2',
|
||||
async () => {
|
||||
// 恢复 120946 的前置条件
|
||||
const c4 = await getConn();
|
||||
const [st] = await c4.query('SELECT locked_quantity FROM wms_storage WHERE id = 184 AND warehouse_id = 100000');
|
||||
const [ st ] = await c4.query('SELECT locked_quantity FROM wms_storage WHERE id = 184 AND warehouse_id = 100000');
|
||||
if (st[0].locked_quantity < 1) {
|
||||
await c4.query('UPDATE wms_storage SET locked_quantity = locked_quantity + 1, quantity = quantity + 1, updated_at = NOW() WHERE id = 184 AND warehouse_id = 100000');
|
||||
console.log(' [前置] storage 184 locked_quantity 已恢复 +1');
|
||||
@ -344,7 +347,7 @@ async function main() {
|
||||
await c4.query("UPDATE wms_order_delivery_100000 SET pick_status = 'none', recheck_status = 'none', updated_at = NOW() WHERE id = 120946 AND warehouse_id = 100000");
|
||||
console.log(' [前置] 120946 数据已恢复');
|
||||
},
|
||||
async (result) => {
|
||||
async result => {
|
||||
const data = result.body && (result.body.data !== undefined ? result.body.data : result.body);
|
||||
if (!data) return `返回数据为空: ${JSON.stringify(result.body)}`;
|
||||
if (data.success_count >= 1 && data.failed_count >= 2) {
|
||||
@ -358,13 +361,13 @@ async function main() {
|
||||
async () => {
|
||||
// 恢复 120946
|
||||
const c5 = await getConn();
|
||||
const [st] = await c5.query('SELECT locked_quantity, quantity FROM wms_storage WHERE id = 184 AND warehouse_id = 100000');
|
||||
const [ st ] = await c5.query('SELECT locked_quantity, quantity FROM wms_storage WHERE id = 184 AND warehouse_id = 100000');
|
||||
// 如果 locked_quantity 减少了(测试成功扣减了),恢复
|
||||
await c5.query("UPDATE wms_picking SET status = 'pending', updated_at = NOW() WHERE id = 87425 AND warehouse_id = 100000");
|
||||
await c5.query('UPDATE wms_wave_pick_task_order SET pick_status = 0, picked_time = NULL, update_time = NOW() WHERE id = 6057 AND warehouse_id = 100000');
|
||||
await c5.query("UPDATE wms_order_delivery_100000 SET pick_status = 'none', recheck_status = 'none', updated_at = NOW() WHERE id = 120946 AND warehouse_id = 100000");
|
||||
// 检查库存是否需要恢复
|
||||
const [st2] = await c5.query('SELECT locked_quantity FROM wms_storage WHERE id = 184 AND warehouse_id = 100000');
|
||||
const [ st2 ] = await c5.query('SELECT locked_quantity FROM wms_storage WHERE id = 184 AND warehouse_id = 100000');
|
||||
console.log(` [用例6恢复] 120946 数据已恢复,storage 184 locked=${st2[0].locked_quantity}`);
|
||||
}
|
||||
));
|
||||
@ -372,7 +375,7 @@ async function main() {
|
||||
// ── 全局恢复:将 storage 184 恢复到测试前状态 ──
|
||||
console.log('\n── 全局恢复:storage 184 ──');
|
||||
// 检查当前状态,恢复到原始值
|
||||
const [finalSt] = await c.query('SELECT quantity, locked_quantity FROM wms_storage WHERE id = 184 AND warehouse_id = 100000');
|
||||
const [ finalSt ] = await c.query('SELECT quantity, locked_quantity FROM wms_storage WHERE id = 184 AND warehouse_id = 100000');
|
||||
console.log(` storage 184 最终: quantity=${finalSt[0].quantity}, locked=${finalSt[0].locked_quantity}`);
|
||||
console.log(` storage 184 原始: quantity=${origStorage[0].quantity}, locked=${origStorage[0].locked_quantity}`);
|
||||
|
||||
|
||||
@ -4,14 +4,14 @@ const TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwidXNlcm5hbWUiOiJs
|
||||
const BASE_URL = 'http://127.0.0.1:6060';
|
||||
const TABLE = 'wms_order_delivery_100000';
|
||||
const mysql = require('mysql2/promise');
|
||||
const DB_CONFIG = {host:'127.0.0.1',port:3307,user:'wms',password:'dspxmRwRdRbWtbm7',database:'wms'};
|
||||
const DB_CONFIG = { host: '127.0.0.1', port: 3307, user: 'wms', password: 'dspxmRwRdRbWtbm7', database: 'wms' };
|
||||
|
||||
async function getOrderSnapshot(conn, ids) {
|
||||
if (!ids.length) return {};
|
||||
const [rows] = await conn.query(
|
||||
const [ rows ] = await conn.query(
|
||||
`SELECT id, delivery_order_code, pre_delivery_order_code,
|
||||
pick_status, recheck_status, storage_status, post_status, status, intercept_status
|
||||
FROM ${TABLE} WHERE id IN (?)`, [ids]
|
||||
FROM ${TABLE} WHERE id IN (?)`, [ ids ]
|
||||
);
|
||||
const map = {};
|
||||
rows.forEach(r => { map[r.id] = r; });
|
||||
@ -22,10 +22,10 @@ async function callApi(ids) {
|
||||
const ts = Math.floor(Date.now() / 1000);
|
||||
const url = `${BASE_URL}/system?method=order.recheckOrder.batchQuickRecheck&v=1.0×tamp=${ts}`;
|
||||
const headers = {
|
||||
'platform': 'web',
|
||||
'project': 'wms',
|
||||
platform: 'web',
|
||||
project: 'wms',
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
'Authorization': `Bearer ${TOKEN}`,
|
||||
Authorization: `Bearer ${TOKEN}`,
|
||||
};
|
||||
// IMPORTANT: body 必须扁平化,ids 直接在顶层。callMethod 将整个 body 传给业务方法
|
||||
const body = JSON.stringify({ ids });
|
||||
@ -51,7 +51,7 @@ async function runTestCase(name, ids, expectedDesc) {
|
||||
try {
|
||||
beforeSnapshot = await getOrderSnapshot(conn, ids);
|
||||
console.log(' 测试前状态:');
|
||||
for (const [id, snap] of Object.entries(beforeSnapshot)) {
|
||||
for (const [ id, snap ] of Object.entries(beforeSnapshot)) {
|
||||
console.log(` ID ${id}: pick="${snap.pick_status}" recheck="${snap.recheck_status}" storage="${snap.storage_status}" post="${snap.post_status}" status="${snap.status}" intercept="${snap.intercept_status}" code="${snap.delivery_order_code || snap.pre_delivery_order_code || ''}"`);
|
||||
}
|
||||
|
||||
@ -64,7 +64,7 @@ async function runTestCase(name, ids, expectedDesc) {
|
||||
|
||||
afterSnapshot = await getOrderSnapshot(conn, ids);
|
||||
console.log(' 测试后状态:');
|
||||
for (const [id, snap] of Object.entries(afterSnapshot)) {
|
||||
for (const [ id, snap ] of Object.entries(afterSnapshot)) {
|
||||
const before = beforeSnapshot[id] || {};
|
||||
const changes = [];
|
||||
if (snap.pick_status !== before.pick_status) changes.push(`pick: ${before.pick_status}→${snap.pick_status}`);
|
||||
@ -102,49 +102,49 @@ async function main() {
|
||||
// 用例8: 不存在ID
|
||||
results.push(await runTestCase(
|
||||
'用例8: 不存在ID',
|
||||
[999999999],
|
||||
[ 999999999 ],
|
||||
'全部 failed, reason="未找到对应订单"'
|
||||
));
|
||||
|
||||
// 用例4: 全失败-未同步
|
||||
results.push(await runTestCase(
|
||||
'用例4: 全失败-未同步',
|
||||
[120858, 120857],
|
||||
[ 120858, 120857 ],
|
||||
'全部 failed, reason="没有同步"'
|
||||
));
|
||||
|
||||
// 用例3: 全失败-无快递
|
||||
results.push(await runTestCase(
|
||||
'用例3: 全失败-无快递',
|
||||
[120944, 120943],
|
||||
[ 120944, 120943 ],
|
||||
'全部 failed, reason="没有分配快递"'
|
||||
));
|
||||
|
||||
// 用例2: 全失败-无储位
|
||||
results.push(await runTestCase(
|
||||
'用例2: 全失败-无储位',
|
||||
[120947, 120939],
|
||||
[ 120947, 120939 ],
|
||||
'全部 failed, reason="未分配储位"'
|
||||
));
|
||||
|
||||
// 用例5: 全失败-已拦截
|
||||
results.push(await runTestCase(
|
||||
'用例5: 全失败-已拦截',
|
||||
[120945],
|
||||
[ 120945 ],
|
||||
'全部 failed, reason="已拦截"'
|
||||
));
|
||||
|
||||
// 用例6: 部分失败-混合(valid + invalid)
|
||||
results.push(await runTestCase(
|
||||
'用例6: 部分失败-混合',
|
||||
[120946, 120947, 999999999],
|
||||
[ 120946, 120947, 999999999 ],
|
||||
'success 和 failed 各有'
|
||||
));
|
||||
|
||||
// 用例1: 全成功-含未拣货 (最后测,会修改数据)
|
||||
results.push(await runTestCase(
|
||||
'用例1: 全成功-含未拣货',
|
||||
[120946],
|
||||
[ 120946 ],
|
||||
'pick_status=none → 自动完成拣货+复核, recheck_status=fin'
|
||||
));
|
||||
|
||||
|
||||
@ -34,7 +34,7 @@ function createSequelizeTypes() {
|
||||
STRING: length => makeType(`VARCHAR(${length})`),
|
||||
BIGINT: unsignedBigInt,
|
||||
DECIMAL: (precision, scale) => makeType(`DECIMAL(${precision},${scale})`),
|
||||
TEXT: (length) => makeType(length ? `TEXT(${length})` : 'TEXT'),
|
||||
TEXT: length => makeType(length ? `TEXT(${length})` : 'TEXT'),
|
||||
ENUM: (...values) => makeType(`ENUM('${values.join("','")}')`),
|
||||
DATE: makeType('DATETIME'),
|
||||
INTEGER: length => makeType(`INT(${length})`),
|
||||
|
||||
@ -35,8 +35,8 @@ function createHarness() {
|
||||
service.getWarehouseId = () => 1;
|
||||
|
||||
// 模拟 normalizeOrderListItem / attachOrderExpressNumbers 为直通
|
||||
service.normalizeOrderListItem = (item) => item;
|
||||
service.attachOrderExpressNumbers = async (list) => list;
|
||||
service.normalizeOrderListItem = item => item;
|
||||
service.attachOrderExpressNumbers = async list => list;
|
||||
|
||||
// 捕获 buildWhere 入参,返回简单条件
|
||||
const originalBuildWhere = service.buildWhere.bind(service);
|
||||
@ -48,7 +48,7 @@ function createHarness() {
|
||||
// 模拟 getOrderModel 返回可控数据
|
||||
service.getOrderModel = async () => ({
|
||||
count: async () => 1,
|
||||
findAll: async (opts) => {
|
||||
findAll: async opts => {
|
||||
captures.modelOpts = opts;
|
||||
return [
|
||||
{
|
||||
|
||||
@ -205,7 +205,7 @@ describe('test/app/service/systemMethods/stock.warehouse.import.test.js', () =>
|
||||
});
|
||||
|
||||
it('should map 条码 to barcode', () => {
|
||||
const row = { '条码': 'A,B' };
|
||||
const row = { 条码: 'A,B' };
|
||||
const normalized = service._normalizeWarehouseImportRow(row);
|
||||
assert.deepEqual(normalized.barcode, [ 'A', 'B' ]);
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user