😎优化系统用户和租户事件订阅
This commit is contained in:
parent
57e33bb3e9
commit
57dbfd3e01
@ -23,7 +23,7 @@
|
|||||||
"DocExpansionState": "List", // List、Full、None
|
"DocExpansionState": "List", // List、Full、None
|
||||||
"EnableAllGroups": true,
|
"EnableAllGroups": true,
|
||||||
//"ServerDir": "t490", // Nginx 有二级目录的,把二级目录设置在这里,并且开启 Servers 的选择列表
|
//"ServerDir": "t490", // Nginx 有二级目录的,把二级目录设置在这里,并且开启 Servers 的选择列表
|
||||||
"HideServers": false,
|
"HideServers": true,
|
||||||
"Servers": [
|
"Servers": [
|
||||||
{
|
{
|
||||||
"Url": "https://ip/二级",
|
"Url": "https://ip/二级",
|
||||||
|
|||||||
@ -0,0 +1,49 @@
|
|||||||
|
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
|
||||||
|
//
|
||||||
|
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
|
||||||
|
//
|
||||||
|
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
||||||
|
|
||||||
|
using Admin.NET.Core.Service;
|
||||||
|
using Furion.EventBus;
|
||||||
|
using Furion.JsonSerialization;
|
||||||
|
|
||||||
|
namespace Admin.NET.Application;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 事件订阅
|
||||||
|
/// </summary>
|
||||||
|
public class AppEventSubscriber : IEventSubscriber, ISingleton, IDisposable
|
||||||
|
{
|
||||||
|
private readonly IServiceScope _serviceScope;
|
||||||
|
|
||||||
|
public AppEventSubscriber(IServiceScopeFactory scopeFactory)
|
||||||
|
{
|
||||||
|
_serviceScope = scopeFactory.CreateScope();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 修改用户
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="context"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[EventSubscribe(UserEventTypeEnum.Update)]
|
||||||
|
public async Task CreateExLog(EventHandlerExecutingContext context)
|
||||||
|
{
|
||||||
|
var addUserInput = context.GetPayload<AddUserInput>();
|
||||||
|
Console.WriteLine(JSON.Serialize(addUserInput));
|
||||||
|
|
||||||
|
await Task.CompletedTask;
|
||||||
|
|
||||||
|
//var db = _serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>();
|
||||||
|
//await db.CopyNew().Insertable(context.GetPayload<AddUserInput>()).ExecuteCommandAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 释放服务作用域
|
||||||
|
/// </summary>
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_serviceScope.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -49,7 +49,7 @@
|
|||||||
<PackageReference Include="SSH.NET" Version="2024.2.0" />
|
<PackageReference Include="SSH.NET" Version="2024.2.0" />
|
||||||
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.5.1" />
|
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.5.1" />
|
||||||
<PackageReference Include="System.Net.Http" Version="4.3.4" />
|
<PackageReference Include="System.Net.Http" Version="4.3.4" />
|
||||||
<PackageReference Include="TencentCloudSDK.Sms" Version="3.0.1157" />
|
<PackageReference Include="TencentCloudSDK.Sms" Version="3.0.1158" />
|
||||||
<PackageReference Include="UAParser" Version="3.1.47" />
|
<PackageReference Include="UAParser" Version="3.1.47" />
|
||||||
<PackageReference Include="Yitter.IdGenerator" Version="1.0.14" />
|
<PackageReference Include="Yitter.IdGenerator" Version="1.0.14" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@ -36,14 +36,4 @@ public class CommonConst
|
|||||||
/// 事件-发送异常邮件
|
/// 事件-发送异常邮件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const string SendErrorMail = "Send:ErrorMail";
|
public const string SendErrorMail = "Send:ErrorMail";
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 事件-增加租户
|
|
||||||
/// </summary>
|
|
||||||
public const string InitTenant = "Add:Tenant";
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 事件-删除租户
|
|
||||||
/// </summary>
|
|
||||||
public const string DeleteTenant = "Delete:Tenant";
|
|
||||||
}
|
}
|
||||||
@ -4,29 +4,29 @@
|
|||||||
//
|
//
|
||||||
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
||||||
|
|
||||||
namespace Admin.NET.Core.Service;
|
namespace Admin.NET.Core;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 系统用户事件处理类
|
/// 事件类型-系统租户操作枚举
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SysUserEventHandler : ISingleton
|
[Description("事件类型-系统租户操作枚举")]
|
||||||
|
public enum TenantEventTypeEnum
|
||||||
{
|
{
|
||||||
private event EventHandler Event;
|
/// <summary>
|
||||||
|
/// 增加租户
|
||||||
|
/// </summary>
|
||||||
|
[Description("增加租户")]
|
||||||
|
Add = 0,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 订阅
|
/// 更新租户
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="eventHandler"></param>
|
[Description("更新租户")]
|
||||||
public void Subscribe(EventHandler eventHandler) => Event += eventHandler;
|
Update = 1,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 发布事件
|
/// 删除租户
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
[Description("删除租户")]
|
||||||
/// <param name="eventType"></param>
|
Delete = 2,
|
||||||
/// <param name="input"></param>
|
|
||||||
public void OnEvent(object sender, SysUserEventTypeEnum eventType, object input)
|
|
||||||
{
|
|
||||||
Event?.Invoke(sender, new SysUserEventArgs(eventType, input));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -10,53 +10,53 @@ namespace Admin.NET.Core;
|
|||||||
/// 事件类型-系统用户操作枚举
|
/// 事件类型-系统用户操作枚举
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Description("事件类型-系统用户操作枚举")]
|
[Description("事件类型-系统用户操作枚举")]
|
||||||
public enum SysUserEventTypeEnum
|
public enum UserEventTypeEnum
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 增加用户
|
/// 增加用户
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Description("增加用户")]
|
[Description("增加用户")]
|
||||||
Add = 111,
|
Add = 0,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 更新用户
|
/// 更新用户
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Description("更新用户")]
|
[Description("更新用户")]
|
||||||
Update = 222,
|
Update = 1,
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 授权用户角色
|
|
||||||
/// </summary>
|
|
||||||
[Description("授权用户角色")]
|
|
||||||
UpdateRole = 333,
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 删除用户
|
/// 删除用户
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Description("删除用户")]
|
[Description("删除用户")]
|
||||||
Delete = 444,
|
Delete = 2,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 授权用户角色
|
||||||
|
/// </summary>
|
||||||
|
[Description("授权用户角色")]
|
||||||
|
UpdateRole = 3,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设置用户状态
|
/// 设置用户状态
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Description("设置用户状态")]
|
[Description("设置用户状态")]
|
||||||
SetStatus = 555,
|
SetStatus = 4,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 修改密码
|
/// 修改密码
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Description("修改密码")]
|
[Description("修改密码")]
|
||||||
ChangePwd = 666,
|
ChangePwd = 5,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 重置密码
|
/// 重置密码
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Description("重置密码")]
|
[Description("重置密码")]
|
||||||
ResetPwd = 777,
|
ResetPwd = 6,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 解除登录锁定
|
/// 解除登录锁定
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Description("解除登录锁定")]
|
[Description("解除登录锁定")]
|
||||||
UnlockLogin = 888
|
UnlockLogin = 7
|
||||||
}
|
}
|
||||||
@ -259,7 +259,7 @@ public class SysTenantService : IDynamicApiController, ITransient
|
|||||||
await _sysRoleMenuService.GrantRoleMenu(new RoleMenuInput() { Id = newRole.Id, MenuIdList = menuIdList });
|
await _sysRoleMenuService.GrantRoleMenu(new RoleMenuInput() { Id = newRole.Id, MenuIdList = menuIdList });
|
||||||
|
|
||||||
// 发布新增租户事件
|
// 发布新增租户事件
|
||||||
await _eventPublisher.PublishAsync(CommonConst.InitTenant, tenant);
|
await _eventPublisher.PublishAsync(TenantEventTypeEnum.Add, tenant);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -303,7 +303,7 @@ public class SysTenantService : IDynamicApiController, ITransient
|
|||||||
await _sysPosRep.AsDeleteable().Where(u => u.TenantId == input.Id).ExecuteCommandAsync();
|
await _sysPosRep.AsDeleteable().Where(u => u.TenantId == input.Id).ExecuteCommandAsync();
|
||||||
|
|
||||||
// 发布删除租户事件
|
// 发布删除租户事件
|
||||||
await _eventPublisher.PublishAsync(CommonConst.DeleteTenant, input);
|
await _eventPublisher.PublishAsync(TenantEventTypeEnum.Delete, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -352,6 +352,9 @@ public class SysTenantService : IDynamicApiController, ITransient
|
|||||||
await _sysUserRep.UpdateAsync(u => new SysUser() { Account = input.AdminAccount, Phone = input.Phone, Email = input.Email }, u => u.Id == input.UserId);
|
await _sysUserRep.UpdateAsync(u => new SysUser() { Account = input.AdminAccount, Phone = input.Phone, Email = input.Email }, u => u.Id == input.UserId);
|
||||||
|
|
||||||
await CacheTenant(input.Id);
|
await CacheTenant(input.Id);
|
||||||
|
|
||||||
|
// 发布更新租户事件
|
||||||
|
await _eventPublisher.PublishAsync(TenantEventTypeEnum.Update, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -15,14 +15,14 @@ public class SysUserEventArgs : EventArgs
|
|||||||
/// 事件类型
|
/// 事件类型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Required]
|
[Required]
|
||||||
public SysUserEventTypeEnum EventType { get; set; }
|
public UserEventTypeEnum EventType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 接口输入参数
|
/// 接口输入参数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public object Input { get; set; }
|
public object Input { get; set; }
|
||||||
|
|
||||||
public SysUserEventArgs(SysUserEventTypeEnum eventType, object input)
|
public SysUserEventArgs(UserEventTypeEnum eventType, object input)
|
||||||
{
|
{
|
||||||
this.EventType = eventType;
|
this.EventType = eventType;
|
||||||
this.Input = input;
|
this.Input = input;
|
||||||
|
|||||||
@ -23,7 +23,7 @@ public class SysUserService : IDynamicApiController, ITransient
|
|||||||
private readonly SysCacheService _sysCacheService;
|
private readonly SysCacheService _sysCacheService;
|
||||||
private readonly SysUserLdapService _sysUserLdapService;
|
private readonly SysUserLdapService _sysUserLdapService;
|
||||||
private readonly SqlSugarRepository<SysUser> _sysUserRep;
|
private readonly SqlSugarRepository<SysUser> _sysUserRep;
|
||||||
private readonly SysUserEventHandler _sysUserEventHandler;
|
private readonly IEventPublisher _eventPublisher;
|
||||||
|
|
||||||
public SysUserService(UserManager userManager,
|
public SysUserService(UserManager userManager,
|
||||||
SysOrgService sysOrgService,
|
SysOrgService sysOrgService,
|
||||||
@ -36,7 +36,7 @@ public class SysUserService : IDynamicApiController, ITransient
|
|||||||
SysCacheService sysCacheService,
|
SysCacheService sysCacheService,
|
||||||
SysUserLdapService sysUserLdapService,
|
SysUserLdapService sysUserLdapService,
|
||||||
SqlSugarRepository<SysUser> sysUserRep,
|
SqlSugarRepository<SysUser> sysUserRep,
|
||||||
SysUserEventHandler sysUserEventHandler)
|
IEventPublisher eventPublisher)
|
||||||
{
|
{
|
||||||
_userManager = userManager;
|
_userManager = userManager;
|
||||||
_sysOrgService = sysOrgService;
|
_sysOrgService = sysOrgService;
|
||||||
@ -49,7 +49,7 @@ public class SysUserService : IDynamicApiController, ITransient
|
|||||||
_sysCacheService = sysCacheService;
|
_sysCacheService = sysCacheService;
|
||||||
_sysUserLdapService = sysUserLdapService;
|
_sysUserLdapService = sysUserLdapService;
|
||||||
_sysUserRep = sysUserRep;
|
_sysUserRep = sysUserRep;
|
||||||
_sysUserEventHandler = sysUserEventHandler;
|
_eventPublisher = eventPublisher;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -122,8 +122,8 @@ public class SysUserService : IDynamicApiController, ITransient
|
|||||||
if (!string.IsNullOrWhiteSpace(input.DomainAccount))
|
if (!string.IsNullOrWhiteSpace(input.DomainAccount))
|
||||||
await _sysUserLdapService.AddUserLdap(newUser.TenantId!.Value, newUser.Id, newUser.Account, input.DomainAccount);
|
await _sysUserLdapService.AddUserLdap(newUser.TenantId!.Value, newUser.Id, newUser.Account, input.DomainAccount);
|
||||||
|
|
||||||
// 执行订阅事件
|
// 发布新增用户事件
|
||||||
_sysUserEventHandler.OnEvent(this, SysUserEventTypeEnum.Add, input);
|
await _eventPublisher.PublishAsync(UserEventTypeEnum.Add, input);
|
||||||
|
|
||||||
return newUser.Id;
|
return newUser.Id;
|
||||||
}
|
}
|
||||||
@ -161,8 +161,8 @@ public class SysUserService : IDynamicApiController, ITransient
|
|||||||
// 更新域账号
|
// 更新域账号
|
||||||
await _sysUserLdapService.AddUserLdap(user.TenantId!.Value, user.Id, user.Account, input.DomainAccount);
|
await _sysUserLdapService.AddUserLdap(user.TenantId!.Value, user.Id, user.Account, input.DomainAccount);
|
||||||
|
|
||||||
// 执行订阅事件
|
// 发布更新用户事件
|
||||||
_sysUserEventHandler.OnEvent(this, SysUserEventTypeEnum.Update, input);
|
await _eventPublisher.PublishAsync(UserEventTypeEnum.Update, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -216,8 +216,8 @@ public class SysUserService : IDynamicApiController, ITransient
|
|||||||
// 删除用户收藏菜单
|
// 删除用户收藏菜单
|
||||||
await _sysUserMenuService.DeleteUserMenuList(input.Id);
|
await _sysUserMenuService.DeleteUserMenuList(input.Id);
|
||||||
|
|
||||||
// 执行订阅事件
|
// 发布删除用户事件
|
||||||
_sysUserEventHandler.OnEvent(this, SysUserEventTypeEnum.Delete, input);
|
await _eventPublisher.PublishAsync(UserEventTypeEnum.Delete, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -266,8 +266,8 @@ public class SysUserService : IDynamicApiController, ITransient
|
|||||||
user.Status = input.Status;
|
user.Status = input.Status;
|
||||||
var rows = await _sysUserRep.AsUpdateable(user).UpdateColumns(u => new { u.Status }).ExecuteCommandAsync();
|
var rows = await _sysUserRep.AsUpdateable(user).UpdateColumns(u => new { u.Status }).ExecuteCommandAsync();
|
||||||
|
|
||||||
// 执行订阅事件
|
// 发布设置用户状态事件
|
||||||
if (rows > 0) _sysUserEventHandler.OnEvent(this, SysUserEventTypeEnum.SetStatus, input);
|
await _eventPublisher.PublishAsync(UserEventTypeEnum.SetStatus, input);
|
||||||
|
|
||||||
return rows;
|
return rows;
|
||||||
}
|
}
|
||||||
@ -309,8 +309,8 @@ public class SysUserService : IDynamicApiController, ITransient
|
|||||||
|
|
||||||
await _sysUserRoleService.GrantUserRole(input);
|
await _sysUserRoleService.GrantUserRole(input);
|
||||||
|
|
||||||
// 执行订阅事件
|
// 发布更新用户角色事件
|
||||||
_sysUserEventHandler.OnEvent(this, SysUserEventTypeEnum.UpdateRole, input);
|
await _eventPublisher.PublishAsync(UserEventTypeEnum.UpdateRole, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -368,8 +368,8 @@ public class SysUserService : IDynamicApiController, ITransient
|
|||||||
user.LastChangePasswordTime = DateTime.Now;
|
user.LastChangePasswordTime = DateTime.Now;
|
||||||
var rows = await _sysUserRep.AsUpdateable(user).UpdateColumns(u => new { u.Password, u.LastChangePasswordTime }).ExecuteCommandAsync();
|
var rows = await _sysUserRep.AsUpdateable(user).UpdateColumns(u => new { u.Password, u.LastChangePasswordTime }).ExecuteCommandAsync();
|
||||||
|
|
||||||
// 执行订阅事件
|
// 发布修改用户密码事件
|
||||||
if (rows > 0) _sysUserEventHandler.OnEvent(this, SysUserEventTypeEnum.ChangePwd, input);
|
await _eventPublisher.PublishAsync(UserEventTypeEnum.ChangePwd, input);
|
||||||
|
|
||||||
return rows;
|
return rows;
|
||||||
}
|
}
|
||||||
@ -392,8 +392,8 @@ public class SysUserService : IDynamicApiController, ITransient
|
|||||||
var keyPasswordErrorTimes = $"{CacheConst.KeyPasswordErrorTimes}{user.Account}";
|
var keyPasswordErrorTimes = $"{CacheConst.KeyPasswordErrorTimes}{user.Account}";
|
||||||
_sysCacheService.Remove(keyPasswordErrorTimes);
|
_sysCacheService.Remove(keyPasswordErrorTimes);
|
||||||
|
|
||||||
// 执行订阅事件
|
// 发布重置用户密码事件
|
||||||
_sysUserEventHandler.OnEvent(this, SysUserEventTypeEnum.ResetPwd, input);
|
await _eventPublisher.PublishAsync(UserEventTypeEnum.ResetPwd, input);
|
||||||
|
|
||||||
return password;
|
return password;
|
||||||
}
|
}
|
||||||
@ -431,8 +431,8 @@ public class SysUserService : IDynamicApiController, ITransient
|
|||||||
var keyPasswordErrorTimes = $"{CacheConst.KeyPasswordErrorTimes}{user.Account}";
|
var keyPasswordErrorTimes = $"{CacheConst.KeyPasswordErrorTimes}{user.Account}";
|
||||||
_sysCacheService.Remove(keyPasswordErrorTimes);
|
_sysCacheService.Remove(keyPasswordErrorTimes);
|
||||||
|
|
||||||
// 执行订阅事件
|
// 发布解除登录锁定事件
|
||||||
_sysUserEventHandler.OnEvent(this, SysUserEventTypeEnum.UnlockLogin, input);
|
await _eventPublisher.PublishAsync(UserEventTypeEnum.UnlockLogin, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -88,8 +88,8 @@
|
|||||||
"@types/node": "^20.17.11",
|
"@types/node": "^20.17.11",
|
||||||
"@types/nprogress": "^0.2.3",
|
"@types/nprogress": "^0.2.3",
|
||||||
"@types/sortablejs": "^1.15.8",
|
"@types/sortablejs": "^1.15.8",
|
||||||
"@typescript-eslint/eslint-plugin": "^8.19.0",
|
"@typescript-eslint/eslint-plugin": "^8.19.1",
|
||||||
"@typescript-eslint/parser": "^8.19.0",
|
"@typescript-eslint/parser": "^8.19.1",
|
||||||
"@vitejs/plugin-vue": "^5.2.1",
|
"@vitejs/plugin-vue": "^5.2.1",
|
||||||
"@vitejs/plugin-vue-jsx": "^4.1.1",
|
"@vitejs/plugin-vue-jsx": "^4.1.1",
|
||||||
"@vue/compiler-sfc": "^3.5.13",
|
"@vue/compiler-sfc": "^3.5.13",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user