mirror of
https://github.com/blossom-editor/blossom
synced 2024-11-17 14:39:21 +08:00
fix: 修复专题的查询逻辑
This commit is contained in:
parent
7d14414605
commit
a718002501
@ -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.doc.DocService;
|
||||||
import com.blossom.backend.server.folder.pojo.*;
|
import com.blossom.backend.server.folder.pojo.*;
|
||||||
import com.blossom.backend.server.utils.DocUtil;
|
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.exception.XzException404;
|
||||||
import com.blossom.common.base.pojo.DelReq;
|
import com.blossom.common.base.pojo.DelReq;
|
||||||
import com.blossom.common.base.pojo.R;
|
import com.blossom.common.base.pojo.R;
|
||||||
@ -46,7 +45,7 @@ public class FolderController {
|
|||||||
if (userId == null) {
|
if (userId == null) {
|
||||||
return R.ok(new ArrayList<>());
|
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 公开状态
|
* @param starStatus 公开状态
|
||||||
*/
|
*/
|
||||||
@GetMapping("/subjects")
|
@GetMapping("/subjects")
|
||||||
public R<List<FolderSubjectRes>> listSubject(@RequestParam("starStatus") Integer starStatus) {
|
public R<List<FolderSubjectRes>> listSubject() {
|
||||||
return R.ok(baseService.subjects(AuthContext.getUserId(), YesNo.getValue(starStatus)));
|
return R.ok(baseService.subjects(AuthContext.getUserId(), false, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,7 +23,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -56,33 +55,38 @@ public class FolderService extends ServiceImpl<FolderMapper, FolderEntity> {
|
|||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @param starStatus 公开状态
|
* @param starStatus 公开状态
|
||||||
*/
|
*/
|
||||||
public List<FolderSubjectRes> subjects(Long userId, @NotNull YesNo starStatus) {
|
public List<FolderSubjectRes> subjects(Long userId, boolean openStatus, boolean starStatus) {
|
||||||
// 1. 查询所有专题
|
// 1. 查询所有专题
|
||||||
FolderEntity where = new FolderEntity();
|
FolderEntity where = new FolderEntity();
|
||||||
where.setTags(TagEnum.subject.name());
|
where.setTags(TagEnum.subject.name());
|
||||||
where.setUserId(userId);
|
where.setUserId(userId);
|
||||||
where.setStarStatus(starStatus.getValue());
|
if (openStatus) {
|
||||||
List<FolderEntity> allOpenSubject = baseMapper.listAll(where);
|
where.setOpenStatus(YesNo.YES.getValue());
|
||||||
if (CollUtil.isEmpty(allOpenSubject)) {
|
}
|
||||||
|
if (starStatus) {
|
||||||
|
where.setStarStatus(YesNo.YES.getValue());
|
||||||
|
}
|
||||||
|
List<FolderEntity> allSubjects = baseMapper.listAll(where);
|
||||||
|
if (CollUtil.isEmpty(allSubjects)) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 专题的ID
|
// 专题的ID
|
||||||
List<Long> allOpenSubjectIds = allOpenSubject.stream().map(FolderEntity::getId).collect(Collectors.toList());
|
List<Long> allSubjectIds = allSubjects.stream().map(FolderEntity::getId).collect(Collectors.toList());
|
||||||
|
|
||||||
// 2. 查询全部专题的子文件夹
|
// 2. 查询全部专题的子文件夹
|
||||||
List<FolderEntity> allOpenSubjectChildFolders = baseMapper.recursiveToChildren(CollUtil.newArrayList(allOpenSubjectIds));
|
List<FolderEntity> allSubjectChildFolders = baseMapper.recursiveToChildren(CollUtil.newArrayList(allSubjectIds));
|
||||||
allOpenSubjectIds.addAll(allOpenSubjectChildFolders.stream().map(FolderEntity::getId).collect(Collectors.toList()));
|
allSubjectIds.addAll(allSubjectChildFolders.stream().map(FolderEntity::getId).collect(Collectors.toList()));
|
||||||
|
|
||||||
// 3. 查询这些文件夹下的所有文章
|
// 3. 查询这些文件夹下的所有文章
|
||||||
ArticleEntity articleWhere = new ArticleEntity();
|
ArticleEntity articleWhere = new ArticleEntity();
|
||||||
articleWhere.setPids(allOpenSubjectIds);
|
articleWhere.setPids(allSubjectIds);
|
||||||
articleWhere.setUserId(userId);
|
articleWhere.setUserId(userId);
|
||||||
List<ArticleEntity> articles = articleMapper.listAll(articleWhere);
|
List<ArticleEntity> articles = articleMapper.listAll(articleWhere);
|
||||||
|
|
||||||
List<FolderSubjectRes> results = new ArrayList<>();
|
List<FolderSubjectRes> results = new ArrayList<>();
|
||||||
|
|
||||||
for (FolderEntity subject : allOpenSubject) {
|
for (FolderEntity subject : allSubjects) {
|
||||||
// 专题对象, 包含字数, 更新日期等信息
|
// 专题对象, 包含字数, 更新日期等信息
|
||||||
FolderSubjectRes result = subject.to(FolderSubjectRes.class);
|
FolderSubjectRes result = subject.to(FolderSubjectRes.class);
|
||||||
// 默认专题字数
|
// 默认专题字数
|
||||||
@ -90,7 +94,7 @@ public class FolderService extends ServiceImpl<FolderMapper, FolderEntity> {
|
|||||||
// 默认专题修改时间
|
// 默认专题修改时间
|
||||||
result.setSubjectUpdTime(subject.getCreTime());
|
result.setSubjectUpdTime(subject.getCreTime());
|
||||||
// 4. 这个专题下的所有文件夹ID
|
// 4. 这个专题下的所有文件夹ID
|
||||||
List<Long> subjectAllId = DocUtil.getChildrenIds(subject.getId(), allOpenSubjectChildFolders);
|
List<Long> subjectAllId = DocUtil.getChildrenIds(subject.getId(), allSubjectChildFolders);
|
||||||
// 5. 遍历文章, 将文章归属到某个专题下, 并统计相关字数, 日期等信息
|
// 5. 遍历文章, 将文章归属到某个专题下, 并统计相关字数, 日期等信息
|
||||||
for (ArticleEntity article : articles) {
|
for (ArticleEntity article : articles) {
|
||||||
if (subjectAllId.contains(article.getPid())) {
|
if (subjectAllId.contains(article.getPid())) {
|
||||||
|
@ -56,7 +56,7 @@ let maxWords = 0
|
|||||||
const subjects = ref<any>([])
|
const subjects = ref<any>([])
|
||||||
|
|
||||||
const getSubjects = () => {
|
const getSubjects = () => {
|
||||||
subjectsApi({ starStatus: 1 }).then((resp) => {
|
subjectsApi().then((resp) => {
|
||||||
subjects.value = resp.data
|
subjects.value = resp.data
|
||||||
if (!isEmpty(resp.data)) {
|
if (!isEmpty(resp.data)) {
|
||||||
maxWords = resp.data
|
maxWords = resp.data
|
||||||
|
Loading…
Reference in New Issue
Block a user