using JNPF.Common.Configuration; using JNPF.DependencyInjection; using JNPF.EventBus; using JNPF.Systems.Interfaces.Permission; using SqlSugar; namespace JNPF.EventHandler; /// /// 用户事件订阅. /// public class UserEventSubscriber : IEventSubscriber, ISingleton { /// /// 初始化客户端. /// private static SqlSugarScope? _sqlSugarClient; /// /// 用户服务. /// private readonly IUsersService _usersService; /// /// 构造函数. /// public UserEventSubscriber( ISqlSugarClient context, IUsersService usersService) { _sqlSugarClient = (SqlSugarScope)context; _usersService = usersService; } /// /// 修改用户登录信息. /// /// /// [EventSubscribe("User:UpdateUserLogin")] public async Task UpdateUserLoginInfo(EventHandlerExecutingContext context) { var log = (UserEventSource)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().Updateable(log.Entity).UpdateColumns(m => new { m.FirstLogIP, m.FirstLogTime, m.PrevLogTime, m.PrevLogIP, m.LastLogTime, m.LastLogIP, m.LogSuccessCount }).ExecuteCommandAsync(); } /// /// 单点登录同步用户信息. /// /// /// [EventSubscribe("User:Maxkey_Identity")] public async Task ReceiveUserInfo(EventHandlerExecutingContext context) { var log = context.Source.Payload; await _usersService.Receive(log.ToString()); } }