55 lines
1.7 KiB
C#
55 lines
1.7 KiB
C#
using JNPF.Common.Configuration;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.EventBus;
|
|
using SqlSugar;
|
|
|
|
namespace JNPF.EventHandler;
|
|
|
|
/// <summary>
|
|
/// 用户事件订阅.
|
|
/// </summary>
|
|
public class UserEventSubscriber : IEventSubscriber, ISingleton
|
|
{
|
|
/// <summary>
|
|
/// 初始化客户端.
|
|
/// </summary>
|
|
private static SqlSugarScope? _sqlSugarClient;
|
|
|
|
/// <summary>
|
|
/// 构造函数.
|
|
/// </summary>
|
|
public UserEventSubscriber(ISqlSugarClient context)
|
|
{
|
|
_sqlSugarClient = (SqlSugarScope)context;
|
|
}
|
|
|
|
/// <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.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 = (UserEventSource)context.Source;
|
|
}
|
|
} |