FindsChildrenUtil.java
4.5 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
package com.skua.modules.assessment.utils;
import com.skua.core.util.ConvertUtils;
import com.skua.modules.assessment.model.DataAssessmentItemIdModel;
import com.skua.modules.assessment.model.DataAssessmentItemTreeModel;
import com.skua.modules.assessment.vo.DataAssessmentItemVO;
import java.util.ArrayList;
import java.util.List;
/**
* 查找对应评分项的表,处理并查找树级数据
*
* @author 11389
*/
public class FindsChildrenUtil {
/**
* queryTreeList的子方法 ====1=====
* 该方法是s将SysDepart类型的list集合转换成SysDepartTreeModel类型的集合
*/
public static List<DataAssessmentItemTreeModel> wrapTreeDataToTreeList(List<DataAssessmentItemVO> recordList) {
// 在该方法每请求一次,都要对全局list集合进行一次清理
List<DataAssessmentItemIdModel> idList = new ArrayList<>();
List<DataAssessmentItemTreeModel> records = new ArrayList<>();
for (int i = 0; i < recordList.size(); i++) {
DataAssessmentItemVO dataAssessmentItem = recordList.get(i);
records.add(new DataAssessmentItemTreeModel(dataAssessmentItem));
}
List<DataAssessmentItemTreeModel> tree = findChildren(records, idList);
setEmptyChildrenAsNull(tree);
return tree;
}
// /**
// * 获取 DepartIdModel
// *
// * @param recordList
// * @return
// */
// public static List<DataAssessmentItemIdModel> wrapTreeDataToDepartIdTreeList(List<DataAssessmentItem> recordList) {
// // 在该方法每请求一次,都要对全局list集合进行一次清理
// List<DataAssessmentItemIdModel> idList = new ArrayList<>();
// List<DataAssessmentItemTreeModel> records = new ArrayList<>();
// for (int i = 0; i < recordList.size(); i++) {
// DataAssessmentItem item = recordList.get(i);
// records.add(new DataAssessmentItemTreeModel(item));
// }
// findChildren(records, idList);
// return idList;
// }
/**
* queryTreeList的子方法 ====2=====
* 该方法是找到并封装顶级父类的节点到TreeList集合
*/
private static List<DataAssessmentItemTreeModel> findChildren(List<DataAssessmentItemTreeModel> recordList,
List<DataAssessmentItemIdModel> itemIdModels) {
List<DataAssessmentItemTreeModel> treeList = new ArrayList<>();
for (int i = 0; i < recordList.size(); i++) {
DataAssessmentItemTreeModel branch = recordList.get(i);
if (ConvertUtils.isEmpty(branch.getPid())) {
treeList.add(branch);
DataAssessmentItemIdModel itemIdModel = new DataAssessmentItemIdModel().convert(branch);
itemIdModels.add(itemIdModel);
}
}
getGrandChildren(treeList, recordList, itemIdModels);
return treeList;
}
/**
* queryTreeList的子方法====3====
* 该方法是找到顶级父类下的所有子节点集合并封装到TreeList集合
*/
private static void getGrandChildren(List<DataAssessmentItemTreeModel> treeList, List<DataAssessmentItemTreeModel> recordList, List<DataAssessmentItemIdModel> idList) {
for (int i = 0; i < treeList.size(); i++) {
DataAssessmentItemTreeModel model = treeList.get(i);
DataAssessmentItemIdModel idModel = idList.get(i);
for (int i1 = 0; i1 < recordList.size(); i1++) {
DataAssessmentItemTreeModel m = recordList.get(i1);
if (m.getPid() != null && m.getPid().equals(model.getId())) {
model.getChildren().add(m);
DataAssessmentItemIdModel dim = new DataAssessmentItemIdModel().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<DataAssessmentItemTreeModel> treeList) {
for (int i = 0; i < treeList.size(); i++) {
DataAssessmentItemTreeModel model = treeList.get(i);
if (model.getChildren().size() == 0) {
model.setChildren(null);
model.setLeaf(true);
} else {
setEmptyChildrenAsNull(model.getChildren());
model.setLeaf(false);
}
}
}
}