fix: 图片文档列表查询

This commit is contained in:
xiaozzzi 2024-04-08 15:55:06 +08:00
parent 832f41b6fe
commit 93e9ac87c3
2 changed files with 67 additions and 38 deletions

View File

@ -6,7 +6,6 @@ import com.blossom.backend.server.article.TagEnum;
import com.blossom.backend.server.article.draft.ArticleMapper; import com.blossom.backend.server.article.draft.ArticleMapper;
import com.blossom.backend.server.article.draft.ArticleService; import com.blossom.backend.server.article.draft.ArticleService;
import com.blossom.backend.server.article.draft.pojo.ArticleEntity; import com.blossom.backend.server.article.draft.pojo.ArticleEntity;
import com.blossom.backend.server.article.draft.pojo.ArticleQueryReq;
import com.blossom.backend.server.doc.pojo.DocTreeReq; import com.blossom.backend.server.doc.pojo.DocTreeReq;
import com.blossom.backend.server.doc.pojo.DocTreeRes; import com.blossom.backend.server.doc.pojo.DocTreeRes;
import com.blossom.backend.server.doc.pojo.DocTreeUpdSortReq; import com.blossom.backend.server.doc.pojo.DocTreeUpdSortReq;
@ -78,7 +77,7 @@ public class DocService {
FolderEntity where = req.to(FolderEntity.class); FolderEntity where = req.to(FolderEntity.class);
List<FolderEntity> folder = folderMapper.listAll(where); List<FolderEntity> folder = folderMapper.listAll(where);
all.addAll(CollUtil.newArrayList(PictureUtil.getDefaultFolder(req.getUserId()))); all.addAll(CollUtil.newArrayList(PictureUtil.getDefaultFolder(req.getUserId())));
all.addAll(DocUtil.toTreeRes(folder)); all.addAll(DocUtil.toDocTreesByFolders(folder));
priorityType = true; priorityType = true;
} }
/* =============================================================================================== /* ===============================================================================================
@ -89,15 +88,18 @@ public class DocService {
FolderEntity where = req.to(FolderEntity.class); FolderEntity where = req.to(FolderEntity.class);
where.setType(FolderTypeEnum.PICTURE.getType()); where.setType(FolderTypeEnum.PICTURE.getType());
List<FolderEntity> picFolder = folderMapper.listAll(where); List<FolderEntity> picFolder = folderMapper.listAll(where);
all.addAll(DocUtil.toTreeRes(picFolder)); all.addAll(DocUtil.toDocTreesByFolders(picFolder));
// 2. 有图片的图片或文章文件夹 // 2. 有图片的图片或文章文件夹
List<Long> pids = pictureService.listDistinctPid(req.getUserId()); List<Long> pids = pictureService.listDistinctPid(req.getUserId());
if (CollUtil.isNotEmpty(pids)) { if (CollUtil.isNotEmpty(pids)) {
List<Long> picFolderIds = picFolder.stream().map(FolderEntity::getId).collect(Collectors.toList()); List<Long> picFolderIds = picFolder.stream().map(FolderEntity::getId).collect(Collectors.toList());
List<Long> withoutPicPids = pids.stream().filter(i -> !picFolderIds.contains(i)).collect(Collectors.toList()); // 剔除掉图片文件夹
List<FolderEntity> articleFolder = folderMapper.recursiveToParent(withoutPicPids); List<Long> articleFolderIds = pids.stream().filter(i -> !picFolderIds.contains(i)).collect(Collectors.toList());
all.addAll(DocUtil.toTreeRes(articleFolder)); if(CollUtil.isNotEmpty(articleFolderIds)) {
List<FolderEntity> articleFolder = folderMapper.recursiveToParent(articleFolderIds);
all.addAll(DocUtil.toDocTreesByFolders(articleFolder));
}
} }
Optional<DocTreeRes> min = all.stream().min((f1, f2) -> SortUtil.intSort.compare(f1.getS(), f2.getS())); Optional<DocTreeRes> min = all.stream().min((f1, f2) -> SortUtil.intSort.compare(f1.getS(), f2.getS()));
@ -112,60 +114,69 @@ public class DocService {
* 只查询公开的的文章和文章文件夹 * 只查询公开的的文章和文章文件夹
* =============================================================================================== */ * =============================================================================================== */
else if (req.getOnlyOpen()) { else if (req.getOnlyOpen()) {
ArticleQueryReq articleWhere = req.to(ArticleQueryReq.class);
articleWhere.setOpenStatus(YesNo.YES.getValue()); ArticleEntity where = req.to(ArticleEntity.class);
List<DocTreeRes> articles = articleService.listTree(articleWhere); where.setOpenStatus(YesNo.YES.getValue());
all.addAll(articles); List<ArticleEntity> articles = articleMapper.listAll(where);
all.addAll(DocUtil.toDocTreesByArticles(articles));
if (CollUtil.isNotEmpty(articles)) { if (CollUtil.isNotEmpty(articles)) {
List<Long> pidList = articles.stream().map(DocTreeRes::getP).collect(Collectors.toList()); List<Long> pidList = articles.stream().map(ArticleEntity::getPid).collect(Collectors.toList());
List<FolderEntity> folders = folderMapper.recursiveToParent(pidList); List<FolderEntity> folders = folderMapper.recursiveToParent(pidList);
all.addAll(DocUtil.toTreeRes(folders)); all.addAll(DocUtil.toDocTreesByFolders(folders));
} }
} }
/* =============================================================================================== /* ===============================================================================================
* 只查询专题的文章和文件夹 * 只查询专题的文章和文件夹
* =============================================================================================== */ * =============================================================================================== */
else if (req.getOnlySubject()) { else if (req.getOnlySubject()) {
FolderEntity folderWhere = req.to(FolderEntity.class);
folderWhere.setTags(TagEnum.subject.name()); FolderEntity where = req.to(FolderEntity.class);
folderWhere.setType(FolderTypeEnum.ARTICLE.getType()); where.setTags(TagEnum.subject.name());
List<FolderEntity> subjects = folderMapper.listAll(folderWhere); where.setType(FolderTypeEnum.ARTICLE.getType());
List<FolderEntity> subjects = folderMapper.listAll(where);
if (CollUtil.isNotEmpty(subjects)) { if (CollUtil.isNotEmpty(subjects)) {
List<Long> subjectIds = subjects.stream().map(FolderEntity::getId).collect(Collectors.toList()); List<Long> subjectIds = subjects.stream().map(FolderEntity::getId).collect(Collectors.toList());
List<FolderEntity> foldersTop = folderMapper.recursiveToParent(subjectIds); List<FolderEntity> foldersTop = folderMapper.recursiveToParent(subjectIds);
List<FolderEntity> foldersBottom = folderMapper.recursiveToChildren(subjectIds); List<FolderEntity> foldersBottom = folderMapper.recursiveToChildren(subjectIds);
all.addAll(DocUtil.toTreeRes(foldersTop)); all.addAll(DocUtil.toDocTreesByFolders(foldersTop));
all.addAll(DocUtil.toTreeRes(foldersBottom)); all.addAll(DocUtil.toDocTreesByFolders(foldersBottom));
} }
List<DocTreeRes> articles = articleService.listTree(req.to(ArticleQueryReq.class));
all.addAll(articles); List<ArticleEntity> articles = articleMapper.listAll(req.to(ArticleEntity.class));
all.addAll(DocUtil.toDocTreesByArticles(articles));
} }
/* =============================================================================================== /* ===============================================================================================
* 只查询关注的 * 只查询关注的
* =============================================================================================== */ * =============================================================================================== */
else if (req.getOnlyStar()) { else if (req.getOnlyStar()) {
ArticleQueryReq articleWhere = req.to(ArticleQueryReq.class);
articleWhere.setStarStatus(YesNo.YES.getValue()); ArticleEntity where = req.to(ArticleEntity.class);
List<DocTreeRes> articles = articleService.listTree(articleWhere); where.setStarStatus(YesNo.YES.getValue());
all.addAll(articles); List<ArticleEntity> articles = articleMapper.listAll(where);
all.addAll(DocUtil.toDocTreesByArticles(articles));
if (CollUtil.isNotEmpty(articles)) { if (CollUtil.isNotEmpty(articles)) {
List<Long> pidList = articles.stream().map(DocTreeRes::getP).collect(Collectors.toList()); List<Long> pidList = articles.stream().map(ArticleEntity::getPid).collect(Collectors.toList());
List<FolderEntity> folders = folderMapper.recursiveToParent(pidList); List<FolderEntity> folders = folderMapper.recursiveToParent(pidList);
all.addAll(DocUtil.toTreeRes(folders)); all.addAll(DocUtil.toDocTreesByFolders(folders));
} }
} }
/* =============================================================================================== /* ===============================================================================================
* 只查询指定文章 * 只查询指定文章
* =============================================================================================== */ * =============================================================================================== */
else if (req.getArticleId() != null && req.getArticleId() > 0) { else if (req.getArticleId() != null && req.getArticleId() > 0) {
ArticleQueryReq articleWhere = req.to(ArticleQueryReq.class);
articleWhere.setId(req.getArticleId()); ArticleEntity where = req.to(ArticleEntity.class);
List<DocTreeRes> articles = articleService.listTree(articleWhere); where.setId(req.getArticleId());
all.addAll(articles); List<ArticleEntity> articles = articleMapper.listAll(where);
all.addAll(DocUtil.toDocTreesByArticles(articles));
if (CollUtil.isNotEmpty(articles)) { if (CollUtil.isNotEmpty(articles)) {
List<Long> pidList = articles.stream().map(DocTreeRes::getP).collect(Collectors.toList()); List<Long> pidList = articles.stream().map(ArticleEntity::getPid).collect(Collectors.toList());
List<FolderEntity> folders = folderMapper.recursiveToParent(pidList); List<FolderEntity> folders = folderMapper.recursiveToParent(pidList);
all.addAll(DocUtil.toTreeRes(folders)); all.addAll(DocUtil.toDocTreesByFolders(folders));
} }
} }
/* =============================================================================================== /* ===============================================================================================
@ -174,10 +185,12 @@ public class DocService {
else { else {
FolderEntity folder = req.to(FolderEntity.class); FolderEntity folder = req.to(FolderEntity.class);
folder.setType(FolderTypeEnum.ARTICLE.getType()); folder.setType(FolderTypeEnum.ARTICLE.getType());
List<FolderEntity> folders = folderMapper.listAll(folder); List<FolderEntity> folders = folderMapper.listAll(folder);
List<DocTreeRes> articles = articleService.listTree(req.to(ArticleQueryReq.class)); all.addAll(DocUtil.toDocTreesByFolders(folders));
all.addAll(DocUtil.toTreeRes(folders));
all.addAll(articles); List<ArticleEntity> articles = articleMapper.listAll(req.to(ArticleEntity.class));
all.addAll(DocUtil.toDocTreesByArticles(articles));
} }
return DocUtil.treeWrap(all.stream().distinct().collect(Collectors.toList()), priorityType); return DocUtil.treeWrap(all.stream().distinct().collect(Collectors.toList()), priorityType);

View File

@ -60,7 +60,6 @@ public class DocUtil {
return SortUtil.intSort.compare(d1.getS(), d2.getS()); return SortUtil.intSort.compare(d1.getS(), d2.getS());
}) })
.collect(Collectors.toList()); .collect(Collectors.toList());
return rootLevel; return rootLevel;
} }
@ -134,6 +133,20 @@ public class DocUtil {
return tree; return tree;
} }
/**
* 文章集合转 docTree集合
*
* @param articles 文章集合
* @return docTree
*/
public static List<DocTreeRes> toDocTreesByArticles(List<ArticleEntity> articles) {
List<DocTreeRes> articleTrees = new ArrayList<>(articles.size());
for (ArticleEntity folder : articles) {
articleTrees.add(toDocTree(folder));
}
return articleTrees;
}
/** /**
* 文件夹转 docTree * 文件夹转 docTree
* *
@ -165,8 +178,11 @@ public class DocUtil {
* @param folders 文件夹集合 * @param folders 文件夹集合
* @return docTree * @return docTree
*/ */
public static List<DocTreeRes> toTreeRes(List<FolderEntity> folders) { public static List<DocTreeRes> toDocTreesByFolders(List<FolderEntity> folders) {
List<DocTreeRes> folderTrees = new ArrayList(folders.size()); if (CollUtil.isEmpty(folders)) {
return new ArrayList<>();
}
List<DocTreeRes> folderTrees = new ArrayList<>(folders.size());
for (FolderEntity folder : folders) { for (FolderEntity folder : folders) {
folderTrees.add(toDocTree(folder)); folderTrees.add(toDocTree(folder));
} }