fix 角色分配

This commit is contained in:
2024-04-16 15:59:37 +08:00
parent 2d2eb9dc49
commit 8fb18ef1c6
4 changed files with 33 additions and 22 deletions

View File

@@ -32,6 +32,7 @@ public class UserService : IUserService
.Select((x, ur, r, c) => new UserResponse
{
Id = x.Id,
RoleId = ur.RoleId,
Role = r.Name,
OperatorName = c.ClaimValue,
@@ -58,7 +59,21 @@ public class UserService : IUserService
public async Task<UserResponse> GetUserByIdAsync(int id)
{
var user = await _dbContext.Queryable<UserEntity>().Where(x => x.Id == id).Select<UserResponse>().FirstAsync();
var user = await _dbContext.Queryable<UserEntity>()
.LeftJoin<UserRoleEntity>((x, ur) => x.Id == ur.UserId)
.LeftJoin<RoleEntity>((x, ur, r) => ur.RoleId == r.Id)
.LeftJoin<UserClaimEntity>((x, ur, r, c) => x.Id == c.UserId && c.ClaimType == "preferred_username")
.Where(x => x.Id == id)
.Select((x, ur, r, c) => new UserResponse
{
Id = x.Id,
RoleId = ur.RoleId,
Role = r.Name,
OperatorName = c.ClaimValue,
}, true)
.FirstAsync();
return user;
}