refactor:优化角色授权查询

This commit is contained in:
橙子
2023-05-24 20:54:26 +08:00
parent 93764fc5b5
commit 496861587d

View File

@@ -132,9 +132,21 @@ namespace Yi.Furion.Application.Rbac.Services.Impl
[Route("/api/role/auth-user/{roleId}/{isAllocated}")] [Route("/api/role/auth-user/{roleId}/{isAllocated}")]
public async Task<PagedResultDto<UserGetListOutputDto>> GetAuthUserByRoleIdAsync([FromRoute] long roleId, [FromRoute] bool isAllocated, [FromQuery] RoleAuthUserGetListInput input) public async Task<PagedResultDto<UserGetListOutputDto>> GetAuthUserByRoleIdAsync([FromRoute] long roleId, [FromRoute] bool isAllocated, [FromQuery] RoleAuthUserGetListInput input)
{ {
PagedResultDto<UserGetListOutputDto> output;
//角色下已授权用户 //角色下已授权用户
if (isAllocated == true) if (isAllocated == true)
{
output = await GetAllocatedAuthUserByRoleIdAsync(roleId, input);
}
//角色下未授权用户
else
{
output = await GetNotAllocatedAuthUserByRoleIdAsync(roleId, input);
}
return output;
}
private async Task<PagedResultDto<UserGetListOutputDto>> GetAllocatedAuthUserByRoleIdAsync(long roleId, RoleAuthUserGetListInput input)
{ {
RefAsync<int> total = 0; RefAsync<int> total = 0;
var output = await _userRoleRepository._DbQueryable var output = await _userRoleRepository._DbQueryable
@@ -146,8 +158,8 @@ namespace Yi.Furion.Application.Rbac.Services.Impl
.ToPageListAsync(input.PageNum, input.PageSize, total); .ToPageListAsync(input.PageNum, input.PageSize, total);
return new PagedResultDto<UserGetListOutputDto>(total, output); return new PagedResultDto<UserGetListOutputDto>(total, output);
} }
//角色下未授权用户
else private async Task<PagedResultDto<UserGetListOutputDto>> GetNotAllocatedAuthUserByRoleIdAsync(long roleId, RoleAuthUserGetListInput input)
{ {
RefAsync<int> total = 0; RefAsync<int> total = 0;
var entities = await _userRoleRepository._Db.Queryable<UserEntity>() var entities = await _userRoleRepository._Db.Queryable<UserEntity>()
@@ -158,9 +170,6 @@ namespace Yi.Furion.Application.Rbac.Services.Impl
var output = entities.Adapt<List<UserGetListOutputDto>>(); var output = entities.Adapt<List<UserGetListOutputDto>>();
return new PagedResultDto<UserGetListOutputDto>(total, output); return new PagedResultDto<UserGetListOutputDto>(total, output);
} }
}
/// <summary> /// <summary>