|
|
@ -7,11 +7,13 @@ using Microsoft.Extensions.Configuration; |
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
using Volo.Abp.Guids; |
|
|
|
using Volo.Abp.ObjectMapping; |
|
|
|
using Win_in.Sfs.Basedata.Application; |
|
|
|
using Win_in.Sfs.Basedata.Application.Contracts; |
|
|
|
using Win_in.Sfs.Wms.DataExchange.Domain; |
|
|
|
using Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Tyrp; |
|
|
|
using Win_in.Sfs.Wms.DataExchange.Domain.Shared; |
|
|
|
using Win_in.Sfs.Wms.DataExchange.WMS.ErpLocationItem; |
|
|
|
using Win_in.Sfs.Wms.DataExchange.WMS.ItemBasic; |
|
|
|
|
|
|
|
namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent.Incoming; |
|
|
|
|
|
|
@ -22,12 +24,16 @@ public class ErpLocationItemReader : IReader |
|
|
|
private readonly ILogger<ErpLocationItemReader> _logger; |
|
|
|
private readonly IGuidGenerator _guidGenerator; |
|
|
|
private readonly IConfiguration _configuration; |
|
|
|
private readonly IErpLocationItemAppService _erpLocationItemAppService; |
|
|
|
private readonly IObjectMapper _objectMapper; |
|
|
|
public ErpLocationItemReader( |
|
|
|
IErpLocationItemManager ilocdoutManager |
|
|
|
, IIncomingFromExternalManager incomingFromExternalManager |
|
|
|
, IGuidGenerator guidGenerator |
|
|
|
, ILogger<ErpLocationItemReader> logger |
|
|
|
, IConfiguration configuration |
|
|
|
, IErpLocationItemAppService erpLocationItemAppService |
|
|
|
, IObjectMapper objectMapper |
|
|
|
) |
|
|
|
{ |
|
|
|
_guidGenerator = guidGenerator; |
|
|
@ -35,35 +41,41 @@ public class ErpLocationItemReader : IReader |
|
|
|
_ilocdoutManager = ilocdoutManager; |
|
|
|
_incomingFromExternalManager = incomingFromExternalManager; |
|
|
|
_logger = logger; |
|
|
|
_erpLocationItemAppService = erpLocationItemAppService; |
|
|
|
_objectMapper = objectMapper; |
|
|
|
} |
|
|
|
|
|
|
|
public virtual async Task<List<IncomingFromExternal>> ReadAsync() |
|
|
|
{ |
|
|
|
//从Tyrp读取待处理locdout
|
|
|
|
var toBeProcessedIssue = await _ilocdoutManager.GetToBeProcessedListAsync().ConfigureAwait(false); |
|
|
|
if (!toBeProcessedIssue.Any()) |
|
|
|
var toBeProcessedItems = await _ilocdoutManager.GetToBeProcessedListAsync().ConfigureAwait(false); |
|
|
|
//获取wms开账数据
|
|
|
|
SfsBaseDataRequestInputBase input = new SfsBaseDataRequestInputBase(); |
|
|
|
var wmsErpLocationItems = await _erpLocationItemAppService.GetAllListByFilterAsync(input).ConfigureAwait(false); |
|
|
|
var wmsToErpLocationItemExchangeDtos = _objectMapper.Map<List<ErpLocationItemDTO>, List<ErpLocationItemExchangeDto>>(wmsErpLocationItems); |
|
|
|
List<ErpLocationItemExchangeDto> tyrpToItemBasicExchangeDtos = new List<ErpLocationItemExchangeDto>(); |
|
|
|
foreach (var locdout in toBeProcessedItems) |
|
|
|
{ |
|
|
|
var erpLocationItem = BuildErpLocationItemExchangeMes(locdout); |
|
|
|
tyrpToItemBasicExchangeDtos.Add(erpLocationItem); |
|
|
|
} |
|
|
|
//和wms和tyrp数据进行比较,获取需要处理得数据
|
|
|
|
var updateDatas = tyrpToItemBasicExchangeDtos.Except(wmsToErpLocationItemExchangeDtos).ToList(); |
|
|
|
|
|
|
|
if (!updateDatas.Any()) |
|
|
|
{ |
|
|
|
_logger.LogInformation("未读到Tyrp开账数据"); |
|
|
|
return new List<IncomingFromExternal>(); |
|
|
|
} |
|
|
|
//locdout逐一转换为locdout
|
|
|
|
var incomingDataList = BuildIncomingFromExternalFromBomAsync(toBeProcessedIssue); |
|
|
|
await _incomingFromExternalManager.CreateBulkAsync(incomingDataList).ConfigureAwait(false); |
|
|
|
return incomingDataList; |
|
|
|
} |
|
|
|
private List<IncomingFromExternal> BuildIncomingFromExternalFromBomAsync(List<locdout> toBeProcessedIssue) |
|
|
|
{ |
|
|
|
var incomingDataList = new List<IncomingFromExternal>(); |
|
|
|
foreach (var locdout in toBeProcessedIssue) |
|
|
|
List<IncomingFromExternal> incomingDataList = new List<IncomingFromExternal>(); |
|
|
|
foreach (var data in updateDatas) |
|
|
|
{ |
|
|
|
var incomingData = BuildIncomingFromExternal(locdout); |
|
|
|
|
|
|
|
var item = toBeProcessedItems.FirstOrDefault(r => r.locdout_loc == data.ErpLocationCode&&r.locdout_part==data.ItemCode); |
|
|
|
var incomingData = BuildIncomingFromExternal(item); |
|
|
|
incomingData.SetEffectiveDate(DateTime.Now); |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
var bm = BuildScrapNoteOrderExchangeMes(locdout); |
|
|
|
incomingData.DestinationDataContent = JsonSerializer.Serialize(bm); |
|
|
|
incomingData.DestinationDataContent = JsonSerializer.Serialize(data); |
|
|
|
incomingData.SetId(_guidGenerator.Create()); |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
@ -74,8 +86,10 @@ public class ErpLocationItemReader : IReader |
|
|
|
incomingDataList.Add(incomingData); |
|
|
|
|
|
|
|
} |
|
|
|
await _incomingFromExternalManager.CreateBulkAsync(incomingDataList).ConfigureAwait(false); |
|
|
|
return incomingDataList; |
|
|
|
} |
|
|
|
|
|
|
|
private IncomingFromExternal BuildIncomingFromExternal(locdout locdout) |
|
|
|
{ |
|
|
|
var incomingData = new IncomingFromExternal() |
|
|
@ -95,7 +109,7 @@ public class ErpLocationItemReader : IReader |
|
|
|
return incomingData; |
|
|
|
} |
|
|
|
|
|
|
|
private static ErpLocationItemExchangeDto BuildScrapNoteOrderExchangeMes(locdout locdout) |
|
|
|
private ErpLocationItemExchangeDto BuildErpLocationItemExchangeMes(locdout locdout) |
|
|
|
{ |
|
|
|
|
|
|
|
var cust = new ErpLocationItemExchangeDto() |
|
|
|