mirror of https://github.com/halo-dev/halo
parent
1f89ba0ed2
commit
0ade01c518
|
@ -100,6 +100,14 @@ public interface CategoryService extends CrudService<Category, Integer> {
|
||||||
@NonNull
|
@NonNull
|
||||||
List<Category> listAll(Sort sort, boolean queryEncryptCategory);
|
List<Category> listAll(Sort sort, boolean queryEncryptCategory);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List all category not encrypt.
|
||||||
|
*
|
||||||
|
* @param queryEncryptCategory whether to query encryption category
|
||||||
|
* @return list of category.
|
||||||
|
*/
|
||||||
|
List<Category> listAll(boolean queryEncryptCategory);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List all by ids
|
* List all by ids
|
||||||
*
|
*
|
||||||
|
|
|
@ -336,7 +336,7 @@ public class BackupServiceImpl implements BackupService {
|
||||||
data.put("version", HaloConst.HALO_VERSION);
|
data.put("version", HaloConst.HALO_VERSION);
|
||||||
data.put("export_date", DateUtil.now());
|
data.put("export_date", DateUtil.now());
|
||||||
data.put("attachments", attachmentService.listAll());
|
data.put("attachments", attachmentService.listAll());
|
||||||
data.put("categories", categoryService.listAll());
|
data.put("categories", categoryService.listAll(true));
|
||||||
data.put("comment_black_list", commentBlackListService.listAll());
|
data.put("comment_black_list", commentBlackListService.listAll());
|
||||||
data.put("journals", journalService.listAll());
|
data.put("journals", journalService.listAll());
|
||||||
data.put("journal_comments", journalCommentService.listAll());
|
data.put("journal_comments", journalCommentService.listAll());
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class CategoryServiceImpl extends AbstractCrudService<Category, Integer>
|
||||||
|
|
||||||
private PostService postService;
|
private PostService postService;
|
||||||
|
|
||||||
private AuthenticationService authenticationService;
|
private final AuthenticationService authenticationService;
|
||||||
|
|
||||||
public CategoryServiceImpl(CategoryRepository categoryRepository,
|
public CategoryServiceImpl(CategoryRepository categoryRepository,
|
||||||
PostCategoryService postCategoryService,
|
PostCategoryService postCategoryService,
|
||||||
|
@ -146,7 +146,7 @@ public class CategoryServiceImpl extends AbstractCrudService<Category, Integer>
|
||||||
*
|
*
|
||||||
* @param parentCategory parent category vo must not be null
|
* @param parentCategory parent category vo must not be null
|
||||||
* @param categories a list of category
|
* @param categories a list of category
|
||||||
* @param fillPassword whether to fill in the password
|
* @param fillPassword whether to fill in the password
|
||||||
*/
|
*/
|
||||||
private void concreteTree(
|
private void concreteTree(
|
||||||
CategoryVO parentCategory,
|
CategoryVO parentCategory,
|
||||||
|
@ -240,8 +240,8 @@ public class CategoryServiceImpl extends AbstractCrudService<Category, Integer>
|
||||||
public Category getBySlugOfNonNull(String slug) {
|
public Category getBySlugOfNonNull(String slug) {
|
||||||
|
|
||||||
Category category = categoryRepository
|
Category category = categoryRepository
|
||||||
.getBySlug(slug)
|
.getBySlug(slug)
|
||||||
.orElseThrow(() -> new NotFoundException("查询不到该分类的信息").setErrorData(slug));
|
.orElseThrow(() -> new NotFoundException("查询不到该分类的信息").setErrorData(slug));
|
||||||
|
|
||||||
if (authenticationService.categoryAuthentication(category.getId(), null)) {
|
if (authenticationService.categoryAuthentication(category.getId(), null)) {
|
||||||
return category;
|
return category;
|
||||||
|
@ -291,7 +291,7 @@ public class CategoryServiceImpl extends AbstractCrudService<Category, Integer>
|
||||||
removeById(categoryId);
|
removeById(categoryId);
|
||||||
// Remove post categories
|
// Remove post categories
|
||||||
List<Integer> affectedPostIdList = postCategoryService.removeByCategoryId(categoryId)
|
List<Integer> affectedPostIdList = postCategoryService.removeByCategoryId(categoryId)
|
||||||
.stream().map(PostCategory::getPostId).collect(Collectors.toList());
|
.stream().map(PostCategory::getPostId).collect(Collectors.toList());
|
||||||
|
|
||||||
refreshPostStatus(affectedPostIdList);
|
refreshPostStatus(affectedPostIdList);
|
||||||
}
|
}
|
||||||
|
@ -311,10 +311,10 @@ public class CategoryServiceImpl extends AbstractCrudService<Category, Integer>
|
||||||
post.setStatus(PostStatus.INTIMATE);
|
post.setStatus(PostStatus.INTIMATE);
|
||||||
} else {
|
} else {
|
||||||
postCategoryService.listByPostId(postId)
|
postCategoryService.listByPostId(postId)
|
||||||
.stream().map(PostCategory::getCategoryId)
|
.stream().map(PostCategory::getCategoryId)
|
||||||
.filter(this::categoryHasEncrypt)
|
.filter(this::categoryHasEncrypt)
|
||||||
.findAny()
|
.findAny()
|
||||||
.ifPresent(id -> post.setStatus(PostStatus.INTIMATE));
|
.ifPresent(id -> post.setStatus(PostStatus.INTIMATE));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (post.getStatus() == null) {
|
if (post.getStatus() == null) {
|
||||||
|
@ -417,12 +417,12 @@ public class CategoryServiceImpl extends AbstractCrudService<Category, Integer>
|
||||||
* Collect all child from tree
|
* Collect all child from tree
|
||||||
*
|
*
|
||||||
* @param collectorList collector
|
* @param collectorList collector
|
||||||
* @param childrenList contains categories of children
|
* @param childrenList contains categories of children
|
||||||
* @param doNotCollectEncryptedCategory true is not collect, false is collect
|
* @param doNotCollectEncryptedCategory true is not collect, false is collect
|
||||||
*/
|
*/
|
||||||
private void collectAllChild(List<Category> collectorList,
|
private void collectAllChild(List<Category> collectorList,
|
||||||
List<CategoryVO> childrenList,
|
List<CategoryVO> childrenList,
|
||||||
Boolean doNotCollectEncryptedCategory) {
|
Boolean doNotCollectEncryptedCategory) {
|
||||||
if (CollectionUtil.isEmpty(childrenList)) {
|
if (CollectionUtil.isEmpty(childrenList)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -451,14 +451,14 @@ public class CategoryServiceImpl extends AbstractCrudService<Category, Integer>
|
||||||
* Collect sub-categories under the specified category.
|
* Collect sub-categories under the specified category.
|
||||||
*
|
*
|
||||||
* @param collectorList collector
|
* @param collectorList collector
|
||||||
* @param childrenList contains categories of children
|
* @param childrenList contains categories of children
|
||||||
* @param categoryId category id
|
* @param categoryId category id
|
||||||
* @param doNotCollectEncryptedCategory true is not collect, false is collect
|
* @param doNotCollectEncryptedCategory true is not collect, false is collect
|
||||||
*/
|
*/
|
||||||
private void collectAllChildByCategoryId(List<Category> collectorList,
|
private void collectAllChildByCategoryId(List<Category> collectorList,
|
||||||
List<CategoryVO> childrenList,
|
List<CategoryVO> childrenList,
|
||||||
Integer categoryId,
|
Integer categoryId,
|
||||||
Boolean doNotCollectEncryptedCategory) {
|
Boolean doNotCollectEncryptedCategory) {
|
||||||
if (CollectionUtil.isEmpty(childrenList)) {
|
if (CollectionUtil.isEmpty(childrenList)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -481,6 +481,15 @@ public class CategoryServiceImpl extends AbstractCrudService<Category, Integer>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Category> listAll(boolean queryEncryptCategory) {
|
||||||
|
if (queryEncryptCategory) {
|
||||||
|
return super.listAll();
|
||||||
|
} else {
|
||||||
|
return this.listAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Category> listAll() {
|
public List<Category> listAll() {
|
||||||
return filterEncryptCategory(super.listAll());
|
return filterEncryptCategory(super.listAll());
|
||||||
|
@ -578,7 +587,7 @@ public class CategoryServiceImpl extends AbstractCrudService<Category, Integer>
|
||||||
List<Category> allCategoryList = super.listAll();
|
List<Category> allCategoryList = super.listAll();
|
||||||
|
|
||||||
Map<Integer, Category> idToCategoryMap = allCategoryList.stream().collect(
|
Map<Integer, Category> idToCategoryMap = allCategoryList.stream().collect(
|
||||||
Collectors.toMap(Category::getId, Function.identity()));
|
Collectors.toMap(Category::getId, Function.identity()));
|
||||||
|
|
||||||
if (doCategoryHasEncrypt(idToCategoryMap, category.getParentId())) {
|
if (doCategoryHasEncrypt(idToCategoryMap, category.getParentId())) {
|
||||||
// If the parent category is encrypted, there is no need to update the encryption status
|
// If the parent category is encrypted, there is no need to update the encryption status
|
||||||
|
@ -622,7 +631,7 @@ public class CategoryServiceImpl extends AbstractCrudService<Category, Integer>
|
||||||
List<Category> allCategoryList = super.listAll();
|
List<Category> allCategoryList = super.listAll();
|
||||||
|
|
||||||
Map<Integer, Category> idToCategoryMap = allCategoryList.stream().collect(
|
Map<Integer, Category> idToCategoryMap = allCategoryList.stream().collect(
|
||||||
Collectors.toMap(Category::getId, Function.identity()));
|
Collectors.toMap(Category::getId, Function.identity()));
|
||||||
|
|
||||||
return doCategoryHasEncrypt(idToCategoryMap, categoryId);
|
return doCategoryHasEncrypt(idToCategoryMap, categoryId);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue