|
|
|
using System;
|
|
|
|
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.Fawtyg.Tyrp;
|
|
|
|
using Win_in.Sfs.Wms.DataExchange.Domain.Shared;
|
|
|
|
using Win_in.Sfs.Wms.DataExchange.WMS.ErpLocationItem;
|
|
|
|
|
|
|
|
namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent.Incoming;
|
|
|
|
|
|
|
|
public class ErpLocationItemReader : IReader
|
|
|
|
{
|
|
|
|
private readonly IErpLocationItemManager _ilocdoutManager;
|
|
|
|
private readonly IIncomingFromExternalManager _incomingFromExternalManager;
|
|
|
|
private readonly ILogger<ErpLocationItemReader> _logger;
|
|
|
|
private readonly IGuidGenerator _guidGenerator;
|
|
|
|
private readonly IConfiguration _configuration;
|
|
|
|
public ErpLocationItemReader(
|
|
|
|
IErpLocationItemManager ilocdoutManager
|
|
|
|
, IIncomingFromExternalManager incomingFromExternalManager
|
|
|
|
, IGuidGenerator guidGenerator
|
|
|
|
, ILogger<ErpLocationItemReader> logger
|
|
|
|
, IConfiguration configuration
|
|
|
|
)
|
|
|
|
{
|
|
|
|
_guidGenerator = guidGenerator;
|
|
|
|
_configuration = configuration;
|
|
|
|
_ilocdoutManager = ilocdoutManager;
|
|
|
|
_incomingFromExternalManager = incomingFromExternalManager;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual async Task<List<IncomingFromExternal>> ReadAsync()
|
|
|
|
{
|
|
|
|
//从Tyrp读取待处理locdout
|
|
|
|
var toBeProcessedIssue = await _ilocdoutManager.GetToBeProcessedListAsync().ConfigureAwait(false);
|
|
|
|
if (!toBeProcessedIssue.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)
|
|
|
|
{
|
|
|
|
var incomingData = BuildIncomingFromExternal(locdout);
|
|
|
|
|
|
|
|
incomingData.SetEffectiveDate(DateTime.Now);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var bm = BuildScrapNoteOrderExchangeMes(locdout);
|
|
|
|
incomingData.DestinationDataContent = JsonSerializer.Serialize(bm);
|
|
|
|
incomingData.SetId(_guidGenerator.Create());
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
incomingData.SetError(EnumExchangeDataErrorCode.Exception, ex.Message, ex.ToString());
|
|
|
|
}
|
|
|
|
|
|
|
|
incomingDataList.Add(incomingData);
|
|
|
|
|
|
|
|
}
|
|
|
|
return incomingDataList;
|
|
|
|
}
|
|
|
|
private IncomingFromExternal BuildIncomingFromExternal(locdout locdout)
|
|
|
|
{
|
|
|
|
var incomingData = new IncomingFromExternal()
|
|
|
|
{
|
|
|
|
|
|
|
|
DataType = EnumIncomingDataType.ErpLocationItem.ToString(),
|
|
|
|
DataAction = EnumExchangeDataAction.Add,
|
|
|
|
SourceSystem = EnumSystemType.ERP.ToString(),
|
|
|
|
SourceDataId = locdout.locdout_loc,
|
|
|
|
SourceDataGroupCode = locdout.locdout_loc,
|
|
|
|
SourceDataDetailCode = locdout.locdout_part,
|
|
|
|
SourceDataContent = JsonSerializer.Serialize(locdout),
|
|
|
|
WriteTime = DateTime.Now,
|
|
|
|
Writer = nameof(TyrpIncomingBackgroundWorker),
|
|
|
|
DestinationSystem = EnumSystemType.ERP.ToString(),
|
|
|
|
};
|
|
|
|
return incomingData;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static ErpLocationItemExchangeDto BuildScrapNoteOrderExchangeMes(locdout locdout)
|
|
|
|
{
|
|
|
|
|
|
|
|
var cust = new ErpLocationItemExchangeDto()
|
|
|
|
{
|
|
|
|
ErpLocationCode = locdout.locdout_loc,
|
|
|
|
ItemCode = locdout.locdout_part,
|
|
|
|
};
|
|
|
|
|
|
|
|
return cust;
|
|
|
|
}
|
|
|
|
}
|