feat 基地/租户tree
This commit is contained in:
@@ -10,6 +10,8 @@ public interface ITenantService : IScopeDependency
|
||||
|
||||
Task<List<TenantResponse>> GetListAsync();
|
||||
|
||||
Task<List<TenantTreeResponse>> GetTreeAsync();
|
||||
|
||||
Task<TenantResponse> GetTenantByCode(string code);
|
||||
|
||||
Task<List<TenantResponse>> GetMyTenantsAsync();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Dlhis.Entity.Sys.Entities;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Sys.Entities;
|
||||
using Dlhis.Sys.Identity.Request;
|
||||
using Dlhis.Sys.Identity.Response;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
@@ -14,11 +15,9 @@ public class TenantService : ITenantService
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
|
||||
public TenantService(IDbContext dbContext, IConfiguration configuration, ICurrentUser currentUser)
|
||||
public TenantService(IDbContext dbContext, ICurrentUser currentUser)
|
||||
{
|
||||
var identityConnection = configuration.GetSection("SqlSugarOptions:IdentityConnectionString").Value;
|
||||
dbContext.Client.CurrentConnectionConfig.ConnectionString = identityConnection;
|
||||
_dbContext = dbContext;
|
||||
_dbContext = dbContext.ChangeDb("identity");
|
||||
_currentUser = currentUser;
|
||||
}
|
||||
|
||||
@@ -52,6 +51,7 @@ public class TenantService : ITenantService
|
||||
{
|
||||
await _dbContext.InsertAsync(new TenantEntity
|
||||
{
|
||||
PCode = request.PCode,
|
||||
Code = request.Code,
|
||||
Name = request.Name,
|
||||
});
|
||||
@@ -89,4 +89,29 @@ public class TenantService : ITenantService
|
||||
|
||||
return myTenants;
|
||||
}
|
||||
|
||||
public async Task<List<TenantTreeResponse>> GetTreeAsync()
|
||||
{
|
||||
var tenants = await _dbContext.Queryable<TenantEntity>()
|
||||
.Select<TenantTreeResponse>()
|
||||
.ToListAsync();
|
||||
|
||||
var tops = tenants.Where(x => x.PCode.IsEmpty()).ToList();
|
||||
foreach (var item in tops)
|
||||
{
|
||||
RecursionGetNext(item, tenants);
|
||||
}
|
||||
return tops;
|
||||
}
|
||||
|
||||
|
||||
private void RecursionGetNext(TenantTreeResponse current, List<TenantTreeResponse> data)
|
||||
{
|
||||
var next = data.Where(x => x.PCode == current.Code).ToList();
|
||||
current.Next = next;
|
||||
foreach (var item in next)
|
||||
{
|
||||
RecursionGetNext(item, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user