fix commentList sort && optimize journal hotCommentList

main
wangqing 8 months ago
parent 783fc2ad16
commit 6dbc6d2345

@ -310,7 +310,15 @@ public class CommentController extends BaseController {
comment.setAvatar(Constants.RESOURCE_PREFIX+userLoginDto.getAvatar()); comment.setAvatar(Constants.RESOURCE_PREFIX+userLoginDto.getAvatar());
comment.setLocation(IpUtil.getIpLocation(getIpAddr(request))); comment.setLocation(IpUtil.getIpLocation(getIpAddr(request)));
Comment commentResp = commentService.save(comment,userLoginDto); Comment commentResp = commentService.save(comment,userLoginDto);
UserInfo commentUserInfo = userInfoService.findById(comment.getUserId());
if (StringUtils.isNotEmpty(commentUserInfo.getBadges())){
Set<Integer> badgeSet = new HashSet<>();
Arrays.stream(commentUserInfo.getBadges().split(",")).forEach(b->{
int code=Integer.valueOf(b.substring(0, 1));
badgeSet.add(code);
});
commentResp.setBadgeList(new ArrayList<>(badgeSet));
}
return Result.success(commentResp); return Result.success(commentResp);
} }

@ -11,6 +11,7 @@ public interface CommentDao extends MongoRepository<Comment,String> {
public Page<Comment> findByParentId(String parentId, Pageable pageable); public Page<Comment> findByParentId(String parentId, Pageable pageable);
public Page<Comment> findByRootIdAndReplyToUserIdNotNullOrderByPublishTimeDesc(String rootId, 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> findByJournalId(String journalId, Pageable pageable);
public Page<Comment> findByJournalIdOrderByPublishTimeDesc(String journalId, Pageable pageable); public Page<Comment> findByJournalIdOrderByPublishTimeDesc(String journalId, Pageable pageable);
public Page<Comment> findByJournalIdOrderByThumbupCountDesc(String journalId, Pageable pageable); public Page<Comment> findByJournalIdOrderByThumbupCountDesc(String journalId, Pageable pageable);

@ -1,12 +1,14 @@
package com.luoo.comment.pojo; package com.luoo.comment.pojo;
import com.fasterxml.jackson.annotation.JsonFormat; 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 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
@ -63,4 +65,8 @@ public class Comment implements Serializable {
private String replyToNickname; private String replyToNickname;
@ApiModelProperty(value = "用户标识,贡献者:1 ")
private List<Integer> badgeList;
} }

@ -198,7 +198,7 @@ public class CommentService {
public Page<Comment> findByParentId(String parentId, int page, int size) { public Page<Comment> findByParentId(String parentId, int page, int size) {
Pageable pageable = PageRequest.of(page-1,size); Pageable pageable = PageRequest.of(page-1,size);
return commentDao.findByRootIdAndReplyToUserIdNotNullOrderByPublishTimeDesc(parentId,pageable); return commentDao.findByRootIdAndReplyToUserIdNotNullOrderByThumbupCountDescPublishTimeDesc(parentId,pageable);
} }

@ -87,7 +87,7 @@ public class CommentMapper {
commentDTO.setCommentList((List<Comment>) cacheChannel.get(Constants.J2CACHE_REGION_JOURNAL_HOT_COMMENTS,journalId, key-> CommentMapper.getList(journalId,commentDao,userClient),false)); commentDTO.setCommentList((List<Comment>) cacheChannel.get(Constants.J2CACHE_REGION_JOURNAL_HOT_COMMENTS,journalId, key-> CommentMapper.getList(journalId,commentDao,userClient),false).getValue());
/** /**
* *
*/ */

Loading…
Cancel
Save