添加项目文件。
This commit is contained in:
55
common/Tnb.Common.Core/EventBus/UserEventSubscriber.cs
Normal file
55
common/Tnb.Common.Core/EventBus/UserEventSubscriber.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user