controller
/**
*
* @param page
* @param pageSize
* @return
*/
@GetMapping(“likes”)
public ResponseEntity queryLikeCommentList(@RequestParam(value = “page”, defaultValue = “1”) Integer page,
@RequestParam(value = “pagesize”, defaultValue = “10”) Integer pageSize) {
try {
PageResult pageResult = this.imService.queryLikeCommentList(page, pageSize);
return ResponseEntity.ok(pageResult);
} catch (Exception e) {
log.error(“查询点赞列表失败~ “, e);
}
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
/**
* 查询消息评论列表
*
* @param page
* @param pageSize
* @return
*/
@GetMapping(“comments”)
public ResponseEntity queryUserCommentList(@RequestParam(value = “page”, defaultValue = “1”) Integer page,
@RequestParam(value = “pagesize”, defaultValue = “10”) Integer pageSize) {
try {
PageResult pageResult = this.imService.queryUserCommentList(page, pageSize);
return ResponseEntity.ok(pageResult);
} catch (Exception e) {
log.error(“查询评论列表失败~ “, e);
}
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
/**
* 查询消息喜欢列表
*
* @param page
* @param pageSize
* @return
*/
@GetMapping(“loves”)
public ResponseEntity queryLoveCommentList(@RequestParam(value = “page”, defaultValue = “1”) Integer page,
@RequestParam(value = “pagesize”, defaultValue = “10”) Integer pageSize) {
try {
PageResult pageResult = this.imService.queryLoveCommentList(page, pageSize);
return ResponseEntity.ok(pageResult);
} catch (Exception e) {
log.error(“查询喜欢列表失败~ “, e);
}
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
service
public PageResult queryLikeCommentList(Integer page, Integer pageSize) {
User user = UserThreadLocal.get();
PageInfo pageInfo = this.quanZiApi.queryLikeCommentListByUser(user.getId(), page, pageSize);
return this.fillUserCommentList(pageInfo);
}
public PageResult queryLoveCommentList(Integer page, Integer pageSize) {
User user = UserThreadLocal.get();
PageInfo pageInfo = this.quanZiApi.queryLoveCommentListByUser(user.getId(), page, pageSize);
return this.fillUserCommentList(pageInfo);
}
public PageResult queryUserCommentList(Integer page, Integer pageSize) {
User user = UserThreadLocal.get();
PageInfo pageInfo = this.quanZiApi.queryCommentListByUser(user.getId(), page, pageSize);
return this.fillUserCommentList(pageInfo);
}
private PageResult fillUserCommentList(PageInfo pageInfo){
PageResult pageResult = new PageResult();
pageResult.setPage(pageInfo.getPageNum());
pageResult.setPagesize(pageInfo.getPageSize());
List records = pageInfo.getRecords();
if(CollUtil.isEmpty(records)){
//没有查询到数据
return pageResult;
}
List userIdList = CollUtil.getFieldValues(records, “userId”);
List userInfoList = this.userInfoService.queryUserInfoByUserIdList(userIdList);
List messageCommentVoList = new ArrayList();
for (Comment comment : records) {
for (UserInfo userInfo : userInfoList) {
if(ObjectUtil.equals(comment.getUserId(), userInfo.getUserId())){
MessageCommentVo messageCommentVo = new MessageCommentVo();
messageCommentVo.setId(comment.getId().toHexString());
messageCommentVo.setAvatar(userInfo.getLogo());
messageCommentVo.setNickname(userInfo.getNickName());
messageCommentVo.setCreateDate(DateUtil.format(new Date(comment.getCreated()), “yyyy-MM-dd HH:mm”));
messageCommentVoList.add(messageCommentVo);
break;
}
}
}
pageResult.setItems(messageCommentVoList);
return pageResult;
}