Skip to content

Commit

Permalink
improve query catalog tree
Browse files Browse the repository at this point in the history
  • Loading branch information
Zzm0809 committed Dec 26, 2023
1 parent a861733 commit 8af2fc4
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ public List<Catalogue> buildCatalogueTree(List<Catalogue> catalogueList) {
.sorted(Comparator.comparing(Catalogue::getId))
.collect(Collectors.toList());
}

List<Task> taskList = taskService.list();
List<Catalogue> returnList = new ArrayList<>();
for (Catalogue catalogue : catalogueList) {
// get all child catalogue of parent catalogue id , the 0 is root catalogue
if (catalogue.getParentId() == 0) {
recursionBuildCatalogueAndChildren(catalogueList, catalogue);
recursionBuildCatalogueAndChildren(catalogueList, catalogue, taskList);
returnList.add(catalogue);
}
}
Expand All @@ -122,22 +122,22 @@ public List<Catalogue> buildCatalogueTree(List<Catalogue> catalogueList) {
* @param list
* @param catalogues
*/
private void recursionBuildCatalogueAndChildren(List<Catalogue> list, Catalogue catalogues) {
private void recursionBuildCatalogueAndChildren(List<Catalogue> list, Catalogue catalogues, List<Task> taskList) {
// 得到子节点列表
List<Catalogue> childList = getChildList(list, catalogues);
catalogues.setChildren(childList);
for (Catalogue tChild : childList) {
if (hasChild(list, tChild)) {
// Determine whether there are child nodes
for (Catalogue children : childList) {
recursionBuildCatalogueAndChildren(list, children);
recursionBuildCatalogueAndChildren(list, children, taskList);
}
} else {
if (tChild.getIsLeaf() || null != tChild.getTaskId()) {
Task task = taskService.getById(tChild.getTaskId());
if (task != null) {
tChild.setTask(task);
}
taskList.stream()
.filter(t -> t.getId().equals(tChild.getTaskId()))
.findFirst()
.ifPresent(tChild::setTask);
}
}
}
Expand Down

0 comments on commit 8af2fc4

Please sign in to comment.