forked from yoone/API
1
0
Fork 0

fix(logistics): 处理获取运单状态失败的情况并优化批量更新

当获取运单状态返回FAIL时抛出错误信息
将运单状态更新改为并行处理并添加日志记录
This commit is contained in:
tikkhun 2026-01-09 11:12:51 +08:00
parent 3d6f488a70
commit cdff083940
2 changed files with 15 additions and 8 deletions

View File

@ -75,17 +75,20 @@ export class SyncUniuniShipmentJob implements IJob{
'255': 'Gateway_To_Gateway_Transit'
};
async onTick() {
try {
const shipments:Shipment[] = await this.shipmentModel.findBy({ finished: false });
shipments.forEach(shipment => {
this.logisticsService.updateShipmentState(shipment);
});
} catch (error) {
this.logger.error(`更新运单状态失败 ${error.message}`);
}
const results = await Promise.all(
shipments.map(async shipment => {
return await this.logisticsService.updateShipmentState(shipment);
})
)
this.logger.info(`更新运单状态完毕 ${JSON.stringify(results)}`);
return results
}
onComplete(result: any) {
this.logger.info(`更新运单状态完成 ${result}`);
}
onError(error: any) {
this.logger.error(`更新运单状态失败 ${error.message}`);
}
}

View File

@ -125,6 +125,10 @@ export class LogisticsService {
try {
const data = await this.uniExpressService.getOrderStatus(shipment.return_tracking_number);
console.log('updateShipmentState data:', data);
// huo
if(data.status === 'FAIL'){
throw new Error('获取运单状态失败,原因为'+ data.ret_msg)
}
shipment.state = data.data[0].state;
if (shipment.state in [203, 215, 216, 230]) { // todo,写常数
shipment.finished = true;