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.
122 lines
5.4 KiB
122 lines
5.4 KiB
2 years ago
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Text.Json;
|
||
|
using System.Threading.Tasks;
|
||
|
using Microsoft.Extensions.Configuration;
|
||
|
using Microsoft.Extensions.Logging;
|
||
|
using Volo.Abp.Guids;
|
||
|
using Volo.Abp.ObjectMapping;
|
||
|
using Win_in.Sfs.Basedata.Application.Contracts;
|
||
|
using Win_in.Sfs.Wms.DataExchange.Domain;
|
||
|
using Win_in.Sfs.Wms.DataExchange.Domain.Shared;
|
||
|
using Win_in.Sfs.Wms.DataExchange.WMS.ItemPack;
|
||
|
|
||
|
namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.EosAgent.Incoming;
|
||
|
|
||
|
public class ProductConverter : IIncomingConverter
|
||
|
{
|
||
|
private readonly IIncomingToWmsManager _incomingToWmsManager;
|
||
|
private readonly ISupplierAppService _supplierAppService;
|
||
|
private readonly IObjectMapper _objectMapper;
|
||
|
private readonly ILogger<ProductConverter> _logger;
|
||
|
private readonly IGuidGenerator _guidGenerator;
|
||
|
private readonly IConfiguration _configuration;
|
||
|
public ProductConverter(
|
||
|
IIncomingToWmsManager incomingToWmsManager,
|
||
|
ISupplierAppService supplierAppService,
|
||
|
IObjectMapper objectMapper,
|
||
|
ILogger<ProductConverter> logger,
|
||
|
IGuidGenerator guidGenerator,
|
||
|
IConfiguration configuration
|
||
|
)
|
||
|
{
|
||
|
_incomingToWmsManager = incomingToWmsManager;
|
||
|
_objectMapper = objectMapper;
|
||
|
_supplierAppService = supplierAppService;
|
||
|
_logger = logger;
|
||
|
_guidGenerator = guidGenerator;
|
||
|
_configuration = configuration;
|
||
|
}
|
||
|
public virtual async Task ConvertAsync(List<IncomingFromExternal> incomingFromExternalList)
|
||
|
{
|
||
|
if (!incomingFromExternalList.Any())
|
||
|
{
|
||
|
_logger.LogInformation("no products");
|
||
|
return;
|
||
|
}
|
||
|
List<IncomingToWms> incomingToWmsDataList = new List<IncomingToWms>();
|
||
|
//按ItemCode合并ItemPack
|
||
|
var itemPackiIncomingToWmsDataList = await BuildItemPackIncomingToWmsOfProductAsync(incomingFromExternalList).ConfigureAwait(false);
|
||
|
incomingToWmsDataList.AddRange(itemPackiIncomingToWmsDataList);
|
||
|
//按ItemCode合并SupplierItem
|
||
|
var supplierItemIncomingToWmsDataList = await BuildSupplierItemIncomingToWmsOfProductAsync(incomingFromExternalList).ConfigureAwait(false);
|
||
|
incomingToWmsDataList.AddRange(supplierItemIncomingToWmsDataList);
|
||
|
//添加IncomingToWms
|
||
|
await _incomingToWmsManager.CreateBulkAsync(incomingToWmsDataList).ConfigureAwait(false);
|
||
|
|
||
|
}
|
||
|
|
||
|
private async Task<List<IncomingToWms>> BuildItemPackIncomingToWmsOfProductAsync(List<IncomingFromExternal> incomingDataList)
|
||
|
{
|
||
|
var incomingToWmsList = new List<IncomingToWms>();
|
||
|
var groups = incomingDataList.GroupBy(p => p.SourceDataGroupCode);
|
||
|
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.SetId(_guidGenerator.Create());
|
||
|
incomingToWms.SetEffectiveDate(first.EffectiveDate);
|
||
|
var exchangeItemPack = JsonSerializer.Deserialize<ItemPackExchangeDto>(first.DestinationDataContent);
|
||
|
var wmsItemPack = await BuildItemPackProductCreateInput(exchangeItemPack).ConfigureAwait(false);
|
||
|
incomingToWms.DataContent = JsonSerializer.Serialize(wmsItemPack);
|
||
|
incomingToWmsList.Add(incomingToWms);
|
||
|
}
|
||
|
return incomingToWmsList;
|
||
|
}
|
||
|
|
||
|
private async Task<ItemPackEditInput> BuildItemPackProductCreateInput(ItemPackExchangeDto exchangeDto)
|
||
|
{
|
||
|
await Task.CompletedTask.ConfigureAwait(false);
|
||
|
var wmsItemPack = _objectMapper.Map<ItemPackExchangeDto, ItemPackEditInput>(exchangeDto);
|
||
|
return wmsItemPack;
|
||
|
}
|
||
|
|
||
|
private async Task<List<IncomingToWms>> BuildSupplierItemIncomingToWmsOfProductAsync(List<IncomingFromExternal> incomingDataList)
|
||
|
{
|
||
|
var incomingToWmsList = new List<IncomingToWms>();
|
||
|
var groups = incomingDataList.GroupBy(p => p.SourceDataGroupCode);
|
||
|
foreach (var group in groups)
|
||
|
{
|
||
|
var first = group.First();
|
||
|
var incomingToWms = new IncomingToWms()
|
||
|
{
|
||
|
DataType = EnumIncomingDataType.SupplierItem.ToString(),
|
||
|
DataAction = first.DataAction,
|
||
|
SourceSystem = first.SourceSystem,
|
||
|
DataIdentityCode = first.SourceDataGroupCode,
|
||
|
};
|
||
|
incomingToWms.SetId(_guidGenerator.Create());
|
||
|
incomingToWms.SetEffectiveDate(first.EffectiveDate);
|
||
|
var exchangeSupplierItem = JsonSerializer.Deserialize<ItemPackExchangeDto>(first.DestinationDataContent);
|
||
|
var wmsSupplierItem = await BuildProductCreateInput(exchangeSupplierItem).ConfigureAwait(false);
|
||
|
incomingToWms.DataContent = JsonSerializer.Serialize(wmsSupplierItem);
|
||
|
incomingToWmsList.Add(incomingToWms);
|
||
|
}
|
||
|
return incomingToWmsList;
|
||
|
}
|
||
|
|
||
|
private async Task<SupplierItemEditInput> BuildProductCreateInput(ItemPackExchangeDto exchangeDto)
|
||
|
{
|
||
|
var wmsSupplierItem = _objectMapper.Map<ItemPackExchangeDto, SupplierItemEditInput>(exchangeDto);
|
||
|
var supplier = await _supplierAppService.GetByCodeAsync(exchangeDto.SupplierCode).ConfigureAwait(false);
|
||
|
wmsSupplierItem.SupplierSimpleName = supplier?.ShortName;
|
||
|
return wmsSupplierItem;
|
||
|
}
|
||
|
}
|