添加项目文件。
This commit is contained in:
52
common/Tnb.Common.Core/EventBus/TaskEventSubscriber.cs
Normal file
52
common/Tnb.Common.Core/EventBus/TaskEventSubscriber.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using JNPF.Common.Configuration;
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.EventBus;
|
||||
using JNPF.Systems.Entitys.System;
|
||||
using SqlSugar;
|
||||
|
||||
namespace JNPF.EventHandler;
|
||||
|
||||
/// <summary>
|
||||
/// 任务事件订阅.
|
||||
/// </summary>
|
||||
public class TaskEventSubscriber : IEventSubscriber, ISingleton
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化客户端.
|
||||
/// </summary>
|
||||
private static SqlSugarScope? _sqlSugarClient;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数.
|
||||
/// </summary>
|
||||
public TaskEventSubscriber(ISqlSugarClient context)
|
||||
{
|
||||
_sqlSugarClient = (SqlSugarScope)context;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建任务日记.
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <returns></returns>
|
||||
[EventSubscribe("Task:UpdateTask")]
|
||||
public async Task UpdateTask(EventHandlerExecutingContext context)
|
||||
{
|
||||
var log = (TaskEventSource)context.Source;
|
||||
if (KeyVariable.MultiTenancy)
|
||||
{
|
||||
if (log.ConnectionConfig.ConfigId == null) return;
|
||||
_sqlSugarClient.AddConnection(JNPFTenantExtensions.GetConfig(log.ConnectionConfig));
|
||||
_sqlSugarClient.ChangeDatabase(log.ConnectionConfig.ConfigId);
|
||||
}
|
||||
|
||||
await _sqlSugarClient.Updateable<TimeTaskEntity>().SetColumns(x => new TimeTaskEntity()
|
||||
{
|
||||
RunCount = x.RunCount + 1,
|
||||
LastRunTime = DateTime.Now,
|
||||
NextRunTime = log.Entity.NextRunTime,
|
||||
LastModifyUserId = "admin",
|
||||
LastModifyTime = DateTime.Now
|
||||
}).Where(x => x.Id == log.Entity.Id).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user