|
|
|
@ -21,48 +21,72 @@ public class CommentMapper {
|
|
|
|
|
* 显示期刊点赞最多5条评论,该五条评论随机显示,每次进入刷新新,超过部分显示为“...”点击评论进入期刊详情页并自动定位到该评论,点击用户头像同上,若为空数据则显示“暂无评论,快去抢沙发吧!
|
|
|
|
|
*/
|
|
|
|
|
CommentDTO commentDTO=new CommentDTO();
|
|
|
|
|
List<Comment> commentList = (List<Comment>) redisTemplate.opsForValue().get("JOURNAL_TOP5_COMMENT___"+journalId);
|
|
|
|
|
if (null!= commentList) {
|
|
|
|
|
commentDTO.setCommentList(commentList);
|
|
|
|
|
} else {
|
|
|
|
|
commentList = commentDao.findTop5ByJournalIdOrderByThumbupCountDesc(journalId);
|
|
|
|
|
commentDTO.setCommentList(commentList);
|
|
|
|
|
redisTemplate.opsForValue().set("JOURNAL_TOP5_COMMENT___"+journalId,commentList,6, TimeUnit.HOURS);
|
|
|
|
|
}
|
|
|
|
|
// List<Comment> commentList = (List<Comment>) redisTemplate.opsForValue().get("JOURNAL_TOP5_COMMENT___"+journalId);
|
|
|
|
|
// if (null!= commentList) {
|
|
|
|
|
// commentDTO.setCommentList(commentList);
|
|
|
|
|
// } else {
|
|
|
|
|
// commentList = commentDao.findTop5ByJournalIdOrderByThumbupCountDesc(journalId);
|
|
|
|
|
// commentDTO.setCommentList(commentList);
|
|
|
|
|
// redisTemplate.opsForValue().set("JOURNAL_TOP5_COMMENT___"+journalId,commentList,6, TimeUnit.HOURS);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
List<Comment> commentList =commentDao.findTop5ByJournalIdOrderByThumbupCountDesc(journalId);
|
|
|
|
|
commentDTO.setCommentList(commentList);
|
|
|
|
|
/**
|
|
|
|
|
* 获取期刊总评论数 一级评论数加上父评论的总回复数
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
String totalString = (String) redisTemplate.opsForValue().get("JOURNAL_TATAL_COMMENT_COUNT__"+journalId);
|
|
|
|
|
if (StringUtils.isNotBlank(totalString)) {
|
|
|
|
|
commentDTO.setTotalCommentReply(totalString);
|
|
|
|
|
}else {
|
|
|
|
|
totalString = "0";
|
|
|
|
|
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();
|
|
|
|
|
totalString = total +"";
|
|
|
|
|
if (total > 99) {
|
|
|
|
|
totalString = "99+";
|
|
|
|
|
}
|
|
|
|
|
// String totalString = (String) redisTemplate.opsForValue().get("JOURNAL_TATAL_COMMENT_COUNT__"+journalId);
|
|
|
|
|
String totalString = "0";
|
|
|
|
|
|
|
|
|
|
// if (StringUtils.isNotBlank(totalString)) {
|
|
|
|
|
// commentDTO.setTotalCommentReply(totalString);
|
|
|
|
|
// }else {
|
|
|
|
|
//// totalString = "0";
|
|
|
|
|
//// 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();
|
|
|
|
|
//// totalString = total +"";
|
|
|
|
|
//// if (total > 99) {
|
|
|
|
|
//// totalString = "99+";
|
|
|
|
|
//// }
|
|
|
|
|
//// }
|
|
|
|
|
//// commentDTO.setTotalCommentReply(totalString);
|
|
|
|
|
//// commentDTO.setTotalCommentReplyInt(total);
|
|
|
|
|
//// redisTemplate.opsForValue().set("JOURNAL_TATAL_COMMENT_COUNT__"+journalId,totalString,6,TimeUnit.HOURS);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
totalString = "0";
|
|
|
|
|
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();
|
|
|
|
|
totalString = total +"";
|
|
|
|
|
if (total > 99) {
|
|
|
|
|
totalString = "99+";
|
|
|
|
|
}
|
|
|
|
|
commentDTO.setTotalCommentReply(totalString);
|
|
|
|
|
commentDTO.setTotalCommentReplyInt(total);
|
|
|
|
|
redisTemplate.opsForValue().set("JOURNAL_TATAL_COMMENT_COUNT__"+journalId,totalString,6,TimeUnit.HOURS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
commentDTO.setTotalCommentReply(totalString);
|
|
|
|
|
commentDTO.setTotalCommentReplyInt(total);
|
|
|
|
|
return commentDTO;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|