将依赖事件总线的发布订阅模式,改为直接调用的形式

This commit is contained in:
yang.lee
2023-11-02 15:58:15 +08:00
parent 02e4dbb45a
commit b13574530d
32 changed files with 226 additions and 154 deletions

View File

@@ -59,6 +59,7 @@ namespace Tnb.WarehouseMgr
private IEventPublisher _eventPublisher; private IEventPublisher _eventPublisher;
protected IEventPublisher EventPublisher protected IEventPublisher EventPublisher
{ {
set { _eventPublisher = value; } set { _eventPublisher = value; }
@@ -107,6 +108,23 @@ namespace Tnb.WarehouseMgr
return Task.FromResult(curUser); return Task.FromResult(curUser);
} }
protected Task SetUserEntity(IUserManager userManager, ClaimsPrincipal principal)
=> Task.Run(() =>
{
FieldInfo fieldInfo = userManager.GetType().GetField("_user", BindingFlags.NonPublic | BindingFlags.Instance);
if (fieldInfo != null)
{
fieldInfo.SetValue(userManager, principal);
}
});
protected Task InvokeGenPretaskExcute()
{
var wareHouseSvc =App.GetRequiredService<IWareHouseService>();
return wareHouseSvc.GenTaskExecute();
}
/// <summary> /// <summary>
/// 判断最终目标库位是否可以放置当前载具 /// 判断最终目标库位是否可以放置当前载具
/// </summary> /// </summary>

View File

@@ -1,7 +1,12 @@
using JNPF.Common.Configuration; using System.Reflection;
using System.Security.Claims;
using JNPF.Common.Configuration;
using JNPF.Common.Core.Manager;
using JNPF.DataEncryption;
using JNPF.DependencyInjection; using JNPF.DependencyInjection;
using JNPF.EventBus; using JNPF.EventBus;
using JNPF.TaskScheduler.Entitys; using JNPF.TaskScheduler.Entitys;
using NetTaste;
using SqlSugar; using SqlSugar;
using Tnb.Common.Core.EventBus.Constants; using Tnb.Common.Core.EventBus.Constants;
using Tnb.Common.Core.EventBus.Sources; using Tnb.Common.Core.EventBus.Sources;
@@ -19,12 +24,14 @@ public class TaskStatusChangeSubscriber : IEventSubscriber, ISingleton
/// </summary> /// </summary>
//private static SqlSugarScope? _sqlSugarClient; //private static SqlSugarScope? _sqlSugarClient;
private readonly IWareHouseService _wareHouseService; private readonly IWareHouseService _wareHouseService;
private readonly IWmskittingOutService _wmskittingOutService;
/// <summary> /// <summary>
/// 构造函数. /// 构造函数.
/// </summary> /// </summary>
public TaskStatusChangeSubscriber(IWareHouseService wareHouseService) public TaskStatusChangeSubscriber(IWareHouseService wareHouseService, IWmskittingOutService wmskittingOutService)
{ {
_wareHouseService = wareHouseService; _wareHouseService = wareHouseService;
_wmskittingOutService = wmskittingOutService;
} }
/// <summary> /// <summary>
@@ -35,12 +42,32 @@ public class TaskStatusChangeSubscriber : IEventSubscriber, ISingleton
[EventSubscribe(EventSubscribeEventConsts.TASKSTATUSCHANGE_EVENTID)] [EventSubscribe(EventSubscribeEventConsts.TASKSTATUSCHANGE_EVENTID)]
public async Task Excute(EventHandlerExecutingContext context) public async Task Excute(EventHandlerExecutingContext context)
{ {
/*var claims = JWTEncryption.ReadJwtToken(UserManager.AsscessToken)?.Claims;
ClaimsIdentity toKen = new ClaimsIdentity();
foreach (Claim item in claims)
{
toKen.AddClaim(item);
}
var principal = new ClaimsPrincipal(toKen);
FieldInfo fieldInfo = _userManager.GetType().GetField("_user", BindingFlags.NonPublic | BindingFlags.Instance);
if (fieldInfo != null)
{
fieldInfo.SetValue(_userManager, principal);
}*/
var tscSource = (TaskStatusChangeSource)context.Source; var tscSource = (TaskStatusChangeSource)context.Source;
switch (tscSource.Payload) switch (tscSource.Payload)
{ {
case nameof(_wareHouseService.GenTaskExecute): case nameof(_wareHouseService.GenTaskExecute):
await _wareHouseService.GenTaskExecute(); await _wareHouseService.GenTaskExecute();
break; break;
case nameof(_wmskittingOutService.KittingOutByAdd):
await _wmskittingOutService.KittingOutByAdd();
break;
case nameof(_wmskittingOutService.KittingOutByIsToBeShipped):
await _wmskittingOutService.KittingOutByIsToBeShipped();
break;
} }
} }

View File

@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.Extensions.DependencyInjection;
using Tnb.WarehouseMgr.Interfaces;
namespace Tnb.WarehouseMgr
{
public class WareHouseBasedControllerActivator : IControllerActivator
{
public object Create(ControllerContext context)
{
if(context == null) { throw new ArgumentNullException("context"); }
var controllerType = context.ActionDescriptor.ControllerTypeInfo.AsType();
//获取Controller实例
var controller =context.HttpContext.RequestServices.GetRequiredService(controllerType);
//判断是否继承了自定义Controller基类
//if(controller is BaseWareHouseService basedWhSvc)
//{
// basedWhSvc.WareHouseSrv = context.HttpContext.RequestServices.GetRequiredService<IWareHouseService>();
//}
return controller;
}
public void Release(ControllerContext context, object controller)
{
}
}
}

View File

@@ -47,17 +47,7 @@ namespace Tnb.WarehouseMgr
private IEventPublisher _eventPublisher = default!; private IEventPublisher _eventPublisher = default!;
private ElevatorControlConfiguration _elevatorControlConfiguration = App.Configuration.Build<ElevatorControlConfiguration>(); private ElevatorControlConfiguration _elevatorControlConfiguration = App.Configuration.Build<ElevatorControlConfiguration>();
private readonly IServiceProvider _serviceProvider; private readonly IServiceProvider _serviceProvider;
private static Dictionary<string, Func<CancellationToken?, Task>> _timedFuncMap = new(StringComparer.OrdinalIgnoreCase); //private static Dictionary<string, Func<CancellationToken?, Task>> _timedFuncMap = new(StringComparer.OrdinalIgnoreCase);
static TimedTaskBackgroundService()
{
//Task.Run(() =>
//{
// _timedFuncMap = App.EffectiveTypes.AsParallel().Where(t => !t.Namespace.IsNullOrWhiteSpace() && t.Namespace.Equals("Tnb.WarehouseMgr", StringComparison.OrdinalIgnoreCase)).SelectMany(t => t.GetMethods())
// .Where(m => m.GetCustomAttribute<TimedAttribute>() != null)
// .ToDictionary(x => x.Name, x =>
// (Func<CancellationToken?, Task>)Delegate.CreateDelegate(typeof(Func<CancellationToken?, Task>), App.GetService(x.DeclaringType), x));
//});
}
public TimedTaskBackgroundService(IServiceProvider serviceProvider) public TimedTaskBackgroundService(IServiceProvider serviceProvider)
{ {
_serviceProvider = serviceProvider; _serviceProvider = serviceProvider;
@@ -66,30 +56,11 @@ namespace Tnb.WarehouseMgr
protected override Task ExecuteAsync(CancellationToken stoppingToken) protected override Task ExecuteAsync(CancellationToken stoppingToken)
{ {
IsStarted = true; IsStarted = true;
//var queueTask = Task.Run(async () =>
// {
// var channelReader = _serviceProvider.GetRequiredService<ITaskMessageNotify>().Reader;
// CancellationTokenSource? cts = new();
// while (channelReader != null && await channelReader.WaitToReadAsync())
// {
// while (channelReader.TryRead(out var message))
// {
// if (_timedFuncMap.ContainsKey(message.TaskName))
// {
// await _timedFuncMap[message.TaskName].Invoke(stoppingToken);
// }
// }
// }
// }, stoppingToken);
var timedTask = Task.Run(() => var timedTask = Task.Run(() =>
{ {
_eventPublisher = App.GetRequiredService<IEventPublisher>(); _eventPublisher = App.GetRequiredService<IEventPublisher>();
var whSvc = App.GetRequiredService<IWareHouseService>();
TimedTask(token => whSvc.GenTaskExecute(), stoppingToken, 1);
//电梯Agv心跳检测 //电梯Agv心跳检测
TimedTask(async token => TimedTask(async token =>
{ {
@@ -130,6 +101,7 @@ namespace Tnb.WarehouseMgr
{ {
await action(ct).Catch(async ex => await action(ct).Catch(async ex =>
{ {
if (ex is TimedTaskException timedTaskEx and not null) if (ex is TimedTaskException timedTaskEx and not null)
{ {
await _eventPublisher.PublishAsync(new LogEventSource("Log:CreateExLog", timedTaskEx.options!, new SysLogEntity await _eventPublisher.PublishAsync(new LogEventSource("Log:CreateExLog", timedTaskEx.options!, new SysLogEntity

View File

@@ -63,7 +63,7 @@ namespace Tnb.WarehouseMgr
_wareHouseService = wareHouseService; _wareHouseService = wareHouseService;
_userManager = userManager; _userManager = userManager;
_billRullService = billRullService; _billRullService = billRullService;
EventPublisher = eventPublisher;
OverideFuncs.CreateAsync = CarryMoveIn; OverideFuncs.CreateAsync = CarryMoveIn;
} }
@@ -178,7 +178,7 @@ namespace Tnb.WarehouseMgr
finally finally
{ {
//向队列写入消息 //向队列写入消息
await Publish(nameof(IWareHouseService.GenTaskExecute)); await InvokeGenPretaskExcute();
} }
return Task.FromResult(true); return Task.FromResult(true);
} }

View File

@@ -56,7 +56,7 @@ namespace Tnb.WarehouseMgr
_wareHouseService = wareHouseService; _wareHouseService = wareHouseService;
_userManager = userManager; _userManager = userManager;
_billRullService = billRullService; _billRullService = billRullService;
EventPublisher = eventPublisher;
OverideFuncs.CreateAsync = CarryMoveOut; OverideFuncs.CreateAsync = CarryMoveOut;
} }
@@ -164,7 +164,7 @@ namespace Tnb.WarehouseMgr
} }
finally finally
{ {
await Publish(nameof(IWareHouseService.GenTaskExecute)); await InvokeGenPretaskExcute();
} }
return Task.FromResult(true); return Task.FromResult(true);
} }

View File

@@ -54,7 +54,7 @@ namespace Tnb.WarehouseMgr
_runService = runService; _runService = runService;
_billRullService = billRullService; _billRullService = billRullService;
_userManager = userManager; _userManager = userManager;
EventPublisher = eventPublisher;
OverideFuncs.CreateAsync = Create; OverideFuncs.CreateAsync = Create;
} }
@@ -224,7 +224,7 @@ namespace Tnb.WarehouseMgr
} }
finally finally
{ {
await Publish(nameof(IWareHouseService.GenTaskExecute)); await InvokeGenPretaskExcute();
} }
return Task.FromResult(row); return Task.FromResult(row);
} }

View File

@@ -67,7 +67,7 @@ namespace Tnb.WarehouseMgr
_wareHouseService = wareHouseService; _wareHouseService = wareHouseService;
_userManager = userManager; _userManager = userManager;
_billRullService = billRullService; _billRullService = billRullService;
EventPublisher = eventPublisher;
OverideFuncs.CreateAsync = Create; OverideFuncs.CreateAsync = Create;
} }
/// <summary> /// <summary>
@@ -204,7 +204,7 @@ namespace Tnb.WarehouseMgr
} }
finally finally
{ {
await Publish(nameof(IWareHouseService.GenTaskExecute)); await InvokeGenPretaskExcute();
} }
return await Task.FromResult(true); return await Task.FromResult(true);
} }

View File

@@ -64,7 +64,7 @@ namespace Tnb.WarehouseMgr
_wareHouseService = wareHouseService; _wareHouseService = wareHouseService;
_userManager = userManager; _userManager = userManager;
_billRullService = billRullService; _billRullService = billRullService;
EventPublisher = eventPublisher;
OverideFuncs.CreateAsync = WmsEmptyIn; OverideFuncs.CreateAsync = WmsEmptyIn;
} }
private async Task<dynamic> WmsEmptyIn(VisualDevModelDataCrInput input) private async Task<dynamic> WmsEmptyIn(VisualDevModelDataCrInput input)
@@ -189,7 +189,7 @@ namespace Tnb.WarehouseMgr
finally finally
{ {
//向队列写入消息 //向队列写入消息
await Publish(nameof(IWareHouseService.GenTaskExecute)); await InvokeGenPretaskExcute();
} }
return Task.FromResult(true); return Task.FromResult(true);
} }

View File

@@ -62,7 +62,7 @@ namespace Tnb.WarehouseMgr
_wareHouseService = wareHouseService; _wareHouseService = wareHouseService;
_userManager = userManager; _userManager = userManager;
_billRullService = billRullService; _billRullService = billRullService;
EventPublisher = eventPublisher;
OverideFuncs.CreateAsync = WmsEmptyOut; OverideFuncs.CreateAsync = WmsEmptyOut;
} }
@@ -220,7 +220,7 @@ namespace Tnb.WarehouseMgr
} }
finally finally
{ {
await Publish(nameof(IWareHouseService.GenTaskExecute)); await InvokeGenPretaskExcute();
} }
return Task.FromResult(true); return Task.FromResult(true);
} }

View File

@@ -65,7 +65,7 @@ namespace Tnb.WarehouseMgr
_billRullService = billRullService; _billRullService = billRullService;
_wareHouseService = wareHouseService; _wareHouseService = wareHouseService;
_prdInstockService = prdInstockService; _prdInstockService = prdInstockService;
EventPublisher = eventPublisher;
} }
/// <summary> /// <summary>
/// 根据入库申请单ID获取申请单明细信息 /// 根据入库申请单ID获取申请单明细信息
@@ -482,7 +482,7 @@ namespace Tnb.WarehouseMgr
} }
finally finally
{ {
await Publish(nameof(IWareHouseService.GenTaskExecute)); await InvokeGenPretaskExcute();
} }
return isSuccessFul; return isSuccessFul;
} }

View File

@@ -59,7 +59,7 @@ namespace Tnb.WarehouseMgr
_wareHouseService = wareHouseService; _wareHouseService = wareHouseService;
_userManager = userManager; _userManager = userManager;
_billRullService = billRullService; _billRullService = billRullService;
EventPublisher = eventPublisher;
OverideFuncs.CreateAsync = KittingInStk; OverideFuncs.CreateAsync = KittingInStk;
} }
@@ -220,7 +220,7 @@ namespace Tnb.WarehouseMgr
} }
finally finally
{ {
await Publish(nameof(IWareHouseService.GenTaskExecute)); await InvokeGenPretaskExcute();
} }
return Task.FromResult(true); return Task.FromResult(true);
} }
@@ -248,11 +248,8 @@ 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));
//}
await Publish(nameof(IWmskittingOutService.KittingOutByIsToBeShipped));
} }
} }
if (row < 1) throw Oops.Oh(ErrorCode.COM1001); if (row < 1) throw Oops.Oh(ErrorCode.COM1001);

View File

@@ -59,7 +59,7 @@ namespace Tnb.WarehouseMgr
_userManager = userManager; _userManager = userManager;
_billRullService = billRullService; _billRullService = billRullService;
_wmsCarryService = wmsCarryService; _wmsCarryService = wmsCarryService;
EventPublisher = eventPublisher;
OverideFuncs.CreateAsync = CarryOutBale; OverideFuncs.CreateAsync = CarryOutBale;
} }
@@ -166,7 +166,7 @@ namespace Tnb.WarehouseMgr
} }
finally finally
{ {
await Publish(nameof(IWareHouseService.GenTaskExecute)); await InvokeGenPretaskExcute();
} }
return Task.FromResult(true); return Task.FromResult(true);
} }

View File

@@ -79,7 +79,7 @@ namespace Tnb.WarehouseMgr
_billRullService = billRullService; _billRullService = billRullService;
_wmsCarryMoveInStockService = wmsCarryMoveInStockService; _wmsCarryMoveInStockService = wmsCarryMoveInStockService;
_wareCarryService = wareCarryService; _wareCarryService = wareCarryService;
EventPublisher = eventPublisher;
OverideFuncs.CreateAsync = OutStockApplyFor; OverideFuncs.CreateAsync = OutStockApplyFor;
} }
@@ -374,7 +374,7 @@ namespace Tnb.WarehouseMgr
} }
finally finally
{ {
await Publish(nameof(IWareHouseService.GenTaskExecute)); await InvokeGenPretaskExcute();
} }
return Task.FromResult(true); return Task.FromResult(true);
} }
@@ -767,7 +767,7 @@ namespace Tnb.WarehouseMgr
} }
finally finally
{ {
await Publish(nameof(IWareHouseService.GenTaskExecute)); await InvokeGenPretaskExcute();
} }
return isSuccessful; return isSuccessful;
} }

View File

@@ -60,7 +60,7 @@ namespace Tnb.WarehouseMgr
_wareHouseService = wareHouseService; _wareHouseService = wareHouseService;
_userManager = userManager; _userManager = userManager;
_billRullService = billRullService; _billRullService = billRullService;
EventPublisher = eventPublisher;
OverideFuncs.CreateAsync = PDACarryMoveIn; OverideFuncs.CreateAsync = PDACarryMoveIn;
} }
@@ -163,7 +163,7 @@ namespace Tnb.WarehouseMgr
//} //}
//finally //finally
//{ //{
// await Publish(nameof(IWareHouseService.GenTaskExecute)); // await InvokeGenPretaskExcute();
//} //}
//return Task.FromResult(true); //return Task.FromResult(true);
#endregion #endregion
@@ -276,7 +276,7 @@ namespace Tnb.WarehouseMgr
finally finally
{ {
//向队列写入消息 //向队列写入消息
await Publish(nameof(IWareHouseService.GenTaskExecute)); await InvokeGenPretaskExcute();
} }
return Task.FromResult(true); return Task.FromResult(true);

View File

@@ -57,7 +57,7 @@ namespace Tnb.WarehouseMgr
_wareHouseService = wareHouseService; _wareHouseService = wareHouseService;
_userManager = userManager; _userManager = userManager;
_billRullService = billRullService; _billRullService = billRullService;
EventPublisher = eventPublisher;
OverideFuncs.CreateAsync = PDACarryMoveOut; OverideFuncs.CreateAsync = PDACarryMoveOut;
} }
@@ -161,7 +161,7 @@ namespace Tnb.WarehouseMgr
} }
finally finally
{ {
await Publish(nameof(IWareHouseService.GenTaskExecute)); await InvokeGenPretaskExcute();
} }
return Task.FromResult(true); return Task.FromResult(true);
} }

View File

@@ -62,7 +62,7 @@ namespace Tnb.WarehouseMgr
_billRullService = billRullService; _billRullService = billRullService;
_wareHouseService = wareHouseService; _wareHouseService = wareHouseService;
_userManager = userManager; _userManager = userManager;
EventPublisher = eventPublisher;
OverideFuncs.CreateAsync = Create; OverideFuncs.CreateAsync = Create;
} }
/// <summary> /// <summary>
@@ -193,7 +193,7 @@ namespace Tnb.WarehouseMgr
} }
finally finally
{ {
await Publish(nameof(IWareHouseService.GenTaskExecute)); await InvokeGenPretaskExcute();
} }
return await Task.FromResult(true); return await Task.FromResult(true);
} }

View File

@@ -57,7 +57,7 @@ namespace Tnb.WarehouseMgr
_wareHouseService = wareHouseService; _wareHouseService = wareHouseService;
_userManager = userManager; _userManager = userManager;
_billRullService = billRullService; _billRullService = billRullService;
EventPublisher = eventPublisher;
OverideFuncs.CreateAsync = PDAWmsEmptyIn; OverideFuncs.CreateAsync = PDAWmsEmptyIn;
} }
@@ -170,7 +170,7 @@ namespace Tnb.WarehouseMgr
} }
finally finally
{ {
await Publish(nameof(IWareHouseService.GenTaskExecute)); await InvokeGenPretaskExcute();
} }
return Task.FromResult(true); return Task.FromResult(true);
} }

View File

@@ -59,7 +59,7 @@ namespace Tnb.WarehouseMgr
_wareHouseService = wareHouseService; _wareHouseService = wareHouseService;
_userManager = userManager; _userManager = userManager;
_billRullService = billRullService; _billRullService = billRullService;
EventPublisher = eventPublisher;
OverideFuncs.CreateAsync = PDAWmsEmptyOut; OverideFuncs.CreateAsync = PDAWmsEmptyOut;
} }
@@ -212,7 +212,7 @@ namespace Tnb.WarehouseMgr
} }
finally finally
{ {
await Publish(nameof(IWareHouseService.GenTaskExecute)); await InvokeGenPretaskExcute();
} }
return Task.FromResult(true); return Task.FromResult(true);
} }

View File

@@ -65,7 +65,7 @@ namespace Tnb.WarehouseMgr
_wareHouseService = wareHouseService; _wareHouseService = wareHouseService;
_userManager = userManager; _userManager = userManager;
_billRullService = billRullService; _billRullService = billRullService;
EventPublisher = eventPublisher;
OverideFuncs.CreateAsync = ScanCodeInStock; OverideFuncs.CreateAsync = ScanCodeInStock;
} }
@@ -282,7 +282,7 @@ namespace Tnb.WarehouseMgr
} }
finally finally
{ {
await Publish(nameof(IWareHouseService.GenTaskExecute)); await InvokeGenPretaskExcute();
} }
return Task.FromResult(true); return Task.FromResult(true);
} }

View File

@@ -60,7 +60,7 @@ namespace Tnb.WarehouseMgr
_wareHouseService = wareHouseService; _wareHouseService = wareHouseService;
_userManager = userManager; _userManager = userManager;
_billRullService = billRullService; _billRullService = billRullService;
EventPublisher = eventPublisher;
OverideFuncs.CreateAsync = Inbale; OverideFuncs.CreateAsync = Inbale;
} }
@@ -174,7 +174,7 @@ namespace Tnb.WarehouseMgr
} }
finally finally
{ {
await Publish(nameof(IWareHouseService.GenTaskExecute)); await InvokeGenPretaskExcute();
} }
return Task.FromResult(true); return Task.FromResult(true);
} }

View File

@@ -58,7 +58,7 @@ namespace Tnb.WarehouseMgr
_wareHouseService = wareHouseService; _wareHouseService = wareHouseService;
_userManager = userManager; _userManager = userManager;
_billRullService = billRullService; _billRullService = billRullService;
EventPublisher= eventPublisher;
OverideFuncs.CreateAsync = PDAOutBale; OverideFuncs.CreateAsync = PDAOutBale;
} }
@@ -162,7 +162,7 @@ namespace Tnb.WarehouseMgr
} }
finally finally
{ {
await Publish(nameof(IWareHouseService.GenTaskExecute)); await InvokeGenPretaskExcute();
} }
return Task.FromResult(true); return Task.FromResult(true);
} }

View File

@@ -56,7 +56,7 @@ namespace Tnb.WarehouseMgr
_billRullService = billRullService; _billRullService = billRullService;
_wareHouseService = wareHouseService; _wareHouseService = wareHouseService;
_prdInstockService = prdInstockService; _prdInstockService = prdInstockService;
EventPublisher = eventPublisher;
OverideFuncs.CreateAsync = ScanInStock; OverideFuncs.CreateAsync = ScanInStock;
} }
public async Task<dynamic> ScanInStock(VisualDevModelDataCrInput input) public async Task<dynamic> ScanInStock(VisualDevModelDataCrInput input)

View File

@@ -61,7 +61,7 @@ namespace Tnb.WarehouseMgr
_wareHouseService = wareHouseService; _wareHouseService = wareHouseService;
_userManager = userManager; _userManager = userManager;
_billRullService = billRullService; _billRullService = billRullService;
EventPublisher = publisher;
OverideFuncs.CreateAsync = CarryTransfer; OverideFuncs.CreateAsync = CarryTransfer;
} }
@@ -157,7 +157,7 @@ namespace Tnb.WarehouseMgr
} }
finally finally
{ {
await Publish(nameof(IWareHouseService.GenTaskExecute)); await InvokeGenPretaskExcute();
} }
return Task.FromResult(true); return Task.FromResult(true);
} }

View File

@@ -55,7 +55,7 @@ namespace Tnb.WarehouseMgr
_warehouseService = warehouseService; _warehouseService = warehouseService;
_billRullService = billRullService; _billRullService = billRullService;
_wmsKittingInStkService = wmsKittingInStkService; _wmsKittingInStkService = wmsKittingInStkService;
EventPublisher = publisher;
} }
/// <summary> /// <summary>
/// 机器人完成任务后回调接口 /// 机器人完成任务后回调接口
@@ -92,6 +92,11 @@ namespace Tnb.WarehouseMgr
var kittingout = await _db.Queryable<WmsKittingoutH>().FirstAsync(it => it.collocation_scheme_id == carry.collocation_scheme_id && it.status == WmsWareHouseConst.BILLSTATUS_CALLED_ID); var kittingout = await _db.Queryable<WmsKittingoutH>().FirstAsync(it => it.collocation_scheme_id == carry.collocation_scheme_id && it.status == WmsWareHouseConst.BILLSTATUS_CALLED_ID);
if (kittingout != null) if (kittingout != null)
{ {
await Publish(nameof(IWmskittingOutService.KittingOutByAdd));
await Publish(nameof(IWmskittingOutService.KittingOutByIsToBeShipped));
visualDevModelCrInput.data = new Dictionary<string, object>(); visualDevModelCrInput.data = new Dictionary<string, object>();
visualDevModelCrInput.data[nameof(InStockStrategyQuery.warehouse_id)] = kittingout.warehouse_id; visualDevModelCrInput.data[nameof(InStockStrategyQuery.warehouse_id)] = kittingout.warehouse_id;
visualDevModelCrInput.data[nameof(WmsKittingInstock.carry_id)] = input.carry_id; visualDevModelCrInput.data[nameof(WmsKittingInstock.carry_id)] = input.carry_id;
@@ -147,7 +152,8 @@ namespace Tnb.WarehouseMgr
genPreTaskAfterUpInput.CarryIds = preTasks.Select(x => x.carry_id).ToList(); genPreTaskAfterUpInput.CarryIds = preTasks.Select(x => x.carry_id).ToList();
genPreTaskAfterUpInput.LocationIds = new List<string> { carry.location_id! }; genPreTaskAfterUpInput.LocationIds = new List<string> { carry.location_id! };
await _warehouseService.GenInStockTaskHandleAfter(genPreTaskAfterUpInput, it => new WmsCarryH { is_lock = 1 }, it => new BasLocation { is_lock = 1 }); await _warehouseService.GenInStockTaskHandleAfter(genPreTaskAfterUpInput, it => new WmsCarryH { is_lock = 1 }, it => new BasLocation { is_lock = 1 });
await Publish(nameof(IWareHouseService.GenTaskExecute));
await InvokeGenPretaskExcute();
} }
} }
else else

View File

@@ -70,7 +70,7 @@ namespace Tnb.WarehouseMgr
_cacheManager = cacheManager; _cacheManager = cacheManager;
_runService = runService; _runService = runService;
_visualDevService = visualDevService; _visualDevService = visualDevService;
EventPublisher = publisher;
//OverideFuncs.CreateAsync = Create; //OverideFuncs.CreateAsync = Create;
} }
@@ -99,10 +99,11 @@ namespace Tnb.WarehouseMgr
[HttpPost, Timed(Name = nameof(PackSortingByAdd))] [HttpPost, Timed(Name = nameof(PackSortingByAdd))]
public async Task PackSortingByAdd(CancellationToken? ct = default) public async Task PackSortingByAdd(CancellationToken? ct = default)
{ {
//if (UserManager.AsscessToken.IsNullOrWhiteSpace()) return; if (_userManager.User.IsNull())
//var curUser = await GetUserIdentity(); {
var curUser = await GetUserIdentity();
//Console.WriteLine($"ThreadID:{Thread.CurrentThread.ManagedThreadId}\t Thread pool: {Thread.CurrentThread.IsThreadPoolThread}"); await SetUserEntity(_userManager, curUser);
}
var curDb = _db.CopyNew(); var curDb = _db.CopyNew();
@@ -284,7 +285,7 @@ namespace Tnb.WarehouseMgr
} }
finally finally
{ {
//await Publish(nameof(IWareHouseService.GenTaskExecute)); await InvokeGenPretaskExcute();
} }
} }

View File

@@ -61,7 +61,7 @@ namespace Tnb.WarehouseMgr
_wareHouseService = wareHouseService; _wareHouseService = wareHouseService;
_userManager = userManager; _userManager = userManager;
_billRullService = billRullService; _billRullService = billRullService;
EventPublisher = publisher;
OverideFuncs.CreateAsync = CarryTransfer; OverideFuncs.CreateAsync = CarryTransfer;
} }
@@ -161,7 +161,7 @@ namespace Tnb.WarehouseMgr
} }
finally finally
{ {
await Publish(nameof(IWareHouseService.GenTaskExecute)); await InvokeGenPretaskExcute();;
} }
return Task.FromResult(true); return Task.FromResult(true);
} }

View File

@@ -72,13 +72,13 @@ namespace Tnb.WarehouseMgr
_billRullService = billRullService; _billRullService = billRullService;
_carryService = carryService; _carryService = carryService;
_cacheManager = cacheManager; _cacheManager = cacheManager;
EventPublisher = eventPublisher;
} }
/// <summary> /// <summary>
/// 齐套出库(新增状态) /// 齐套出库(新增状态)
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[HttpPost, Timed(Name = nameof(KittingOutByAdd))] [HttpPost]
public async Task KittingOutByAdd(CancellationToken? ct = default) public async Task KittingOutByAdd(CancellationToken? ct = default)
{ {
//if (ct?.IsCancellationRequested ?? false) //if (ct?.IsCancellationRequested ?? false)
@@ -121,7 +121,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(); _ = KittingOutByIsToBeShipped();
if (firstCarry != null) if (firstCarry != null)
{ {
firstCarry.source_id = ko.source_id; firstCarry.source_id = ko.source_id;
@@ -188,7 +188,7 @@ namespace Tnb.WarehouseMgr
/// 齐套出库,(待配送状态) /// 齐套出库,(待配送状态)
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[HttpPost, Timed(Name = nameof(KittingOutByIsToBeShipped))] [HttpPost]
public async Task KittingOutByIsToBeShipped(CancellationToken? ct = default) public async Task KittingOutByIsToBeShipped(CancellationToken? ct = default)
{ {
//if (UserManager.AsscessToken.IsNullOrWhiteSpace()) return; //if (UserManager.AsscessToken.IsNullOrWhiteSpace()) return;
@@ -296,7 +296,7 @@ namespace Tnb.WarehouseMgr
} }
finally finally
{ {
//await Publish(nameof(IWareHouseService.GenTaskExecute)); //await InvokeGenPretaskExcute();
} }
} }

View File

@@ -1,4 +1,5 @@
using IGeekFan.AspNetCore.Knife4jUI; using System.Reflection;
using IGeekFan.AspNetCore.Knife4jUI;
using JNPF.API.Entry.Handlers; using JNPF.API.Entry.Handlers;
using JNPF.Common.Cache; using JNPF.Common.Cache;
using JNPF.Common.Core; using JNPF.Common.Core;
@@ -62,15 +63,14 @@ public class Startup : AppStartup
.AddSenparcWeixinServices(App.Configuration); // Senparc.Weixin 注册如果使用Senparc.Weixin SDK则添加 .AddSenparcWeixinServices(App.Configuration); // Senparc.Weixin 注册如果使用Senparc.Weixin SDK则添加
services.AddOverideVisualDev(); services.AddOverideVisualDev();
//注册任务消息通知 added by ly on 20230814
//services.AddTaskMessageNotify();
SnowflakeIdHelper.InitYitIdWorker();
//定时任务 //定时任务
//services.AddHostedService<TimedTaskBackgroundService>(); services.AddHostedService<TimedTaskBackgroundService>();
} }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider serviceProvider, IOptions<SenparcSetting> senparcSetting, IOptions<SenparcWeixinSetting> senparcWeixinSetting) public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider serviceProvider, IOptions<SenparcSetting> senparcSetting, IOptions<SenparcWeixinSetting> senparcWeixinSetting)
{ {
// 添加状态码拦截中间件 // 添加状态码拦截中间件
@@ -115,7 +115,7 @@ public class Startup : AppStartup
endpoints.MapControllerRoute(name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapControllerRoute(name: "default", pattern: "{controller=Home}/{action=Index}/{id?}");
}); });
//SnowflakeIdHelper.InitYitIdWorker(); SnowflakeIdHelper.InitYitIdWorker();
bool isStartTimeJob = App.GetConfig<bool>("IsStartTimeJob"); bool isStartTimeJob = App.GetConfig<bool>("IsStartTimeJob");
if (isStartTimeJob) if (isStartTimeJob)

View File

@@ -1,29 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<Import Project="$(SolutionDir)\common.props" /> <Import Project="$(SolutionDir)\common.props" />
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<SatelliteResourceLanguages>none</SatelliteResourceLanguages> <SatelliteResourceLanguages>none</SatelliteResourceLanguages>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Remove="logs\**" /> <Compile Remove="logs\**" />
<Content Remove="logs\**" /> <Content Remove="logs\**" />
<EmbeddedResource Remove="logs\**" /> <EmbeddedResource Remove="logs\**" />
<None Remove="logs\**" /> <None Remove="logs\**" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="wwwroot\Template\VengineSqlSugar\AppService.cshtml" /> <None Include="wwwroot\Template\VengineSqlSugar\AppService.cshtml" />
<None Include="wwwroot\Template\VengineSqlSugar\EntityDto.cshtml" /> <None Include="wwwroot\Template\VengineSqlSugar\EntityDto.cshtml" />
<None Include="wwwroot\Template\VengineSqlSugar\EntityDtoAcmen.cshtml" /> <None Include="wwwroot\Template\VengineSqlSugar\EntityDtoAcmen.cshtml" />
<None Include="wwwroot\Template\VengineSqlSugar\EntityInfo.cshtml" /> <None Include="wwwroot\Template\VengineSqlSugar\EntityInfo.cshtml" />
<None Include="wwwroot\Template\VengineSqlSugar\EntityInfoAcmen.cshtml" /> <None Include="wwwroot\Template\VengineSqlSugar\EntityInfoAcmen.cshtml" />
</ItemGroup> </ItemGroup>
<!--<ItemGroup> <!--<ItemGroup>
<None Remove="lib\regworkerid_lib_v1.3.1\yitidgengo.dll" /> <None Remove="lib\regworkerid_lib_v1.3.1\yitidgengo.dll" />
<None Remove="lib\regworkerid_lib_v1.3.1\yitidgengo.so" /> <None Remove="lib\regworkerid_lib_v1.3.1\yitidgengo.so" />
<None Remove="sensitive-words.txt" /> <None Remove="sensitive-words.txt" />
@@ -35,38 +35,38 @@
<EmbeddedResource Include="sensitive-words.txt" /> <EmbeddedResource Include="sensitive-words.txt" />
</ItemGroup>--> </ItemGroup>-->
<ItemGroup> <ItemGroup>
<PackageReference Include="IGeekFan.AspNetCore.Knife4jUI" Version="0.0.13" /> <PackageReference Include="IGeekFan.AspNetCore.Knife4jUI" Version="0.0.13" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="7.0.0" /> <PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="7.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\app\Tnb.Apps\Tnb.Apps.csproj" /> <ProjectReference Include="..\..\app\Tnb.Apps\Tnb.Apps.csproj" />
<ProjectReference Include="..\..\BasicData\Tnb.BasicData\Tnb.BasicData.csproj" /> <ProjectReference Include="..\..\BasicData\Tnb.BasicData\Tnb.BasicData.csproj" />
<ProjectReference Include="..\..\EquipMgr\Tnb.EquipMgr\Tnb.EquipMgr.csproj" /> <ProjectReference Include="..\..\EquipMgr\Tnb.EquipMgr\Tnb.EquipMgr.csproj" />
<ProjectReference Include="..\..\message\Tnb.Message\Tnb.Message.csproj" /> <ProjectReference Include="..\..\message\Tnb.Message\Tnb.Message.csproj" />
<ProjectReference Include="..\..\PerMgr\Tnb.PerMgr\Tnb.PerMgr.csproj" /> <ProjectReference Include="..\..\PerMgr\Tnb.PerMgr\Tnb.PerMgr.csproj" />
<ProjectReference Include="..\..\ProductionMgr\Tnb.ProductionMgr\Tnb.ProductionMgr.csproj" /> <ProjectReference Include="..\..\ProductionMgr\Tnb.ProductionMgr\Tnb.ProductionMgr.csproj" />
<ProjectReference Include="..\..\QcMgr\Tnb.QcMgr\Tnb.QcMgr.csproj" /> <ProjectReference Include="..\..\QcMgr\Tnb.QcMgr\Tnb.QcMgr.csproj" />
<ProjectReference Include="..\..\system\Tnb.OAuth\Tnb.OAuth.csproj" /> <ProjectReference Include="..\..\system\Tnb.OAuth\Tnb.OAuth.csproj" />
<ProjectReference Include="..\..\system\Tnb.Systems\Tnb.Systems.csproj" /> <ProjectReference Include="..\..\system\Tnb.Systems\Tnb.Systems.csproj" />
<ProjectReference Include="..\..\taskschedule\Tnb.TaskScheduler\Tnb.TaskScheduler.csproj" /> <ProjectReference Include="..\..\taskschedule\Tnb.TaskScheduler\Tnb.TaskScheduler.csproj" />
<ProjectReference Include="..\..\visualdev\Tnb.Vengine\Tnb.Vengine.csproj" /> <ProjectReference Include="..\..\visualdev\Tnb.Vengine\Tnb.Vengine.csproj" />
<ProjectReference Include="..\..\visualdev\Tnb.VisualDev\Tnb.VisualDev.csproj" /> <ProjectReference Include="..\..\visualdev\Tnb.VisualDev\Tnb.VisualDev.csproj" />
<ProjectReference Include="..\..\WarehouseMgr\Tnb.WarehouseMgr\Tnb.WarehouseMgr.csproj" /> <ProjectReference Include="..\..\WarehouseMgr\Tnb.WarehouseMgr\Tnb.WarehouseMgr.csproj" />
<ProjectReference Include="..\..\workflow\Tnb.WorkFlow\Tnb.WorkFlow.csproj" /> <ProjectReference Include="..\..\workflow\Tnb.WorkFlow\Tnb.WorkFlow.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Update="wwwroot\Template\*.vm"> <Content Update="wwwroot\Template\*.vm">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Update="_install.bat"> <None Update="_install.bat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -25,6 +25,21 @@ namespace Tnb.Common.Extension
return tcs.Task; return tcs.Task;
} }
public static async Task<T> Retry<T>(Func<Task<T>> task, int retries,
TimeSpan delay, CancellationToken cts = default) =>
await task().ContinueWith(async innerTask =>
{
cts.ThrowIfCancellationRequested();
if (innerTask.Status != TaskStatus.Faulted)
return innerTask.Result;
if (retries == 0)
throw innerTask.Exception ?? throw new Exception();
await Task.Delay(delay, cts);
return await Retry(task, retries - 1, delay, cts);
}).Unwrap();
public static async Task Catch(this Task task, Func<Exception,Task> exceptionHandler) public static async Task Catch(this Task task, Func<Exception,Task> exceptionHandler)
{ {
try try

View File

@@ -24,7 +24,7 @@ namespace Tnb.TaskScheduler.Listener
/// <summary> /// <summary>
/// 生成质检任务 /// 生成质检任务
/// </summary> /// </summary>
public class QcTaskTimeWorker : ISpareTimeWorker public class QcTaskTimeWorker //u: ISpareTimeWorker
{ {
private ISqlSugarRepository<QcCheckPlanH> repository => App.GetService<ISqlSugarRepository<QcCheckPlanH>>(); private ISqlSugarRepository<QcCheckPlanH> repository => App.GetService<ISqlSugarRepository<QcCheckPlanH>>();
private ITimeTaskService timeTaskService => App.GetService<ITimeTaskService>(); private ITimeTaskService timeTaskService => App.GetService<ITimeTaskService>();