release-- 抽奖详情增加评论数字段,修复评论模块最新和热门列表总评论数

release-2024-04-25
wangqing 1 month ago
parent 98dcb76e59
commit 6bebe1bf08

@ -138,23 +138,25 @@ public class CommentController extends BaseController {
@GetMapping("/hot/{journalId}/{page}/{size}") @GetMapping("/hot/{journalId}/{page}/{size}")
public Result findHotByJournalId(@PathVariable String journalId,@PathVariable int page,@PathVariable int size, @RequestHeader(value = "Authorization", required = false) String authorization) { public Result findHotByJournalId(@PathVariable String journalId,@PathVariable int page,@PathVariable int size, @RequestHeader(value = "Authorization", required = false) String authorization) {
List<CommentResp> list = (List<CommentResp>) cacheChannel.get(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_HOT+"_"+journalId,page+"_"+size, key->getHotList(journalId,page,size),true).getValue(); List<CommentResp> list = (List<CommentResp>) 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<CommentResp> list = getHotList(journalId,page,size); // List<CommentResp> list = getHotList(journalId,page,size);
//验证是否登录并且拿到ID //验证是否登录并且拿到ID
UserLoginDto userLoginDto = getUserLoginDto(authorization); UserLoginDto userLoginDto = getUserLoginDto(authorization);
if (null == userLoginDto) { if (null == userLoginDto) {
return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list)); return Result.success(new PageResult<CommentResp>(Long.valueOf(count),list));
} }
String userId = userLoginDto.getUserId(); String userId = userLoginDto.getUserId();
Set<String> publicationLikeSet = publicationLikeDao.findAllByUserId(userId).parallelStream().map(p->p.getLikedItemId()).collect(Collectors.toSet()); Set<String> publicationLikeSet = publicationLikeDao.findAllByUserId(userId).parallelStream().map(p->p.getLikedItemId()).collect(Collectors.toSet());
list = list.parallelStream().map(c->updateHaveThumbup(c,publicationLikeSet)).collect(Collectors.toList()); list = list.parallelStream().map(c->updateHaveThumbup(c,publicationLikeSet)).collect(Collectors.toList());
return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list)); return Result.success(new PageResult<CommentResp>(Long.valueOf(count),list));
} }
private List<CommentResp> getHotList(String journalId,int page,int size) { private List<CommentResp> getHotList(String journalId,int page,int size) {
Page<Comment> pageList = commentService.findHotByJournalId(journalId,page,size); Page<Comment> pageList = commentService.findHotByJournalId(journalId,page,size);
List<CommentResp> list =pageList.stream().parallel().map(x->getCommentResp(x)).collect(Collectors.toList()); List<CommentResp> list =pageList.stream().parallel().map(x->getCommentResp(x)).collect(Collectors.toList());
return list; 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) { public Result findNewByJournalId(@PathVariable String journalId,@PathVariable int page,@PathVariable int size, @RequestHeader(value = "Authorization", required = false) String authorization) {
// List<CommentResp> list = getNewList(journalId,page,size); // List<CommentResp> list = getNewList(journalId,page,size);
List<CommentResp> list = (List<CommentResp>) cacheChannel.get(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_NEW+"_"+journalId,page+"_"+size, key->getNewList(journalId,page,size),true).getValue(); List<CommentResp> list = (List<CommentResp>) 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 //验证是否登录并且拿到ID
UserLoginDto userLoginDto = getUserLoginDto(authorization); UserLoginDto userLoginDto = getUserLoginDto(authorization);
if (null == userLoginDto) { if (null == userLoginDto) {
return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list)); return Result.success(new PageResult<CommentResp>(Long.valueOf(count),list));
} }
String userId = userLoginDto.getUserId(); String userId = userLoginDto.getUserId();
Set<String> publicationLikeSet = publicationLikeDao.findAllByUserId(userId).parallelStream().map(p->p.getLikedItemId()).collect(Collectors.toSet()); Set<String> publicationLikeSet = publicationLikeDao.findAllByUserId(userId).parallelStream().map(p->p.getLikedItemId()).collect(Collectors.toSet());
list = list.parallelStream().map(c->updateHaveThumbup(c,publicationLikeSet)).collect(Collectors.toList()); list = list.parallelStream().map(c->updateHaveThumbup(c,publicationLikeSet)).collect(Collectors.toList());
return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list)); return Result.success(new PageResult<CommentResp>(Long.valueOf(count),list));
} }
private CommentResp getCommentResp(Comment comment,String userId) { private CommentResp getCommentResp(Comment comment,String userId) {
@ -436,7 +439,7 @@ public class CommentController extends BaseController {
UserLoginDto userLoginDto = getUserLoginDto(authorization); UserLoginDto userLoginDto = getUserLoginDto(authorization);
if (null == userLoginDto) { if (null == userLoginDto) {
return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list)); return Result.success(new PageResult<CommentResp>(Long.valueOf(count),list));
} }
String userId = userLoginDto.getUserId(); String userId = userLoginDto.getUserId();
Set<String> publicationLikeSet = publicationLikeDao.findAllByUserId(userId).parallelStream().map(p->p.getLikedItemId()).collect(Collectors.toSet()); Set<String> publicationLikeSet = publicationLikeDao.findAllByUserId(userId).parallelStream().map(p->p.getLikedItemId()).collect(Collectors.toSet());
@ -456,6 +459,11 @@ public class CommentController extends BaseController {
Page<Comment> pageList = commentService.findByParentId(parentId,page,size); Page<Comment> pageList = commentService.findByParentId(parentId,page,size);
return pageList.getTotalElements(); return pageList.getTotalElements();
} }
private Long getCommentListCount(String journalId,int page,int size) {
Page<Comment> pageList = commentService.findByJournalId(journalId,page,size);
return pageList.getTotalElements();
}
@ApiOperation(value = "点赞/取消点赞评论",notes = "返回") @ApiOperation(value = "点赞/取消点赞评论",notes = "返回")
@PutMapping("/thumbup/{commentId}") @PutMapping("/thumbup/{commentId}")
public Result thumbup(@PathVariable String commentId,@RequestHeader(value = "Authorization", required = true) String authorization) { public Result thumbup(@PathVariable String commentId,@RequestHeader(value = "Authorization", required = true) String authorization) {

@ -146,6 +146,7 @@ public class CommentService {
cacheChannel.clear(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_CHILDREN+"_"+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_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_HOT+"_"+comment.getRootJournalId());
cacheChannel.clear(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_NEW+"_"+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_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()); rabbitTemplate.convertAndSend(Constants.RABBIT_MESSAGE_CLEAN_JOURANL_QUERY_PAGE,comment.getRootJournalId());
return comment; 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_CHILDREN+"_"+comment.getRootId());
cacheChannel.clear(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_HOT+"_"+comment.getRootJournalId()); cacheChannel.clear(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_HOT+"_"+comment.getRootJournalId());
cacheChannel.clear(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_NEW+"_"+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()); rabbitTemplate.convertAndSend(Constants.RABBIT_MESSAGE_CLEAN_JOURANL_QUERY_PAGE,comment.getRootJournalId());
if (StringUtils.isNotEmpty(comment.getParentId())){ if (StringUtils.isNotEmpty(comment.getParentId())){
cacheChannel.clear(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_CHILDREN+"_"+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_CHILDREN_COUNT,comment.getParentId());
cacheChannel.evict(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_COUNT,comment.getRootJournalId());
Query query = new Query(); Query query = new Query();
query.addCriteria(Criteria.where("_id").is(comment.getRootId())); query.addCriteria(Criteria.where("_id").is(comment.getRootId()));
Update update = new Update(); Update update = new Update();
@ -228,6 +232,8 @@ public class CommentService {
return commentDao.findByJournalIdOrderByThumbupCountDescPublishTimeDesc(journalId,pageable); return commentDao.findByJournalIdOrderByThumbupCountDescPublishTimeDesc(journalId,pageable);
} }
public Page<Comment> findNewByJournalId(String journalId, int page, int size) { public Page<Comment> findNewByJournalId(String journalId, int page, int size) {
Pageable pageable = PageRequest.of(page-1,size); Pageable pageable = PageRequest.of(page-1,size);

@ -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_PAGE = "journal_query_page";
public static final String J2CACHE_REGION_JOURNAL_QUERY_COUNT = "journal_query_count"; 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_ID = "journal_id";
public static final String J2CACHE_REGION_JOURNAL_NO = "journal_no"; public static final String J2CACHE_REGION_JOURNAL_NO = "journal_no";
public static final String J2CACHE_REGION_JOURNAL_NO_SONG_ID = "journal_song_key"; 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 = "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_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_SEARCH_AUTO_COMPLETE = "search_auto_complete";
public static final String J2CACHE_REGION_JOURNAL_HOT_COMMENTS = "journal_hot_comments"; public static final String J2CACHE_REGION_JOURNAL_HOT_COMMENTS = "journal_hot_comments";

@ -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<Comment,String> {
public Page<Comment> findByParentId(String parentId, Pageable pageable);
public Page<Comment> findByRootIdAndReplyToUserIdNotNullOrderByPublishTimeDesc(String rootId, Pageable pageable);
public Page<Comment> findByRootIdAndReplyToUserIdNotNullOrderByThumbupCountDescPublishTimeDesc(String rootId, Pageable pageable);
public Page<Comment> findByJournalId(String journalId, Pageable pageable);
public Page<Comment> findByJournalIdOrderByPublishTimeDesc(String journalId, Pageable pageable);
public Page<Comment> findByJournalIdOrderByThumbupCountDesc(String journalId, Pageable pageable);
public Page<Comment> findByJournalIdOrderByThumbupCountDescPublishTimeDesc(String journalId, Pageable pageable);
public Page<Comment> findAllByOrderByPublishTimeDesc(Pageable pageable);
public List<Comment> findAllByUserId(String userId);
}

@ -1,10 +1,14 @@
package com.luoo.user.pojo; package com.luoo.user.pojo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.List;
@Data @Data
@ -16,6 +20,8 @@ public class Comment implements Serializable {
// 评论内容 // 评论内容
private String content; 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 Date publishTime;
private String userId; private String userId;
@ -34,6 +40,8 @@ public class Comment implements Serializable {
// 状态 // 状态
private Integer state; private Integer state;
private Integer type;
private String location; //归属地 private String location; //归属地
/** /**
@ -42,4 +50,31 @@ public class Comment implements Serializable {
private String parentId; private String parentId;
private String journalId; 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<Integer> badgeList;
/**
* 10
*/
private Integer isBetaUser;
} }

@ -31,6 +31,8 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeanUtils; 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.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
@ -94,6 +96,9 @@ public class LotteryService {
private final UserPointLogDao userPointLogDao; 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, 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) { UserPointLogDao userPointLogDao) {
this.lotteryDao = lotteryDao; this.lotteryDao = lotteryDao;
@ -904,6 +909,9 @@ public class LotteryService {
result.setParticipateNum(participateNum); result.setParticipateNum(participateNum);
result.setSystemTime(LocalDateTime.now()); result.setSystemTime(LocalDateTime.now());
Pageable pageable = PageRequest.of(0,1);
Page<Comment> pageList =commentDao.findByJournalId(lotteryId, pageable);
result.setTotalCommentNum(pageList.getTotalElements());
return result; return result;
} }

@ -71,6 +71,9 @@ public class LotteryDetailAPPVO implements Serializable {
@ApiModelProperty(value = "抽奖状态 0-编辑中 1-报名中 2-已抽奖 3-已停止") @ApiModelProperty(value = "抽奖状态 0-编辑中 1-报名中 2-已抽奖 3-已停止")
private Integer status; private Integer status;
@ApiModelProperty(value = "总评论数")
private Long totalCommentNum;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty("创建时间") @ApiModelProperty("创建时间")

Loading…
Cancel
Save