|
|
|
@ -6,7 +6,8 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import com.luoo.music.client.UserClient;
|
|
|
|
|
import com.luoo.music.dto.response.UserInfoDTO;
|
|
|
|
|
import com.luoo.music.util.Constants;
|
|
|
|
|
import constants.Constants;
|
|
|
|
|
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;
|
|
|
|
@ -26,14 +27,6 @@ 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 =commentDao.findTop5ByJournalIdOrderByThumbupCountDesc(journalId);
|
|
|
|
|
commentDTO.setCommentList(commentList);
|
|
|
|
@ -41,35 +34,8 @@ public class CommentMapper {
|
|
|
|
|
* 获取期刊总评论数 一级评论数加上父评论的总回复数
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
@ -95,67 +61,39 @@ public class CommentMapper {
|
|
|
|
|
return commentDTO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static CommentDTO getCommentDTO(String journalId, MongoTemplate mongoTemplate, CommentDao commentDao, RedisTemplate redisTemplate, UserClient userClient) {
|
|
|
|
|
public static List<Comment> getList(String journalId,CommentDao commentDao,UserClient userClient){
|
|
|
|
|
List<Comment> commentList =commentDao.findTop5ByJournalIdOrderByThumbupCountDesc(journalId);
|
|
|
|
|
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条评论,该五条评论随机显示,每次进入刷新新,超过部分显示为“...”点击评论进入期刊详情页并自动定位到该评论,点击用户头像同上,若为空数据则显示“暂无评论,快去抢沙发吧!
|
|
|
|
|
*/
|
|
|
|
|
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 =commentDao.findTop5ByJournalIdOrderByThumbupCountDesc(journalId);
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
commentDTO.setCommentList(commentList);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
commentDTO.setCommentList((List<Comment>) cacheChannel.get(Constants.J2CACHE_REGION_JOURNAL_HOT_COMMENTS,journalId, key-> CommentMapper.getList(journalId,commentDao,userClient),false));
|
|
|
|
|
/**
|
|
|
|
|
* 获取期刊总评论数 一级评论数加上父评论的总回复数
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|