You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
5.0 KiB
107 lines
5.0 KiB
1 year ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Text.Json;
|
||
|
using System.Threading.Tasks;
|
||
|
using Microsoft.Extensions.Logging;
|
||
|
using Volo.Abp.ObjectMapping;
|
||
|
using Win_in.Sfs.Basedata.Application.Contracts;
|
||
|
using Win_in.Sfs.Wms.DataExchange.Domain;
|
||
|
using Win_in.Sfs.Wms.DataExchange.WMS.DeliverRequest;
|
||
|
using Win_in.Sfs.Wms.Store.Application.Contracts;
|
||
|
|
||
|
namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.MesAgent.Incoming;
|
||
|
public class DeliveryConverter : IIncomingConverter
|
||
|
{
|
||
|
private readonly IIncomingFromExternalManager _incomingFromExternalManager;
|
||
|
private readonly IIncomingToWmsManager _incomingToWmsManager;
|
||
|
private readonly IObjectMapper _objectMapper;
|
||
|
private readonly IItemBasicAppService _itemBasicAppService;
|
||
|
private readonly ICustomerAppService _customerAppService;
|
||
|
private readonly ILogger<DeliveryConverter> _logger;
|
||
|
|
||
|
public DeliveryConverter(
|
||
|
IIncomingToWmsManager incomingToWmsManager
|
||
|
, IObjectMapper objectMapper
|
||
|
, IItemBasicAppService itemBasicAppService
|
||
|
, ILogger<DeliveryConverter> logger,
|
||
|
ICustomerAppService customerAppService,
|
||
|
IIncomingFromExternalManager incomingFromExternalManager)
|
||
|
{
|
||
|
_incomingToWmsManager = incomingToWmsManager;
|
||
|
_objectMapper = objectMapper;
|
||
|
_itemBasicAppService = itemBasicAppService;
|
||
|
_logger = logger;
|
||
|
_customerAppService = customerAppService;
|
||
|
_incomingFromExternalManager = incomingFromExternalManager;
|
||
|
}
|
||
|
|
||
|
public virtual async Task ConvertAsync(List<IncomingFromExternal> incomingFromExternalList)
|
||
|
{
|
||
|
if (!incomingFromExternalList.Any())
|
||
|
{
|
||
|
_logger.LogInformation("no Deliverys");
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
//按Number合并DeliveryRequest单据
|
||
|
var transferRequestList = await BuildIncomingToWmsOfDeliveryRequestAsync(incomingFromExternalList).ConfigureAwait(false);
|
||
|
await _incomingToWmsManager.CreateManyAsync(transferRequestList).ConfigureAwait(false);
|
||
|
//归档
|
||
|
await _incomingFromExternalManager.ArchiveManyAsync(incomingFromExternalList).ConfigureAwait(false);
|
||
|
}
|
||
|
|
||
|
private async Task<List<IncomingToWms>> BuildIncomingToWmsOfDeliveryRequestAsync(List<IncomingFromExternal> incomingDataList)
|
||
|
{
|
||
|
var incomingToWmsList = new List<IncomingToWms>();
|
||
|
var groups = incomingDataList.GroupBy(p => new { p.SourceDataGroupCode ,p.SourceDataDetailCode});
|
||
|
foreach (var group in groups)
|
||
|
{
|
||
|
var first = group.First();
|
||
|
var incomingToWms = new IncomingToWms()
|
||
|
{
|
||
|
DataType = first.DataType,
|
||
|
DataAction = first.DataAction,
|
||
|
SourceSystem = first.SourceSystem,
|
||
|
DataIdentityCode = first.SourceDataGroupCode,
|
||
|
};
|
||
|
incomingToWms.SetEffectiveDate(first.EffectiveDate);
|
||
|
var exchangeDeliveryRequest = JsonSerializer.Deserialize<DeliverRequestExchangeDto>(first.DestinationDataContent);
|
||
|
var wmsDeliveryRequest = _objectMapper.Map<DeliverRequestExchangeDto, DeliverRequestEditInput>(exchangeDeliveryRequest);
|
||
|
wmsDeliveryRequest.Details = new List<DeliverRequestDetailInput>();
|
||
|
var cust= await _customerAppService.GetByCodeAsync(wmsDeliveryRequest.CustomerCode).ConfigureAwait(false);
|
||
|
wmsDeliveryRequest.CustomerAddressCode = String.IsNullOrEmpty( cust?.Address)?"无": cust.Address;
|
||
|
foreach (var incomingFromExternal in group.ToList())
|
||
|
{
|
||
|
var transferRequest = JsonSerializer.Deserialize<DeliverRequestExchangeDto>(incomingFromExternal.DestinationDataContent);
|
||
|
var wmsDeliveryRequestDetail = _objectMapper.Map<DeliverRequestDetailExchangeDto, DeliverRequestDetailInput>(transferRequest.Detail);
|
||
|
var item = await _itemBasicAppService.GetByCodeAsync(wmsDeliveryRequestDetail.ItemCode).ConfigureAwait(false);
|
||
|
try
|
||
|
{
|
||
|
if (item != null)
|
||
|
{
|
||
|
wmsDeliveryRequestDetail.ItemName = item.Name;
|
||
|
wmsDeliveryRequestDetail.ItemDesc1 = !string.IsNullOrEmpty(item.Desc1) ? item.Desc1 : "";
|
||
|
wmsDeliveryRequestDetail.ItemDesc2 = !string.IsNullOrEmpty(item.Desc2) ? item.Desc2 : "";
|
||
|
wmsDeliveryRequestDetail.Uom = !string.IsNullOrEmpty(item.BasicUom) ? item.BasicUom : "";
|
||
|
wmsDeliveryRequestDetail.StdPackQty = item.StdPackQty;
|
||
|
}
|
||
|
}
|
||
|
catch (Exception)
|
||
|
{
|
||
|
wmsDeliveryRequestDetail.ItemName = "";
|
||
|
wmsDeliveryRequestDetail.ItemDesc1 = "";
|
||
|
wmsDeliveryRequestDetail.ItemDesc2 = "";
|
||
|
wmsDeliveryRequestDetail.Uom = "";
|
||
|
}
|
||
|
|
||
|
wmsDeliveryRequest.Details.Add(wmsDeliveryRequestDetail);
|
||
|
}
|
||
|
incomingToWms.DataContent = JsonSerializer.Serialize(wmsDeliveryRequest);
|
||
|
incomingToWmsList.Add(incomingToWms);
|
||
|
}
|
||
|
return incomingToWmsList;
|
||
|
}
|
||
|
|
||
|
}
|