fix 功能调整

This commit is contained in:
2024-02-01 17:46:40 +08:00
parent 2f5f6be7d7
commit 28871aa450
23 changed files with 164 additions and 59 deletions

View File

@@ -61,4 +61,13 @@ public class TenantsController : ControllerBase
return await _tenantService.GetTenantByCode(code);
}
/// <summary>
/// 获取我的管理租户
/// </summary>
/// <returns></returns>
[HttpGet("my")]
public async Task<List<TenantResponse>> GetMyTenants()
{
return await _tenantService.GetMyTenantsAsync();
}
}

View File

@@ -11,4 +11,6 @@ public interface ITenantService : IScopeDependency
Task<List<TenantResponse>> GetListAsync();
Task<TenantResponse> GetTenantByCode(string code);
Task<List<TenantResponse>> GetMyTenantsAsync();
}

View File

@@ -3,6 +3,7 @@ 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;
@@ -11,12 +12,14 @@ namespace Dlhis.Sys.Identity.Services.Implements;
public class TenantService : ITenantService
{
private readonly IDbContext _dbContext;
private readonly ICurrentUser _currentUser;
public TenantService(IDbContext dbContext, IConfiguration configuration)
public TenantService(IDbContext dbContext, IConfiguration configuration, ICurrentUser currentUser)
{
var identityConnection = configuration.GetSection("SqlSugarOptions:IdentityConnectionString").Value;
dbContext.Client.CurrentConnectionConfig.ConnectionString = identityConnection;
_dbContext = dbContext;
_currentUser = currentUser;
}
public async Task<Pagination<TenantResponse>> GetPageAsync(TenantPageRequest request)
@@ -41,4 +44,26 @@ public class TenantService : ITenantService
.Select<TenantResponse>()
.FirstAsync();
}
public async Task<List<TenantResponse>> GetMyTenantsAsync()
{
var userId = _currentUser.GetIntSubjectId();
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,
Code = t.Code,
Name = t.Name,
})
.ToListAsync();
if (myTenants.IsEmpty())
{
myTenants = await GetListAsync();
}
return myTenants;
}
}