Unverified Commit 0590f7e0 authored by Zzm0809's avatar Zzm0809 Committed by GitHub

improve-query-catalog-tree (#2805)

parent f9ff0aba
...@@ -101,12 +101,12 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata ...@@ -101,12 +101,12 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata
.sorted(Comparator.comparing(Catalogue::getId)) .sorted(Comparator.comparing(Catalogue::getId))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
List<Task> taskList = taskService.list();
List<Catalogue> returnList = new ArrayList<>(); List<Catalogue> returnList = new ArrayList<>();
for (Catalogue catalogue : catalogueList) { for (Catalogue catalogue : catalogueList) {
// get all child catalogue of parent catalogue id , the 0 is root catalogue // get all child catalogue of parent catalogue id , the 0 is root catalogue
if (catalogue.getParentId() == 0) { if (catalogue.getParentId() == 0) {
recursionBuildCatalogueAndChildren(catalogueList, catalogue); recursionBuildCatalogueAndChildren(catalogueList, catalogue, taskList);
returnList.add(catalogue); returnList.add(catalogue);
} }
} }
...@@ -122,7 +122,7 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata ...@@ -122,7 +122,7 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata
* @param list * @param list
* @param catalogues * @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); List<Catalogue> childList = getChildList(list, catalogues);
catalogues.setChildren(childList); catalogues.setChildren(childList);
...@@ -130,14 +130,14 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata ...@@ -130,14 +130,14 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata
if (hasChild(list, tChild)) { if (hasChild(list, tChild)) {
// Determine whether there are child nodes // Determine whether there are child nodes
for (Catalogue children : childList) { for (Catalogue children : childList) {
recursionBuildCatalogueAndChildren(list, children); recursionBuildCatalogueAndChildren(list, children, taskList);
} }
} else { } else {
if (tChild.getIsLeaf() || null != tChild.getTaskId()) { if (tChild.getIsLeaf() || null != tChild.getTaskId()) {
Task task = taskService.getById(tChild.getTaskId()); taskList.stream()
if (task != null) { .filter(t -> t.getId().equals(tChild.getTaskId()))
tChild.setTask(task); .findFirst()
} .ifPresent(tChild::setTask);
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment