Beispiel #1
0
        private async Task CreateShipments(ImportShipmentsFromExcelJobArgs args, List <ImportShipmentDto> shipmentDtos)
        {
            var invalidShipments = new List <ImportShipmentDto>();

            var logistics = await _logisticsManager.GetTenantLogisticsByIdAsync(args.TenantLogisticsId);

            foreach (var shipmentDto in shipmentDtos)
            {
                if (shipmentDto.CanBeImported())
                {
                    var order = await _orderManager.FindByOrderNumberAsync(shipmentDto.OrderNumber);

                    if (order == null)
                    {
                        shipmentDto.Exception = "找不到订单";
                        continue;
                    }
                    try
                    {
                        var shipment = await _orderImportor.AddShipment(new OrderImport()
                        {
                            OrderStatus    = OrderStatus.Processing,
                            TrackingNumber = shipmentDto.LogisticsNumber,
                            LogisticsId    = logistics.LogisticsId,
                            LogisticsName  = logistics.Name,
                            CreatedOnUtc   = DateTime.UtcNow,
                        }, order);

                        await _orderProcessingManager.ShipAsync(shipment, false);
                    }
                    catch (UserFriendlyException exception)
                    {
                        shipmentDto.Exception = exception.Message;
                        invalidShipments.Add(shipmentDto);
                    }
                    catch (Exception exception)
                    {
                        shipmentDto.Exception = exception.ToString();
                        invalidShipments.Add(shipmentDto);
                    }
                }
                else
                {
                    invalidShipments.Add(shipmentDto);
                }
            }

            AsyncHelper.RunSync(() => ProcessImportShipmentsResultAsync(args, invalidShipments));
        }
Beispiel #2
0
        public async Task <GetLogisticsForEditOutput> GetTenantLogisticsForEdit(NullableIdDto <int> input)
        {
            GetLogisticsForEditOutput logisticsDto;

            if (input.Id.HasValue)
            {
                var tenantLogistics = await _logisticsManager.GetTenantLogisticsByIdAsync(input.Id.Value);

                logisticsDto = ObjectMapper.Map <GetLogisticsForEditOutput>(tenantLogistics);

                var logistics = await _logisticsManager.GetByIdAsync(tenantLogistics.LogisticsId);

                logisticsDto.Key  = logistics.Key;
                logisticsDto.Memo = logistics.Memo;
            }
            else
            {
                logisticsDto = new GetLogisticsForEditOutput();
            }

            return(logisticsDto);
        }