评论排序、分页
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.peanut.modules.bookAbroad.controller;
|
package com.peanut.modules.bookAbroad.controller;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.peanut.common.utils.R;
|
import com.peanut.common.utils.R;
|
||||||
import com.peanut.common.utils.ShiroUtils;
|
import com.peanut.common.utils.ShiroUtils;
|
||||||
import com.peanut.modules.bookAbroad.service.BookAbroadCommentLikeService;
|
import com.peanut.modules.bookAbroad.service.BookAbroadCommentLikeService;
|
||||||
@@ -41,23 +42,30 @@ public class BookAbroadController {
|
|||||||
//评论树
|
//评论树
|
||||||
@RequestMapping("/getBookAbroadCommentTree")
|
@RequestMapping("/getBookAbroadCommentTree")
|
||||||
public R getBookAbroadCommentTree(@RequestBody Map<String,Object> params) {
|
public R getBookAbroadCommentTree(@RequestBody Map<String,Object> params) {
|
||||||
|
int current = Integer.parseInt(params.get("current").toString())-1;
|
||||||
|
int limit = Integer.parseInt(params.get("limit").toString());
|
||||||
List<BookAbroadComment> comments = bookAbroadCommentService.list(new LambdaQueryWrapper<BookAbroadComment>()
|
List<BookAbroadComment> comments = bookAbroadCommentService.list(new LambdaQueryWrapper<BookAbroadComment>()
|
||||||
.eq(BookAbroadComment::getBookId,params.get("bookId")));
|
.eq(BookAbroadComment::getBookId,params.get("bookId"))
|
||||||
List<BookAbroadComment> commentsTree = comments.stream().filter((bookAbroadComment) ->
|
.orderByDesc(BookAbroadComment::getId));
|
||||||
bookAbroadComment.getPid() == 0
|
int commentsCount = comments.stream().filter((bookAbroadComment) -> bookAbroadComment.getPid() == 0).collect(Collectors.toList()).size();
|
||||||
).map((comment)->{
|
List<BookAbroadComment> commentsTree = comments.stream()
|
||||||
comment.setIsLike(bookAbroadCommentLikeService.count(new LambdaQueryWrapper<BookAbroadCommentLike>()
|
.filter((bookAbroadComment) -> bookAbroadComment.getPid() == 0)
|
||||||
.eq(BookAbroadCommentLike::getCommentId,comment.getId())
|
.map((comment)->{
|
||||||
.eq(BookAbroadCommentLike::getUserId,ShiroUtils.getUId())));
|
comment.setIsLike(bookAbroadCommentLikeService.count(new LambdaQueryWrapper<BookAbroadCommentLike>()
|
||||||
comment.setLikeCount(bookAbroadCommentLikeService.count(new LambdaQueryWrapper<BookAbroadCommentLike>()
|
.eq(BookAbroadCommentLike::getCommentId,comment.getId())
|
||||||
.eq(BookAbroadCommentLike::getCommentId,comment.getId())));
|
.eq(BookAbroadCommentLike::getUserId,ShiroUtils.getUId())));
|
||||||
comment.setUserEntity(userService.getOne(new LambdaQueryWrapper<MyUserEntity>()
|
comment.setLikeCount(bookAbroadCommentLikeService.count(new LambdaQueryWrapper<BookAbroadCommentLike>()
|
||||||
.select(MyUserEntity::getId,MyUserEntity::getName,MyUserEntity::getNickname,MyUserEntity::getAvatar)
|
.eq(BookAbroadCommentLike::getCommentId,comment.getId())));
|
||||||
.eq(MyUserEntity::getId,comment.getUserId())));
|
comment.setUserEntity(userService.getOne(new LambdaQueryWrapper<MyUserEntity>()
|
||||||
comment.setChildren(getLabelChildrens(comment,comments));
|
.select(MyUserEntity::getId,MyUserEntity::getName,MyUserEntity::getNickname,MyUserEntity::getAvatar)
|
||||||
return comment;
|
.eq(MyUserEntity::getId,comment.getUserId())));
|
||||||
}).collect(Collectors.toList());
|
comment.setChildren(getLabelChildrens(comment,comments));
|
||||||
return R.ok().put("commentsTree",commentsTree);
|
return comment; })
|
||||||
|
.sorted((comment1,comment2)->{
|
||||||
|
return comment2.getLikeCount() - comment1.getLikeCount();})
|
||||||
|
.collect(Collectors.toList())
|
||||||
|
.subList(current*limit,((current*limit)+limit)<commentsCount?((current*limit)+limit):commentsCount);
|
||||||
|
return R.ok().put("commentsCount",commentsCount).put("commentsTree",commentsTree);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<BookAbroadComment> getLabelChildrens(BookAbroadComment root,List<BookAbroadComment> all){
|
private List<BookAbroadComment> getLabelChildrens(BookAbroadComment root,List<BookAbroadComment> all){
|
||||||
@@ -67,6 +75,8 @@ public class BookAbroadController {
|
|||||||
bookAbroadComment.setIsLike(bookAbroadCommentLikeService.count(new LambdaQueryWrapper<BookAbroadCommentLike>()
|
bookAbroadComment.setIsLike(bookAbroadCommentLikeService.count(new LambdaQueryWrapper<BookAbroadCommentLike>()
|
||||||
.eq(BookAbroadCommentLike::getCommentId,bookAbroadComment.getId())
|
.eq(BookAbroadCommentLike::getCommentId,bookAbroadComment.getId())
|
||||||
.eq(BookAbroadCommentLike::getUserId,ShiroUtils.getUId())));
|
.eq(BookAbroadCommentLike::getUserId,ShiroUtils.getUId())));
|
||||||
|
bookAbroadComment.setLikeCount(bookAbroadCommentLikeService.count(new LambdaQueryWrapper<BookAbroadCommentLike>()
|
||||||
|
.eq(BookAbroadCommentLike::getCommentId,bookAbroadComment.getId())));
|
||||||
bookAbroadComment.setUserEntity(userService.getOne(new LambdaQueryWrapper<MyUserEntity>()
|
bookAbroadComment.setUserEntity(userService.getOne(new LambdaQueryWrapper<MyUserEntity>()
|
||||||
.select(MyUserEntity::getId,MyUserEntity::getName,MyUserEntity::getNickname,MyUserEntity::getAvatar)
|
.select(MyUserEntity::getId,MyUserEntity::getName,MyUserEntity::getNickname,MyUserEntity::getAvatar)
|
||||||
.eq(MyUserEntity::getId,bookAbroadComment.getUserId())));
|
.eq(MyUserEntity::getId,bookAbroadComment.getUserId())));
|
||||||
@@ -97,7 +107,9 @@ public class BookAbroadController {
|
|||||||
//取消点赞
|
//取消点赞
|
||||||
@RequestMapping("/delBookAbroadCommentLike")
|
@RequestMapping("/delBookAbroadCommentLike")
|
||||||
public R delBookAbroadCommentLike(@RequestBody Map<String,Object> params){
|
public R delBookAbroadCommentLike(@RequestBody Map<String,Object> params){
|
||||||
bookAbroadCommentLikeService.removeById(params.get("commentLikeId").toString());
|
bookAbroadCommentLikeService.remove(new LambdaQueryWrapper<BookAbroadCommentLike>()
|
||||||
|
.eq(BookAbroadCommentLike::getCommentId,params.get("commentId"))
|
||||||
|
.eq(BookAbroadCommentLike::getUserId,ShiroUtils.getUId()));
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user