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.
65 lines
2.6 KiB
65 lines
2.6 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.Fawtyg.EosAgent.Incoming;
|
|
|
|
namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.EosAgent;
|
|
|
|
public class EosIncomingBackgroundWorker : AsyncPeriodicBackgroundWorkerBase
|
|
{
|
|
private readonly string Incoming = "EOS Incoming";
|
|
|
|
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($"Starting: Handling {Incoming}");
|
|
if (!_options.Value.IncomingOptions.Active)
|
|
{
|
|
Logger.LogInformation($"{Incoming} is not active!");
|
|
return;
|
|
}
|
|
|
|
Logger.LogInformation($"Read Plan");
|
|
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($"Read Ship");
|
|
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($"Read Product");
|
|
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($"Completed: Handling {Incoming}");
|
|
}
|
|
|
|
}
|
|
|