public override void Execute(int arg) { AsyncHelper.RunSync(async() => { using (_unitOfWorkManager.Current.SetTenantId(arg)) { var status = new List <ShippingStatus> { ShippingStatus.NoTrace, ShippingStatus.Taked, ShippingStatus.OnPassag, ShippingStatus.DestinationCity, ShippingStatus.Delivering, ShippingStatus.Issue }; var shipments = await _shipmentManager.Shipments .Include(o => o.Items) .Include(o => o.Order) .Where(s => status.Contains(s.Status)).ToListAsync(); foreach (var shipment in shipments) { try { var trace = await _shipmentTracker.GetShipmentTracesAsync(shipment, true); } catch (Exception) { //_logger.Error(string.Format("订单跟踪失败,{0}。", exc.Message), exc); } } } }); }
public async Task <TrackingDto> GetShipmentTracking(GetShipmentTrackingInput input) { var resultDto = new TrackingDto() { Status = ShippingStatus.NotYetShipped.GetLocalizedEnum(_localizationManager) }; Shipment shipment = null; if (input.OrderId.HasValue && input.OrderId > 0) { var order = await _orderManager.GetByIdAsync(input.OrderId.Value); if (order != null) { await _orderManager.OrderRepository.EnsureCollectionLoadedAsync(order, t => t.Shipments); shipment = order.Shipments.FirstOrDefault(); } } else { shipment = await _shipmentManager.GetByIdAsync(input.ShipmentId.Value); } if (await IsShippingSettingAvailable()) { return(resultDto); } var traces = await _shipmentTracker.GetShipmentTracesAsync(shipment, input.Refresh); resultDto.Status = ((ShippingStatus)traces.State).GetLocalizedEnum(_localizationManager); resultDto.Traces = traces.Traces.Select(t => { return(new TrackingItemDto() { Station = t.AcceptStation, Time = t.AcceptTime, Remark = t.Remark }); }).ToList(); return(resultDto); }