From 6872518b65cf95f40759ab8daa2e0f3efb1070ad Mon Sep 17 00:00:00 2001 From: liguoyang Date: Sun, 17 Mar 2024 20:58:11 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E5=A4=84=E7=90=86next=E7=A9=BA=E6=95=B0?= =?UTF-8?q?=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Response/DepartmentTreeResponse.cs | 13 +++++++++---- .../Services/Implements/DepartmentService.cs | 15 ++++++++++----- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Src/Dlhis.Basic/Organization/Response/DepartmentTreeResponse.cs b/Src/Dlhis.Basic/Organization/Response/DepartmentTreeResponse.cs index 88aba019..b7cfe8fe 100644 --- a/Src/Dlhis.Basic/Organization/Response/DepartmentTreeResponse.cs +++ b/Src/Dlhis.Basic/Organization/Response/DepartmentTreeResponse.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using Kurisu.AspNetCore.Utils.Extensions; +using Newtonsoft.Json; namespace Dlhis.Basic.Organization.Response; @@ -26,7 +27,7 @@ public class DepartmentTreeResponse /// 下级部门 /// [JsonIgnore] - public List _Next { get; set; } = new List(); + public List CurrentNext { get; set; } /// /// 下级部门 @@ -35,8 +36,12 @@ public class DepartmentTreeResponse { get { - _Next.ForEach(x => x.Tenant = Tenant); - return _Next; + if (CurrentNext.IsPresent()) + { + CurrentNext.ForEach(x => x.Tenant = Tenant); + } + + return CurrentNext; } } } diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/DepartmentService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/DepartmentService.cs index a7cfd72d..8a8a510b 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/DepartmentService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/DepartmentService.cs @@ -37,7 +37,7 @@ public class DepartmentService : IDepartmentService No = x.Code, PNo = null, Tenant = x.Code, - _Next = tops.Select(item => + CurrentNext = tops.Select(item => { var i = item.Adapt(); i.PNo = x.Code; @@ -48,13 +48,18 @@ public class DepartmentService : IDepartmentService .ToList(); } - private void RecursionGetNext(DepartmentTreeResponse current, List data) + //***************************************************** help methods **************************************************************** + + private static void RecursionGetNext(DepartmentTreeResponse current, List data) { var next = data.Where(x => x.PNo == current.No).ToList(); - current._Next = next; - foreach (var item in next) + if (next.Any()) { - RecursionGetNext(item, data); + current.CurrentNext = next; + foreach (var item in next) + { + RecursionGetNext(item, data); + } } } }