fix 处理next空数组
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace Dlhis.Basic.Organization.Response;
|
namespace Dlhis.Basic.Organization.Response;
|
||||||
|
|
||||||
@@ -26,7 +27,7 @@ public class DepartmentTreeResponse
|
|||||||
/// 下级部门
|
/// 下级部门
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public List<DepartmentTreeResponse> _Next { get; set; } = new List<DepartmentTreeResponse>();
|
public List<DepartmentTreeResponse> CurrentNext { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 下级部门
|
/// 下级部门
|
||||||
@@ -35,8 +36,12 @@ public class DepartmentTreeResponse
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
_Next.ForEach(x => x.Tenant = Tenant);
|
if (CurrentNext.IsPresent())
|
||||||
return _Next;
|
{
|
||||||
|
CurrentNext.ForEach(x => x.Tenant = Tenant);
|
||||||
|
}
|
||||||
|
|
||||||
|
return CurrentNext;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class DepartmentService : IDepartmentService
|
|||||||
No = x.Code,
|
No = x.Code,
|
||||||
PNo = null,
|
PNo = null,
|
||||||
Tenant = x.Code,
|
Tenant = x.Code,
|
||||||
_Next = tops.Select(item =>
|
CurrentNext = tops.Select(item =>
|
||||||
{
|
{
|
||||||
var i = item.Adapt<DepartmentTreeResponse>();
|
var i = item.Adapt<DepartmentTreeResponse>();
|
||||||
i.PNo = x.Code;
|
i.PNo = x.Code;
|
||||||
@@ -48,13 +48,18 @@ public class DepartmentService : IDepartmentService
|
|||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RecursionGetNext(DepartmentTreeResponse current, List<DepartmentTreeResponse> data)
|
//***************************************************** help methods ****************************************************************
|
||||||
|
|
||||||
|
private static void RecursionGetNext(DepartmentTreeResponse current, List<DepartmentTreeResponse> data)
|
||||||
{
|
{
|
||||||
var next = data.Where(x => x.PNo == current.No).ToList();
|
var next = data.Where(x => x.PNo == current.No).ToList();
|
||||||
current._Next = next;
|
if (next.Any())
|
||||||
foreach (var item in next)
|
|
||||||
{
|
{
|
||||||
RecursionGetNext(item, data);
|
current.CurrentNext = next;
|
||||||
|
foreach (var item in next)
|
||||||
|
{
|
||||||
|
RecursionGetNext(item, data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user