mirror of https://github.com/halo-dev/halo
Refactor category tree concrete
parent
4c8d38ae07
commit
1b2f5270e2
|
@ -1,5 +1,6 @@
|
||||||
package run.halo.app.service.impl;
|
package run.halo.app.service.impl;
|
||||||
|
|
||||||
|
import com.google.common.base.Objects;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
|
@ -101,23 +102,20 @@ public class CategoryServiceImpl extends AbstractCrudService<Category, Integer>
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create children container for removing after
|
// Get children for removing after
|
||||||
List<Category> children = new LinkedList<>();
|
List<Category> children = categories.stream()
|
||||||
|
.filter(category -> Objects.equal(parentCategory.getId(), category.getParentId()))
|
||||||
categories.forEach(category -> {
|
.collect(Collectors.toList());
|
||||||
if (parentCategory.getId().equals(category.getParentId())) {
|
|
||||||
// Save child category
|
|
||||||
children.add(category);
|
|
||||||
|
|
||||||
|
children.forEach(category -> {
|
||||||
// Convert to child category vo
|
// Convert to child category vo
|
||||||
CategoryVO child = new CategoryVO().convertFrom(category);
|
CategoryVO child = new CategoryVO().convertFrom(category);
|
||||||
|
|
||||||
// Init children if absent
|
// Init children if absent
|
||||||
if (parentCategory.getChildren() == null) {
|
if (parentCategory.getChildren() == null) {
|
||||||
parentCategory.setChildren(new LinkedList<>());
|
parentCategory.setChildren(new LinkedList<>());
|
||||||
}
|
}
|
||||||
|
// Add child
|
||||||
parentCategory.getChildren().add(child);
|
parentCategory.getChildren().add(child);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Remove all child categories
|
// Remove all child categories
|
||||||
|
|
Loading…
Reference in New Issue