|
|
@ -1,15 +1,12 @@
|
|
|
|
package com.luoo.music.dto.mapper;
|
|
|
|
package com.luoo.music.dto.mapper;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
import com.luoo.music.client.UserClient;
|
|
|
|
import com.luoo.music.client.UserClient;
|
|
|
|
import com.luoo.music.dto.response.UserInfoDTO;
|
|
|
|
import com.luoo.music.dto.response.UserInfoDTO;
|
|
|
|
import constants.Constants;
|
|
|
|
import constants.Constants;
|
|
|
|
import net.oschina.j2cache.CacheChannel;
|
|
|
|
import net.oschina.j2cache.CacheChannel;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
|
|
|
import org.apache.tomcat.util.bcel.classfile.Constant;
|
|
|
|
|
|
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
|
import org.springframework.data.mongodb.core.aggregation.Aggregation;
|
|
|
|
import org.springframework.data.mongodb.core.aggregation.Aggregation;
|
|
|
|
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
|
|
|
|
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
|
|
|
@ -22,79 +19,41 @@ import com.luoo.music.dto.response.TotalCommentVo;
|
|
|
|
import com.luoo.music.pojo.Comment;
|
|
|
|
import com.luoo.music.pojo.Comment;
|
|
|
|
|
|
|
|
|
|
|
|
public class CommentMapper {
|
|
|
|
public class CommentMapper {
|
|
|
|
public static CommentDTO getCommentDTO(String journalId, MongoTemplate mongoTemplate, CommentDao commentDao,RedisTemplate redisTemplate) {
|
|
|
|
public static List<Comment> getList(String journalId, CommentDao commentDao, UserClient userClient) {
|
|
|
|
/**
|
|
|
|
List<Comment> commentList = commentDao.findTop2ByJournalIdOrderByThumbupCountDesc(journalId);
|
|
|
|
* 显示期刊点赞最多5条评论,该五条评论随机显示,每次进入刷新新,超过部分显示为“...”点击评论进入期刊详情页并自动定位到该评论,点击用户头像同上,若为空数据则显示“暂无评论,快去抢沙发吧!
|
|
|
|
if (commentList.size() > 0) {
|
|
|
|
*/
|
|
|
|
commentList = commentList.stream().map(comment -> {
|
|
|
|
CommentDTO commentDTO=new CommentDTO();
|
|
|
|
UserInfoDTO userInfoDTO = userClient.findByUserId(comment.getUserId());
|
|
|
|
|
|
|
|
if (null != userInfoDTO) {
|
|
|
|
List<Comment> commentList =commentDao.findTop2ByJournalIdOrderByThumbupCountDesc(journalId);
|
|
|
|
comment.setNickName(userInfoDTO.getNickName());
|
|
|
|
commentDTO.setCommentList(commentList);
|
|
|
|
comment.setAvatar(Constants.RESOURCE_PREFIX + userInfoDTO.getAvatar());
|
|
|
|
/**
|
|
|
|
}
|
|
|
|
* 获取期刊总评论数 一级评论数加上父评论的总回复数
|
|
|
|
|
|
|
|
*/
|
|
|
|
return comment;
|
|
|
|
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
String totalString = "0";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
return commentList;
|
|
|
|
commentDTO.setTotalCommentReplyInt(total);
|
|
|
|
|
|
|
|
return commentDTO;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static List<Comment> getList(String journalId,CommentDao commentDao,UserClient userClient){
|
|
|
|
public static CommentDTO getCommentDTO(String journalId, MongoTemplate mongoTemplate, CommentDao commentDao,
|
|
|
|
List<Comment> commentList =commentDao.findTop2ByJournalIdOrderByThumbupCountDesc(journalId);
|
|
|
|
RedisTemplate redisTemplate, UserClient userClient, CacheChannel cacheChannel) {
|
|
|
|
if(commentList.size()>0){
|
|
|
|
|
|
|
|
commentList= commentList.stream().map(comment -> {
|
|
|
|
|
|
|
|
UserInfoDTO userInfoDTO =userClient.findByUserId(comment.getUserId());
|
|
|
|
|
|
|
|
if(null != userInfoDTO){
|
|
|
|
|
|
|
|
comment.setNickName(userInfoDTO.getNickName());
|
|
|
|
|
|
|
|
comment.setAvatar(Constants.RESOURCE_PREFIX+userInfoDTO.getAvatar());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return comment;
|
|
|
|
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return commentList;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static CommentDTO getCommentDTO(String journalId, MongoTemplate mongoTemplate, CommentDao commentDao, RedisTemplate redisTemplate, UserClient userClient, CacheChannel cacheChannel) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 显示期刊点赞最多5条评论,该五条评论随机显示,每次进入刷新新,超过部分显示为“...”点击评论进入期刊详情页并自动定位到该评论,点击用户头像同上,若为空数据则显示“暂无评论,快去抢沙发吧!
|
|
|
|
* 显示期刊点赞最多5条评论,该五条评论随机显示,每次进入刷新新,超过部分显示为“...”点击评论进入期刊详情页并自动定位到该评论,点击用户头像同上,若为空数据则显示“暂无评论,快去抢沙发吧!
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
CommentDTO commentDTO=new CommentDTO();
|
|
|
|
CommentDTO commentDTO = new CommentDTO();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
commentDTO
|
|
|
|
|
|
|
|
.setCommentList(
|
|
|
|
|
|
|
|
(List<Comment>) cacheChannel
|
|
|
|
|
|
|
|
.get(Constants.J2CACHE_REGION_JOURNAL_HOT_COMMENTS, journalId,
|
|
|
|
commentDTO.setCommentList((List<Comment>) cacheChannel.get(Constants.J2CACHE_REGION_JOURNAL_HOT_COMMENTS,journalId, key-> CommentMapper.getList(journalId,commentDao,userClient),false).getValue());
|
|
|
|
key -> CommentMapper.getList(journalId, commentDao, userClient), false)
|
|
|
|
|
|
|
|
.getValue());
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 获取期刊总评论数 一级评论数加上父评论的总回复数
|
|
|
|
* 获取期刊总评论数 一级评论数加上父评论的总回复数
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
String totalString = "0";
|
|
|
|
String totalString = "0";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
totalString = "0";
|
|
|
|
totalString = "0";
|
|
|
|
Criteria criteria = Criteria.where("journalId").is(journalId);
|
|
|
|
Criteria criteria = Criteria.where("journalId").is(journalId);
|
|
|
|
Aggregation agg = Aggregation.newAggregation(Aggregation.match(criteria), // 匹配条件
|
|
|
|
Aggregation agg = Aggregation.newAggregation(Aggregation.match(criteria), // 匹配条件
|
|
|
@ -109,7 +68,7 @@ public class CommentMapper {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (null != totalCommentVo) {
|
|
|
|
if (null != totalCommentVo) {
|
|
|
|
total = total + totalCommentVo.getTotalComment();
|
|
|
|
total = total + totalCommentVo.getTotalComment();
|
|
|
|
totalString = total +"";
|
|
|
|
totalString = total + "";
|
|
|
|
if (total > 99) {
|
|
|
|
if (total > 99) {
|
|
|
|
totalString = "99+";
|
|
|
|
totalString = "99+";
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -119,6 +78,4 @@ public class CommentMapper {
|
|
|
|
return commentDTO;
|
|
|
|
return commentDTO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|