1
This commit is contained in:
18
WarehouseMgr/Tnb.WarehouseMgr.Entities/Enums/TimeSpanUnit.cs
Normal file
18
WarehouseMgr/Tnb.WarehouseMgr.Entities/Enums/TimeSpanUnit.cs
Normal file
@@ -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
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,6 +27,7 @@ using Natasha.CSharp;
|
|||||||
using Tnb.Common.Extension;
|
using Tnb.Common.Extension;
|
||||||
using Tnb.WarehouseMgr.Entities.Attributes;
|
using Tnb.WarehouseMgr.Entities.Attributes;
|
||||||
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
|
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
|
||||||
|
using Tnb.WarehouseMgr.Entities.Enums;
|
||||||
using Tnb.WarehouseMgr.Entities.Exceptions;
|
using Tnb.WarehouseMgr.Entities.Exceptions;
|
||||||
using Tnb.WarehouseMgr.Interfaces;
|
using Tnb.WarehouseMgr.Interfaces;
|
||||||
|
|
||||||
@@ -43,11 +44,13 @@ namespace Tnb.WarehouseMgr
|
|||||||
private static Dictionary<string, Func<CancellationTokenSource?, Task>> _timedFuncMap = new(StringComparer.OrdinalIgnoreCase);
|
private static Dictionary<string, Func<CancellationTokenSource?, Task>> _timedFuncMap = new(StringComparer.OrdinalIgnoreCase);
|
||||||
static TimedTaskBackgroundService()
|
static TimedTaskBackgroundService()
|
||||||
{
|
{
|
||||||
_timedFuncMap = App.EffectiveTypes.AsParallel().Where(t => !t.Namespace.IsNullOrWhiteSpace() && t.Namespace.Contains("Tnb.WarehouseMgr")).SelectMany(t => t.GetMethods())
|
Task.Run(() =>
|
||||||
.Where(m => m.GetCustomAttribute<TimedAttribute>() != null)
|
{
|
||||||
.ToDictionary(x => x.Name, x =>
|
_timedFuncMap = App.EffectiveTypes.AsParallel().Where(t => !t.Namespace.IsNullOrWhiteSpace() && t.Namespace.Contains("Tnb.WarehouseMgr")).SelectMany(t => t.GetMethods())
|
||||||
(Func<CancellationTokenSource?, Task>)Delegate.CreateDelegate(typeof(Func<CancellationTokenSource?, Task>), App.GetService(x.DeclaringType), x));
|
.Where(m => m.GetCustomAttribute<TimedAttribute>() != null)
|
||||||
|
.ToDictionary(x => x.Name, x =>
|
||||||
|
(Func<CancellationTokenSource?, Task>)Delegate.CreateDelegate(typeof(Func<CancellationTokenSource?, Task>), App.GetService(x.DeclaringType), x));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
public TimedTaskBackgroundService(IServiceProvider serviceProvider)
|
public TimedTaskBackgroundService(IServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
@@ -73,32 +76,27 @@ namespace Tnb.WarehouseMgr
|
|||||||
}
|
}
|
||||||
|
|
||||||
#region 定时
|
#region 定时
|
||||||
_eventPublisher = App.GetRequiredService<IEventPublisher>();
|
//_eventPublisher = App.GetRequiredService<IEventPublisher>();
|
||||||
List<string> toUserIds = new List<string>() { "25398501929509" };
|
//List<string> toUserIds = new List<string>() { "25398501929509" };
|
||||||
////生成任务执行
|
////生成任务执行
|
||||||
//CancellationTokenSource genTaskCTS = new();
|
//CancellationTokenSource genTaskCTS = new();
|
||||||
//CancellationTokenSource kittingOutAddCts = new();
|
//CancellationTokenSource kittingOutAddCts = new();
|
||||||
//CancellationTokenSource kittingOutShippedCts = new();
|
//CancellationTokenSource kittingOutShippedCts = new();
|
||||||
//CancellationTokenSource setSortingCts = new();
|
//CancellationTokenSource setSortingCts = new();
|
||||||
CancellationTokenSource isMinStorageCts = new();
|
|
||||||
//var wareHouseService = App.GetRequiredService<IWareHouseService>();
|
//var wareHouseService = App.GetRequiredService<IWareHouseService>();
|
||||||
//TimedTask(cts => wareHouseService.GenTaskExecute(cts), genTaskCTS, toUserIds);
|
//TimedTask(cts => wareHouseService.GenTaskExecute(cts), genTaskCTS);
|
||||||
////齐套出库
|
//齐套出库
|
||||||
|
var kittingOutService = App.GetRequiredService<IWmskittingOutService>();
|
||||||
//var kittingOutService = App.GetRequiredService<IWmskittingOutService>();
|
TimedTask(cts => kittingOutService.KittingOutByAdd(cts), kittingOutAddCts, 1);
|
||||||
//TimedTask(cts => kittingOutService.KittingOutByAdd(cts), kittingOutAddCts, toUserIds);
|
TimedTask(cts => kittingOutService.KittingOutByIsToBeShipped(cts), kittingOutShippedCts, 1);
|
||||||
//TimedTask(cts => kittingOutService.KittingOutByIsToBeShipped(cts), kittingOutShippedCts, toUserIds);
|
//齐套分拣
|
||||||
////齐套分拣
|
var setSortingService = App.GetRequiredService<IWmsSetSortingService>();
|
||||||
//var setSortingService = App.GetRequiredService<IWmsSetSortingService>();
|
TimedTask(cts => setSortingService.PackSortingByAdd(cts), setSortingCts, 1);
|
||||||
//TimedTask(cts => setSortingService.PackSortingByAdd(cts), setSortingCts, toUserIds);
|
|
||||||
|
|
||||||
//最低库存检查
|
|
||||||
var transferSignService = App.GetRequiredService<IWmsPDATransferSignService>();
|
|
||||||
TimedTask(cts => transferSignService.IsMinStorage(cts), isMinStorageCts, toUserIds);
|
|
||||||
#endregion
|
#endregion
|
||||||
}, stoppingToken);
|
}, stoppingToken);
|
||||||
|
|
||||||
private Task TimedTask(Func<CancellationTokenSource, Task> action, CancellationTokenSource cts, List<string>? toUserIds = default)
|
private Task TimedTask(Func<CancellationTokenSource, Task> action, CancellationTokenSource cts, int interval, TimeSpanUnit timeType = TimeSpanUnit.Seconds)
|
||||||
{
|
{
|
||||||
var token = cts.Token;
|
var token = cts.Token;
|
||||||
return Task.Run(async () =>
|
return Task.Run(async () =>
|
||||||
@@ -124,10 +122,23 @@ namespace Tnb.WarehouseMgr
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
await Task.Delay(TimeSpan.FromMinutes(30));
|
await Task.Delay(1000);
|
||||||
}
|
}
|
||||||
}, token);
|
}, 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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -246,6 +246,10 @@ namespace Tnb.WarehouseMgr
|
|||||||
kittingOut.carry_id = kittingIn.carry_id;
|
kittingOut.carry_id = kittingIn.carry_id;
|
||||||
kittingOut.carry_code = kittingIn.carry_code;
|
kittingOut.carry_code = kittingIn.carry_code;
|
||||||
await _db.Updateable(kittingOut).UpdateColumns(it => new { it.status, it.carry_id, it.carry_code }).ExecuteCommandAsync();
|
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));
|
||||||
|
//}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,12 +8,16 @@ using System.Threading.Tasks;
|
|||||||
using JNPF;
|
using JNPF;
|
||||||
using JNPF.Common.Const;
|
using JNPF.Common.Const;
|
||||||
using JNPF.Common.Core.Manager;
|
using JNPF.Common.Core.Manager;
|
||||||
|
using JNPF.Common.Dtos.VisualDev;
|
||||||
using JNPF.Common.Enums;
|
using JNPF.Common.Enums;
|
||||||
using JNPF.Common.Extension;
|
using JNPF.Common.Extension;
|
||||||
using JNPF.Common.Manager;
|
using JNPF.Common.Manager;
|
||||||
using JNPF.Common.Security;
|
using JNPF.Common.Security;
|
||||||
using JNPF.FriendlyException;
|
using JNPF.FriendlyException;
|
||||||
using JNPF.Systems.Interfaces.System;
|
using JNPF.Systems.Interfaces.System;
|
||||||
|
using JNPF.VisualDev;
|
||||||
|
using JNPF.VisualDev.Entitys;
|
||||||
|
using JNPF.VisualDev.Interfaces;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using NPOI.SS.Formula;
|
using NPOI.SS.Formula;
|
||||||
@@ -36,6 +40,7 @@ namespace Tnb.WarehouseMgr
|
|||||||
/// 齐套分拣服务类
|
/// 齐套分拣服务类
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ServiceModule(BizTypeId)]
|
[ServiceModule(BizTypeId)]
|
||||||
|
[OverideVisualDev(ModuleConsts.MODULE_WMSSETSORTING_ID)]
|
||||||
public class WmsSetSortingService : BaseWareHouseService, IWmsSetSortingService
|
public class WmsSetSortingService : BaseWareHouseService, IWmsSetSortingService
|
||||||
{
|
{
|
||||||
private readonly ISqlSugarClient _db;
|
private readonly ISqlSugarClient _db;
|
||||||
@@ -43,15 +48,46 @@ namespace Tnb.WarehouseMgr
|
|||||||
private readonly IBillRullService _billRullService;
|
private readonly IBillRullService _billRullService;
|
||||||
private readonly IUserManager _userManager;
|
private readonly IUserManager _userManager;
|
||||||
private readonly ICacheManager _cacheManager;
|
private readonly ICacheManager _cacheManager;
|
||||||
|
private readonly IRunService _runService;
|
||||||
|
private readonly IVisualDevService _visualDevService;
|
||||||
private const string BizTypeId = "26186830379045";
|
private const string BizTypeId = "26186830379045";
|
||||||
|
|
||||||
public WmsSetSortingService(ISqlSugarRepository<WmsSetsortingH> repository, IWareHouseService wareHouseService, IUserManager userManager, IBillRullService billRullService, ICacheManager cacheManager)
|
public WmsSetSortingService(
|
||||||
|
ISqlSugarRepository<WmsSetsortingH> repository,
|
||||||
|
IWareHouseService wareHouseService,
|
||||||
|
IUserManager userManager, IBillRullService billRullService,
|
||||||
|
ICacheManager cacheManager,
|
||||||
|
IRunService runService,
|
||||||
|
IVisualDevService visualDevService,
|
||||||
|
ITaskMessageNotify taskMessageNotify
|
||||||
|
) : base(taskMessageNotify.Writer)
|
||||||
{
|
{
|
||||||
_db = repository.AsSugarClient();
|
_db = repository.AsSugarClient();
|
||||||
_wareHouseService = wareHouseService;
|
_wareHouseService = wareHouseService;
|
||||||
_billRullService = billRullService;
|
_billRullService = billRullService;
|
||||||
_userManager = userManager;
|
_userManager = userManager;
|
||||||
_cacheManager = cacheManager;
|
_cacheManager = cacheManager;
|
||||||
|
_runService = runService;
|
||||||
|
_visualDevService = visualDevService;
|
||||||
|
OverideFuncs.CreateAsync = Create;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<dynamic> 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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -188,12 +224,12 @@ namespace Tnb.WarehouseMgr
|
|||||||
{
|
{
|
||||||
var leftCarrys = carrys[..mid];
|
var leftCarrys = carrys[..mid];
|
||||||
var rightCarrys = carrys[mid..];
|
var rightCarrys = carrys[mid..];
|
||||||
await InnerGenPreTask(leftCarrys, locIds, firstLocationId, 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, curUser);
|
await InnerGenPreTask(rightCarrys, locIds, secondLocationId, singleSorting.id, singleSorting.bill_code, preTasks, endLocation);
|
||||||
}
|
}
|
||||||
else
|
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<WmsPretaskCode> pretaskCodes = new();
|
List<WmsPretaskCode> pretaskCodes = new();
|
||||||
foreach (var pt in preTasks)
|
foreach (var pt in preTasks)
|
||||||
@@ -225,19 +261,13 @@ namespace Tnb.WarehouseMgr
|
|||||||
{
|
{
|
||||||
JNPF.Logging.Log.Error("齐套分拣执行时出现错误", ex);
|
JNPF.Logging.Log.Error("齐套分拣执行时出现错误", ex);
|
||||||
await curDb.Ado.RollbackTranAsync();
|
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();
|
cts?.Cancel();
|
||||||
throw timedTaskEx;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task InnerGenPreTask(WmsCarryH[] carrys, List<string> locIds, string eLocationId, string requireId, string requireCode, List<WmsPretaskH> preTasks, BasLocation endLocation, ClaimsPrincipal curUser)
|
private async Task InnerGenPreTask(WmsCarryH[] carrys, List<string> locIds, string eLocationId, string requireId, string requireCode, List<WmsPretaskH> preTasks, BasLocation endLocation)
|
||||||
{
|
{
|
||||||
foreach (var carry in carrys)
|
foreach (var carry in carrys)
|
||||||
{
|
{
|
||||||
@@ -262,7 +292,7 @@ namespace Tnb.WarehouseMgr
|
|||||||
|
|
||||||
WmsPretaskH preTask = new()
|
WmsPretaskH preTask = new()
|
||||||
{
|
{
|
||||||
org_id = curUser.FindFirst(ClaimConst.CLAINMORGID)?.Value,
|
org_id = _userManager.User.OrganizeId,
|
||||||
startlocation_id = sPoint?.location_id!,
|
startlocation_id = sPoint?.location_id!,
|
||||||
startlocation_code = sPoint?.location_code!,
|
startlocation_code = sPoint?.location_code!,
|
||||||
endlocation_id = ePoint?.location_id!,
|
endlocation_id = ePoint?.location_id!,
|
||||||
@@ -279,7 +309,7 @@ namespace Tnb.WarehouseMgr
|
|||||||
area_code = it.Key,
|
area_code = it.Key,
|
||||||
require_id = requireId,
|
require_id = requireId,
|
||||||
require_code = requireCode,
|
require_code = requireCode,
|
||||||
create_id = curUser.FindFirst(ClaimConst.CLAINMUSERID)?.Value!,
|
create_id = _userManager.UserId,
|
||||||
create_time = DateTime.Now,
|
create_time = DateTime.Now,
|
||||||
source_id = carry.source_id,
|
source_id = carry.source_id,
|
||||||
source_code = carry.source_code,
|
source_code = carry.source_code,
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ namespace Tnb.WarehouseMgr
|
|||||||
ko.carry_id = firstCarry?.id;
|
ko.carry_id = firstCarry?.id;
|
||||||
ko.carry_code = firstCarry?.carry_code;
|
ko.carry_code = firstCarry?.carry_code;
|
||||||
await _db.Updateable(ko).UpdateColumns(it => new { it.status, it.carry_id, it.carry_code }).ExecuteCommandAsync();
|
await _db.Updateable(ko).UpdateColumns(it => new { it.status, it.carry_id, it.carry_code }).ExecuteCommandAsync();
|
||||||
|
//await KittingOutByIsToBeShipped();
|
||||||
if (firstCarry != null)
|
if (firstCarry != null)
|
||||||
{
|
{
|
||||||
firstCarry.source_id = ko.source_id;
|
firstCarry.source_id = ko.source_id;
|
||||||
@@ -155,6 +156,7 @@ namespace Tnb.WarehouseMgr
|
|||||||
ko.status = WmsWareHouseConst.BILLSTATUS_CALLED_ID;
|
ko.status = WmsWareHouseConst.BILLSTATUS_CALLED_ID;
|
||||||
await curDb.Updateable(ko).UpdateColumns(it => it.status).ExecuteCommandAsync();
|
await curDb.Updateable(ko).UpdateColumns(it => it.status).ExecuteCommandAsync();
|
||||||
isCalled = true;
|
isCalled = true;
|
||||||
|
//await Publish(nameof(IWmsSetSortingService.PackSortingByAdd));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -409,7 +411,7 @@ namespace Tnb.WarehouseMgr
|
|||||||
|
|
||||||
await _db.Insertable(kittingOuts).ExecuteCommandAsync();
|
await _db.Insertable(kittingOuts).ExecuteCommandAsync();
|
||||||
await _db.Insertable(kittingOutDs).ExecuteCommandAsync();
|
await _db.Insertable(kittingOutDs).ExecuteCommandAsync();
|
||||||
|
|
||||||
await _db.Ado.CommitTranAsync();
|
await _db.Ado.CommitTranAsync();
|
||||||
await KittingOutByAdd();
|
await KittingOutByAdd();
|
||||||
isSuccessFul = true;
|
isSuccessFul = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user