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); } } }