Skip to content

Commit

Permalink
fix: 图片文档列表查询
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaozzzi committed Apr 8, 2024
1 parent 832f41b commit 93e9ac8
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.blossom.backend.server.article.draft.ArticleMapper;
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.ArticleQueryReq;
import com.blossom.backend.server.doc.pojo.DocTreeReq;
import com.blossom.backend.server.doc.pojo.DocTreeRes;
import com.blossom.backend.server.doc.pojo.DocTreeUpdSortReq;
Expand Down Expand Up @@ -78,7 +77,7 @@ public List<DocTreeRes> listTree(DocTreeReq req) {
FolderEntity where = req.to(FolderEntity.class);
List<FolderEntity> folder = folderMapper.listAll(where);
all.addAll(CollUtil.newArrayList(PictureUtil.getDefaultFolder(req.getUserId())));
all.addAll(DocUtil.toTreeRes(folder));
all.addAll(DocUtil.toDocTreesByFolders(folder));
priorityType = true;
}
/* ===============================================================================================
Expand All @@ -89,15 +88,18 @@ else if (req.getOnlyPicture()) {
FolderEntity where = req.to(FolderEntity.class);
where.setType(FolderTypeEnum.PICTURE.getType());
List<FolderEntity> picFolder = folderMapper.listAll(where);
all.addAll(DocUtil.toTreeRes(picFolder));
all.addAll(DocUtil.toDocTreesByFolders(picFolder));

// 2. 有图片的图片或文章文件夹
List<Long> pids = pictureService.listDistinctPid(req.getUserId());
if (CollUtil.isNotEmpty(pids)) {
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);
all.addAll(DocUtil.toTreeRes(articleFolder));
// 剔除掉图片文件夹
List<Long> articleFolderIds = pids.stream().filter(i -> !picFolderIds.contains(i)).collect(Collectors.toList());
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()));
Expand All @@ -112,60 +114,69 @@ else if (req.getOnlyPicture()) {
* 只查询公开的的文章和文章文件夹
* =============================================================================================== */
else if (req.getOnlyOpen()) {
ArticleQueryReq articleWhere = req.to(ArticleQueryReq.class);
articleWhere.setOpenStatus(YesNo.YES.getValue());
List<DocTreeRes> articles = articleService.listTree(articleWhere);
all.addAll(articles);

ArticleEntity where = req.to(ArticleEntity.class);
where.setOpenStatus(YesNo.YES.getValue());
List<ArticleEntity> articles = articleMapper.listAll(where);
all.addAll(DocUtil.toDocTreesByArticles(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);
all.addAll(DocUtil.toTreeRes(folders));
all.addAll(DocUtil.toDocTreesByFolders(folders));
}
}
/* ===============================================================================================
* 只查询专题的文章和文件夹
* =============================================================================================== */
else if (req.getOnlySubject()) {
FolderEntity folderWhere = req.to(FolderEntity.class);
folderWhere.setTags(TagEnum.subject.name());
folderWhere.setType(FolderTypeEnum.ARTICLE.getType());
List<FolderEntity> subjects = folderMapper.listAll(folderWhere);

FolderEntity where = req.to(FolderEntity.class);
where.setTags(TagEnum.subject.name());
where.setType(FolderTypeEnum.ARTICLE.getType());
List<FolderEntity> subjects = folderMapper.listAll(where);

if (CollUtil.isNotEmpty(subjects)) {
List<Long> subjectIds = subjects.stream().map(FolderEntity::getId).collect(Collectors.toList());
List<FolderEntity> foldersTop = folderMapper.recursiveToParent(subjectIds);
List<FolderEntity> foldersBottom = folderMapper.recursiveToChildren(subjectIds);
all.addAll(DocUtil.toTreeRes(foldersTop));
all.addAll(DocUtil.toTreeRes(foldersBottom));
all.addAll(DocUtil.toDocTreesByFolders(foldersTop));
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()) {
ArticleQueryReq articleWhere = req.to(ArticleQueryReq.class);
articleWhere.setStarStatus(YesNo.YES.getValue());
List<DocTreeRes> articles = articleService.listTree(articleWhere);
all.addAll(articles);

ArticleEntity where = req.to(ArticleEntity.class);
where.setStarStatus(YesNo.YES.getValue());
List<ArticleEntity> articles = articleMapper.listAll(where);
all.addAll(DocUtil.toDocTreesByArticles(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);
all.addAll(DocUtil.toTreeRes(folders));
all.addAll(DocUtil.toDocTreesByFolders(folders));
}
}
/* ===============================================================================================
* 只查询指定文章
* =============================================================================================== */
else if (req.getArticleId() != null && req.getArticleId() > 0) {
ArticleQueryReq articleWhere = req.to(ArticleQueryReq.class);
articleWhere.setId(req.getArticleId());
List<DocTreeRes> articles = articleService.listTree(articleWhere);
all.addAll(articles);

ArticleEntity where = req.to(ArticleEntity.class);
where.setId(req.getArticleId());
List<ArticleEntity> articles = articleMapper.listAll(where);
all.addAll(DocUtil.toDocTreesByArticles(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);
all.addAll(DocUtil.toTreeRes(folders));
all.addAll(DocUtil.toDocTreesByFolders(folders));
}
}
/* ===============================================================================================
Expand All @@ -174,10 +185,12 @@ else if (req.getArticleId() != null && req.getArticleId() > 0) {
else {
FolderEntity folder = req.to(FolderEntity.class);
folder.setType(FolderTypeEnum.ARTICLE.getType());

List<FolderEntity> folders = folderMapper.listAll(folder);
List<DocTreeRes> articles = articleService.listTree(req.to(ArticleQueryReq.class));
all.addAll(DocUtil.toTreeRes(folders));
all.addAll(articles);
all.addAll(DocUtil.toDocTreesByFolders(folders));

List<ArticleEntity> articles = articleMapper.listAll(req.to(ArticleEntity.class));
all.addAll(DocUtil.toDocTreesByArticles(articles));
}

return DocUtil.treeWrap(all.stream().distinct().collect(Collectors.toList()), priorityType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public static List<DocTreeRes> treeWrap(List<DocTreeRes> list, boolean priorityT
return SortUtil.intSort.compare(d1.getS(), d2.getS());
})
.collect(Collectors.toList());

return rootLevel;
}

Expand Down Expand Up @@ -134,6 +133,20 @@ public static DocTreeRes toDocTree(ArticleEntity article) {
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
*
Expand Down Expand Up @@ -165,8 +178,11 @@ public static DocTreeRes toDocTree(FolderEntity folder) {
* @param folders 文件夹集合
* @return docTree
*/
public static List<DocTreeRes> toTreeRes(List<FolderEntity> folders) {
List<DocTreeRes> folderTrees = new ArrayList(folders.size());
public static List<DocTreeRes> toDocTreesByFolders(List<FolderEntity> folders) {
if (CollUtil.isEmpty(folders)) {
return new ArrayList<>();
}
List<DocTreeRes> folderTrees = new ArrayList<>(folders.size());
for (FolderEntity folder : folders) {
folderTrees.add(toDocTree(folder));
}
Expand Down

0 comments on commit 93e9ac8

Please sign in to comment.