feat 用户基地配置
This commit is contained in:
42
Src/Dlhis.Sys/Identity/Controllers/UserTenantsController.cs
Normal file
42
Src/Dlhis.Sys/Identity/Controllers/UserTenantsController.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using Dlhis.Sys.Identity.Request;
|
||||||
|
using Dlhis.Sys.Identity.Response;
|
||||||
|
using Dlhis.Sys.Identity.Services;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace Dlhis.Sys.Identity.Controllers;
|
||||||
|
|
||||||
|
[Authorize(Roles = "admin")]
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
[ApiController]
|
||||||
|
public class UserTenantsController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly IUserTenantService _userTenantService;
|
||||||
|
|
||||||
|
public UserTenantsController(IUserTenantService userTenantService)
|
||||||
|
{
|
||||||
|
_userTenantService = userTenantService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取用户的基地配置
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<List<UserTenantResponse>> GetUserTenantsByIdAsync(int userId)
|
||||||
|
{
|
||||||
|
return await _userTenantService.GetUserTenantsByIdAsync(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 保存
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
[HttpPost("save")]
|
||||||
|
public async Task SaveUserTenantsAsync(UserTenantSaveRequest request)
|
||||||
|
{
|
||||||
|
await _userTenantService.SaveUserTenantsAsync(request);
|
||||||
|
}
|
||||||
|
}
|
||||||
9
Src/Dlhis.Sys/Identity/Request/UserTenantSaveRequest.cs
Normal file
9
Src/Dlhis.Sys/Identity/Request/UserTenantSaveRequest.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
namespace Dlhis.Sys.Identity.Request
|
||||||
|
{
|
||||||
|
public class UserTenantSaveRequest
|
||||||
|
{
|
||||||
|
public int UserId { get; set; }
|
||||||
|
|
||||||
|
public List<string> TenantCodes { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
||||||
6
Src/Dlhis.Sys/Identity/Response/UserTenantResponse.cs
Normal file
6
Src/Dlhis.Sys/Identity/Response/UserTenantResponse.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Dlhis.Sys.Identity.Response;
|
||||||
|
|
||||||
|
public class UserTenantResponse
|
||||||
|
{
|
||||||
|
public string Code { get; set; }
|
||||||
|
}
|
||||||
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