feat: 新增VIP过期自动卸载功能
- 新增`AiRechargeManager`类,实现VIP过期用户的自动卸载逻辑。 - 新增`AiHubConst`常量类,统一管理角色名称。 - 在`IRoleService`中添加`RemoveUserRoleByRoleCodeAsync`方法,用于移除指定用户的角色。 - 在`RoleManager`中实现`RemoveUserRoleByRoleCodeAsync`方法。 - 优化`CurrentExtensions`中VIP角色判断逻辑,使用常量替代硬编码。 - 调整`YiAbpWebModule`中部分代码格式,提升可读性。
This commit is contained in:
@@ -9,6 +9,12 @@ namespace Yi.Framework.Rbac.Application.Contracts.IServices
|
||||
/// </summary>
|
||||
public interface IRoleService : IYiCrudAppService<RoleGetOutputDto, RoleGetListOutputDto, Guid, RoleGetListInputVo, RoleCreateInputVo, RoleUpdateInputVo>
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 根据角色名称移除指定用户的角色
|
||||
/// </summary>
|
||||
/// <param name="userIds"></param>
|
||||
/// <param name="roleName"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> RemoveUserRoleByRoleCodeAsync(List<Guid> userIds, string roleName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,7 @@ using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
using Volo.Abp.Application.Dtos;
|
||||
using Volo.Abp.Application.Services;
|
||||
using Volo.Abp.Domain.Entities;
|
||||
using Volo.Abp.Uow;
|
||||
using Yi.Framework.Ddd.Application;
|
||||
using Yi.Framework.Rbac.Application.Contracts.Dtos.Role;
|
||||
using Yi.Framework.Rbac.Application.Contracts.Dtos.User;
|
||||
@@ -98,7 +96,8 @@ namespace Yi.Framework.Rbac.Application.Services.System
|
||||
{
|
||||
var entity = await _repository.GetByIdAsync(id);
|
||||
|
||||
var isExist = await _repository._DbQueryable.Where(x => x.Id != entity.Id).AnyAsync(x => x.RoleCode == input.RoleCode || x.RoleName == input.RoleName);
|
||||
var isExist = await _repository._DbQueryable.Where(x => x.Id != entity.Id)
|
||||
.AnyAsync(x => x.RoleCode == input.RoleCode || x.RoleName == input.RoleName);
|
||||
if (isExist)
|
||||
{
|
||||
throw new UserFriendlyException(RoleConst.Exist);
|
||||
@@ -213,7 +212,18 @@ namespace Yi.Framework.Rbac.Application.Services.System
|
||||
await _userRoleRepository._Db.Deleteable<UserRoleEntity>().Where(x => x.RoleId == input.RoleId)
|
||||
.Where(x => input.UserIds.Contains(x.UserId))
|
||||
.ExecuteCommandAsync();
|
||||
;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据角色名称移除指定用户的角色
|
||||
/// </summary>
|
||||
/// <param name="userIds"></param>
|
||||
/// <param name="roleCode"></param>
|
||||
/// <returns></returns>
|
||||
[RemoteService(isEnabled: false)]
|
||||
public Task<int> RemoveUserRoleByRoleCodeAsync(List<Guid> userIds, string roleCode)
|
||||
{
|
||||
return _roleManager.RemoveUserRoleByRoleCodeAsync(userIds, roleCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,10 +8,12 @@ namespace Yi.Framework.Rbac.Domain.Managers
|
||||
{
|
||||
private ISqlSugarRepository<RoleAggregateRoot> _repository;
|
||||
private ISqlSugarRepository<RoleMenuEntity> _roleMenuRepository;
|
||||
public RoleManager(ISqlSugarRepository<RoleAggregateRoot> repository, ISqlSugarRepository<RoleMenuEntity> roleMenuRepository)
|
||||
private ISqlSugarRepository<UserRoleEntity> _userRoleRepository;
|
||||
public RoleManager(ISqlSugarRepository<RoleAggregateRoot> repository, ISqlSugarRepository<RoleMenuEntity> roleMenuRepository, ISqlSugarRepository<UserRoleEntity> userRoleRepository)
|
||||
{
|
||||
_repository = repository;
|
||||
_roleMenuRepository = roleMenuRepository;
|
||||
_userRoleRepository = userRoleRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -38,5 +40,30 @@ namespace Yi.Framework.Rbac.Domain.Managers
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据角色名称移除指定用户的角色
|
||||
/// </summary>
|
||||
/// <param name="userIds">用户ID列表</param>
|
||||
/// <param name="roleName">角色名称</param>
|
||||
/// <returns>移除的角色关系数量</returns>
|
||||
public async Task<int> RemoveUserRoleByRoleCodeAsync(List<Guid> userIds, string roleName)
|
||||
{
|
||||
// 获取角色ID
|
||||
var role = await _repository._DbQueryable
|
||||
.Where(x => x.RoleCode == roleName)
|
||||
.FirstAsync();
|
||||
|
||||
if (role == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 移除用户角色关系
|
||||
var removedCount = await _userRoleRepository._Db.Deleteable<UserRoleEntity>()
|
||||
.Where(x => userIds.Contains(x.UserId) && x.RoleId == role.Id)
|
||||
.ExecuteCommandAsync();
|
||||
return removedCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user