using JNPF.Common.Configuration; using JNPF.DependencyInjection; using JNPF.EventBus; using SqlSugar; namespace JNPF.EventHandler; /// /// 日记事件订阅. /// public class LogEventSubscriber : IEventSubscriber, ISingleton { /// /// 初始化客户端. /// private static SqlSugarScope? _sqlSugarClient; /// /// 构造函数. /// public LogEventSubscriber(ISqlSugarClient context) { _sqlSugarClient = (SqlSugarScope)context; } /// /// 创建日记. /// /// /// [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.CopyNew().Insertable(log.Entity).IgnoreColumns(ignoreNullColumn: true).ExecuteCommandAsync(); } /// /// 创建任务日记. /// /// /// [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.CopyNew().Insertable(log.Entity).IgnoreColumns(ignoreNullColumn: true).ExecuteCommandAsync(); } }