fix 部门数移除厂区节点

This commit is contained in:
2024-06-09 02:44:23 +08:00
parent f1bf86ec0c
commit 452192d36e
2 changed files with 19 additions and 47 deletions

View File

@@ -1,20 +1,16 @@
using Dlhis.Basic.Organization.Response;
using Dlhis.Entity.Basic.Entity;
using Dlhis.Sys.Api;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
using Mapster;
namespace Dlhis.Basic.Organization.Services.Implements;
public class DepartmentService : IDepartmentService
{
private readonly IDbContext _dbContext;
private readonly ITenantApi _tenantApi;
public DepartmentService(IDbContext dbContext, ITenantApi tenantApi)
public DepartmentService(IDbContext dbContext)
{
_dbContext = dbContext;
_tenantApi = tenantApi;
}
public async Task<List<DepartmentTreeResponse>> GetTreeAsync()
@@ -23,29 +19,8 @@ public class DepartmentService : IDepartmentService
//00001000 一定是这个开头的
var tops = departments.Where(x => x.PNo == "00001000").ToList();
tops.ForEach(x =>
{
RecursionGetNext(x, departments);
});
var myTenantResult = await _tenantApi.GetMyTenantsAsync();
var tenants = myTenantResult.Data;
return tenants.Select(x => new DepartmentTreeResponse
{
Name = x.Name,
No = x.Code,
PNo = null,
Tenant = x.Code,
CurrentNext = tops.Select(item =>
{
var i = item.Adapt<DepartmentTreeResponse>();
i.PNo = x.Code;
return i;
}).ToList()
})
.ToList();
tops.ForEach(x => { RecursionGetNext(x, departments); });
return tops;
}
//***************************************************** help methods ****************************************************************
@@ -53,13 +28,10 @@ public class DepartmentService : IDepartmentService
private static void RecursionGetNext(DepartmentTreeResponse current, List<DepartmentTreeResponse> data)
{
var next = data.Where(x => x.PNo == current.No).ToList();
if (next.Any())
current.CurrentNext = next;
foreach (var item in next)
{
current.CurrentNext = next;
foreach (var item in next)
{
RecursionGetNext(item, data);
}
RecursionGetNext(item, data);
}
}
}
}

View File

@@ -59,17 +59,17 @@ public class SqlSugarPack : BaseAppPack
return;
}
using var scope = app.ApplicationServices.CreateScope();
var db = scope.ServiceProvider.GetService<IDbContext>();
var tables = App.ActiveTypes.Where(x => x.IsDefined(typeof(SugarTable), false))
.Where(x => !x.IsDefined(typeof(SkipScanAttribute), false))
.ToArray();
db.Client.DbMaintenance.CreateDatabase();
db.Client.CodeFirst.InitTables(tables);
var faceDb = db.ChangeDb("face");
faceDb.Client.DbMaintenance.CreateDatabase();
faceDb.Client.CodeFirst.InitTables<GainfoFaceEntity>();
// using var scope = app.ApplicationServices.CreateScope();
// var db = scope.ServiceProvider.GetService<IDbContext>();
// var tables = App.ActiveTypes.Where(x => x.IsDefined(typeof(SugarTable), false))
// .Where(x => !x.IsDefined(typeof(SkipScanAttribute), false))
// .ToArray();
//
// db.Client.DbMaintenance.CreateDatabase();
// db.Client.CodeFirst.InitTables(tables);
//
// var faceDb = db.ChangeDb("face");
// faceDb.Client.DbMaintenance.CreateDatabase();
// faceDb.Client.CodeFirst.InitTables<GainfoFaceEntity>();
}
}