forked from integrated_whb/integrated_whb
电子围栏树结构适配
parent
e358657730
commit
5e1f9ad7dc
|
@ -53,10 +53,10 @@ public class ElectronicFenceServiceImpl implements ElectronicFenceService {
|
||||||
if ("children".equals(pd.getString("childKey"))) {
|
if ("children".equals(pd.getString("childKey"))) {
|
||||||
// 手机端
|
// 手机端
|
||||||
List<Map<String, Object>> dataList = electronicFenceMapper.listTreeApp(pd);
|
List<Map<String, Object>> dataList = electronicFenceMapper.listTreeApp(pd);
|
||||||
return buildTree(dataList, pd.getString("childKey"));
|
return buildTreeApp(dataList);
|
||||||
}
|
}
|
||||||
List<Map<String, Object>> dataList = electronicFenceMapper.listTree(pd);
|
List<Map<String, Object>> dataList = electronicFenceMapper.listTree(pd);
|
||||||
return buildTree(dataList, pd.getString("childKey"));
|
return buildTree(dataList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -64,7 +64,7 @@ public class ElectronicFenceServiceImpl implements ElectronicFenceService {
|
||||||
return electronicFenceMapper.findByPId(pd).size() > 0 ;
|
return electronicFenceMapper.findByPId(pd).size() > 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Map<String, Object>> buildTree(List<Map<String, Object>> dataList,String key) {
|
public static List<Map<String, Object>> buildTree(List<Map<String, Object>> dataList) {
|
||||||
Map<String, Map<String, Object>> idToNodeMap = new HashMap<>();
|
Map<String, Map<String, Object>> idToNodeMap = new HashMap<>();
|
||||||
List<Map<String, Object>> rootNodes = new ArrayList<>();
|
List<Map<String, Object>> rootNodes = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -83,9 +83,37 @@ public class ElectronicFenceServiceImpl implements ElectronicFenceService {
|
||||||
} else {
|
} else {
|
||||||
Map<String, Object> parentNode = idToNodeMap.get(pId);
|
Map<String, Object> parentNode = idToNodeMap.get(pId);
|
||||||
if (parentNode != null) {
|
if (parentNode != null) {
|
||||||
List<Map<String, Object>> children = (List<Map<String, Object>>) parentNode.getOrDefault(key, new ArrayList<>());
|
List<Map<String, Object>> children = (List<Map<String, Object>>) parentNode.getOrDefault("nodes", new ArrayList<>());
|
||||||
children.add(node);
|
children.add(node);
|
||||||
parentNode.put(key, children);
|
parentNode.put("nodes", children);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rootNodes;
|
||||||
|
}
|
||||||
|
public static List<Map<String, Object>> buildTreeApp(List<Map<String, Object>> dataList) {
|
||||||
|
Map<String, Map<String, Object>> idToNodeMap = new HashMap<>();
|
||||||
|
List<Map<String, Object>> rootNodes = new ArrayList<>();
|
||||||
|
|
||||||
|
// Map IDs to their nodes
|
||||||
|
for (Map<String, Object> data : dataList) {
|
||||||
|
String id = (String) data.get("ELECTRONIC_FENCE_AREA_ID");
|
||||||
|
idToNodeMap.put(id, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find root nodes and attach children
|
||||||
|
for (Map.Entry<String, Map<String, Object>> entry : idToNodeMap.entrySet()) {
|
||||||
|
Map<String, Object> node = entry.getValue();
|
||||||
|
String pId = (String) node.get("pId");
|
||||||
|
if ("0".equals(pId)) {
|
||||||
|
rootNodes.add(node);
|
||||||
|
} else {
|
||||||
|
Map<String, Object> parentNode = idToNodeMap.get(pId);
|
||||||
|
if (parentNode != null) {
|
||||||
|
List<Map<String, Object>> children = (List<Map<String, Object>>) parentNode.getOrDefault("children", new ArrayList<>());
|
||||||
|
children.add(node);
|
||||||
|
parentNode.put("children", children);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue