forked from yoone/API
fix(logistics): 处理获取运单状态失败的情况并优化批量更新
当获取运单状态返回FAIL时抛出错误信息 将运单状态更新改为并行处理并添加日志记录
This commit is contained in:
parent
3d6f488a70
commit
cdff083940
|
|
@ -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}`);
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue