content: package com.ld.poetry.controller;
  
  
  import com.ld.poetry.aop.LoginCheck;
  import com.ld.poetry.config.PoetryResult;
  import com.ld.poetry.aop.SaveCheck;
  import com.ld.poetry.service.CommentService;
  import com.ld.poetry.constants.CommonConst;
  import com.ld.poetry.utils.CommonQuery;
  import com.ld.poetry.utils.cache.PoetryCache;
  import com.ld.poetry.utils.StringUtil;
  import com.ld.poetry.vo.BaseRequestVO;
  import com.ld.poetry.vo.CommentVO;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.util.StringUtils;
  import org.springframework.validation.annotation.Validated;
  import org.springframework.web.bind.annotation.*;
  
  
  /**
   * <p>
   * 文章评论表 前端控制器
   * </p>
   *
   * @author sara
   * @since 2021-08-13
   */
  @RestController
  @RequestMapping("/comment")
  public class CommentController {
  
  
      @Autowired
      private CommentService commentService;
  
      @Autowired
      private CommonQuery commonQuery;
  
  
      /**
       * 保存评论
       */
      @PostMapping("/saveComment")
      @LoginCheck
      @SaveCheck
      public PoetryResult saveComment(@Validated @RequestBody CommentVO commentVO) {
          String content = StringUtil.removeHtml(commentVO.getCommentContent());
          if (!StringUtils.hasText(content)) {
              return PoetryResult.fail("评论内容不合法！");
          }
          commentVO.setCommentContent(content);
  
          PoetryCache.remove(CommonConst.COMMENT_COUNT_CACHE + commentVO.getSource().toString() + "_" + commentVO.getType());
          return commentService.saveComment(commentVO);
      }
  
  
      /**
       * 删除评论
       */
      @GetMapping("/deleteComment")
      @LoginCheck
      public PoetryResult deleteComment(@RequestParam("id") Integer id) {
          return commentService.deleteComment(id);
      }
  
  
      /**
       * 查询评论数量
       */
      @GetMapping("/getCommentCount")
      public PoetryResult<Integer> getCommentCount(@RequestParam("source") Integer source, @RequestParam("type") String type) {
          return PoetryResult.success(commonQuery.getCommentCount(source, type));
      }
  
  
      /**
       * 查询评论
       */
      @PostMapping("/listComment")
      public PoetryResult<BaseRequestVO> listComment(@RequestBody BaseRequestVO baseRequestVO) {
          return commentService.listComment(baseRequestVO);
      }
  }
  
  