From e892c087344a03298f53222c6dd7b019bf857a8e Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 4 Aug 2023 11:26:08 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=98=E5=8E=9F=E4=BB=A3=E7=A0=81=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=E7=B3=BB=E7=BB=9F=E5=B4=A9=E6=BA=83=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConditionalBackgroundService.cs | 30 ++++++++++++ .../TimedTaskBackgroundService.cs | 49 +++++++++---------- .../Tnb.WarehouseMgr/WareHouseService.cs | 1 - .../WmsRobotCallbackService.cs | 4 +- .../Tnb.WarehouseMgr/WmskittingOutService.cs | 2 + .../Tnb.TaskScheduler/TimeTaskService.cs | 2 +- 6 files changed, 59 insertions(+), 29 deletions(-) create mode 100644 WarehouseMgr/Tnb.WarehouseMgr/ConditionalBackgroundService.cs diff --git a/WarehouseMgr/Tnb.WarehouseMgr/ConditionalBackgroundService.cs b/WarehouseMgr/Tnb.WarehouseMgr/ConditionalBackgroundService.cs new file mode 100644 index 00000000..745a3cf2 --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr/ConditionalBackgroundService.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Hosting; + +namespace Tnb.WarehouseMgr +{ + public class ConditionalBackgroundService : IHostedService + { + private readonly IHostedService _backgroundService; + //private readonly Func _condition; + + public ConditionalBackgroundService(IHostedService backgroundService) + { + _backgroundService = backgroundService; + } + + public async Task StartAsync(CancellationToken cancellationToken) + { + await _backgroundService.StartAsync(cancellationToken); + } + public async Task StopAsync(CancellationToken cancellationToken) + { + await _backgroundService.StopAsync(cancellationToken); + } + + } +} diff --git a/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs b/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs index 3f3b38f1..53391ee2 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs @@ -25,32 +25,33 @@ namespace Tnb.WarehouseMgr public class TimedTaskBackgroundService : BackgroundService { private ISendMessageService? _sendService; - protected override async Task ExecuteAsync(CancellationToken stoppingToken) + + protected override Task ExecuteAsync(CancellationToken stoppingToken) { - - await Task.Run(() => - { - _sendService = App.GetRequiredService(); - var userManager = App.GetRequiredService(); - List toUserIds = new List() { "25398501929509" }; - //生成任务执行 - CancellationTokenSource genTaskCTS = new(); - CancellationTokenSource kittingOutAddCts = new(); - CancellationTokenSource kittingOutShippedCts = new(); - CancellationTokenSource setSortingCts = new(); + return Task.Run(() => + { + //_sendService = 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, toUserIds); - //齐套出库 + var wareHouseService = App.GetRequiredService(); + TimedTask(cts => wareHouseService.GenTaskExecute(cts), genTaskCTS, toUserIds); + //齐套出库 - var kittingOutService = App.GetRequiredService(); - TimedTask(cts => kittingOutService.KittingOutByAdd(cts), kittingOutAddCts, toUserIds); - TimedTask(cts => kittingOutService.KittingOutByIsToBeShipped(cts), kittingOutShippedCts, toUserIds); - //齐套分拣 - var setSortingService = App.GetRequiredService(); - TimedTask(cts => setSortingService.PackSortingByAdd(cts), setSortingCts, toUserIds); - }); + var kittingOutService = App.GetRequiredService(); + TimedTask(cts => kittingOutService.KittingOutByAdd(cts), kittingOutAddCts, toUserIds); + TimedTask(cts => kittingOutService.KittingOutByIsToBeShipped(cts), kittingOutShippedCts, toUserIds); + //齐套分拣 + var setSortingService = App.GetRequiredService(); + TimedTask(cts => setSortingService.PackSortingByAdd(cts), setSortingCts, toUserIds); + }); } + + private Task TimedTask(Func action, CancellationTokenSource cts, List? toUserIds = default) { var token = cts.Token; @@ -60,9 +61,7 @@ namespace Tnb.WarehouseMgr { await action(cts).Catch(ex => { - //MessageSendModel messageSendModel = new(); - //_sendService?.SendMessage(); - //messageService.SentMessage(toUserIds!, ex.Message, ex.ToString()); + //notify operator }); await Task.Delay(1000); } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs index 78fabc26..5aacae45 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs @@ -283,7 +283,6 @@ namespace Tnb.WarehouseMgr start = end; end = Math.Min((end + moveNum), arrary.Length); } - foreach (var arr in arrList) { for (int j = 1, len = arr.Length; j <= len; j++) diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsRobotCallbackService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsRobotCallbackService.cs index 53a612da..eb14d720 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsRobotCallbackService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsRobotCallbackService.cs @@ -99,8 +99,8 @@ namespace Tnb.WarehouseMgr visualDevModelCrInput.data[nameof(WmsKittingInstock.create_time)] = DateTime.Now; visualDevModelCrInput.data[nameof(WmsKittingInstock.location_id)] = carry!.location_id!; visualDevModelCrInput.data[nameof(WmsKittingInstock.bill_code)] = _billRullService.GetBillNumber("WmsKittingInStk").GetAwaiter().GetResult(); - visualDevModelCrInput.data[nameof(WmsKittingInstock.source_id)] = kittingout.source_id; - visualDevModelCrInput.data[nameof(WmsKittingInstock.source_code)] = kittingout.source_code; + visualDevModelCrInput.data[nameof(WmsKittingInstock.source_id)] = kittingout.id; + visualDevModelCrInput.data[nameof(WmsKittingInstock.source_code)] = kittingout.bill_code; var location = await _db.Queryable().SingleAsync(it => it.id == kittingout.location_id); diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmskittingOutService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmskittingOutService.cs index adbee72a..c6141429 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmskittingOutService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmskittingOutService.cs @@ -155,6 +155,8 @@ namespace Tnb.WarehouseMgr [HttpPost] public async Task KittingOutByIsToBeShipped(CancellationTokenSource? cts = default) { + if (_userManager.User == null) return; + var curDb = _db.CopyNew(); try { diff --git a/taskschedule/Tnb.TaskScheduler/TimeTaskService.cs b/taskschedule/Tnb.TaskScheduler/TimeTaskService.cs index 41e779a2..9b62e4c1 100644 --- a/taskschedule/Tnb.TaskScheduler/TimeTaskService.cs +++ b/taskschedule/Tnb.TaskScheduler/TimeTaskService.cs @@ -302,7 +302,7 @@ public class TimeTaskService : ITimeTaskService, IDynamicApiController, ITransie // 非多租户模式启动自启任务 if (!KeyVariable.MultiTenancy) { - _repository.AsQueryable().Where(x => x.DeleteMark == null && x.EnabledMark == 1).ToList().ForEach(x=>AddTimerJob(x,false));//modifyby zhoukeda 20230607 + _repository.AsSugarClient().CopyNew().Queryable().Where(x => x.DeleteMark == null && x.EnabledMark == 1).ToList().ForEach(x=>AddTimerJob(x,false));//modifyby zhoukeda 20230607 } }