diff --git a/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs b/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs index 53391ee2..5db6aab0 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs @@ -22,7 +22,7 @@ namespace Tnb.WarehouseMgr /// 定时任务 /// added by ly on 20230802 /// - public class TimedTaskBackgroundService : BackgroundService + public class TimedTaskBackgroundService : IHostedService { private ISendMessageService? _sendService; @@ -50,8 +50,6 @@ namespace Tnb.WarehouseMgr TimedTask(cts => setSortingService.PackSortingByAdd(cts), setSortingCts, toUserIds); }); } - - private Task TimedTask(Func action, CancellationTokenSource cts, List? toUserIds = default) { var token = cts.Token; diff --git a/apihost/Tnb.API.Entry/Startup.cs b/apihost/Tnb.API.Entry/Startup.cs index dd5e6ed7..148569d4 100644 --- a/apihost/Tnb.API.Entry/Startup.cs +++ b/apihost/Tnb.API.Entry/Startup.cs @@ -64,7 +64,9 @@ public class Startup : AppStartup services.AddOverideVisualDev(); //定时任务 - services.AddHostedService(); + //services.AddHostedService(); + //services.AddSingleton(); + //services.AddHostedService(sp => new ConditionalBackgroundService(sp.GetRequiredService())); } diff --git a/system/Tnb.OAuth/OAuthService.cs b/system/Tnb.OAuth/OAuthService.cs index afebf9dd..37e1e397 100644 --- a/system/Tnb.OAuth/OAuthService.cs +++ b/system/Tnb.OAuth/OAuthService.cs @@ -41,6 +41,9 @@ using JNPF.Common.Core.Handlers; using JNPF.Message.Interfaces.Message; using JNPF.Extras.DatabaseAccessor.SqlSugar.Models; using Aop.Api.Domain; +using Tnb.WarehouseMgr; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; namespace JNPF.OAuth; @@ -140,6 +143,8 @@ public class OAuthService : IDynamicApiController, ITransient private readonly IMHandler _imHandler; + + /// /// 初始化一个类型的新实例. /// @@ -382,10 +387,14 @@ public class OAuthService : IDynamicApiController, ITransient [HttpGet("Logout")] public async Task Logout([FromQuery] string ticket) { + var tenantId = _userManager.TenantId ?? "default"; var userId = _userManager.UserId ?? "admim"; var httpContext = _httpContextAccessor.HttpContext; httpContext.SignoutToSwagger(); + //用户退出时停止Wms定时任务 modify by ly on 20230804 + var timedTaskService = ActivatorUtilities.CreateInstance(httpContext.RequestServices); + await timedTaskService.StopAsync(CancellationToken.None); // 清除IM中的webSocket var list = await GetOnlineUserList(tenantId); @@ -672,6 +681,12 @@ public class OAuthService : IDynamicApiController, ITransient } } + //启动Wms定时服务 modify by ly on 20230804 + //var conditionalBackgroundService = App.GetRequiredService(); + //await conditionalBackgroundService.StartAsync(CancellationToken.None); + var httpContext = _httpContextAccessor.HttpContext; + var timedTaskService = ActivatorUtilities.CreateInstance(httpContext.RequestServices); + await timedTaskService.StartAsync(default); return new { theme = user.Theme == null ? "classic" : user.Theme, diff --git a/system/Tnb.OAuth/Tnb.OAuth.csproj b/system/Tnb.OAuth/Tnb.OAuth.csproj index af2ae6c7..418136aa 100644 --- a/system/Tnb.OAuth/Tnb.OAuth.csproj +++ b/system/Tnb.OAuth/Tnb.OAuth.csproj @@ -12,6 +12,7 @@ +