diff --git a/src/job/sync_tms.job.ts b/src/job/sync_tms.job.ts index ece6af6..a45896e 100644 --- a/src/job/sync_tms.job.ts +++ b/src/job/sync_tms.job.ts @@ -15,20 +15,20 @@ export class SyncTmsJob implements IJob { logger: ILogger; @Inject() - logisticsService: LogisticsService; - - @InjectEntityModel(Shipment) - shipmentModel: Repository + logisticsService: LogisticsService; + + @InjectEntityModel(Shipment) + shipmentModel: Repository async onTick() { - const shipments:Shipment[] = await this.shipmentModel.findBy({ tracking_provider: 'freightwaves',finished: false }); - const results = await Promise.all( - shipments.map(async shipment => { - return await this.logisticsService.updateFreightwavesShipmentState(shipment); - }) - ) - this.logger.info(`更新运单状态完毕 ${JSON.stringify(results)}`); - return results + const shipments: Shipment[] = await this.shipmentModel.findBy({ tracking_provider: 'freightwaves', finished: false }); + const results = await Promise.all( + shipments.map(async shipment => { + return await this.logisticsService.updateFreightwavesShipmentState(shipment); + }) + ) + this.logger.info(`更新运单状态完毕 ${JSON.stringify(results)}`); + return results } onComplete(result: any) { diff --git a/src/service/freightwaves.service.ts b/src/service/freightwaves.service.ts index 6719629..4f5bc4b 100644 --- a/src/service/freightwaves.service.ts +++ b/src/service/freightwaves.service.ts @@ -140,20 +140,20 @@ interface QueryOrderResponseData { } // 修改订单响应数据接口 -interface ModifyOrderResponseData extends CreateOrderResponseData {} +interface ModifyOrderResponseData extends CreateOrderResponseData { } // 订单退款响应数据接口 -interface RefundOrderResponseData {} +interface RefundOrderResponseData { } @Provide() export class FreightwavesService { @Inject() logger; - // 默认配置 + // 默认配置 private config: FreightwavesConfig = { appSecret: 'gELCHguGmdTLo!zfihfM91hae8G@9Sz23Mh6pHrt', - apiBaseUrl: 'http://tms.freightwaves.ca:8901/', - partner: '25072621035200000060' + apiBaseUrl: 'http://tms.freightwaves.ca:8901/', + partner: '25072621035200000060' }; // 初始化配置 @@ -180,19 +180,19 @@ export class FreightwavesService { }; // 记录请求前的详细信息 - console.log(`Sending request to: ${this.config.apiBaseUrl}${url}`,JSON.stringify({ + console.log(`Sending request to: ${this.config.apiBaseUrl}${url}`, JSON.stringify({ headers, data })) - console.log('Request data:', `${this.config.apiBaseUrl}${url}`, data,headers); + console.log('Request data:', `${this.config.apiBaseUrl}${url}`, data, headers); // 发送请求 - 临时禁用SSL证书验证以解决UNABLE_TO_VERIFY_LEAF_SIGNATURE错误 const response = await axios.post>( `${this.config.apiBaseUrl}${url}`, data, - { + { headers, - httpsAgent: new (require('https').Agent)({ - rejectUnauthorized: false + httpsAgent: new (require('https').Agent)({ + rejectUnauthorized: false }) } ); @@ -400,12 +400,12 @@ export class FreightwavesService { // 调用创建订单方法 this.log('开始测试创建订单...'); this.log('测试参数:', testParams); - + // 注意:在实际环境中取消注释以下行来执行真实请求 const result = await this.createOrder(testParams); - this.log('创建订单成功:', result); - - + this.log('创建订单成功:', result); + + // 返回模拟结果 return { partnerOrderNumber: testParams.partnerOrderNumber, @@ -485,14 +485,14 @@ export class FreightwavesService { // 调用费用试算方法 this.log('开始测试费用试算...'); this.log('测试参数:', testParams); - + // 注意:在实际环境中取消注释以下行来执行真实请求 const result = await this.rateTry(testParams); this.log('费用试算成功:', result); - + this.log('测试完成:费用试算方法调用成功(模拟)'); this.log('提示:在实际环境中,取消注释代码中的rateTry调用行来执行真实请求'); - + // 返回模拟结果 return { shipCompany: 'DHL', @@ -529,13 +529,13 @@ export class FreightwavesService { // 调用查询订单方法 this.log('开始测试查询订单...'); this.log('测试参数:', testParams); - + // 注意:在实际环境中取消注释以下行来执行真实请求 const result = await this.queryOrder(testParams); this.log('查询订单成功:', result); - + this.log('测试完成:查询订单方法调用成功(模拟)'); - + // 返回模拟结果 return { thirdOrderId: 'thirdOrder-123456789',