parent
7e1af4eceb
commit
749e0469f9
@ -0,0 +1,45 @@
|
||||
package com.luoo.music.dto.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.aggregation.Aggregation;
|
||||
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
|
||||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
|
||||
import com.luoo.music.dao.CommentDao;
|
||||
import com.luoo.music.dto.response.CommentDTO;
|
||||
import com.luoo.music.dto.response.TotalCommentVo;
|
||||
import com.luoo.music.pojo.Comment;
|
||||
|
||||
public class CommentMapper {
|
||||
public static CommentDTO getCommentDTO(String journalId, MongoTemplate mongoTemplate, CommentDao commentDao) {
|
||||
CommentDTO commentDTO=new CommentDTO();
|
||||
List<Comment> commentList = commentDao.findTop5ByJournalIdOrderByThumbupCountDesc(journalId);
|
||||
commentDTO.setCommentList(commentList);
|
||||
|
||||
/**
|
||||
* 获取期刊总评论数 一级评论数加上父评论的总回复数
|
||||
*/
|
||||
Criteria criteria = Criteria.where("journalId").is(journalId);
|
||||
Aggregation agg = Aggregation.newAggregation(Aggregation.match(criteria), // 匹配条件
|
||||
Aggregation.group().sum("commentCount").as("totalComment"));
|
||||
AggregationResults<TotalCommentVo> results = mongoTemplate.aggregate(agg, "comment", TotalCommentVo.class);
|
||||
TotalCommentVo totalCommentVo = results.getUniqueMappedResult();
|
||||
commentDTO.setTotalCommentReply("0");
|
||||
List<Comment> list = commentDao.findByJournalId(journalId);
|
||||
int total = 0;
|
||||
if (null != list && list.size() > 0) {
|
||||
total = list.size();
|
||||
}
|
||||
if (null != totalCommentVo) {
|
||||
total = total + totalCommentVo.getTotalComment();
|
||||
commentDTO.setTotalCommentReply(total + "");
|
||||
if (total > 99) {
|
||||
commentDTO.setTotalCommentReply("99+");
|
||||
}
|
||||
}
|
||||
|
||||
return commentDTO;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue