diff --git a/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs b/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs index 9ed682ae..d5b06ffd 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs @@ -57,44 +57,56 @@ namespace Tnb.WarehouseMgr _serviceProvider = serviceProvider; } - protected override Task ExecuteAsync(CancellationToken stoppingToken) => Task.Run(async () => - { + protected override Task ExecuteAsync(CancellationToken stoppingToken) + { + var queueTask = Task.Run(async () => + { - var channelReader = _serviceProvider.GetRequiredService().Reader; + var channelReader = _serviceProvider.GetRequiredService().Reader; - CancellationTokenSource? cts = new(); + CancellationTokenSource? cts = new(); - while (channelReader != null && await channelReader.WaitToReadAsync()) - { - while (channelReader.TryRead(out var message)) - { - if (_timedFuncMap.ContainsKey(message.TaskName)) - { - await _timedFuncMap[message.TaskName].Invoke(cts); - } - } - } + while (channelReader != null && await channelReader.WaitToReadAsync()) + { + while (channelReader.TryRead(out var message)) + { + if (_timedFuncMap.ContainsKey(message.TaskName)) + { + await _timedFuncMap[message.TaskName].Invoke(cts); + } + } + } + + }, stoppingToken); + + var timedTask = Task.Run(() => + { + _eventPublisher = App.GetRequiredService(); + ////生成任务执行 + //CancellationTokenSource genTaskCTS = new(); + CancellationTokenSource kittingOutAddCts = new(); + CancellationTokenSource kittingOutShippedCts = new(); + CancellationTokenSource setSortingCts = new(); + CancellationTokenSource isMinStorageCts = new(); + //var wareHouseService = App.GetRequiredService(); + //TimedTask(cts => wareHouseService.GenTaskExecute(cts), genTaskCTS); + //齐套出库 + var kittingOutService = App.GetRequiredService(); + TimedTask(cts => kittingOutService.KittingOutByAdd(cts), kittingOutAddCts, 1); + TimedTask(cts => kittingOutService.KittingOutByIsToBeShipped(cts), kittingOutShippedCts, 1); + //齐套分拣 + var setSortingService = App.GetRequiredService(); + TimedTask(cts => setSortingService.PackSortingByAdd(cts), setSortingCts, 1); + + var transferSignService = App.GetRequiredService(); + TimedTask(cts => transferSignService.IsMinStorage(cts), isMinStorageCts, 30, TimeSpanUnit.Minutes); + + }); + + return Task.WhenAll(queueTask, timedTask); + } - #region 定时 - //_eventPublisher = App.GetRequiredService(); - //List toUserIds = new List() { "25398501929509" }; - ////生成任务执行 - //CancellationTokenSource genTaskCTS = new(); - //CancellationTokenSource kittingOutAddCts = new(); - //CancellationTokenSource kittingOutShippedCts = new(); - //CancellationTokenSource setSortingCts = new(); - //var wareHouseService = App.GetRequiredService(); - //TimedTask(cts => wareHouseService.GenTaskExecute(cts), genTaskCTS); - //齐套出库 - var kittingOutService = App.GetRequiredService(); - TimedTask(cts => kittingOutService.KittingOutByAdd(cts), kittingOutAddCts, 1); - TimedTask(cts => kittingOutService.KittingOutByIsToBeShipped(cts), kittingOutShippedCts, 1); - //齐套分拣 - var setSortingService = App.GetRequiredService(); - TimedTask(cts => setSortingService.PackSortingByAdd(cts), setSortingCts, 1); - #endregion - }, stoppingToken); private Task TimedTask(Func action, CancellationTokenSource cts, int interval, TimeSpanUnit timeType = TimeSpanUnit.Seconds) { @@ -136,6 +148,7 @@ namespace Tnb.WarehouseMgr TimeSpanUnit.Minutes => Task.Delay(TimeSpan.FromMinutes(interval)), TimeSpanUnit.Hours => Task.Delay(TimeSpan.FromHours(interval)), TimeSpanUnit.Days => Task.Delay(TimeSpan.FromDays(interval)), + _ => throw new NotImplementedException() }; return delayTask; }