forked from integrated_whb/integrated_whb
电子围栏树结构适配
parent
8cf8ac2c1d
commit
63ff90c79b
|
@ -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)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)));
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ public class ElectronicFenceServiceImpl implements ElectronicFenceService {
|
|||
@Override
|
||||
public List<Map<String, Object>> listTree(PageData pd) {
|
||||
List<Map<String, Object>> 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<Map<String,Object>> dataList = new ArrayList<>();
|
||||
HashMap<String,Object> 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<String,Object> 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<Map<String, Object>> maps = buildTree(dataList);
|
||||
System.out.println(maps);
|
||||
}
|
||||
|
||||
public static List<Map<String, Object>> buildTree(List<Map<String, Object>> dataList) {
|
||||
public static List<Map<String, Object>> buildTree(List<Map<String, Object>> dataList,String key) {
|
||||
Map<String, Map<String, Object>> idToNodeMap = new HashMap<>();
|
||||
List<Map<String, Object>> rootNodes = new ArrayList<>();
|
||||
|
||||
|
@ -98,9 +78,9 @@ public class ElectronicFenceServiceImpl implements ElectronicFenceService {
|
|||
} else {
|
||||
Map<String, Object> parentNode = idToNodeMap.get(pId);
|
||||
if (parentNode != null) {
|
||||
List<Map<String, Object>> children = (List<Map<String, Object>>) parentNode.getOrDefault("nodes", new ArrayList<>());
|
||||
List<Map<String, Object>> children = (List<Map<String, Object>>) parentNode.getOrDefault(key, new ArrayList<>());
|
||||
children.add(node);
|
||||
parentNode.put("nodes", children);
|
||||
parentNode.put(key, children);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue