1.remove redundant commment method

main
Gary 8 months ago
parent 9ce74e850c
commit 3f7a38cad1

@ -246,18 +246,6 @@ public class JournalController {
private boolean isLatest10(String journalNo) { private boolean isLatest10(String journalNo) {
return journalService.isLatest10ByJournalNo(journalNo); return journalService.isLatest10ByJournalNo(journalNo);
} }
@ApiOperation(value = "3.2 根据期刊id查询评论信息")
@GetMapping("/comment/{id}")
@GlobalInterceptor
public Result<CommentDTO> findCommentById(
@RequestHeader(value = "Authorization", required = false) String authorization,
@PathVariable @VerifyParam(required = true) String id) {
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
if (null == user && !journalService.isLatest10ByJournalId(id)) {
return Result.unauthorized(null);
}
return Result.success(CommentMapper.getCommentDTO(id,mongoTemplate,commentDao,redisTemplate));
}
@ApiOperation(value = "4.获取期刊筛选条件") @ApiOperation(value = "4.获取期刊筛选条件")
@GetMapping("/filter") @GetMapping("/filter")

@ -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,53 +19,14 @@ 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);
commentDTO.setCommentList(commentList);
/**
*
*/
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);
commentDTO.setTotalCommentReplyInt(total);
return commentDTO;
}
public static List<Comment> getList(String journalId,CommentDao commentDao,UserClient userClient){
List<Comment> commentList =commentDao.findTop2ByJournalIdOrderByThumbupCountDesc(journalId);
if(commentList.size()>0){
commentList= commentList.stream().map(comment -> {
UserInfoDTO userInfoDTO =userClient.findByUserId(comment.getUserId());
if(null != userInfoDTO){
comment.setNickName(userInfoDTO.getNickName()); comment.setNickName(userInfoDTO.getNickName());
comment.setAvatar(Constants.RESOURCE_PREFIX+userInfoDTO.getAvatar()); comment.setAvatar(Constants.RESOURCE_PREFIX + userInfoDTO.getAvatar());
} }
return comment; return comment;
@ -77,24 +35,25 @@ public class CommentMapper {
return commentList; return commentList;
} }
public static CommentDTO getCommentDTO(String journalId, MongoTemplate mongoTemplate, CommentDao commentDao, RedisTemplate redisTemplate, UserClient userClient, CacheChannel cacheChannel) { 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;
} }
} }

@ -55,29 +55,7 @@ public class JournalMapper {
return journalRespDTO; return journalRespDTO;
} }
public static JournalRespDTO getJournalRespDTO(Journal journal, Set<String> journalCollectSet,
MongoTemplate mongoTemplate, RedisTemplate redisTemplate, CommentDao commentDao) {
JournalRespDTO journalRespDTO = getJournalRespDTO(journal, journalCollectSet);
CommentDTO commentDTO = CommentMapper.getCommentDTO(journalRespDTO.getId(), mongoTemplate, commentDao,
redisTemplate);
journalRespDTO.setCommentList(commentDTO.getCommentList());
journalRespDTO.setTotalCommentReply(commentDTO.getTotalCommentReply());
journalRespDTO.setTotalCommentReplyInt(commentDTO.getTotalCommentReplyInt());
return journalRespDTO;
}
public static JournalRespDTO getJournalRespDTO(Journal journal,
MongoTemplate mongoTemplate, RedisTemplate redisTemplate, CommentDao commentDao) {
JournalRespDTO journalRespDTO = getJournalRespDTO(journal);
CommentDTO commentDTO = CommentMapper.getCommentDTO(journalRespDTO.getId(), mongoTemplate, commentDao,
redisTemplate);
journalRespDTO.setCommentList(commentDTO.getCommentList());
journalRespDTO.setTotalCommentReply(commentDTO.getTotalCommentReply());
journalRespDTO.setTotalCommentReplyInt(commentDTO.getTotalCommentReplyInt());
return journalRespDTO;
}
public static JournalRespDTO getJournalRespDTO(Journal journal, public static JournalRespDTO getJournalRespDTO(Journal journal,
MongoTemplate mongoTemplate, RedisTemplate redisTemplate, CommentDao commentDao, UserClient userClient, CacheChannel cacheChannel) { MongoTemplate mongoTemplate, RedisTemplate redisTemplate, CommentDao commentDao, UserClient userClient, CacheChannel cacheChannel) {
JournalRespDTO journalRespDTO = getJournalRespDTO(journal); JournalRespDTO journalRespDTO = getJournalRespDTO(journal);

@ -362,7 +362,7 @@ public class JournalService {
private void updateComment(JournalRespDTO journalRespDTO) { private void updateComment(JournalRespDTO journalRespDTO) {
CommentDTO commentDTO = CommentMapper.getCommentDTO(journalRespDTO.getId(), mongoTemplate, commentDao, CommentDTO commentDTO = CommentMapper.getCommentDTO(journalRespDTO.getId(), mongoTemplate, commentDao,
redisTemplate); redisTemplate,userClient,cacheChannel);
journalRespDTO.setCommentList(commentDTO.getCommentList()); journalRespDTO.setCommentList(commentDTO.getCommentList());
journalRespDTO.setTotalCommentReply(commentDTO.getTotalCommentReply()); journalRespDTO.setTotalCommentReply(commentDTO.getTotalCommentReply());
journalRespDTO.setTotalCommentReplyInt(commentDTO.getTotalCommentReplyInt()); journalRespDTO.setTotalCommentReplyInt(commentDTO.getTotalCommentReplyInt());
@ -391,7 +391,7 @@ public class JournalService {
if(null==journal) { if(null==journal) {
return null; return null;
} }
return JournalMapper.getJournalRespDTO(journal,mongoTemplate,redisTemplate,commentDao); return JournalMapper.getJournalRespDTO(journal,mongoTemplate,redisTemplate,commentDao,userClient,cacheChannel);
} }
public JournalRespDTO queryJournalByJournalNo(String journalNo) { public JournalRespDTO queryJournalByJournalNo(String journalNo) {
@ -403,7 +403,7 @@ public class JournalService {
if(null==journal) { if(null==journal) {
return null; return null;
} }
return JournalMapper.getJournalRespDTO(journal,mongoTemplate,redisTemplate,commentDao); return JournalMapper.getJournalRespDTO(journal,mongoTemplate,redisTemplate,commentDao,userClient,cacheChannel);
} }
public JournalFilterDTO getJournalFilterDTO() { public JournalFilterDTO getJournalFilterDTO() {

Loading…
Cancel
Save