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.
82 lines
3.4 KiB
82 lines
3.4 KiB
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Options;
|
|
using Volo.Abp.BackgroundWorkers;
|
|
using Volo.Abp.Threading;
|
|
using Volo.Abp.Uow;
|
|
using Win_in.Sfs.Wms.DataExchange.Domain;
|
|
using Win_in.Sfs.Wms.DataExchange.Fawtyg.EosAgent.Incoming;
|
|
|
|
namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.EosAgent;
|
|
|
|
public class EosIncomingBackgroundWorker : AsyncPeriodicBackgroundWorkerBase
|
|
{
|
|
private readonly string Incoming = "EOS接收";
|
|
|
|
private readonly IOptions<EosOptions> _options;
|
|
|
|
public EosIncomingBackgroundWorker(
|
|
AbpAsyncTimer timer,
|
|
IOptions<EosOptions> options,
|
|
IServiceScopeFactory serviceScopeFactory
|
|
) : base(timer, serviceScopeFactory)
|
|
{
|
|
_options = options;
|
|
Timer.Period = options.Value.IncomingOptions.PeriodSeconds * 1000; //default 10 minutes
|
|
}
|
|
|
|
[UnitOfWork]
|
|
protected override async Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext)
|
|
{
|
|
Logger.LogInformation($"开始: 执行 {Incoming}");
|
|
var configManager = workerContext.ServiceProvider.GetRequiredService<IInterfaceConfigManager>();
|
|
var confitem = await configManager.GetInterfaceConfig("EOS-IN").ConfigureAwait(false);
|
|
if (confitem == null)
|
|
{
|
|
if (!_options.Value.IncomingOptions.Active)
|
|
{
|
|
Logger.LogInformation($"{Incoming} 已关闭没有执行!");
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!confitem.Active)
|
|
{
|
|
Logger.LogInformation($"{Incoming} 已关闭没有执行!");
|
|
return;
|
|
}
|
|
}
|
|
|
|
Logger.LogInformation($"读取 采购订单");
|
|
var planReader = workerContext.ServiceProvider.GetRequiredService<PlanReader>();
|
|
var planConverter = workerContext.ServiceProvider.GetRequiredService<PlanConverter>();
|
|
//读取并保存Plan
|
|
var plansFromExternalList = await planReader.ReadAsync().ConfigureAwait(false);
|
|
//转换Plan
|
|
await planConverter.ConvertAsync(plansFromExternalList).ConfigureAwait(false);
|
|
Logger.LogInformation($"处理采购订单【{plansFromExternalList.Count}】条数据");
|
|
|
|
Logger.LogInformation($"读取 发货单");
|
|
var shipHandleService = workerContext.ServiceProvider.GetRequiredService<ShipReader>();
|
|
var shipConverter = workerContext.ServiceProvider.GetRequiredService<ShipConverter>();
|
|
//读取并保持Ship
|
|
var shipsFromExternalList = await shipHandleService.ReadAsync().ConfigureAwait(false);
|
|
//转换Ship
|
|
await shipConverter.ConvertAsync(shipsFromExternalList).ConfigureAwait(false);
|
|
Logger.LogInformation($"处理发货单【{shipsFromExternalList.Count}】条数据");
|
|
|
|
Logger.LogInformation($"读取 产品");
|
|
var productHandleService = workerContext.ServiceProvider.GetRequiredService<ProductReader>();
|
|
var productConverter = workerContext.ServiceProvider.GetRequiredService<ProductConverter>();
|
|
//读取并保持Product
|
|
var productsFromExternalList = await productHandleService.ReadAsync().ConfigureAwait(false);
|
|
// 转换Product
|
|
await productConverter.ConvertAsync(productsFromExternalList).ConfigureAwait(false);
|
|
Logger.LogInformation($"处理产品【{productsFromExternalList.Count}】条数据");
|
|
|
|
Logger.LogInformation($"提交: 执行 {Incoming}");
|
|
}
|
|
|
|
}
|
|
|