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/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/apihost/Tnb.API.Entry/Startup.cs b/apihost/Tnb.API.Entry/Startup.cs index dd5e6ed7..6b72c8c3 100644 --- a/apihost/Tnb.API.Entry/Startup.cs +++ b/apihost/Tnb.API.Entry/Startup.cs @@ -64,7 +64,7 @@ public class Startup : AppStartup services.AddOverideVisualDev(); //定时任务 - services.AddHostedService(); + services.AddHostedService(sp => new ConditionalBackgroundService(sp.GetRequiredService())); } diff --git a/system/Tnb.OAuth/OAuthService.cs b/system/Tnb.OAuth/OAuthService.cs index afebf9dd..ea5d3651 100644 --- a/system/Tnb.OAuth/OAuthService.cs +++ b/system/Tnb.OAuth/OAuthService.cs @@ -41,6 +41,7 @@ using JNPF.Common.Core.Handlers; using JNPF.Message.Interfaces.Message; using JNPF.Extras.DatabaseAccessor.SqlSugar.Models; using Aop.Api.Domain; +using Tnb.WarehouseMgr; namespace JNPF.OAuth; @@ -382,6 +383,10 @@ public class OAuthService : IDynamicApiController, ITransient [HttpGet("Logout")] public async Task Logout([FromQuery] string ticket) { + //用户退出时停止Wms定时任务 modify by ly on 20230804 + var conditionalBackgroundService = App.GetRequiredService(); + await conditionalBackgroundService.StopAsync(CancellationToken.None); + var tenantId = _userManager.TenantId ?? "default"; var userId = _userManager.UserId ?? "admim"; var httpContext = _httpContextAccessor.HttpContext; @@ -672,6 +677,10 @@ public class OAuthService : IDynamicApiController, ITransient } } + //启动Wms定时服务 modify by ly on 20230804 + var conditionalBackgroundService = App.GetRequiredService(); + await conditionalBackgroundService.StartAsync(CancellationToken.None); + 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 @@ +