|
|
@ -21,11 +21,18 @@ import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
|
|
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
|
|
|
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
|
|
|
|
|
import org.springframework.data.mongodb.core.query.Query;
|
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@RestController
|
|
|
|
@CrossOrigin
|
|
|
|
@CrossOrigin
|
|
|
@ -45,6 +52,9 @@ public class CommentController extends BaseController {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private RedisTemplate redisTemplate;
|
|
|
|
private RedisTemplate redisTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private MongoTemplate mongoTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private HttpServletRequest request;
|
|
|
|
private HttpServletRequest request;
|
|
|
@ -64,17 +74,81 @@ public class CommentController extends BaseController {
|
|
|
|
* ,页面在请求添加评论的时候,当给评论添加子评论的时候,父评论parentID有值,就无法添加子评论并且不显示回复2字,控制到两级
|
|
|
|
* ,页面在请求添加评论的时候,当给评论添加子评论的时候,父评论parentID有值,就无法添加子评论并且不显示回复2字,控制到两级
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@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("/{journalId}/{page}/{size}")
|
|
|
|
@GetMapping("/{journalId}/{page}/{size}")
|
|
|
|
public Result findAllByJournalId(@PathVariable String journalId,@PathVariable int page,@PathVariable int size) {
|
|
|
|
public Result findAllByJournalId(@PathVariable String journalId,@PathVariable int page,@PathVariable int size, @RequestHeader(value = "Authorization", required = false) String authorization) {
|
|
|
|
|
|
|
|
//验证是否登录,并且拿到ID
|
|
|
|
|
|
|
|
UserLoginDto userLoginDto = getUserLoginDto(authorization);
|
|
|
|
|
|
|
|
if (null == userLoginDto) {
|
|
|
|
|
|
|
|
Page<Comment> pageList = commentService.findByJournalId(journalId,page,size);
|
|
|
|
|
|
|
|
List<CommentResp> list =pageList.stream().map(x->getCommentResp(x,"")).collect(Collectors.toList());
|
|
|
|
|
|
|
|
return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String userId = userLoginDto.getUserId();
|
|
|
|
|
|
|
|
Page<Comment> pageList = commentService.findByJournalId(journalId,page,size);
|
|
|
|
|
|
|
|
List<CommentResp> list =pageList.stream().map(x->getCommentResp(x,userId)).collect(Collectors.toList());
|
|
|
|
|
|
|
|
return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Page<Comment> pageData = commentService.findByJournalId(journalId,page,size);
|
|
|
|
|
|
|
|
return Result.success(new PageResult<Comment>(pageData.getTotalElements(),pageData.getContent()));
|
|
|
|
@ApiOperation(value = "根据期刊ID获取分页评论列表(热门),按点赞数倒序",notes = "根据期刊ID获取根节点评论分页列表 ,数据库中保存的有期刊号的都是根节点,期刊号为空的代表有父评论且parentID一定有值,拿到当然根节点评论列表,每个根评论有 commentCount字段,页面可以显示有 280个回复,然后根据 @GetMapping(\"/comment/{parentId}/{page}/{size}\") 接口,分页拿到该评论下的子评论列表,页面在请求添加评论的时候,当给评论添加子评论的时候,父评论parentID有值,就无法添加子评论并且不显示回复2字,控制到两级")
|
|
|
|
|
|
|
|
@ApiImplicitParams({@ApiImplicitParam(name = "journalId", value = "剘刊id", required = true),
|
|
|
|
|
|
|
|
@ApiImplicitParam(name = "page", value = "分页: 页码,以1开始", required = true),
|
|
|
|
|
|
|
|
@ApiImplicitParam(name = "size", value = "分页: 每页数量", required = true)})
|
|
|
|
|
|
|
|
@GetMapping("/hot/{journalId}/{page}/{size}")
|
|
|
|
|
|
|
|
public Result findHotByJournalId(@PathVariable String journalId,@PathVariable int page,@PathVariable int size, @RequestHeader(value = "Authorization", required = false) String authorization) {
|
|
|
|
|
|
|
|
//验证是否登录,并且拿到ID
|
|
|
|
|
|
|
|
UserLoginDto userLoginDto = getUserLoginDto(authorization);
|
|
|
|
|
|
|
|
if (null == userLoginDto) {
|
|
|
|
|
|
|
|
Page<Comment> pageList = commentService.findByJournalId(journalId,page,size);
|
|
|
|
|
|
|
|
List<CommentResp> list =pageList.stream().map(x->getCommentResp(x,"")).collect(Collectors.toList());
|
|
|
|
|
|
|
|
return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String userId = userLoginDto.getUserId();
|
|
|
|
|
|
|
|
Page<Comment> pageList = commentService.findHotByJournalId(journalId,page,size);
|
|
|
|
|
|
|
|
List<CommentResp> list =pageList.stream().map(x->getCommentResp(x,userId)).collect(Collectors.toList());
|
|
|
|
|
|
|
|
return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "根据期刊ID获取分页评论列表(最新),按时间倒序",notes = "根据期刊ID获取根节点评论分页列表 ,数据库中保存的有期刊号的都是根节点,期刊号为空的代表有父评论且parentID一定有值,拿到当然根节点评论列表,每个根评论有 commentCount字段,页面可以显示有 280个回复,然后根据 @GetMapping(\"/comment/{parentId}/{page}/{size}\") 接口,分页拿到该评论下的子评论列表,页面在请求添加评论的时候,当给评论添加子评论的时候,父评论parentID有值,就无法添加子评论并且不显示回复2字,控制到两级")
|
|
|
|
|
|
|
|
@ApiImplicitParams({@ApiImplicitParam(name = "journalId", value = "剘刊id", required = true),
|
|
|
|
|
|
|
|
@ApiImplicitParam(name = "page", value = "分页: 页码,以1开始", required = true),
|
|
|
|
|
|
|
|
@ApiImplicitParam(name = "size", value = "分页: 每页数量", required = true)})
|
|
|
|
|
|
|
|
@GetMapping("/new/{journalId}/{page}/{size}")
|
|
|
|
|
|
|
|
public Result findNewByJournalId(@PathVariable String journalId,@PathVariable int page,@PathVariable int size, @RequestHeader(value = "Authorization", required = false) String authorization) {
|
|
|
|
|
|
|
|
//验证是否登录,并且拿到ID
|
|
|
|
|
|
|
|
UserLoginDto userLoginDto = getUserLoginDto(authorization);
|
|
|
|
|
|
|
|
if (null == userLoginDto) {
|
|
|
|
|
|
|
|
Page<Comment> pageList = commentService.findByJournalId(journalId,page,size);
|
|
|
|
|
|
|
|
List<CommentResp> list =pageList.stream().map(x->getCommentResp(x,"")).collect(Collectors.toList());
|
|
|
|
|
|
|
|
return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String userId = userLoginDto.getUserId();
|
|
|
|
|
|
|
|
Page<Comment> pageList = commentService.findNewByJournalId(journalId,page,size);
|
|
|
|
|
|
|
|
List<CommentResp> list =pageList.stream().map(x->getCommentResp(x,userId)).collect(Collectors.toList());
|
|
|
|
|
|
|
|
return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private CommentResp getCommentResp(Comment comment,String userId) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Criteria criteria = Criteria.where("userId").is(userId)
|
|
|
|
|
|
|
|
.and("type").is(2)
|
|
|
|
|
|
|
|
.and("likedItemId").is(comment.get_id());
|
|
|
|
|
|
|
|
// 创建查询对象并应用查询条件
|
|
|
|
|
|
|
|
Query query = new Query(criteria);
|
|
|
|
|
|
|
|
boolean isExists = mongoTemplate.exists(query, PublicationLike.class);
|
|
|
|
|
|
|
|
comment.setHaveThumbup(isExists); //是否已点赞
|
|
|
|
|
|
|
|
CommentResp commentResp = new CommentResp();
|
|
|
|
|
|
|
|
BeanUtils.copyProperties(comment,commentResp);
|
|
|
|
|
|
|
|
commentResp.setThumbupCountString(comment.getThumbupCount()+"");
|
|
|
|
|
|
|
|
if(comment.getThumbupCount()>999) {
|
|
|
|
|
|
|
|
commentResp.setThumbupCountString("999+");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return commentResp;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/{page}/{size}")
|
|
|
|
@GetMapping("/{page}/{size}")
|
|
|
|
public Result search(@PathVariable int page,@PathVariable int size){
|
|
|
|
public Result search(@PathVariable int page,@PathVariable int size){
|
|
|
@ -118,7 +192,17 @@ public class CommentController extends BaseController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@DeleteMapping("/{commentId}")
|
|
|
|
@DeleteMapping("/{commentId}")
|
|
|
|
public Result delete(@PathVariable String commentId) {
|
|
|
|
public Result delete(@PathVariable String commentId,@RequestHeader(value = "Authorization", required = true) String authorization) {
|
|
|
|
|
|
|
|
//验证是否登录,并且拿到ID
|
|
|
|
|
|
|
|
UserLoginDto userLoginDto = getUserLoginDto(authorization);
|
|
|
|
|
|
|
|
if (null == userLoginDto) {
|
|
|
|
|
|
|
|
return Result.unauthorized(null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String userId = userLoginDto.getUserId();
|
|
|
|
|
|
|
|
Comment comment = commentService.findById(commentId);
|
|
|
|
|
|
|
|
if(!userId.equals(comment.get_id())) {
|
|
|
|
|
|
|
|
return Result.failed("您只能删除自己发表的评论");
|
|
|
|
|
|
|
|
}
|
|
|
|
commentService.deleteById(commentId);
|
|
|
|
commentService.deleteById(commentId);
|
|
|
|
return Result.success();
|
|
|
|
return Result.success();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -130,11 +214,19 @@ public class CommentController extends BaseController {
|
|
|
|
@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("/comment/{parentId}/{page}/{size}")
|
|
|
|
@GetMapping("/comment/{parentId}/{page}/{size}")
|
|
|
|
public Result findByParentId(@PathVariable String parentId,@PathVariable int page,@PathVariable int size) {
|
|
|
|
public Result findByParentId(@PathVariable String parentId,@PathVariable int page,@PathVariable int size, @RequestHeader(value = "Authorization", required = false) String authorization) {
|
|
|
|
|
|
|
|
|
|
|
|
Page<Comment> pageData = commentService.findByParentId(parentId,page,size);
|
|
|
|
//验证是否登录,并且拿到ID
|
|
|
|
|
|
|
|
UserLoginDto userLoginDto = getUserLoginDto(authorization);
|
|
|
|
return Result.success(new PageResult<Comment>(pageData.getTotalElements(),pageData.getContent()));
|
|
|
|
if (null == userLoginDto) {
|
|
|
|
|
|
|
|
Page<Comment> pageList = commentService.findByParentId(parentId,page,size);
|
|
|
|
|
|
|
|
List<CommentResp> list =pageList.stream().map(x->getCommentResp(x,"")).collect(Collectors.toList());
|
|
|
|
|
|
|
|
return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String userId = userLoginDto.getUserId();
|
|
|
|
|
|
|
|
Page<Comment> pageList = commentService.findByParentId(parentId,page,size);
|
|
|
|
|
|
|
|
List<CommentResp> list =pageList.stream().map(x->getCommentResp(x,userId)).collect(Collectors.toList());
|
|
|
|
|
|
|
|
return Result.success(new PageResult<CommentResp>(Long.valueOf(list.size()),list));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -159,15 +251,18 @@ public class CommentController extends BaseController {
|
|
|
|
if (flag==0) {
|
|
|
|
if (flag==0) {
|
|
|
|
//当前用户已经点过赞,执行取消点赞
|
|
|
|
//当前用户已经点过赞,执行取消点赞
|
|
|
|
likeService.unlikePublication(commentId,userId,2);
|
|
|
|
likeService.unlikePublication(commentId,userId,2);
|
|
|
|
return Result.success(null,"取消点赞成功");
|
|
|
|
Map map = new HashMap();
|
|
|
|
|
|
|
|
map.put("thumbState",0);
|
|
|
|
|
|
|
|
return Result.success(map,"取消点赞成功");
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
commentService.thumbup(commentId,userLoginDto);
|
|
|
|
commentService.thumbup(commentId,userLoginDto);
|
|
|
|
|
|
|
|
Map map = new HashMap();
|
|
|
|
|
|
|
|
map.put("thumbState",1);
|
|
|
|
// redisTemplate.opsForValue().set("thumbup_"+commentId+"_"+userId,1,10, TimeUnit.SECONDS);
|
|
|
|
// redisTemplate.opsForValue().set("thumbup_"+commentId+"_"+userId,1,10, TimeUnit.SECONDS);
|
|
|
|
return Result.success(null,"点赞成功");
|
|
|
|
return Result.success(map,"点赞成功");
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|