From 63ff90c79bfb1fa995f7c26dde86e08ca4c77fcd Mon Sep 17 00:00:00 2001 From: dearlin <1261008090@qq.com> Date: Tue, 30 Jan 2024 16:27:19 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=B5=E5=AD=90=E5=9B=B4=E6=A0=8F=E6=A0=91?= =?UTF-8?q?=E7=BB=93=E6=9E=84=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/AppElectronicFenceController.java | 1 + .../ElectronicFenceController.java | 1 + .../impl/ElectronicFenceServiceImpl.java | 28 +++---------------- 3 files changed, 6 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/zcloud/controller/app/AppElectronicFenceController.java b/src/main/java/com/zcloud/controller/app/AppElectronicFenceController.java index 64edd41..5b91ceb 100644 --- a/src/main/java/com/zcloud/controller/app/AppElectronicFenceController.java +++ b/src/main/java/com/zcloud/controller/app/AppElectronicFenceController.java @@ -33,6 +33,7 @@ public class AppElectronicFenceController extends BaseController { @ResponseBody public Object listTree() { PageData pd = this.getPageData(); + pd.put("childKey", "children"); return ReturnMap.ok().put("zTreeNodes", JSON.toJSONString(electronicFenceService.listTree(pd))); } } diff --git a/src/main/java/com/zcloud/controller/electronicFence/ElectronicFenceController.java b/src/main/java/com/zcloud/controller/electronicFence/ElectronicFenceController.java index a8ddb80..6a216d6 100644 --- a/src/main/java/com/zcloud/controller/electronicFence/ElectronicFenceController.java +++ b/src/main/java/com/zcloud/controller/electronicFence/ElectronicFenceController.java @@ -62,6 +62,7 @@ public class ElectronicFenceController extends BaseController { String KEYWORDS = pd.getString("KEYWORDS"); //关键词检索条件 if (Tools.notEmpty(KEYWORDS)) pd.put("KEYWORDS", KEYWORDS.trim()); pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); + pd.put("childKey", "nodes"); return ReturnMap.ok().put("zTreeNodes", JSON.toJSONString(electronicFenceService.listTree(pd))); } diff --git a/src/main/java/com/zcloud/service/electronicFence/impl/ElectronicFenceServiceImpl.java b/src/main/java/com/zcloud/service/electronicFence/impl/ElectronicFenceServiceImpl.java index 0c5e728..a905dd4 100644 --- a/src/main/java/com/zcloud/service/electronicFence/impl/ElectronicFenceServiceImpl.java +++ b/src/main/java/com/zcloud/service/electronicFence/impl/ElectronicFenceServiceImpl.java @@ -51,7 +51,7 @@ public class ElectronicFenceServiceImpl implements ElectronicFenceService { @Override public List> listTree(PageData pd) { List> dataList = electronicFenceMapper.listTree(pd); - return buildTree(dataList); + return buildTree(dataList, pd.getString("childKey")); } @Override @@ -59,27 +59,7 @@ public class ElectronicFenceServiceImpl implements ElectronicFenceService { return electronicFenceMapper.findByPId(pd).size() > 0 ; } - public static void main(String[] args) { - List> dataList = new ArrayList<>(); - HashMap d1 = new HashMap(); - d1.put("id","96acf1a16df646dda03592af042f3abc"); - d1.put("name","卓云企业"); - d1.put("pId","0"); - d1.put("ELECTRONIC_FENCE_ID","1"); - d1.put("ELECTRONIC_FENCE_NAME","电子围栏1"); - HashMap d2 = new HashMap(); - d2.put("id","e16f4020df5145bd8ada827ec1bf310f"); - d2.put("name","开发部"); - d2.put("pId","96acf1a16df646dda03592af042f3abc"); - d2.put("ELECTRONIC_FENCE_ID","2"); - d2.put("ELECTRONIC_FENCE_NAME","电子围栏2"); - dataList.add(d1); - dataList.add(d2); - List> maps = buildTree(dataList); - System.out.println(maps); - } - - public static List> buildTree(List> dataList) { + public static List> buildTree(List> dataList,String key) { Map> idToNodeMap = new HashMap<>(); List> rootNodes = new ArrayList<>(); @@ -98,9 +78,9 @@ public class ElectronicFenceServiceImpl implements ElectronicFenceService { } else { Map parentNode = idToNodeMap.get(pId); if (parentNode != null) { - List> children = (List>) parentNode.getOrDefault("nodes", new ArrayList<>()); + List> children = (List>) parentNode.getOrDefault(key, new ArrayList<>()); children.add(node); - parentNode.put("nodes", children); + parentNode.put(key, children); } } }