diff --git a/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.EosAgent/Incoming/ProductReader.cs b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.EosAgent/Incoming/ProductReader.cs index c974dae55..2d77cc231 100644 --- a/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.EosAgent/Incoming/ProductReader.cs +++ b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.EosAgent/Incoming/ProductReader.cs @@ -45,7 +45,7 @@ public class ProductReader : IReader return new List(); } //Product逐一转换为ItemPack - var incomingDataList = BuildIncomingFromExternalFromProductAsync(toBeProcessedProducts.Where(r => !string.IsNullOrWhiteSpace(r.Code)).ToList()); + var incomingDataList = BuildIncomingFromExternalFromProductAsync(toBeProcessedProducts).ToList(); await _incomingFromExternalManager.CreateBulkAsync(incomingDataList).ConfigureAwait(false); return incomingDataList; diff --git a/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent/FawtygAutoMapperProfile.cs b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent/FawtygAutoMapperProfile.cs index 300c8bd05..53f9205a6 100644 --- a/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent/FawtygAutoMapperProfile.cs +++ b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent/FawtygAutoMapperProfile.cs @@ -130,5 +130,6 @@ public class FawtygAutoMapperProfile : Profile CreateMap(); CreateMap(); CreateMap(); + CreateMap(); } } diff --git a/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent/Incoming/ErpLocationItemReader.cs b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent/Incoming/ErpLocationItemReader.cs index 5fdea32b5..59dbe2d5b 100644 --- a/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent/Incoming/ErpLocationItemReader.cs +++ b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent/Incoming/ErpLocationItemReader.cs @@ -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 _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 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> 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>(wmsErpLocationItems); + List tyrpToItemBasicExchangeDtos = new List(); + 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(); } - //locdout逐一转换为locdout - var incomingDataList = BuildIncomingFromExternalFromBomAsync(toBeProcessedIssue); - await _incomingFromExternalManager.CreateBulkAsync(incomingDataList).ConfigureAwait(false); - return incomingDataList; - } - private List BuildIncomingFromExternalFromBomAsync(List toBeProcessedIssue) - { - var incomingDataList = new List(); - foreach (var locdout in toBeProcessedIssue) + List incomingDataList = new List(); + 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() diff --git a/be/DataExchange/src/Win_in.Sfs.Wms.DataExchange.Application.Contracts/WMS/ErpLocationItem/ErpLocationItem.cs b/be/DataExchange/src/Win_in.Sfs.Wms.DataExchange.Application.Contracts/WMS/ErpLocationItem/ErpLocationItem.cs index 180e65e2b..2e5694bf9 100644 --- a/be/DataExchange/src/Win_in.Sfs.Wms.DataExchange.Application.Contracts/WMS/ErpLocationItem/ErpLocationItem.cs +++ b/be/DataExchange/src/Win_in.Sfs.Wms.DataExchange.Application.Contracts/WMS/ErpLocationItem/ErpLocationItem.cs @@ -20,4 +20,18 @@ public class ErpLocationItemExchangeDto [Required(ErrorMessage = "{0}是必填项")] [StringLength(SfsEfCorePropertyConst.CodeLength, ErrorMessage = "{0}最多输入{1}个字符")] public string ItemCode { get; set; } + + public override bool Equals(object obj) + { + if (obj is ErpLocationItemExchangeDto) + { + ErpLocationItemExchangeDto item = obj as ErpLocationItemExchangeDto; + return ErpLocationCode == item.ErpLocationCode && ItemCode == item.ItemCode; + } + return false; + } + public override int GetHashCode() + { + return ErpLocationCode.GetHashCode()^ ItemCode.GetHashCode(); + } }