From a71800250123bc76622a71efd49504c6de210bd1 Mon Sep 17 00:00:00 2001 From: xiaozzzi <42293085+xiaozzzi@users.noreply.github.com> Date: Wed, 10 Apr 2024 20:53:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=B8=93=E9=A2=98?= =?UTF-8?q?=E7=9A=84=E6=9F=A5=E8=AF=A2=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/folder/FolderController.java | 7 +++-- .../backend/server/folder/FolderService.java | 26 +++++++++++-------- .../src/views/home/ArticleSubjects.vue | 2 +- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/blossom-backend/backend/src/main/java/com/blossom/backend/server/folder/FolderController.java b/blossom-backend/backend/src/main/java/com/blossom/backend/server/folder/FolderController.java index ffcee95..7a2233c 100644 --- a/blossom-backend/backend/src/main/java/com/blossom/backend/server/folder/FolderController.java +++ b/blossom-backend/backend/src/main/java/com/blossom/backend/server/folder/FolderController.java @@ -9,7 +9,6 @@ import com.blossom.backend.server.article.draft.pojo.ArticleUpdTagReq; import com.blossom.backend.server.doc.DocService; import com.blossom.backend.server.folder.pojo.*; import com.blossom.backend.server.utils.DocUtil; -import com.blossom.common.base.enums.YesNo; import com.blossom.common.base.exception.XzException404; import com.blossom.common.base.pojo.DelReq; import com.blossom.common.base.pojo.R; @@ -46,7 +45,7 @@ public class FolderController { if (userId == null) { return R.ok(new ArrayList<>()); } - return R.ok(baseService.subjects(userId, YesNo.YES)); + return R.ok(baseService.subjects(userId, true, false)); } /** @@ -55,8 +54,8 @@ public class FolderController { * @param starStatus 公开状态 */ @GetMapping("/subjects") - public R> listSubject(@RequestParam("starStatus") Integer starStatus) { - return R.ok(baseService.subjects(AuthContext.getUserId(), YesNo.getValue(starStatus))); + public R> listSubject() { + return R.ok(baseService.subjects(AuthContext.getUserId(), false, true)); } /** diff --git a/blossom-backend/backend/src/main/java/com/blossom/backend/server/folder/FolderService.java b/blossom-backend/backend/src/main/java/com/blossom/backend/server/folder/FolderService.java index 16119bd..b703c5f 100644 --- a/blossom-backend/backend/src/main/java/com/blossom/backend/server/folder/FolderService.java +++ b/blossom-backend/backend/src/main/java/com/blossom/backend/server/folder/FolderService.java @@ -23,7 +23,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import javax.validation.constraints.NotNull; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -56,33 +55,38 @@ public class FolderService extends ServiceImpl { * @param userId 用户ID * @param starStatus 公开状态 */ - public List subjects(Long userId, @NotNull YesNo starStatus) { + public List subjects(Long userId, boolean openStatus, boolean starStatus) { // 1. 查询所有专题 FolderEntity where = new FolderEntity(); where.setTags(TagEnum.subject.name()); where.setUserId(userId); - where.setStarStatus(starStatus.getValue()); - List allOpenSubject = baseMapper.listAll(where); - if (CollUtil.isEmpty(allOpenSubject)) { + if (openStatus) { + where.setOpenStatus(YesNo.YES.getValue()); + } + if (starStatus) { + where.setStarStatus(YesNo.YES.getValue()); + } + List allSubjects = baseMapper.listAll(where); + if (CollUtil.isEmpty(allSubjects)) { return new ArrayList<>(); } // 专题的ID - List allOpenSubjectIds = allOpenSubject.stream().map(FolderEntity::getId).collect(Collectors.toList()); + List allSubjectIds = allSubjects.stream().map(FolderEntity::getId).collect(Collectors.toList()); // 2. 查询全部专题的子文件夹 - List allOpenSubjectChildFolders = baseMapper.recursiveToChildren(CollUtil.newArrayList(allOpenSubjectIds)); - allOpenSubjectIds.addAll(allOpenSubjectChildFolders.stream().map(FolderEntity::getId).collect(Collectors.toList())); + List allSubjectChildFolders = baseMapper.recursiveToChildren(CollUtil.newArrayList(allSubjectIds)); + allSubjectIds.addAll(allSubjectChildFolders.stream().map(FolderEntity::getId).collect(Collectors.toList())); // 3. 查询这些文件夹下的所有文章 ArticleEntity articleWhere = new ArticleEntity(); - articleWhere.setPids(allOpenSubjectIds); + articleWhere.setPids(allSubjectIds); articleWhere.setUserId(userId); List articles = articleMapper.listAll(articleWhere); List results = new ArrayList<>(); - for (FolderEntity subject : allOpenSubject) { + for (FolderEntity subject : allSubjects) { // 专题对象, 包含字数, 更新日期等信息 FolderSubjectRes result = subject.to(FolderSubjectRes.class); // 默认专题字数 @@ -90,7 +94,7 @@ public class FolderService extends ServiceImpl { // 默认专题修改时间 result.setSubjectUpdTime(subject.getCreTime()); // 4. 这个专题下的所有文件夹ID - List subjectAllId = DocUtil.getChildrenIds(subject.getId(), allOpenSubjectChildFolders); + List subjectAllId = DocUtil.getChildrenIds(subject.getId(), allSubjectChildFolders); // 5. 遍历文章, 将文章归属到某个专题下, 并统计相关字数, 日期等信息 for (ArticleEntity article : articles) { if (subjectAllId.contains(article.getPid())) { diff --git a/blossom-editor/src/renderer/src/views/home/ArticleSubjects.vue b/blossom-editor/src/renderer/src/views/home/ArticleSubjects.vue index 47b4466..35e82fd 100644 --- a/blossom-editor/src/renderer/src/views/home/ArticleSubjects.vue +++ b/blossom-editor/src/renderer/src/views/home/ArticleSubjects.vue @@ -56,7 +56,7 @@ let maxWords = 0 const subjects = ref([]) const getSubjects = () => { - subjectsApi({ starStatus: 1 }).then((resp) => { + subjectsApi().then((resp) => { subjects.value = resp.data if (!isEmpty(resp.data)) { maxWords = resp.data