CommentController.java 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package com.ruoyi.web.controller.front;
  2. import cn.hutool.core.util.RandomUtil;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.ruoyi.common.core.domain.AjaxResult;
  5. import com.ruoyi.common.enums.ApprovalStatus;
  6. import com.ruoyi.common.enums.CommentType;
  7. import com.ruoyi.common.utils.ip.IpUtils;
  8. import com.ruoyi.framework.security.anno.IgnoreAuth;
  9. import com.ruoyi.system.domain.ZbComment;
  10. import com.ruoyi.system.service.IZbCommentService;
  11. import io.swagger.annotations.Api;
  12. import io.swagger.annotations.ApiImplicitParam;
  13. import io.swagger.annotations.ApiImplicitParams;
  14. import io.swagger.annotations.ApiOperation;
  15. import lombok.RequiredArgsConstructor;
  16. import org.springframework.web.bind.annotation.*;
  17. import javax.servlet.http.HttpServletRequest;
  18. import java.util.Date;
  19. import java.util.List;
  20. /**
  21. * @author Admin
  22. * @date 2020/12/2
  23. */
  24. @IgnoreAuth
  25. @RestController
  26. @RequestMapping("/front/comment")
  27. @RequiredArgsConstructor
  28. @Api("评论相关接口")
  29. public class CommentController {
  30. private final IZbCommentService commentService;
  31. @GetMapping
  32. @ApiOperation("获取图库或者图片故事的评论信息")
  33. @ApiImplicitParams({
  34. @ApiImplicitParam(value = "图库或者图片故事的id", name = "id", required = true),
  35. @ApiImplicitParam(
  36. value = "类型:图库还是图片故事,GALLERY:图库,PICTURE:图片故事",
  37. name = "type", required = true
  38. )
  39. })
  40. public AjaxResult comment(
  41. @RequestParam("id") Long id,
  42. @RequestParam("type") CommentType commentType,
  43. @RequestParam(value = "page", defaultValue = "1") Integer page,
  44. @RequestParam(value = "size", defaultValue = "10") Integer size
  45. ) {
  46. ZbComment zbComment = new ZbComment();
  47. zbComment.setStatus(ApprovalStatus.PASS.name());
  48. zbComment.setType(commentType.name());
  49. zbComment.setFkId(id);
  50. Page<ZbComment> pageInfo = new Page<>(page, size);
  51. List<ZbComment> zbComments = commentService.selectZbCommentList(zbComment, pageInfo);
  52. pageInfo.setRecords(zbComments);
  53. return AjaxResult.success(pageInfo);
  54. }
  55. @PutMapping
  56. @ApiOperation("发表评论")
  57. @ApiImplicitParams({
  58. @ApiImplicitParam(value = "图库或者图片故事的id", name = "id", required = true),
  59. @ApiImplicitParam(value = "评论内容", name = "content", required = true),
  60. @ApiImplicitParam(value = "联系方式", name = "concat", required = true),
  61. @ApiImplicitParam(
  62. value = "类型:图库还是图片故事,GALLERY:图库,PICTURE:图片故事",
  63. name = "commentType", required = true
  64. )
  65. })
  66. public AjaxResult comment(
  67. @RequestParam("id") Long id,
  68. @RequestParam("type") CommentType commentType,
  69. @RequestParam("content") String content,
  70. @RequestParam("concat") String concat,
  71. HttpServletRequest request
  72. ) {
  73. ZbComment comment = new ZbComment();
  74. comment.setFkId(id);
  75. comment.setType(commentType.name());
  76. comment.setStatus(ApprovalStatus.SUBMIT.name());
  77. comment.setConcat(concat);
  78. comment.setContent(content);
  79. comment.setIp(IpUtils.getIpAddr(request));
  80. comment.setName("访客" + RandomUtil.randomNumbers(8));
  81. comment.setCreateTime(new Date());
  82. commentService.save(comment);
  83. return AjaxResult.success("发布成功,请等待管理员审核");
  84. }
  85. }