65 lines
2.0 KiB
C#
65 lines
2.0 KiB
C#
using JNPF.Common.Configuration;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.EventBus;
|
|
using JNPF.Systems.Interfaces.Permission;
|
|
using SqlSugar;
|
|
|
|
namespace JNPF.EventHandler;
|
|
|
|
/// <summary>
|
|
/// 用户事件订阅.
|
|
/// </summary>
|
|
public class UserEventSubscriber : IEventSubscriber, ISingleton
|
|
{
|
|
/// <summary>
|
|
/// 初始化客户端.
|
|
/// </summary>
|
|
private static SqlSugarScope? _sqlSugarClient;
|
|
|
|
/// <summary>
|
|
/// 用户服务.
|
|
/// </summary>
|
|
private readonly IUsersService _usersService;
|
|
|
|
/// <summary>
|
|
/// 构造函数.
|
|
/// </summary>
|
|
public UserEventSubscriber(
|
|
ISqlSugarClient context,
|
|
IUsersService usersService)
|
|
{
|
|
_sqlSugarClient = (SqlSugarScope)context;
|
|
_usersService = usersService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改用户登录信息.
|
|
/// </summary>
|
|
/// <param name="context"></param>
|
|
/// <returns></returns>
|
|
[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();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 单点登录同步用户信息.
|
|
/// </summary>
|
|
/// <param name="context"></param>
|
|
/// <returns></returns>
|
|
[EventSubscribe("User:Maxkey_Identity")]
|
|
public async Task ReceiveUserInfo(EventHandlerExecutingContext context)
|
|
{
|
|
var log = context.Source.Payload;
|
|
await _usersService.Receive(log.ToString());
|
|
}
|
|
} |