Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
JackyLiang522 authored and halo-dev-bot committed Sep 13, 2022
1 parent f67d86e commit a5a1100
Showing 1 changed file with 25 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -124,9 +123,11 @@ public List<Post> listPostBy(Integer categoryId) {
Assert.notNull(categoryId, "Category id must not be null");

// Find all post ids
Set<Integer> postIds = new HashSet<>();
categoryService.listAllByParentId(categoryId).forEach(
x -> postIds.addAll(postCategoryRepository.findAllPostIdsByCategoryId(x.getId())));
Set<Integer> postIds = categoryService.listAllByParentId(categoryId)
.stream()
.map(item -> postCategoryRepository.findAllPostIdsByCategoryId(item.getId()))
.flatMap(Set::stream)
.collect(Collectors.toSet());

return postRepository.findAllById(postIds);
}
Expand All @@ -137,9 +138,11 @@ public List<Post> listPostBy(Integer categoryId, PostStatus status) {
Assert.notNull(status, "Post status must not be null");

// Find all post ids
Set<Integer> postIds = new HashSet<>();
categoryService.listAllByParentId(categoryId).forEach(x -> postIds.addAll(
postCategoryRepository.findAllPostIdsByCategoryId(x.getId(), status)));
Set<Integer> postIds = categoryService.listAllByParentId(categoryId)
.stream()
.map(item -> postCategoryRepository.findAllPostIdsByCategoryId(item.getId(), status))
.flatMap(Set::stream)
.collect(Collectors.toSet());

return postRepository.findAllById(postIds);
}
Expand All @@ -150,9 +153,11 @@ public List<Post> listPostBy(Integer categoryId, Set<PostStatus> status) {
Assert.notNull(status, "Post status must not be null");

// Find all post ids
Set<Integer> postIds = new HashSet<>();
categoryService.listAllByParentId(categoryId).forEach(x -> postIds.addAll(
postCategoryRepository.findAllPostIdsByCategoryId(x.getId(), status)));
Set<Integer> postIds = categoryService.listAllByParentId(categoryId)
.stream()
.map(item -> postCategoryRepository.findAllPostIdsByCategoryId(item.getId(), status))
.flatMap(Set::stream)
.collect(Collectors.toSet());

return postRepository.findAllById(postIds);
}
Expand All @@ -168,9 +173,11 @@ public List<Post> listPostBy(String slug, Set<PostStatus> status) {
throw new NotFoundException("查询不到该分类的信息").setErrorData(slug);
}

Set<Integer> postIds = new HashSet<>();
categoryService.listAllByParentId(category.getId()).forEach(x -> postIds.addAll(
postCategoryRepository.findAllPostIdsByCategoryId(x.getId(), status)));
Set<Integer> postIds = categoryService.listAllByParentId(category.getId())
.stream()
.map(item -> postCategoryRepository.findAllPostIdsByCategoryId(item.getId(), status))
.flatMap(Set::stream)
.collect(Collectors.toSet());

return postRepository.findAllById(postIds);
}
Expand All @@ -186,9 +193,11 @@ public List<Post> listPostBy(String slug, PostStatus status) {
throw new NotFoundException("查询不到该分类的信息").setErrorData(slug);
}

Set<Integer> postIds = new HashSet<>();
categoryService.listAllByParentId(category.getId()).forEach(x -> postIds.addAll(
postCategoryRepository.findAllPostIdsByCategoryId(x.getId(), status)));
Set<Integer> postIds = categoryService.listAllByParentId(category.getId())
.stream()
.map(item -> postCategoryRepository.findAllPostIdsByCategoryId(item.getId(), status))
.flatMap(Set::stream)
.collect(Collectors.toSet());

return postRepository.findAllById(postIds);
}
Expand Down

0 comments on commit a5a1100

Please sign in to comment.