|
|
|
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.MesAgent.Outgoing;
|
|
|
|
|
|
|
|
namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.MesAgent;
|
|
|
|
|
|
|
|
public class MesOutgoingBackgroundWorker : AsyncPeriodicBackgroundWorkerBase
|
|
|
|
{
|
|
|
|
private readonly string Outgoing = "MES Outgoing";
|
|
|
|
|
|
|
|
private readonly IOptions<MesOptions> _options;
|
|
|
|
|
|
|
|
public MesOutgoingBackgroundWorker(
|
|
|
|
AbpAsyncTimer timer
|
|
|
|
, IOptions<MesOptions> options
|
|
|
|
, IServiceScopeFactory serviceScopeFactory
|
|
|
|
) : base(timer, serviceScopeFactory)
|
|
|
|
{
|
|
|
|
_options = options;
|
|
|
|
Timer.Period = options.Value.OutgoingOptions.PeriodSeconds * 1000; //default 10 minutes
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
[UnitOfWork]
|
|
|
|
protected override async Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext)
|
|
|
|
{
|
|
|
|
Logger.LogInformation($"Starting: Handling {Outgoing}");
|
|
|
|
|
|
|
|
var configManager = workerContext.ServiceProvider.GetRequiredService<IInterfaceConfigManager>();
|
|
|
|
var confitem = await configManager.GetInterfaceConfig("MES-OUT").ConfigureAwait(false);
|
|
|
|
if (confitem == null)
|
|
|
|
{
|
|
|
|
if (!_options.Value.OutgoingOptions.Active)
|
|
|
|
{
|
|
|
|
Logger.LogInformation($"{Outgoing} 已关闭没有执行!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!confitem.Active)
|
|
|
|
{
|
|
|
|
Logger.LogInformation($"{Outgoing} 已关闭没有执行!");
|
|
|
|
if (confitem.Status == 0)
|
|
|
|
{
|
|
|
|
await configManager.UpsertStatusAsync("MES-OUT").ConfigureAwait(false);
|
|
|
|
Logger.LogInformation($"{Outgoing} 运行已结束,更新接口运行状态!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Logger.LogInformation($"Write Issue");
|
|
|
|
var issueConvert = workerContext.ServiceProvider.GetRequiredService<IssuesConverter>();
|
|
|
|
var issueNoteList = await issueConvert.ConvertAsync().ConfigureAwait(false);
|
|
|
|
var issueWriter = workerContext.ServiceProvider.GetRequiredService<IssueNoteWriter>();
|
|
|
|
await issueWriter.WriteAsync(issueNoteList).ConfigureAwait(false);
|
|
|
|
|
|
|
|
Logger.LogInformation($"Completed: Handling {Outgoing}");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|