diff --git a/Yi.Furion.Net6/Yi.Furion.Application/Rbac/Services/Impl/RoleService.cs b/Yi.Furion.Net6/Yi.Furion.Application/Rbac/Services/Impl/RoleService.cs index 7286c1a2..7156c599 100644 --- a/Yi.Furion.Net6/Yi.Furion.Application/Rbac/Services/Impl/RoleService.cs +++ b/Yi.Furion.Net6/Yi.Furion.Application/Rbac/Services/Impl/RoleService.cs @@ -132,35 +132,44 @@ namespace Yi.Furion.Application.Rbac.Services.Impl [Route("/api/role/auth-user/{roleId}/{isAllocated}")] public async Task> GetAuthUserByRoleIdAsync([FromRoute] long roleId, [FromRoute] bool isAllocated, [FromQuery] RoleAuthUserGetListInput input) { - + PagedResultDto output; //角色下已授权用户 if (isAllocated == true) { - RefAsync total = 0; - var output = await _userRoleRepository._DbQueryable - .LeftJoin((ur, u) => ur.UserId == u.Id && ur.RoleId == roleId) - .Where((ur, u) => ur.RoleId == roleId) - .WhereIF(!string.IsNullOrEmpty(input.UserName), (ur, u) => u.UserName.Contains(input.UserName)) - .WhereIF(input.Phone is not null, (ur, u) => u.Phone.ToString().Contains(input.Phone.ToString())) - .Select((ur, u) => new UserGetListOutputDto { Id = u.Id }, true) - .ToPageListAsync(input.PageNum, input.PageSize, total); - return new PagedResultDto(total, output); + output = await GetAllocatedAuthUserByRoleIdAsync(roleId, input); } //角色下未授权用户 else { - RefAsync total = 0; - var entities = await _userRoleRepository._Db.Queryable() - .Where(u => SqlFunc.Subqueryable().Where(x => x.RoleId == roleId).Where(x => x.UserId == u.Id).NotAny()) - .WhereIF(!string.IsNullOrEmpty(input.UserName), u => u.UserName.Contains(input.UserName)) - .WhereIF(input.Phone is not null, u => u.Phone.ToString().Contains(input.Phone.ToString())) - .ToPageListAsync(input.PageNum, input.PageSize, total); - var output = entities.Adapt>(); - return new PagedResultDto(total, output); + output = await GetNotAllocatedAuthUserByRoleIdAsync(roleId, input); } + return output; } + private async Task> GetAllocatedAuthUserByRoleIdAsync(long roleId, RoleAuthUserGetListInput input) + { + RefAsync total = 0; + var output = await _userRoleRepository._DbQueryable + .LeftJoin((ur, u) => ur.UserId == u.Id && ur.RoleId == roleId) + .Where((ur, u) => ur.RoleId == roleId) + .WhereIF(!string.IsNullOrEmpty(input.UserName), (ur, u) => u.UserName.Contains(input.UserName)) + .WhereIF(input.Phone is not null, (ur, u) => u.Phone.ToString().Contains(input.Phone.ToString())) + .Select((ur, u) => new UserGetListOutputDto { Id = u.Id }, true) + .ToPageListAsync(input.PageNum, input.PageSize, total); + return new PagedResultDto(total, output); + } + private async Task> GetNotAllocatedAuthUserByRoleIdAsync(long roleId, RoleAuthUserGetListInput input) + { + RefAsync total = 0; + var entities = await _userRoleRepository._Db.Queryable() + .Where(u => SqlFunc.Subqueryable().Where(x => x.RoleId == roleId).Where(x => x.UserId == u.Id).NotAny()) + .WhereIF(!string.IsNullOrEmpty(input.UserName), u => u.UserName.Contains(input.UserName)) + .WhereIF(input.Phone is not null, u => u.Phone.ToString().Contains(input.Phone.ToString())) + .ToPageListAsync(input.PageNum, input.PageSize, total); + var output = entities.Adapt>(); + return new PagedResultDto(total, output); + } ///