diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Enums/TimeSpanUnit.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Enums/TimeSpanUnit.cs new file mode 100644 index 00000000..b9a26e80 --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Enums/TimeSpanUnit.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tnb.WarehouseMgr.Entities.Enums +{ + public enum TimeSpanUnit + { + Milliseconds, + Seconds, + Minutes, + Hours, + Days + + } +} diff --git a/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs b/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs index ca8b341e..d9a42d88 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs @@ -27,6 +27,7 @@ using Natasha.CSharp; using Tnb.Common.Extension; using Tnb.WarehouseMgr.Entities.Attributes; using Tnb.WarehouseMgr.Entities.Dto.Inputs; +using Tnb.WarehouseMgr.Entities.Enums; using Tnb.WarehouseMgr.Entities.Exceptions; using Tnb.WarehouseMgr.Interfaces; @@ -43,11 +44,13 @@ namespace Tnb.WarehouseMgr private static Dictionary> _timedFuncMap = new(StringComparer.OrdinalIgnoreCase); static TimedTaskBackgroundService() { - _timedFuncMap = App.EffectiveTypes.AsParallel().Where(t => !t.Namespace.IsNullOrWhiteSpace() && t.Namespace.Contains("Tnb.WarehouseMgr")).SelectMany(t => t.GetMethods()) - .Where(m => m.GetCustomAttribute() != null) - .ToDictionary(x => x.Name, x => - (Func)Delegate.CreateDelegate(typeof(Func), App.GetService(x.DeclaringType), x)); - + Task.Run(() => + { + _timedFuncMap = App.EffectiveTypes.AsParallel().Where(t => !t.Namespace.IsNullOrWhiteSpace() && t.Namespace.Contains("Tnb.WarehouseMgr")).SelectMany(t => t.GetMethods()) + .Where(m => m.GetCustomAttribute() != null) + .ToDictionary(x => x.Name, x => + (Func)Delegate.CreateDelegate(typeof(Func), App.GetService(x.DeclaringType), x)); + }); } public TimedTaskBackgroundService(IServiceProvider serviceProvider) { @@ -74,27 +77,24 @@ namespace Tnb.WarehouseMgr #region 定时 //_eventPublisher = App.GetRequiredService(); - //List toUserIds = new List() { "25398501929509" }; - ////生成任务执行 - //CancellationTokenSource genTaskCTS = new(); - //CancellationTokenSource kittingOutAddCts = new(); - //CancellationTokenSource kittingOutShippedCts = new(); - //CancellationTokenSource setSortingCts = new(); + CancellationTokenSource kittingOutAddCts = new(); + CancellationTokenSource kittingOutShippedCts = new(); + CancellationTokenSource setSortingCts = new(); //var wareHouseService = App.GetRequiredService(); - //TimedTask(cts => wareHouseService.GenTaskExecute(cts), genTaskCTS, toUserIds); - ////齐套出库 + //TimedTask(cts => wareHouseService.GenTaskExecute(cts), genTaskCTS); + //齐套出库 - //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, 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, List? toUserIds = default) + private Task TimedTask(Func action, CancellationTokenSource cts, int interval, TimeSpanUnit timeType = TimeSpanUnit.Seconds) { var token = cts.Token; return Task.Run(async () => @@ -120,10 +120,24 @@ namespace Tnb.WarehouseMgr })); } }); - await Task.Delay(1000); + + await GetDelayTask(timeType, interval); } }, token); } + private Task GetDelayTask(TimeSpanUnit timeType, int interval) + { + Task delayTask = timeType switch + { + TimeSpanUnit.Milliseconds => Task.Delay(TimeSpan.FromMilliseconds(interval)), + TimeSpanUnit.Seconds => Task.Delay(TimeSpan.FromSeconds(interval)), + TimeSpanUnit.Minutes => Task.Delay(TimeSpan.FromMinutes(interval)), + TimeSpanUnit.Hours => Task.Delay(TimeSpan.FromHours(interval)), + TimeSpanUnit.Days => Task.Delay(TimeSpan.FromDays(interval)), + }; + return delayTask; + } + } } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsKittingInStkService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsKittingInStkService.cs index bc460308..9935c4cf 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsKittingInStkService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsKittingInStkService.cs @@ -246,6 +246,10 @@ namespace Tnb.WarehouseMgr kittingOut.carry_id = kittingIn.carry_id; kittingOut.carry_code = kittingIn.carry_code; await _db.Updateable(kittingOut).UpdateColumns(it => new { it.status, it.carry_id, it.carry_code }).ExecuteCommandAsync(); + //if (kittingOut.status == WmsWareHouseConst.BILLSTATUS_TOBESHIPPED_ID) + //{ + // await Publish(nameof(IWmskittingOutService.KittingOutByIsToBeShipped)); + //} } } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsSetSortingService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsSetSortingService.cs index e519dfa0..8cee9278 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsSetSortingService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsSetSortingService.cs @@ -8,12 +8,16 @@ using System.Threading.Tasks; using JNPF; using JNPF.Common.Const; using JNPF.Common.Core.Manager; +using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Enums; using JNPF.Common.Extension; using JNPF.Common.Manager; using JNPF.Common.Security; using JNPF.FriendlyException; using JNPF.Systems.Interfaces.System; +using JNPF.VisualDev; +using JNPF.VisualDev.Entitys; +using JNPF.VisualDev.Interfaces; using Mapster; using Microsoft.AspNetCore.Mvc; using NPOI.SS.Formula; @@ -36,6 +40,7 @@ namespace Tnb.WarehouseMgr /// 齐套分拣服务类 /// [ServiceModule(BizTypeId)] + [OverideVisualDev(ModuleConsts.MODULE_WMSSETSORTING_ID)] public class WmsSetSortingService : BaseWareHouseService, IWmsSetSortingService { private readonly ISqlSugarClient _db; @@ -43,15 +48,46 @@ namespace Tnb.WarehouseMgr private readonly IBillRullService _billRullService; private readonly IUserManager _userManager; private readonly ICacheManager _cacheManager; + private readonly IRunService _runService; + private readonly IVisualDevService _visualDevService; private const string BizTypeId = "26186830379045"; - public WmsSetSortingService(ISqlSugarRepository repository, IWareHouseService wareHouseService, IUserManager userManager, IBillRullService billRullService, ICacheManager cacheManager) + public WmsSetSortingService( + ISqlSugarRepository repository, + IWareHouseService wareHouseService, + IUserManager userManager, IBillRullService billRullService, + ICacheManager cacheManager, + IRunService runService, + IVisualDevService visualDevService, + ITaskMessageNotify taskMessageNotify + ) : base(taskMessageNotify.Writer) { _db = repository.AsSugarClient(); _wareHouseService = wareHouseService; _billRullService = billRullService; _userManager = userManager; _cacheManager = cacheManager; + _runService = runService; + _visualDevService = visualDevService; + OverideFuncs.CreateAsync = Create; + } + + private async Task Create(VisualDevModelDataCrInput input) + { + //在线开发 + try + { + VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleConsts.MODULE_WMSEMPTYINSTOCK_ID, true); + await _runService.Create(templateEntity, input); + + await PackSortingByAdd(); + } + catch (Exception) + { + throw; + } + return Task.FromResult(1); + } /// @@ -61,9 +97,6 @@ namespace Tnb.WarehouseMgr [HttpPost, Timed(Name = nameof(PackSortingByAdd))] public async Task PackSortingByAdd(CancellationTokenSource? cts = default) { - var aToken = await _cacheManager.GetAsync("AccessToken"); - if (aToken.IsNullOrWhiteSpace()) return; - var curUser = await GetUserIdentity(aToken); var curDb = _db.CopyNew(); string firstLocationId = "27010980724501", secondLocationId = "27010987857941"; @@ -189,12 +222,12 @@ namespace Tnb.WarehouseMgr { var leftCarrys = carrys[..mid]; var rightCarrys = carrys[mid..]; - await InnerGenPreTask(leftCarrys, locIds, firstLocationId, singleSorting.id, singleSorting.bill_code, preTasks, endLocation, curUser); - await InnerGenPreTask(rightCarrys, locIds, secondLocationId, singleSorting.id, singleSorting.bill_code, preTasks, endLocation, curUser); + await InnerGenPreTask(leftCarrys, locIds, firstLocationId, singleSorting.id, singleSorting.bill_code, preTasks, endLocation); + await InnerGenPreTask(rightCarrys, locIds, secondLocationId, singleSorting.id, singleSorting.bill_code, preTasks, endLocation); } else { - await InnerGenPreTask(carrys, locIds, firstLocationId, singleSorting.id, singleSorting.bill_code, preTasks, endLocation, curUser); + await InnerGenPreTask(carrys, locIds, firstLocationId, singleSorting.id, singleSorting.bill_code, preTasks, endLocation); } List pretaskCodes = new(); foreach (var pt in preTasks) @@ -226,19 +259,13 @@ namespace Tnb.WarehouseMgr { JNPF.Logging.Log.Error("齐套分拣执行时出现错误", ex); await curDb.Ado.RollbackTranAsync(); - TimedTaskErrorInfo ei = new() - { - RequestURL = App.HttpContext?.Request?.Path, - RequestMethod = App.HttpContext?.Request?.Method, - userIdentity = curUser, - }; - var timedTaskEx = ex.ToTimedTaskException(ei); + cts?.Cancel(); - throw timedTaskEx; + throw; } } - private async Task InnerGenPreTask(WmsCarryH[] carrys, List locIds, string eLocationId, string requireId, string requireCode, List preTasks, BasLocation endLocation, ClaimsPrincipal curUser) + private async Task InnerGenPreTask(WmsCarryH[] carrys, List locIds, string eLocationId, string requireId, string requireCode, List preTasks, BasLocation endLocation) { foreach (var carry in carrys) { @@ -263,7 +290,7 @@ namespace Tnb.WarehouseMgr WmsPretaskH preTask = new() { - org_id = curUser.FindFirst(ClaimConst.CLAINMORGID)?.Value, + org_id = _userManager.User.OrganizeId, startlocation_id = sPoint?.location_id!, startlocation_code = sPoint?.location_code!, endlocation_id = ePoint?.location_id!, @@ -280,7 +307,7 @@ namespace Tnb.WarehouseMgr area_code = it.Key, require_id = requireId, require_code = requireCode, - create_id = curUser.FindFirst(ClaimConst.CLAINMUSERID)?.Value!, + create_id = _userManager.UserId, create_time = DateTime.Now, source_id = carry.source_id, source_code = carry.source_code, diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmskittingOutService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmskittingOutService.cs index 6a66e2f5..ef031ce3 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmskittingOutService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmskittingOutService.cs @@ -116,6 +116,7 @@ namespace Tnb.WarehouseMgr ko.carry_id = firstCarry?.id; ko.carry_code = firstCarry?.carry_code; await _db.Updateable(ko).UpdateColumns(it => new { it.status, it.carry_id, it.carry_code }).ExecuteCommandAsync(); + //await KittingOutByIsToBeShipped(); if (firstCarry != null) { firstCarry.source_id = ko.source_id; @@ -153,6 +154,7 @@ namespace Tnb.WarehouseMgr ko.status = WmsWareHouseConst.BILLSTATUS_CALLED_ID; await curDb.Updateable(ko).UpdateColumns(it => it.status).ExecuteCommandAsync(); isCalled = true; + //await Publish(nameof(IWmsSetSortingService.PackSortingByAdd)); } } } @@ -405,7 +407,7 @@ namespace Tnb.WarehouseMgr await _db.Insertable(kittingOuts).ExecuteCommandAsync(); await _db.Insertable(kittingOutDs).ExecuteCommandAsync(); - + await _db.Ado.CommitTranAsync(); await KittingOutByAdd(); isSuccessFul = true;