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.
109 lines
3.8 KiB
109 lines
3.8 KiB
|
|
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 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.Customer;
|
|
|
|
namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent.Incoming;
|
|
|
|
public class CustomerReader : IReader
|
|
{
|
|
private readonly ICustomerManager _icustomerManager;
|
|
private readonly IIncomingFromExternalManager _incomingFromExternalManager;
|
|
private readonly ILogger<CustomerReader> _logger;
|
|
private readonly IGuidGenerator _guidGenerator;
|
|
private readonly IConfiguration _configuration;
|
|
public CustomerReader(
|
|
ICustomerManager icustomerManager
|
|
, IIncomingFromExternalManager incomingFromExternalManager
|
|
, IGuidGenerator guidGenerator
|
|
, ILogger<CustomerReader> logger
|
|
, IConfiguration configuration
|
|
)
|
|
{
|
|
_guidGenerator = guidGenerator;
|
|
_configuration = configuration;
|
|
_icustomerManager = icustomerManager;
|
|
_incomingFromExternalManager = incomingFromExternalManager;
|
|
_logger = logger;
|
|
}
|
|
|
|
public virtual async Task<List<IncomingFromExternal>> ReadAsync()
|
|
{
|
|
//从Tyrp读取待处理customer
|
|
var toBeProcessedIssue = await _icustomerManager.GetToBeProcessedListAsync().ConfigureAwait(false);
|
|
if (!toBeProcessedIssue.Any())
|
|
{
|
|
_logger.LogInformation("no customers");
|
|
return new List<IncomingFromExternal>();
|
|
}
|
|
//customer逐一转换为customer
|
|
var incomingDataList = BuildIncomingFromExternalFromBomAsync(toBeProcessedIssue);
|
|
await _incomingFromExternalManager.CreateBulkAsync(incomingDataList).ConfigureAwait(false);
|
|
return incomingDataList;
|
|
}
|
|
private List<IncomingFromExternal> BuildIncomingFromExternalFromBomAsync(List<cmout> toBeProcessedIssue)
|
|
{
|
|
var incomingDataList = new List<IncomingFromExternal>();
|
|
foreach (var customer in toBeProcessedIssue)
|
|
{
|
|
var incomingData = BuildIncomingFromExternal(customer);
|
|
|
|
incomingData.SetEffectiveDate(DateTime.Now);
|
|
|
|
try
|
|
{
|
|
var bm = BuildScrapNoteOrderExchangeMes(customer);
|
|
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(cmout customer)
|
|
{
|
|
var incomingData = new IncomingFromExternal()
|
|
{
|
|
|
|
DataType = EnumIncomingDataType.Customer.ToString(),
|
|
DataAction = EnumExchangeDataAction.Add,
|
|
SourceSystem = EnumSystemType.ERP.ToString(),
|
|
SourceDataId = customer.cmout_shot,
|
|
SourceDataGroupCode = customer.cmout_cust,
|
|
SourceDataDetailCode = customer.cmout_name,
|
|
SourceDataContent = JsonSerializer.Serialize(customer),
|
|
WriteTime = DateTime.Now,
|
|
Writer = nameof(TyrpIncomingBackgroundWorker),
|
|
DestinationSystem = EnumSystemType.ERP.ToString(),
|
|
};
|
|
return incomingData;
|
|
}
|
|
|
|
private static CustomerExchangeDto BuildScrapNoteOrderExchangeMes(cmout customer)
|
|
{
|
|
|
|
var cust = new CustomerExchangeDto()
|
|
{
|
|
Code = customer.cmout_cust,
|
|
ShortName = customer.cmout_shot,
|
|
Name = customer.cmout_name,
|
|
};
|
|
|
|
return cust;
|
|
}
|
|
}
|
|
|