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 _options; public EosIncomingBackgroundWorker( AbpAsyncTimer timer, IOptions 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(); 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} 已关闭没有执行!"); if (confitem.Status == 0) { await configManager.UpsertStatusAsync("EOS-IN").ConfigureAwait(false); Logger.LogInformation($"{Incoming} 运行已结束,更新接口运行状态!"); } return; } } Logger.LogInformation($"读取 采购订单"); var planReader = workerContext.ServiceProvider.GetRequiredService(); var planConverter = workerContext.ServiceProvider.GetRequiredService(); //读取并保存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(); var shipConverter = workerContext.ServiceProvider.GetRequiredService(); //读取并保持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(); var productConverter = workerContext.ServiceProvider.GetRequiredService(); //读取并保持Product var productsFromExternalList = await productHandleService.ReadAsync().ConfigureAwait(false); // 转换Product await productConverter.ConvertAsync(productsFromExternalList).ConfigureAwait(false); Logger.LogInformation($"处理产品【{productsFromExternalList.Count}】条数据"); Logger.LogInformation($"提交: 执行 {Incoming}"); } }