FindEmergencyChildrenUtil.java
5.0 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package com.skua.modules.emergency.util;
import com.skua.core.util.ConvertUtils;
import com.skua.modules.emergency.entity.EmergencyCommandLiaison;
import com.skua.modules.emergency.model.EmergencyCommandLiaisonIdModel;
import com.skua.modules.emergency.model.EmergencyCommandLiaisonTreeModel;
import com.skua.modules.emergency.service.IEmergencyCommandLiaisonUserService;
import com.skua.modules.emergency.vo.EmergencyCommandLiaisonVO;
import com.skua.modules.system.entity.SysDepart;
import com.skua.modules.system.entity.SysUser;
import com.skua.modules.system.model.DepartIdModel;
import com.skua.modules.system.model.SysDepartTreeModel;
import com.skua.modules.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.List;
/**
* 对应应急的表,处理并查找树级数据
* @author 11389
*/
public class FindEmergencyChildrenUtil {
/**
* queryTreeList的子方法 ====1=====
* 该方法是将EmergencyCommandLiaison类型的list集合转换成EmergencyCommandLiaisonTreeModel类型的集合
*/
public static List<EmergencyCommandLiaisonTreeModel> wrapTreeDataToTreeList(List<EmergencyCommandLiaisonVO> recordList) {
List<EmergencyCommandLiaisonIdModel> idList = new ArrayList<EmergencyCommandLiaisonIdModel>();
List<EmergencyCommandLiaisonTreeModel> records = new ArrayList<>();
for (int i = 0; i < recordList.size(); i++) {
EmergencyCommandLiaisonVO emergencyCommandLiaisonVO = recordList.get(i);
records.add(new EmergencyCommandLiaisonTreeModel(emergencyCommandLiaisonVO));
}
List<EmergencyCommandLiaisonTreeModel> tree = findChildren(records, idList);
setEmptyChildrenAsNull(tree);
return tree;
}
/**
* 获取 DepartIdModel
* @param recordList
* @return
*/
public List<EmergencyCommandLiaisonIdModel> wrapTreeDataToDepartIdTreeList(List<EmergencyCommandLiaisonVO> recordList) {
List<EmergencyCommandLiaisonIdModel> idList = new ArrayList<>();
List<EmergencyCommandLiaisonTreeModel> records = new ArrayList<>();
for (int i = 0; i < recordList.size(); i++) {
EmergencyCommandLiaisonVO emergencyCommandLiaison = recordList.get(i);
records.add(new EmergencyCommandLiaisonTreeModel(emergencyCommandLiaison));
}
findChildren(records, idList);
return idList;
}
/**
* queryTreeList的子方法 ====2=====
* 该方法是找到并封装顶级父类的节点到TreeList集合
*/
private static List<EmergencyCommandLiaisonTreeModel> findChildren(List<EmergencyCommandLiaisonTreeModel> recordList,
List<EmergencyCommandLiaisonIdModel> idModelList) {
List<EmergencyCommandLiaisonTreeModel> treeList = new ArrayList<>();
for (int i = 0; i < recordList.size(); i++) {
EmergencyCommandLiaisonTreeModel branch = recordList.get(i);
if (ConvertUtils.isEmpty(branch.getParentId())) {
treeList.add(branch);
EmergencyCommandLiaisonIdModel idModel = new EmergencyCommandLiaisonIdModel().convert(branch);
idModelList.add(idModel);
}
}
getGrandChildren(treeList,recordList,idModelList);
return treeList;
}
/**
* queryTreeList的子方法====3====
*该方法是找到顶级父类下的所有子节点集合并封装到TreeList集合
*/
private static void getGrandChildren(List<EmergencyCommandLiaisonTreeModel> treeList,List<EmergencyCommandLiaisonTreeModel> recordList,List<EmergencyCommandLiaisonIdModel> idList) {
for (int i = 0; i < treeList.size(); i++) {
EmergencyCommandLiaisonTreeModel model = treeList.get(i);
EmergencyCommandLiaisonIdModel idModel = idList.get(i);
for (int i1 = 0; i1 < recordList.size(); i1++) {
EmergencyCommandLiaisonTreeModel m = recordList.get(i1);
if (m.getParentId()!=null && m.getParentId().equals(model.getId())) {
model.getChildren().add(m);
EmergencyCommandLiaisonIdModel dim = new EmergencyCommandLiaisonIdModel().convert(m);
idModel.getChildren().add(dim);
}
}
getGrandChildren(treeList.get(i).getChildren(), recordList, idList.get(i).getChildren());
}
}
/**
* queryTreeList的子方法 ====4====
* 该方法是将子节点为空的List集合设置为Null值
*/
private static void setEmptyChildrenAsNull(List<EmergencyCommandLiaisonTreeModel> treeList) {
for (int i = 0; i < treeList.size(); i++) {
EmergencyCommandLiaisonTreeModel model = treeList.get(i);
if (model.getChildren().size() == 0) {
model.setChildren(null);
model.setLeaf(true);
}else{
setEmptyChildrenAsNull(model.getChildren());
model.setLeaf(false);
}
}
}
}