- warehouseNotify: 按固定群订阅经 wms_api_app 回调推送(MD5 验签),消息表登记+失败重试 - notice: 货主群缺失时降级发仓库异常群(前缀标记失败),合约停用/已解除货主不发货主群也不降级 - order_async: 订单同步通知 3 分钟去抖合并,Redis 队列+定时冲刷+失败重试 - receiving: 收货完成/驳回/审核通知走仓库通道,仓库/货主侧文案分离 - storage/inventory: 移除移库完成群通知(事件码保留,库存余量提醒仍复用) - 新增 debug:warehouse:push-receiver 调试接收服务与文档/变更记录
117 lines
3.1 KiB
JavaScript
117 lines
3.1 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* 调试脚本:为指定账号铸造 JWT 并调用系统接口完成收货。
|
|
* 用法:
|
|
* node script/debug-complete-receiving.cjs --receiving-id=1512 --account-id=1
|
|
* node script/debug-complete-receiving.cjs --receiving-id=1512 --account-id=1 --host=127.0.0.1 --port=6060
|
|
*/
|
|
|
|
const http = require('node:http');
|
|
const jwt = require('jsonwebtoken');
|
|
|
|
const JWT_SECRET = 'E5#ex.g@,GfL_8?';
|
|
const JWT_EXPIRES_IN = 14400;
|
|
|
|
function parseArgs(argv) {
|
|
const options = {
|
|
receivingId: 0,
|
|
accountId: 1,
|
|
host: '127.0.0.1',
|
|
port: 6060,
|
|
remark: '',
|
|
};
|
|
|
|
for (const arg of argv) {
|
|
if (!arg.startsWith('--')) {
|
|
continue;
|
|
}
|
|
const [ rawKey, ...rest ] = arg.slice(2).split('=');
|
|
const value = rest.join('=');
|
|
switch (rawKey) {
|
|
case 'receiving-id':
|
|
options.receivingId = Number(value || options.receivingId);
|
|
break;
|
|
case 'account-id':
|
|
options.accountId = Number(value || options.accountId);
|
|
break;
|
|
case 'host':
|
|
options.host = value || options.host;
|
|
break;
|
|
case 'port':
|
|
options.port = Number(value || options.port);
|
|
break;
|
|
case 'remark':
|
|
options.remark = value || '';
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
return options;
|
|
}
|
|
|
|
function postSystemMethod(options, token, method, body) {
|
|
return new Promise((resolve, reject) => {
|
|
const bodyJson = JSON.stringify(body);
|
|
const path = `/system?method=${encodeURIComponent(method)}&v=1×tamp=${Math.floor(Date.now() / 1000)}`;
|
|
const req = http.request({
|
|
hostname: options.host,
|
|
port: options.port,
|
|
path,
|
|
method: 'POST',
|
|
headers: {
|
|
platform: 'web',
|
|
project: 'wms',
|
|
Authorization: `Bearer ${token}`,
|
|
'Content-Type': 'application/json',
|
|
'Content-Length': Buffer.byteLength(bodyJson),
|
|
},
|
|
}, res => {
|
|
let data = '';
|
|
res.on('data', chunk => {
|
|
data += chunk;
|
|
});
|
|
res.on('end', () => {
|
|
resolve({ status: res.statusCode, body: data });
|
|
});
|
|
});
|
|
req.on('error', reject);
|
|
req.write(bodyJson);
|
|
req.end();
|
|
});
|
|
}
|
|
|
|
async function main() {
|
|
const options = parseArgs(process.argv.slice(2));
|
|
if (!options.receivingId) {
|
|
console.error('缺少 --receiving-id');
|
|
process.exit(1);
|
|
}
|
|
|
|
const token = jwt.sign({
|
|
id: options.accountId,
|
|
platform_code: 'web',
|
|
current_store_id: 100000,
|
|
}, JWT_SECRET, { expiresIn: JWT_EXPIRES_IN });
|
|
|
|
console.log(`[debug-complete-receiving] accountId=${options.accountId} receivingId=${options.receivingId}`);
|
|
const result = await postSystemMethod(options, token, 'storage.receiving.completeReceiving', {
|
|
id: options.receivingId,
|
|
remark: options.remark || undefined,
|
|
});
|
|
|
|
console.log(`HTTP ${result.status}`);
|
|
try {
|
|
console.log(JSON.stringify(JSON.parse(result.body), null, 2).substring(0, 3000));
|
|
} catch (_) {
|
|
console.log(result.body.substring(0, 1000));
|
|
}
|
|
}
|
|
|
|
main().catch(error => {
|
|
console.error('[debug-complete-receiving] failed:', error.message);
|
|
process.exit(1);
|
|
});
|