feat 用户基地配置
This commit is contained in:
11
Src/Dlhis.Sys/Identity/Services/IUserTenantService.cs
Normal file
11
Src/Dlhis.Sys/Identity/Services/IUserTenantService.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Dlhis.Sys.Identity.Request;
|
||||
using Dlhis.Sys.Identity.Response;
|
||||
|
||||
namespace Dlhis.Sys.Identity.Services;
|
||||
|
||||
public interface IUserTenantService : IScopeDependency
|
||||
{
|
||||
Task<List<UserTenantResponse>> GetUserTenantsByIdAsync(int id);
|
||||
|
||||
Task SaveUserTenantsAsync(UserTenantSaveRequest request);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using Dlhis.Entity.Sys.Entities;
|
||||
using Dlhis.Sys.Identity.Request;
|
||||
using Dlhis.Sys.Identity.Response;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
|
||||
namespace Dlhis.Sys.Identity.Services.Implements;
|
||||
|
||||
public class UserTenantService : IUserTenantService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
|
||||
public UserTenantService(IDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext.ChangeDb("identity");
|
||||
}
|
||||
|
||||
public async Task<List<UserTenantResponse>> GetUserTenantsByIdAsync(int id)
|
||||
{
|
||||
return await _dbContext.Queryable<UserTenantEntity>()
|
||||
.Where(x => x.UserId == id)
|
||||
.Select(x => new UserTenantResponse
|
||||
{
|
||||
Code = x.TenantCode
|
||||
})
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task SaveUserTenantsAsync(UserTenantSaveRequest request)
|
||||
{
|
||||
var userTenants = await _dbContext.Queryable<UserTenantEntity>().Where(x => x.UserId == request.UserId).ToListAsync();
|
||||
await _dbContext.DeleteReallyAsync(userTenants);
|
||||
|
||||
await _dbContext.InsertAsync(request.TenantCodes.Select(x => new UserTenantEntity
|
||||
{
|
||||
UserId = request.UserId,
|
||||
TenantCode = x
|
||||
})
|
||||
.ToList());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user