using System; using System.Linq; 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.Shared; using Win_in.Sfs.Wms.DataExchange.Fawtyg.MesAgent.Incoming; namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.MesAgent; public class MesIncomingBackgroundWorker : AsyncPeriodicBackgroundWorkerBase { private readonly string Incoming = "MES接收"; private readonly IOptions _options; public MesIncomingBackgroundWorker( 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}"); if (!_options.Value.IncomingOptions.Active) { Logger.LogInformation($"{Incoming} 已关闭没有执行!"); return; } int min = DateTime.Now.Hour*60+ DateTime.Now.Minute;//第二天00:05:00与当天23:55:00不执行避免tyrpnumber重复 if ( (24*60-5)<= min || min <= 5) { Logger.LogInformation($"{Incoming} 时间小于第二天00:05:00大于当天23:55:00"); return; } //#region 缴库 MesOut //Logger.LogInformation($"读取缴库(MesOut)");//缴库 //var mesOutReader = workerContext.ServiceProvider.GetRequiredService(); //var mesOutConverter = workerContext.ServiceProvider.GetRequiredService(); //var TransferNoteConverter = workerContext.ServiceProvider.GetRequiredService(); ////读取mes缴库 //var mesOutsFromExternalList = await mesOutReader.ReadAsync().ConfigureAwait(false); //var mesOutsFromExternalList_ProductReceipt = mesOutsFromExternalList.Where(r => r.DataType == EnumIncomingDataType.ProductReceipt.ToString()).ToList(); //var mesOutsFromExternalList_TransferNote = mesOutsFromExternalList.Where(r => r.DataType == EnumIncomingDataType.TransferNote.ToString()).ToList(); ////转换缴库数据(如果有质量补得数据直接生产移库数据移到客户库位) //await mesOutConverter.ConvertAsync(mesOutsFromExternalList_ProductReceipt).ConfigureAwait(false); //if (mesOutsFromExternalList_TransferNote.Count > 0)//如果有质量补则生产储位调拨任务 //{ // await TransferNoteConverter.ConvertAsync(mesOutsFromExternalList_TransferNote).ConfigureAwait(false); //} //Logger.LogInformation($"处理完工收货(缴库)【{mesOutsFromExternalList_ProductReceipt.Count}】条数据"); //Logger.LogInformation($"处理储位调拨【{mesOutsFromExternalList_TransferNote.Count}】条数据"); //#endregion //#region 冻结解冻 Frozen //Logger.LogInformation($"读取冻结解冻 (Frozen)");//冻结解冻 //var FrozenReader = workerContext.ServiceProvider.GetRequiredService(); //var FrozenConverter = workerContext.ServiceProvider.GetRequiredService(); ////读取并保存Frozen //var mesNoteFromExternalList = await FrozenReader.ReadAsync().ConfigureAwait(false); ////转换Frozen //await FrozenConverter.ConvertAsync(mesNoteFromExternalList).ConfigureAwait(false); //Logger.LogInformation($"处理冻结解冻【{mesNoteFromExternalList.Count}】条数据"); //#endregion //#region 报废 Scrap //Logger.LogInformation($"读取报废(Scrap)");//报废 //var scrapReader = workerContext.ServiceProvider.GetRequiredService(); //var scrapConverter = workerContext.ServiceProvider.GetRequiredService(); ////读取并保存Scrap //var scrapsFromExternalList = await scrapReader.ReadAsync().ConfigureAwait(false); ////转换Scrap //await scrapConverter.ConvertAsync(scrapsFromExternalList).ConfigureAwait(false); //Logger.LogInformation($"处理报废【{scrapsFromExternalList.Count}】条数据"); //#endregion //#region 耗用单 BackFlush //Logger.LogInformation($"读取耗用单 (BackFlush)");//耗用单 //var BackFlushReader = workerContext.ServiceProvider.GetRequiredService(); //var BackFlushConverter = workerContext.ServiceProvider.GetRequiredService(); ////读取并保存BackFlush //var backFlushsFromExternalList = await BackFlushReader.ReadAsync().ConfigureAwait(false); ////转换BackFlush //await BackFlushConverter.ConvertAsync(backFlushsFromExternalList).ConfigureAwait(false); //Logger.LogInformation($"处理耗用单【{backFlushsFromExternalList.Count}】条数据"); //#endregion //#region 储位调拨 TransferNote //Logger.LogInformation($"读取储位调拨 (TransferNote)");//储位调拨 //var TransferNoteReader = workerContext.ServiceProvider.GetRequiredService(); //// var TransferNoteConverter = workerContext.ServiceProvider.GetRequiredService(); ////读取并保存TransferNote //var transferNoteFromExternalList = await TransferNoteReader.ReadAsync().ConfigureAwait(false); ////转换TransferNote //await TransferNoteConverter.ConvertAsync(transferNoteFromExternalList).ConfigureAwait(false); //Logger.LogInformation($"处理储位调拨【{transferNoteFromExternalList.Count}】条数据"); //#endregion //#region 成品发运 Delivery //Logger.LogInformation($"读取成品发运 (Delivery)");//成品发运 //var DeliveryReader = workerContext.ServiceProvider.GetRequiredService(); //var DeliveryConverter = workerContext.ServiceProvider.GetRequiredService(); ////读取并保存Delivery //var deliveryNoteFromExternalList = await DeliveryReader.ReadAsync().ConfigureAwait(false); ////转换Delivery //await DeliveryConverter.ConvertAsync(deliveryNoteFromExternalList).ConfigureAwait(false); //Logger.LogInformation($"处理成品发运【{deliveryNoteFromExternalList.Count}】条数据"); //#endregion //#region 自动叫料 CallMtl //Logger.LogInformation($"读取自动叫料 (CallMtl)");//自动叫料 //var CallMtlReader = workerContext.ServiceProvider.GetRequiredService(); //var CallMtlConverter = workerContext.ServiceProvider.GetRequiredService(); ////读取并保存Delivery //var callMtlFromExternalList = await CallMtlReader.ReadAsync().ConfigureAwait(false); ////转换Delivery //await CallMtlConverter.ConvertAsync(callMtlFromExternalList).ConfigureAwait(false); //Logger.LogInformation($"处理自动叫料【{callMtlFromExternalList.Count}】条数据"); //#endregion #region 底盘 Chassis Logger.LogInformation($"读取底盘(Chassis)");//底盘 var mesChassisReader = workerContext.ServiceProvider.GetRequiredService(); var mesChassisConverter = workerContext.ServiceProvider.GetRequiredService(); //读取并保存Chassis var mesChassisFromExternalList = await mesChassisReader.ReadAsync().ConfigureAwait(false); //转换Chassis await mesChassisConverter.ConvertAsync(mesChassisFromExternalList).ConfigureAwait(false); Logger.LogInformation($"处理底盘【{mesChassisFromExternalList.Count}】条数据"); #endregion Logger.LogInformation($"提交: 执行 {Incoming}"); #region 未启用接口启用时需要看逻辑修改 //上海和安徽无此接口 //Logger.LogInformation($"读取拉动任务 (PullTask)");//拉动任务 //var pullTaskReader = workerContext.ServiceProvider.GetRequiredService(); //var pullTaskConverter = workerContext.ServiceProvider.GetRequiredService(); ////读取并保存PullTask //var pullTaskFromExternalList = await pullTaskReader.ReadAsync().ConfigureAwait(false); ////转换PullTask //await pullTaskConverter.ConvertAsync(pullTaskFromExternalList).ConfigureAwait(false); // Logger.LogInformation($"处理拉动任务【{pullTaskFromExternalList.Count}】条数据"); //上海和安徽无此接口 //Logger.LogInformation($"Read (Issue)"); //var pckHandleService = workerContext.ServiceProvider.GetRequiredService(); //var pckConverter = workerContext.ServiceProvider.GetRequiredService(); ////读取并保持Pck //var pcksFromExternalList = await pckHandleService.ReadAsync().ConfigureAwait(false); ////转换Pck //await pckConverter.ConvertAsync(pcksFromExternalList).ConfigureAwait(false); #endregion } }