From f9086e7debf0f9eb0a6d629310fdd0d7b023379d Mon Sep 17 00:00:00 2001 From: Gary Date: Thu, 7 Mar 2024 01:29:03 +0800 Subject: [PATCH] 1.add comment for filter query page --- .../luoo/music/service/JournalService.java | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/luoo_music/src/main/java/com/luoo/music/service/JournalService.java b/luoo_music/src/main/java/com/luoo/music/service/JournalService.java index 57b4b72..3b402dd 100644 --- a/luoo_music/src/main/java/com/luoo/music/service/JournalService.java +++ b/luoo_music/src/main/java/com/luoo/music/service/JournalService.java @@ -1,12 +1,8 @@ package com.luoo.music.service; -import java.time.LocalDateTime; import java.util.*; -import java.util.concurrent.TimeUnit; import java.util.regex.Pattern; import java.util.stream.Collectors; -import java.util.stream.IntStream; - import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Predicate; @@ -14,36 +10,30 @@ import javax.persistence.criteria.Root; import api.Result; import constants.Constants; -import enums.CollectTypeEnum; import enums.JournalPublishEnum; import enums.JournalStatusEnum; import net.oschina.j2cache.CacheChannel; -import net.oschina.j2cache.CacheObject; - import org.apache.commons.lang.StringUtils; import org.apache.commons.lang3.tuple.Pair; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cache.annotation.Cacheable; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.jpa.domain.Specification; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; - -import util.IdWorker; import util.StringTools; import com.luoo.music.dao.CommentDao; import com.luoo.music.dao.JournalDao; import com.luoo.music.dao.JournalSongDao; import com.luoo.music.dao.JournalTagDao; -import com.luoo.music.dao.TagDao; +import com.luoo.music.dto.mapper.CommentMapper; import com.luoo.music.dto.mapper.JournalMapper; import com.luoo.music.dto.request.JournalQueryReq; +import com.luoo.music.dto.response.CommentDTO; import com.luoo.music.dto.response.JournalFilterDTO; import com.luoo.music.dto.response.JournalRespDTO; -import com.luoo.music.dto.response.SearchCategoryDTO; import com.luoo.music.dto.response.TagDTO; import com.luoo.music.pojo.Journal; import com.luoo.music.pojo.Tag; @@ -359,9 +349,22 @@ public class JournalService { if(StringTools.isEmpty(queryReq.getCategoryId())&&StringTools.isEmpty(queryReq.getJournalNoRange())) { return (List) this.cacheChannel.get(Constants.J2CACHE_REGION_JOURNAL_QUERY_PAGE, queryReq.toString(), key -> getJournalRespDTOWithComment(queryReq) , true).getValue() ; } - return (List) this.cacheChannel.get(Constants.J2CACHE_REGION_JOURNAL_QUERY_PAGE, queryReq.toString(), key -> getJournalRespDTO(queryReq) , true).getValue() ; + List list= (List) this.cacheChannel.get(Constants.J2CACHE_REGION_JOURNAL_QUERY_PAGE, queryReq.toString(), key -> getJournalRespDTO(queryReq) , true).getValue() ; + list.parallelStream().forEach(j->{ + updateComment(j); + }); + return list; } + private void updateComment(JournalRespDTO journalRespDTO) { + CommentDTO commentDTO = CommentMapper.getCommentDTO(journalRespDTO.getId(), mongoTemplate, commentDao, + redisTemplate); + journalRespDTO.setCommentList(commentDTO.getCommentList()); + journalRespDTO.setTotalCommentReply(commentDTO.getTotalCommentReply()); + journalRespDTO.setTotalCommentReplyInt(commentDTO.getTotalCommentReplyInt()); + } + + private List getJournalRespDTO(JournalQueryReq queryReq) { List pageList = queryPage(queryReq); return pageList.stream().map(a ->