package com.ruoyi.web.controller.front; import cn.hutool.core.util.RandomUtil; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.enums.ApprovalStatus; import com.ruoyi.common.enums.CommentType; import com.ruoyi.common.utils.ip.IpUtils; import com.ruoyi.framework.security.anno.IgnoreAuth; import com.ruoyi.system.domain.ZbComment; import com.ruoyi.system.service.IZbCommentService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import java.util.Date; import java.util.List; /** * @author Admin * @date 2020/12/2 */ @IgnoreAuth @RestController @RequestMapping("/front/comment") @RequiredArgsConstructor @Api("评论相关接口") public class CommentController { private final IZbCommentService commentService; @GetMapping @ApiOperation("获取图库或者图片故事的评论信息") @ApiImplicitParams({ @ApiImplicitParam(value = "图库或者图片故事的id", name = "id", required = true), @ApiImplicitParam( value = "类型:图库还是图片故事,GALLERY:图库,PICTURE:图片故事", name = "type", required = true ) }) public AjaxResult comment( @RequestParam("id") Long id, @RequestParam("type") CommentType commentType, @RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(value = "size", defaultValue = "10") Integer size ) { ZbComment zbComment = new ZbComment(); zbComment.setStatus(ApprovalStatus.PASS.name()); zbComment.setType(commentType.name()); zbComment.setFkId(id); Page pageInfo = new Page<>(page, size); List zbComments = commentService.selectZbCommentList(zbComment, pageInfo); pageInfo.setRecords(zbComments); return AjaxResult.success(pageInfo); } @PutMapping @ApiOperation("发表评论") @ApiImplicitParams({ @ApiImplicitParam(value = "图库或者图片故事的id", name = "id", required = true), @ApiImplicitParam(value = "评论内容", name = "content", required = true), @ApiImplicitParam(value = "联系方式", name = "concat", required = true), @ApiImplicitParam( value = "类型:图库还是图片故事,GALLERY:图库,PICTURE:图片故事", name = "commentType", required = true ) }) public AjaxResult comment( @RequestParam("id") Long id, @RequestParam("type") CommentType commentType, @RequestParam("content") String content, @RequestParam("concat") String concat, HttpServletRequest request ) { ZbComment comment = new ZbComment(); comment.setFkId(id); comment.setType(commentType.name()); comment.setStatus(ApprovalStatus.SUBMIT.name()); comment.setConcat(concat); comment.setContent(content); comment.setIp(IpUtils.getIpAddr(request)); comment.setName("访客" + RandomUtil.randomNumbers(8)); comment.setCreateTime(new Date()); commentService.save(comment); return AjaxResult.success("发布成功,请等待管理员审核"); } }