显示好友对自己发布内容 点赞 喜欢 评论信息 逻辑 参考代码

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;

}

郑重声明:本文内容及图片均整理自互联网,不代表本站立场,版权归原作者所有,如有侵权请联系管理员(admin#wlmqw.com)删除。
上一篇 2022年6月17日 18:21
下一篇 2022年6月17日 18:22

相关推荐

联系我们

联系邮箱:admin#wlmqw.com
工作时间:周一至周五,10:30-18:30,节假日休息