fix 优化人员列表展示
This commit is contained in:
@@ -29,7 +29,7 @@ public class RolesController : ControllerBase
|
||||
/// <returns></returns>
|
||||
[Authorize(Roles = "admin")]
|
||||
[HttpGet("page")]
|
||||
public async Task<Pagination<RoleRespone>> GetPageAsync([FromQuery] RolePageRequest request)
|
||||
public async Task<Pagination<RoleResponse>> GetPageAsync([FromQuery] RolePageRequest request)
|
||||
{
|
||||
return await _roleService.GetPageAsync(request);
|
||||
}
|
||||
@@ -40,7 +40,7 @@ public class RolesController : ControllerBase
|
||||
/// <returns></returns>
|
||||
[Authorize(Roles = "admin")]
|
||||
[HttpGet("list")]
|
||||
public async Task<List<RoleRespone>> GetListAsync()
|
||||
public async Task<List<RoleResponse>> GetListAsync()
|
||||
{
|
||||
return await _roleService.GetListAsync();
|
||||
}
|
||||
@@ -85,7 +85,7 @@ public class RolesController : ControllerBase
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("my")]
|
||||
public async Task<RoleRespone> GetMyRoleAsync(int? userId)
|
||||
public async Task<RoleResponse> GetMyRoleAsync(int? userId)
|
||||
{
|
||||
return await _roleService.GetMyRoleAsync(userId);
|
||||
}
|
||||
|
||||
@@ -92,4 +92,4 @@ public class TenantsController : ControllerBase
|
||||
{
|
||||
return await _tenantService.GetMyTenantsAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ public class UsersController : ControllerBase
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize(Roles = "admin")]
|
||||
[Authorize(Roles = "admin,tenant-admin")]
|
||||
[HttpGet("page")]
|
||||
public async Task<Pagination<UserResponse>> GetPageAsync([FromQuery] UserPageRequest request)
|
||||
{
|
||||
@@ -64,7 +64,7 @@ public class UsersController : ControllerBase
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// 创建用户
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
@@ -6,6 +6,9 @@ public class RoleSaveRequest
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "角色名不能为空")]
|
||||
[Required(ErrorMessage = "角色标识不能为空")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "描述不能为空")]
|
||||
public string Description { get; set; }
|
||||
}
|
||||
|
||||
@@ -4,4 +4,8 @@ namespace Dlhis.Sys.Identity.Request;
|
||||
|
||||
public class UserPageRequest : PageDto
|
||||
{
|
||||
}
|
||||
/// <summary>
|
||||
/// 操作员
|
||||
/// </summary>
|
||||
public bool IsOperator { get; set; }
|
||||
}
|
||||
@@ -1,13 +1,24 @@
|
||||
namespace Dlhis.Sys.Identity.Response;
|
||||
|
||||
public class RoleRespone
|
||||
public class RoleResponse
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 标准化名称
|
||||
/// </summary>
|
||||
public string NormalizedName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 描述
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否可编辑
|
||||
/// </summary>
|
||||
@@ -6,13 +6,13 @@ namespace Dlhis.User.Identity.Services;
|
||||
|
||||
public interface IRoleService : IScopeDependency
|
||||
{
|
||||
Task<Pagination<RoleRespone>> GetPageAsync(RolePageRequest request);
|
||||
Task<Pagination<RoleResponse>> GetPageAsync(RolePageRequest request);
|
||||
|
||||
Task<List<RoleRespone>> GetListAsync();
|
||||
Task<List<RoleResponse>> GetListAsync();
|
||||
|
||||
Task SaveRoleAsync(RoleSaveRequest request);
|
||||
|
||||
Task<RoleRespone> GetMyRoleAsync(int? userId);
|
||||
Task<RoleResponse> GetMyRoleAsync(int? userId);
|
||||
|
||||
Task RemoveRoleAsync(RoleRemoveRequest request);
|
||||
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
using Dlhis.Sys.Identity.Request;
|
||||
using Dlhis.Sys.Identity.Response;
|
||||
using Dlhis.User.Identity.Services;
|
||||
using Kurisu.AspNetCore.Scope;
|
||||
using Kurisu.AspNetCore.UnifyResultAndValidation;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.Core.CustomClass;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
@@ -24,29 +22,24 @@ public class RoleService : IRoleService
|
||||
_dbContext = dbContext.ChangeDb("identity");
|
||||
}
|
||||
|
||||
public async Task<Pagination<RoleRespone>> GetPageAsync(RolePageRequest request)
|
||||
public async Task<Pagination<RoleResponse>> GetPageAsync(RolePageRequest request)
|
||||
{
|
||||
return await _dbContext.Queryable<RoleEntity>()
|
||||
.WhereIF(request.Search.IsPresent(), x => x.Name.Contains(request.Search) || x.NormalizedName.Contains(request.Search))
|
||||
.Where(x => x.Name != "admin")
|
||||
.Select<RoleRespone>()
|
||||
.ToPageListAsync(request);
|
||||
.WhereIF(request.Search.IsPresent(), x => x.Name.Contains(request.Search) || x.NormalizedName.Contains(request.Search))
|
||||
.Where(x => x.Name != "admin")
|
||||
.Select<RoleResponse>()
|
||||
.ToPageListAsync(request);
|
||||
}
|
||||
|
||||
public async Task<RoleRespone> GetMyRoleAsync(int? userId)
|
||||
public async Task<RoleResponse> GetMyRoleAsync(int? userId)
|
||||
{
|
||||
userId ??= _currentUser.GetIntSubjectId();
|
||||
|
||||
return await _dbContext.Queryable<UserRoleEntity>()
|
||||
.LeftJoin<RoleEntity>((x, r) => x.RoleId == r.Id)
|
||||
.Where(x => x.UserId == userId)
|
||||
.Select((x, r) => new RoleRespone
|
||||
{
|
||||
Id = r.Id,
|
||||
Name = r.Name,
|
||||
NormalizedName = r.NormalizedName,
|
||||
})
|
||||
.FirstAsync();
|
||||
.LeftJoin<RoleEntity>((x, r) => x.RoleId == r.Id)
|
||||
.Where(x => x.UserId == userId)
|
||||
.Select<RoleResponse>()
|
||||
.FirstAsync();
|
||||
}
|
||||
|
||||
public async Task SaveRoleAsync(RoleSaveRequest request)
|
||||
@@ -59,6 +52,7 @@ public class RoleService : IRoleService
|
||||
{
|
||||
Name = request.Name,
|
||||
NormalizedName = request.Name.ToUpperInvariant(),
|
||||
Description = request.Description,
|
||||
ConcurrencyStamp = Guid.NewGuid(),
|
||||
});
|
||||
}
|
||||
@@ -69,6 +63,7 @@ public class RoleService : IRoleService
|
||||
|
||||
entity.Name = request.Name;
|
||||
entity.NormalizedName = request.Name.ToUpperInvariant();
|
||||
entity.Description = request.Description;
|
||||
entity.ConcurrencyStamp = Guid.NewGuid();
|
||||
|
||||
await _dbContext.UpdateAsync(entity);
|
||||
@@ -107,9 +102,9 @@ public class RoleService : IRoleService
|
||||
else
|
||||
{
|
||||
await _dbContext.Updateable<UserRoleEntity>()
|
||||
.SetColumns(x => x.RoleId == request.RoleId)
|
||||
.Where(x => x.UserId == request.UserId)
|
||||
.ExecuteCommandAsync();
|
||||
.SetColumns(x => x.RoleId == request.RoleId)
|
||||
.Where(x => x.UserId == request.UserId)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -127,12 +122,12 @@ public class RoleService : IRoleService
|
||||
await _dbContext.DeleteReallyAsync(role);
|
||||
}
|
||||
|
||||
public async Task<List<RoleRespone>> GetListAsync()
|
||||
public async Task<List<RoleResponse>> GetListAsync()
|
||||
{
|
||||
return await _dbContext.Queryable<RoleEntity>()
|
||||
.Where(x => x.Name != "admin")
|
||||
.Select<RoleRespone>()
|
||||
.ToListAsync();
|
||||
.Where(x => x.Name != "admin")
|
||||
.Select<RoleResponse>()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
@@ -148,4 +143,4 @@ public class RoleService : IRoleService
|
||||
|
||||
exists.ThrowIfTrue($"重复角色名称{request.Name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,16 +23,16 @@ public class TenantService : ITenantService
|
||||
public async Task<Pagination<TenantResponse>> GetPageAsync(TenantPageRequest request)
|
||||
{
|
||||
return await _dbContext.Queryable<TenantEntity>()
|
||||
.WhereIF(request.Search.IsPresent(), (tenant) => tenant.Name.Contains(request.Search))
|
||||
.Select<TenantResponse>()
|
||||
.ToPageListAsync(request);
|
||||
.WhereIF(request.Search.IsPresent(), (tenant) => tenant.Name.Contains(request.Search))
|
||||
.Select<TenantResponse>()
|
||||
.ToPageListAsync(request);
|
||||
}
|
||||
|
||||
public async Task<List<TenantResponse>> GetListAsync()
|
||||
{
|
||||
return await _dbContext.Queryable<TenantEntity>()
|
||||
.Select<TenantResponse>()
|
||||
.ToListAsync();
|
||||
.Select<TenantResponse>()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<TenantResponse> GetTenantByCode(string code)
|
||||
@@ -73,16 +73,16 @@ public class TenantService : ITenantService
|
||||
var tenantId = _currentUser.GetStringTenantId();
|
||||
|
||||
var myTenants = await _dbContext.Queryable<UserTenantEntity>()
|
||||
.LeftJoin<TenantEntity>((ut, t) => ut.TenantCode == t.Code)
|
||||
.Where(ut => ut.UserId == userId)
|
||||
.Select((ut, t) => new TenantResponse
|
||||
{
|
||||
Id = t.Id,
|
||||
PCode = t.PCode,
|
||||
Code = t.Code,
|
||||
Name = t.Name,
|
||||
})
|
||||
.ToListAsync();
|
||||
.LeftJoin<TenantEntity>((ut, t) => ut.TenantCode == t.Code)
|
||||
.Where(ut => ut.UserId == userId)
|
||||
.Select((ut, t) => new TenantResponse
|
||||
{
|
||||
Id = t.Id,
|
||||
PCode = t.PCode,
|
||||
Code = t.Code,
|
||||
Name = t.Name,
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
var currentTenant = myTenants.FirstOrDefault(x => x.Code == tenantId);
|
||||
var otherTenants = myTenants.Where(x => x.Code != tenantId);
|
||||
@@ -100,17 +100,16 @@ public class TenantService : ITenantService
|
||||
public async Task<List<TenantTreeResponse>> GetTreeAsync()
|
||||
{
|
||||
var tenants = await _dbContext.Queryable<TenantEntity>()
|
||||
.Select<TenantTreeResponse>()
|
||||
.ToListAsync();
|
||||
.Select<TenantTreeResponse>()
|
||||
.ToListAsync();
|
||||
|
||||
var tops = tenants.Where(x => x.PCode.IsEmpty()).ToList();
|
||||
foreach (var item in tops)
|
||||
{
|
||||
RecursionGetNext(item, tenants);
|
||||
}
|
||||
tops.ForEach(item => RecursionGetNext(item, tenants));
|
||||
|
||||
return tops;
|
||||
}
|
||||
|
||||
//****************************************************************** help methods *****************************************************************************
|
||||
|
||||
private static void RecursionGetNext(TenantTreeResponse current, List<TenantTreeResponse> data)
|
||||
{
|
||||
@@ -121,4 +120,4 @@ public class TenantService : ITenantService
|
||||
RecursionGetNext(item, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,40 +3,49 @@ using Dlhis.Sys.Identity.Request;
|
||||
using Dlhis.Sys.Identity.Response;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Kurisu.Core.User.Abstractions;
|
||||
using Kurisu.SqlSugar.Extensions;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.Sys.Identity.Services.Implements;
|
||||
|
||||
public class UserService : IUserService
|
||||
{
|
||||
private readonly ICurrentUser _currentUser;
|
||||
private readonly IDbContext _dbContext;
|
||||
|
||||
public UserService(IDbContext dbContext)
|
||||
public UserService(IDbContext dbContext, ICurrentUser currentUser)
|
||||
{
|
||||
_currentUser = currentUser;
|
||||
_dbContext = dbContext.ChangeDb("identity");
|
||||
}
|
||||
|
||||
public async Task<Pagination<UserResponse>> GetPageAsync(UserPageRequest request)
|
||||
{
|
||||
var tenant = _currentUser.GetStringTenantId();
|
||||
|
||||
var page = 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")
|
||||
.LeftJoin<UserClaimEntity>((x, ur, r, c, cc) => x.Id == c.UserId && c.ClaimType == "tenant")
|
||||
.Where(x => x.UserName != "admin")
|
||||
.Where((x, ur, r, c, cc) => cc.ClaimValue == tenant)
|
||||
.WhereIF(request.IsOperator, (x, ur, r, c) => !SqlFunc.IsNullOrEmpty(r.Name))
|
||||
.WhereIF(!request.IsOperator, (x, ur, r, c) => SqlFunc.IsNullOrEmpty(r.Name))
|
||||
.WhereIF(request.Search.IsPresent(), (x, ur, r, c) => x.UserName == request.Search
|
||||
|| x.Email == request.Search
|
||||
|| x.PhoneNumber == request.Search
|
||||
|| c.ClaimValue == request.Search
|
||||
|| x.Email == request.Search
|
||||
|| x.PhoneNumber == request.Search
|
||||
|| c.ClaimValue == request.Search
|
||||
)
|
||||
.Select((x, ur, r, c) => new UserResponse
|
||||
.Select((x, ur, r, c, cc) => new UserResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
RoleId = ur.RoleId,
|
||||
Role = r.Name,
|
||||
OperatorName = c.ClaimValue,
|
||||
|
||||
}, true)
|
||||
.ToPageListAsync(request);
|
||||
|
||||
@@ -74,7 +83,6 @@ public class UserService : IUserService
|
||||
RoleId = ur.RoleId,
|
||||
Role = r.Name,
|
||||
OperatorName = c.ClaimValue,
|
||||
|
||||
}, true)
|
||||
.FirstAsync();
|
||||
|
||||
@@ -124,4 +132,4 @@ public class UserService : IUserService
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,10 +31,9 @@ public class UserTenantService : IUserTenantService
|
||||
await _dbContext.DeleteReallyAsync(userTenants);
|
||||
|
||||
await _dbContext.InsertAsync(request.TenantCodes.Select(x => new UserTenantEntity
|
||||
{
|
||||
UserId = request.UserId,
|
||||
TenantCode = x
|
||||
})
|
||||
.ToList());
|
||||
{
|
||||
UserId = request.UserId,
|
||||
TenantCode = x
|
||||
}).ToList());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user