66 lines
2.0 KiB
C#
66 lines
2.0 KiB
C#
using JNPF.Common.Configuration;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.EventBus;
|
|
using SqlSugar;
|
|
|
|
namespace JNPF.EventHandler;
|
|
|
|
/// <summary>
|
|
/// 日记事件订阅.
|
|
/// </summary>
|
|
public class LogEventSubscriber : IEventSubscriber, ISingleton
|
|
{
|
|
/// <summary>
|
|
/// 初始化客户端.
|
|
/// </summary>
|
|
private static SqlSugarScope? _sqlSugarClient;
|
|
|
|
/// <summary>
|
|
/// 构造函数.
|
|
/// </summary>
|
|
public LogEventSubscriber(ISqlSugarClient context)
|
|
{
|
|
_sqlSugarClient = (SqlSugarScope)context;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建日记.
|
|
/// </summary>
|
|
/// <param name="context"></param>
|
|
/// <returns></returns>
|
|
[EventSubscribe("Log:CreateReLog")]
|
|
[EventSubscribe("Log:CreateExLog")]
|
|
[EventSubscribe("Log:CreateVisLog")]
|
|
[EventSubscribe("Log:CreateOpLog")]
|
|
public async Task CreateLog(EventHandlerExecutingContext context)
|
|
{
|
|
var log = (LogEventSource)context.Source;
|
|
if (KeyVariable.MultiTenancy)
|
|
{
|
|
if (log.ConnectionConfig.ConfigId == null) return;
|
|
_sqlSugarClient.AddConnection(JNPFTenantExtensions.GetConfig(log.ConnectionConfig));
|
|
_sqlSugarClient.ChangeDatabase(log.ConnectionConfig.ConfigId);
|
|
}
|
|
|
|
await _sqlSugarClient.Insertable(log.Entity).IgnoreColumns(ignoreNullColumn: true).ExecuteCommandAsync();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建任务日记.
|
|
/// </summary>
|
|
/// <param name="context"></param>
|
|
/// <returns></returns>
|
|
[EventSubscribe("Log:CreateTaskLog")]
|
|
public async Task CreateTaskLog(EventHandlerExecutingContext context)
|
|
{
|
|
var log = (TaskLogEventSource)context.Source;
|
|
if (KeyVariable.MultiTenancy)
|
|
{
|
|
if (log.ConnectionConfig.ConfigId == null) return;
|
|
_sqlSugarClient.AddConnection(JNPFTenantExtensions.GetConfig(log.ConnectionConfig));
|
|
_sqlSugarClient.ChangeDatabase(log.ConnectionConfig.ConfigId);
|
|
}
|
|
|
|
await _sqlSugarClient.Insertable(log.Entity).IgnoreColumns(ignoreNullColumn: true).ExecuteCommandAsync();
|
|
}
|
|
} |