AlarmDFS.java
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.skua.modules.entity;
import com.alibaba.fastjson.JSONObject;
import com.skua.modules.vo.AlarmVO;
import com.skua.tool.util.BeanExtUtils;
import org.apache.commons.lang.StringUtils;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
/**
* <pre>
* <请输入描述信息>
* </pre>
*
* @author sonin
* @version 1.0 2023/4/10 10:17
*/
public class AlarmDFS {
private LinkedList<LinkedList<Alarm>> routeList = new LinkedList<>();
private void backtrack(List<AlarmVO> tree, LinkedList<AlarmVO> track) {
if (!track.isEmpty() && track.getLast().getChildren().isEmpty()) {
List<Alarm> route;
try {
route = BeanExtUtils.beans2Beans(track, Alarm.class);
} catch (Exception e) {
route = new ArrayList<>();
}
routeList.add(new LinkedList<>(route));
}
for (AlarmVO alarmVO : tree) {
track.addLast(alarmVO);
backtrack(alarmVO.getChildren(), track);
track.removeLast();
}
}
public List<AlarmVO> buildTree(List<Alarm> equipCategoryList) {
List<AlarmVO> tree = new ArrayList<>();
List<AlarmVO> alarmVOList;
try {
alarmVOList = BeanExtUtils.beans2Beans(equipCategoryList, AlarmVO.class);
} catch (Exception e) {
alarmVOList = new ArrayList<>();
}
for (AlarmVO k : alarmVOList) {
for (AlarmVO v : alarmVOList) {
if (k.getId().equals(v.getParentId())) {
k.getChildren().add(v);
}
}
// 先按照departOrder排序,再按照departName排序
k.getChildren().sort((o1, o2) -> {
if (o1.getDepartOrder() == null || o2.getDepartOrder() == null) {
return o1.getDepartName().compareTo(o2.getDepartName());
} else {
if (o1.getDepartOrder().equals(o2.getDepartOrder())) {
return o1.getDepartName().compareTo(o2.getDepartName());
} else {
return o1.getDepartOrder().compareTo(o2.getDepartOrder());
}
}
});
// 提取出父节点
if (StringUtils.isBlank(k.getParentId()) || "0".equals(k.getParentId()) || "root".equals(k.getParentId())) {
tree.add(k);
}
}
return tree;
}
}