|
|
@ -4,6 +4,7 @@ package com.luoo.comment.controller;
|
|
|
|
import api.PageResult;
|
|
|
|
import api.PageResult;
|
|
|
|
import api.Result;
|
|
|
|
import api.Result;
|
|
|
|
import api.StatusCode;
|
|
|
|
import api.StatusCode;
|
|
|
|
|
|
|
|
import com.luoo.comment.dao.PublicationLikeDao;
|
|
|
|
import com.luoo.comment.pojo.*;
|
|
|
|
import com.luoo.comment.pojo.*;
|
|
|
|
import com.luoo.comment.service.CommentService;
|
|
|
|
import com.luoo.comment.service.CommentService;
|
|
|
|
import com.luoo.comment.service.ComplaintService;
|
|
|
|
import com.luoo.comment.service.ComplaintService;
|
|
|
@ -19,6 +20,7 @@ import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
|
|
import net.oschina.j2cache.CacheChannel;
|
|
|
|
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;
|
|
|
@ -32,10 +34,7 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
import util.IdWorker;
|
|
|
|
import util.IdWorker;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
@ -74,6 +73,12 @@ public class CommentController extends BaseController {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private IdWorker idWorker;
|
|
|
|
private IdWorker idWorker;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private CacheChannel cacheChannel;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private PublicationLikeDao publicationLikeDao;
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping
|
|
|
|
@GetMapping
|
|
|
|
public Result findAll(){
|
|
|
|
public Result findAll(){
|
|
|
|
return Result.success(commentService.findAll());
|
|
|
|
return Result.success(commentService.findAll());
|
|
|
@ -113,35 +118,55 @@ public class CommentController extends BaseController {
|
|
|
|
@ApiImplicitParam(name = "size", value = "分页: 每页数量", required = true)})
|
|
|
|
@ApiImplicitParam(name = "size", value = "分页: 每页数量", required = true)})
|
|
|
|
@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 = getHotList(journalId,page,size);
|
|
|
|
//验证是否登录,并且拿到ID
|
|
|
|
//验证是否登录,并且拿到ID
|
|
|
|
UserLoginDto userLoginDto = getUserLoginDto(authorization);
|
|
|
|
UserLoginDto userLoginDto = getUserLoginDto(authorization);
|
|
|
|
if (null == userLoginDto) {
|
|
|
|
if (null == userLoginDto) {
|
|
|
|
Page<Comment> pageList = commentService.findByJournalId(journalId,page,size);
|
|
|
|
|
|
|
|
List<CommentResp> list =pageList.stream().parallel().map(x->getCommentResp(x,"")).collect(Collectors.toList());
|
|
|
|
|
|
|
|
return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list));
|
|
|
|
return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String userId = userLoginDto.getUserId();
|
|
|
|
String userId = userLoginDto.getUserId();
|
|
|
|
Page<Comment> pageList = commentService.findHotByJournalId(journalId,page,size);
|
|
|
|
|
|
|
|
List<CommentResp> list =pageList.stream().parallel().map(x->getCommentResp(x,userId)).collect(Collectors.toList());
|
|
|
|
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());
|
|
|
|
return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list));
|
|
|
|
return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<CommentResp> getHotList(String journalId,int page,int size) {
|
|
|
|
|
|
|
|
Page<Comment> pageList = commentService.findHotByJournalId(journalId,page,size);
|
|
|
|
|
|
|
|
List<CommentResp> list =pageList.stream().parallel().map(x->getCommentResp(x)).collect(Collectors.toList());
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<CommentResp> getNewList(String journalId,int page,int size) {
|
|
|
|
|
|
|
|
Page<Comment> pageList = commentService.findNewByJournalId(journalId,page,size);
|
|
|
|
|
|
|
|
List<CommentResp> list =pageList.stream().parallel().map(x->getCommentResp(x)).collect(Collectors.toList());
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private CommentResp updateHaveThumbup(CommentResp commentResp,Set<String> publicationLikeSet) {
|
|
|
|
|
|
|
|
commentResp.setHaveThumbup(publicationLikeSet.contains(commentResp.get_id()));
|
|
|
|
|
|
|
|
return commentResp;
|
|
|
|
|
|
|
|
}
|
|
|
|
@ApiOperation(value = "根据期刊ID获取分页评论列表(最新),按时间倒序",notes = "根据期刊ID获取根节点评论分页列表 ,数据库中保存的有期刊号的都是根节点,期刊号为空的代表有父评论且parentID一定有值,拿到当然根节点评论列表,每个根评论有 commentCount字段,页面可以显示有 280个回复,然后根据 @GetMapping(\"/comment/{parentId}/{page}/{size}\") 接口,分页拿到该评论下的子评论列表,页面在请求添加评论的时候,当给评论添加子评论的时候,父评论parentID有值,就无法添加子评论并且不显示回复2字,控制到两级")
|
|
|
|
@ApiOperation(value = "根据期刊ID获取分页评论列表(最新),按时间倒序",notes = "根据期刊ID获取根节点评论分页列表 ,数据库中保存的有期刊号的都是根节点,期刊号为空的代表有父评论且parentID一定有值,拿到当然根节点评论列表,每个根评论有 commentCount字段,页面可以显示有 280个回复,然后根据 @GetMapping(\"/comment/{parentId}/{page}/{size}\") 接口,分页拿到该评论下的子评论列表,页面在请求添加评论的时候,当给评论添加子评论的时候,父评论parentID有值,就无法添加子评论并且不显示回复2字,控制到两级")
|
|
|
|
@ApiImplicitParams({@ApiImplicitParam(name = "journalId", value = "剘刊id", required = true),
|
|
|
|
@ApiImplicitParams({@ApiImplicitParam(name = "journalId", value = "剘刊id", required = true),
|
|
|
|
@ApiImplicitParam(name = "page", value = "分页: 页码,以1开始", required = true),
|
|
|
|
@ApiImplicitParam(name = "page", value = "分页: 页码,以1开始", required = true),
|
|
|
|
@ApiImplicitParam(name = "size", value = "分页: 每页数量", required = true)})
|
|
|
|
@ApiImplicitParam(name = "size", value = "分页: 每页数量", required = true)})
|
|
|
|
@GetMapping("/new/{journalId}/{page}/{size}")
|
|
|
|
@GetMapping("/new/{journalId}/{page}/{size}")
|
|
|
|
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);
|
|
|
|
//验证是否登录,并且拿到ID
|
|
|
|
//验证是否登录,并且拿到ID
|
|
|
|
UserLoginDto userLoginDto = getUserLoginDto(authorization);
|
|
|
|
UserLoginDto userLoginDto = getUserLoginDto(authorization);
|
|
|
|
if (null == userLoginDto) {
|
|
|
|
if (null == userLoginDto) {
|
|
|
|
Page<Comment> pageList = commentService.findByJournalId(journalId,page,size);
|
|
|
|
|
|
|
|
List<CommentResp> list =pageList.stream().parallel().map(x->getCommentResp(x,"")).collect(Collectors.toList());
|
|
|
|
|
|
|
|
return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list));
|
|
|
|
return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String userId = userLoginDto.getUserId();
|
|
|
|
String userId = userLoginDto.getUserId();
|
|
|
|
Page<Comment> pageList = commentService.findNewByJournalId(journalId,page,size);
|
|
|
|
Set<String> publicationLikeSet = publicationLikeDao.findAllByUserId(userId).parallelStream().map(p->p.getLikedItemId()).collect(Collectors.toSet());
|
|
|
|
List<CommentResp> list =pageList.stream().parallel().map(x->getCommentResp(x,userId)).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(list.size()),list));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -165,7 +190,50 @@ public class CommentController extends BaseController {
|
|
|
|
CommentResp commentResp = new CommentResp();
|
|
|
|
CommentResp commentResp = new CommentResp();
|
|
|
|
BeanUtils.copyProperties(comment,commentResp);
|
|
|
|
BeanUtils.copyProperties(comment,commentResp);
|
|
|
|
if(comment.getCommentCount()>0){
|
|
|
|
if(comment.getCommentCount()>0){
|
|
|
|
|
|
|
|
|
|
|
|
Comment topComment = commentService.findByParentId(comment.get_id(),1,1).getContent().get(0);
|
|
|
|
Comment topComment = commentService.findByParentId(comment.get_id(),1,1).getContent().get(0);
|
|
|
|
|
|
|
|
UserInfo topCommentUserInfo = userInfoService.findById(topComment.getUserId());
|
|
|
|
|
|
|
|
topComment.setNickName(topCommentUserInfo.getNickName());
|
|
|
|
|
|
|
|
topComment.setAvatar(Constants.RESOURCE_PREFIX+topCommentUserInfo.getAvatar());
|
|
|
|
|
|
|
|
if(StringUtils.isNotEmpty(topComment.getReplyToUserId())){
|
|
|
|
|
|
|
|
UserInfo topReplyUserInfo = userInfoService.findById(topComment.getReplyToUserId());
|
|
|
|
|
|
|
|
topComment.setReplyToNickname(topReplyUserInfo.getNickName());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
commentResp.setTopChildrenComment(topComment);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
commentResp.setThumbupCountString(comment.getThumbupCount()+"");
|
|
|
|
|
|
|
|
commentResp.setThumbupCountInt(comment.getThumbupCount());
|
|
|
|
|
|
|
|
if(comment.getThumbupCount()>999) {
|
|
|
|
|
|
|
|
commentResp.setThumbupCountString("999+");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return commentResp;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private CommentResp getCommentResp(Comment comment) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UserInfo commentUserInfo = userInfoService.findById(comment.getUserId());
|
|
|
|
|
|
|
|
comment.setNickName(commentUserInfo.getNickName());
|
|
|
|
|
|
|
|
comment.setAvatar(Constants.RESOURCE_PREFIX+commentUserInfo.getAvatar());
|
|
|
|
|
|
|
|
if(StringUtils.isNotEmpty(comment.getReplyToUserId())){
|
|
|
|
|
|
|
|
UserInfo replyToUserInfo = userInfoService.findById(comment.getReplyToUserId());
|
|
|
|
|
|
|
|
comment.setReplyToNickname(replyToUserInfo.getNickName());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
CommentResp commentResp = new CommentResp();
|
|
|
|
|
|
|
|
BeanUtils.copyProperties(comment,commentResp);
|
|
|
|
|
|
|
|
if(comment.getCommentCount()>0){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Comment topComment = commentService.findByParentId(comment.get_id(),1,1).getContent().get(0);
|
|
|
|
|
|
|
|
UserInfo topCommentUserInfo = userInfoService.findById(topComment.getUserId());
|
|
|
|
|
|
|
|
topComment.setNickName(topCommentUserInfo.getNickName());
|
|
|
|
|
|
|
|
topComment.setAvatar(Constants.RESOURCE_PREFIX+topCommentUserInfo.getAvatar());
|
|
|
|
|
|
|
|
if(StringUtils.isNotEmpty(topComment.getReplyToUserId())){
|
|
|
|
|
|
|
|
UserInfo topReplyUserInfo = userInfoService.findById(topComment.getReplyToUserId());
|
|
|
|
|
|
|
|
topComment.setReplyToNickname(topReplyUserInfo.getNickName());
|
|
|
|
|
|
|
|
}
|
|
|
|
commentResp.setTopChildrenComment(topComment);
|
|
|
|
commentResp.setTopChildrenComment(topComment);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
commentResp.setThumbupCountString(comment.getThumbupCount()+"");
|
|
|
|
commentResp.setThumbupCountString(comment.getThumbupCount()+"");
|
|
|
@ -189,7 +257,7 @@ public class CommentController extends BaseController {
|
|
|
|
UserLoginDto userLoginDto = getUserLoginDto(authorization);
|
|
|
|
UserLoginDto userLoginDto = getUserLoginDto(authorization);
|
|
|
|
Comment comment = commentService.findById(commentId);
|
|
|
|
Comment comment = commentService.findById(commentId);
|
|
|
|
if (null == userLoginDto) {
|
|
|
|
if (null == userLoginDto) {
|
|
|
|
CommentResp commentResp = getCommentResp(comment,"");
|
|
|
|
CommentResp commentResp = getCommentResp(comment);
|
|
|
|
return Result.success(commentResp);
|
|
|
|
return Result.success(commentResp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Result.success(getCommentResp(comment,userLoginDto.getUserId()));
|
|
|
|
return Result.success(getCommentResp(comment,userLoginDto.getUserId()));
|
|
|
@ -249,19 +317,27 @@ public class CommentController extends BaseController {
|
|
|
|
@GetMapping("/comment/{parentId}/{page}/{size}")
|
|
|
|
@GetMapping("/comment/{parentId}/{page}/{size}")
|
|
|
|
public Result findByParentId(@PathVariable String parentId,@PathVariable int page,@PathVariable int size, @RequestHeader(value = "Authorization", required = false) String authorization) {
|
|
|
|
public Result findByParentId(@PathVariable String parentId,@PathVariable int page,@PathVariable int size, @RequestHeader(value = "Authorization", required = false) String authorization) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<CommentResp> list = getChildrenCommentList(parentId,page,size);
|
|
|
|
//验证是否登录,并且拿到ID
|
|
|
|
//验证是否登录,并且拿到ID
|
|
|
|
UserLoginDto userLoginDto = getUserLoginDto(authorization);
|
|
|
|
UserLoginDto userLoginDto = getUserLoginDto(authorization);
|
|
|
|
if (null == userLoginDto) {
|
|
|
|
if (null == userLoginDto) {
|
|
|
|
Page<Comment> pageList = commentService.findByParentId(parentId,page,size);
|
|
|
|
|
|
|
|
List<CommentResp> list =pageList.stream().parallel().map(x->getCommentResp(x,"")).collect(Collectors.toList());
|
|
|
|
|
|
|
|
return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list));
|
|
|
|
return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String userId = userLoginDto.getUserId();
|
|
|
|
String userId = userLoginDto.getUserId();
|
|
|
|
Page<Comment> pageList = commentService.findByParentId(parentId,page,size);
|
|
|
|
Set<String> publicationLikeSet = publicationLikeDao.findAllByUserId(userId).parallelStream().map(p->p.getLikedItemId()).collect(Collectors.toSet());
|
|
|
|
List<CommentResp> list =pageList.stream().parallel().map(x->getCommentResp(x,userId)).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(list.size()),list));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<CommentResp> getChildrenCommentList(String parentId,int page,int size) {
|
|
|
|
|
|
|
|
Page<Comment> pageList = commentService.findByParentId(parentId,page,size);
|
|
|
|
|
|
|
|
List<CommentResp> list =pageList.stream().parallel().map(x->getCommentResp(x)).collect(Collectors.toList());
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
|
|
|
}
|
|
|
|
@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) {
|
|
|
|