diff --git a/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java b/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java index 54abf34..0d44701 100644 --- a/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java +++ b/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java @@ -138,23 +138,25 @@ public class CommentController extends BaseController { @GetMapping("/hot/{journalId}/{page}/{size}") public Result findHotByJournalId(@PathVariable String journalId,@PathVariable int page,@PathVariable int size, @RequestHeader(value = "Authorization", required = false) String authorization) { List list = (List) cacheChannel.get(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_HOT+"_"+journalId,page+"_"+size, key->getHotList(journalId,page,size),true).getValue(); + String count = cacheChannel.get(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_COUNT,journalId, key->getCommentListCount(journalId,page,size),true).getValue().toString(); // List list = getHotList(journalId,page,size); //验证是否登录,并且拿到ID UserLoginDto userLoginDto = getUserLoginDto(authorization); if (null == userLoginDto) { - return Result.success(new PageResult(Long.valueOf(list.size()),list)); + return Result.success(new PageResult(Long.valueOf(count),list)); } String userId = userLoginDto.getUserId(); Set publicationLikeSet = publicationLikeDao.findAllByUserId(userId).parallelStream().map(p->p.getLikedItemId()).collect(Collectors.toSet()); list = list.parallelStream().map(c->updateHaveThumbup(c,publicationLikeSet)).collect(Collectors.toList()); - return Result.success(new PageResult(Long.valueOf(list.size()),list)); + return Result.success(new PageResult(Long.valueOf(count),list)); } private List getHotList(String journalId,int page,int size) { Page pageList = commentService.findHotByJournalId(journalId,page,size); + List list =pageList.stream().parallel().map(x->getCommentResp(x)).collect(Collectors.toList()); return list; } @@ -178,16 +180,17 @@ public class CommentController extends BaseController { public Result findNewByJournalId(@PathVariable String journalId,@PathVariable int page,@PathVariable int size, @RequestHeader(value = "Authorization", required = false) String authorization) { // List list = getNewList(journalId,page,size); List list = (List) cacheChannel.get(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_NEW+"_"+journalId,page+"_"+size, key->getNewList(journalId,page,size),true).getValue(); + String count = cacheChannel.get(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_COUNT,journalId, key->getCommentListCount(journalId,page,size),true).getValue().toString(); //验证是否登录,并且拿到ID UserLoginDto userLoginDto = getUserLoginDto(authorization); if (null == userLoginDto) { - return Result.success(new PageResult(Long.valueOf(list.size()),list)); + return Result.success(new PageResult(Long.valueOf(count),list)); } String userId = userLoginDto.getUserId(); Set publicationLikeSet = publicationLikeDao.findAllByUserId(userId).parallelStream().map(p->p.getLikedItemId()).collect(Collectors.toSet()); list = list.parallelStream().map(c->updateHaveThumbup(c,publicationLikeSet)).collect(Collectors.toList()); - return Result.success(new PageResult(Long.valueOf(list.size()),list)); + return Result.success(new PageResult(Long.valueOf(count),list)); } private CommentResp getCommentResp(Comment comment,String userId) { @@ -436,7 +439,7 @@ public class CommentController extends BaseController { UserLoginDto userLoginDto = getUserLoginDto(authorization); if (null == userLoginDto) { - return Result.success(new PageResult(Long.valueOf(list.size()),list)); + return Result.success(new PageResult(Long.valueOf(count),list)); } String userId = userLoginDto.getUserId(); Set publicationLikeSet = publicationLikeDao.findAllByUserId(userId).parallelStream().map(p->p.getLikedItemId()).collect(Collectors.toSet()); @@ -456,6 +459,11 @@ public class CommentController extends BaseController { Page pageList = commentService.findByParentId(parentId,page,size); return pageList.getTotalElements(); } + + private Long getCommentListCount(String journalId,int page,int size) { + Page pageList = commentService.findByJournalId(journalId,page,size); + return pageList.getTotalElements(); + } @ApiOperation(value = "点赞/取消点赞评论",notes = "返回") @PutMapping("/thumbup/{commentId}") public Result thumbup(@PathVariable String commentId,@RequestHeader(value = "Authorization", required = true) String authorization) { diff --git a/luoo_comment/src/main/java/com/luoo/comment/service/CommentService.java b/luoo_comment/src/main/java/com/luoo/comment/service/CommentService.java index 63fa9e9..a926410 100644 --- a/luoo_comment/src/main/java/com/luoo/comment/service/CommentService.java +++ b/luoo_comment/src/main/java/com/luoo/comment/service/CommentService.java @@ -146,6 +146,7 @@ public class CommentService { cacheChannel.clear(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_CHILDREN+"_"+comment.getParentId()); cacheChannel.evict(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_CHILDREN_COUNT,comment.getParentId()); + cacheChannel.evict(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_COUNT,comment.getRootJournalId()); } @@ -154,6 +155,7 @@ public class CommentService { cacheChannel.clear(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_HOT+"_"+comment.getRootJournalId()); cacheChannel.clear(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_NEW+"_"+comment.getRootJournalId()); cacheChannel.evict(Constants.J2CACHE_REGION_JOURNAL_HOT_COMMENTS,comment.getRootJournalId()); + cacheChannel.evict(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_COUNT,comment.getRootJournalId()); rabbitTemplate.convertAndSend(Constants.RABBIT_MESSAGE_CLEAN_JOURANL_QUERY_PAGE,comment.getRootJournalId()); return comment; } @@ -168,11 +170,13 @@ public class CommentService { cacheChannel.clear(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_CHILDREN+"_"+comment.getRootId()); cacheChannel.clear(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_HOT+"_"+comment.getRootJournalId()); cacheChannel.clear(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_NEW+"_"+comment.getRootJournalId()); + cacheChannel.evict(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_COUNT,comment.getRootJournalId()); rabbitTemplate.convertAndSend(Constants.RABBIT_MESSAGE_CLEAN_JOURANL_QUERY_PAGE,comment.getRootJournalId()); if (StringUtils.isNotEmpty(comment.getParentId())){ cacheChannel.clear(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_CHILDREN+"_"+comment.getParentId()); cacheChannel.evict(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_CHILDREN_COUNT,comment.getParentId()); + cacheChannel.evict(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_COUNT,comment.getRootJournalId()); Query query = new Query(); query.addCriteria(Criteria.where("_id").is(comment.getRootId())); Update update = new Update(); @@ -228,6 +232,8 @@ public class CommentService { return commentDao.findByJournalIdOrderByThumbupCountDescPublishTimeDesc(journalId,pageable); } + + public Page findNewByJournalId(String journalId, int page, int size) { Pageable pageable = PageRequest.of(page-1,size); diff --git a/luoo_common/src/main/java/constants/Constants.java b/luoo_common/src/main/java/constants/Constants.java index e6da96c..1f40e4f 100644 --- a/luoo_common/src/main/java/constants/Constants.java +++ b/luoo_common/src/main/java/constants/Constants.java @@ -14,6 +14,7 @@ public class Constants { public static final String J2CACHE_REGION_JOURNAL_QUERY_PAGE = "journal_query_page"; public static final String J2CACHE_REGION_JOURNAL_QUERY_COUNT = "journal_query_count"; + public static final String J2CACHE_REGION_JOURNAL_ID = "journal_id"; public static final String J2CACHE_REGION_JOURNAL_NO = "journal_no"; public static final String J2CACHE_REGION_JOURNAL_NO_SONG_ID = "journal_song_key"; @@ -25,6 +26,7 @@ public class Constants { public static final String J2CACHE_REGION_JOURNAL_COMMENT_PAGE_CHILDREN = "journal_comment_page_children"; public static final String J2CACHE_REGION_JOURNAL_COMMENT_PAGE_CHILDREN_COUNT = "journal_comment_page_children_count"; + public static final String J2CACHE_REGION_JOURNAL_COMMENT_PAGE_COUNT = "journal_comment_page_count"; public static final String J2CACHE_REGION_SEARCH_AUTO_COMPLETE = "search_auto_complete"; public static final String J2CACHE_REGION_JOURNAL_HOT_COMMENTS = "journal_hot_comments"; diff --git a/luoo_user/src/main/java/com/luoo/user/dao/CommentDao.java b/luoo_user/src/main/java/com/luoo/user/dao/CommentDao.java new file mode 100644 index 0000000..bde1697 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/dao/CommentDao.java @@ -0,0 +1,24 @@ +package com.luoo.user.dao; + +import com.luoo.user.pojo.Comment; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.mongodb.repository.MongoRepository; + +import java.util.List; + +public interface CommentDao extends MongoRepository { + + public Page findByParentId(String parentId, Pageable pageable); + public Page findByRootIdAndReplyToUserIdNotNullOrderByPublishTimeDesc(String rootId, Pageable pageable); + public Page findByRootIdAndReplyToUserIdNotNullOrderByThumbupCountDescPublishTimeDesc(String rootId, Pageable pageable); + public Page findByJournalId(String journalId, Pageable pageable); + public Page findByJournalIdOrderByPublishTimeDesc(String journalId, Pageable pageable); + public Page findByJournalIdOrderByThumbupCountDesc(String journalId, Pageable pageable); + public Page findByJournalIdOrderByThumbupCountDescPublishTimeDesc(String journalId, Pageable pageable); + + public Page findAllByOrderByPublishTimeDesc(Pageable pageable); + + + public List findAllByUserId(String userId); +} diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/Comment.java b/luoo_user/src/main/java/com/luoo/user/pojo/Comment.java index 74e60b2..11de8a5 100644 --- a/luoo_user/src/main/java/com/luoo/user/pojo/Comment.java +++ b/luoo_user/src/main/java/com/luoo/user/pojo/Comment.java @@ -1,10 +1,14 @@ package com.luoo.user.pojo; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import org.springframework.data.annotation.Id; +import org.springframework.format.annotation.DateTimeFormat; import java.io.Serializable; import java.util.Date; +import java.util.List; @Data @@ -16,6 +20,8 @@ public class Comment implements Serializable { // 评论内容 private String content; // 发布时间 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date publishTime; private String userId; @@ -34,6 +40,8 @@ public class Comment implements Serializable { // 状态 private Integer state; + private Integer type; + private String location; //归属地 /** @@ -42,4 +50,31 @@ public class Comment implements Serializable { private String parentId; private String journalId; + + private String journalImage; + + private boolean haveThumbup; + + /** + * + */ + private String rootId; + + private String rootJournalId; + + private String rootJournalName; + + private String replyToUserId; + + private String replyToNickname; + + + @ApiModelProperty(value = "用户标识,贡献者:1 ") + private List badgeList; + + + /** + * 是否内测用户,1表示是,0表示不是 + */ + private Integer isBetaUser; } diff --git a/luoo_user/src/main/java/com/luoo/user/service/LotteryService.java b/luoo_user/src/main/java/com/luoo/user/service/LotteryService.java index f2fe293..f0c9266 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/LotteryService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/LotteryService.java @@ -31,6 +31,8 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.domain.Specification; @@ -94,6 +96,9 @@ public class LotteryService { private final UserPointLogDao userPointLogDao; + @Autowired + private CommentDao commentDao; + public LotteryService(LotteryDao lotteryDao, JwtUtil jwtUtil, IdWorker idWorker, RedisLockUtil redisLockUtil, RegionService regionService, LotteryRegionDao lotteryRegionDao, UserInfoDao userInfoDao, RabbitTemplate rabbitTemplate, LotteryUserDao lotteryUserDao, DrawLotteryScheduler drawLotteryScheduler, JPAQueryFactory jpaQueryFactory, EnvConfig envConfig, UserinfoShippingAddressService userinfoShippingAddressService, UserPointLogService userPointLogService, UserPointLogDao userPointLogDao) { this.lotteryDao = lotteryDao; @@ -904,6 +909,9 @@ public class LotteryService { result.setParticipateNum(participateNum); result.setSystemTime(LocalDateTime.now()); + Pageable pageable = PageRequest.of(0,1); + Page pageList =commentDao.findByJournalId(lotteryId, pageable); + result.setTotalCommentNum(pageList.getTotalElements()); return result; } diff --git a/luoo_user/src/main/java/com/luoo/user/vo/point/LotteryDetailAPPVO.java b/luoo_user/src/main/java/com/luoo/user/vo/point/LotteryDetailAPPVO.java index 8abf4d2..190a636 100644 --- a/luoo_user/src/main/java/com/luoo/user/vo/point/LotteryDetailAPPVO.java +++ b/luoo_user/src/main/java/com/luoo/user/vo/point/LotteryDetailAPPVO.java @@ -71,6 +71,9 @@ public class LotteryDetailAPPVO implements Serializable { @ApiModelProperty(value = "抽奖状态 0-编辑中 1-报名中 2-已抽奖 3-已停止") private Integer status; + @ApiModelProperty(value = "总评论数") + private Long totalCommentNum; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @ApiModelProperty("创建时间")