package com.caimei.controller.admin.data; import com.alibaba.fastjson.JSONObject; import com.caimei.model.ResponseJson; import com.caimei.model.vo.ArticleFormVo; import com.caimei.model.vo.ArticleListVo; import com.caimei.service.auth.ArticleService; import com.github.pagehelper.PageInfo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; import java.util.Map; /** * 资料库文章API * * @author : Aslee * @date : 2021/7/8 */ @Api(tags = "资料库文章API") @Slf4j @RestController @RequiredArgsConstructor @RequestMapping("/data/article") public class ArticleApi { private final ArticleService articleService; @ApiOperation("文章列表") @ApiImplicitParams({ @ApiImplicitParam(name = "listType", required = false, value = "列表类型:1文章列表,2文章审核列表"), @ApiImplicitParam(name = "authUserId", required = true, value = "供应商用户id"), @ApiImplicitParam(name = "articleTitle", required = false, value = "文章标题"), @ApiImplicitParam(name = "auditStatus", required = false, value = "审核状态:0审核未通过,1审核通过,2待审核"), @ApiImplicitParam(name = "status", required = false, value = "文章状态:0已下线,1已上线,2待上线"), @ApiImplicitParam(name = "pageNum", required = false, value = "第几页"), @ApiImplicitParam(name = "pageSize", required = false, value = "一页多少条") }) @GetMapping("/list") public ResponseJson> getArticleList(Integer listType, Integer authUserId, String articleTitle, Integer auditStatus, Integer status, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { return articleService.getArticleList(listType, authUserId, articleTitle, auditStatus, status, pageNum, pageSize); } @ApiOperation("添加/编辑文章") @ApiImplicitParam(name = "params", value = "articleId:文章id;authUserId:供应商用户id;articleTitle:文章标题;articleImage:文章图片;articleContent:文章内容", required = true) @PostMapping("/save") public ResponseJson saveArticle(@RequestBody String params) { JSONObject paramsMap = JSONObject.parseObject(params); Integer articleId = paramsMap.getInteger("articleId"); Integer authUserId = paramsMap.getInteger("authUserId"); String articleTitle = paramsMap.getString("articleTitle"); String articleImage = paramsMap.getString("articleImage"); String articleContent = paramsMap.getString("articleContent"); return articleService.saveArticle(articleId, authUserId, articleTitle, articleImage, articleContent); } @ApiOperation("文章回显数据") @ApiImplicitParam(name = "articleId", value = "文章id", required = true) @GetMapping("/form/data") public ResponseJson getArticleFormData(Integer articleId) { return articleService.getArticleFormData(articleId); } @ApiOperation("更新文章状态") @ApiImplicitParam(name = "params", value = "articleId:文章id;status:文章状态:0停用 1启用;", required = true) @PostMapping("/update/status") public ResponseJson updateArticleStatus(@RequestBody Map params) { Integer articleId = params.get("articleId"); Integer status = params.get("status"); return articleService.updateArticleStatus(articleId, status); } @ApiOperation("删除文章") @ApiImplicitParam(name = "params", value = "articleId:文章id", required = true) @PostMapping("/delete") public ResponseJson deleteArticle(@RequestBody Map params) { Integer articleId = params.get("articleId"); return articleService.deleteArticle(articleId); } @ApiOperation("审核文章") @ApiImplicitParam(name = "params", value = "articleId:文章id;auditStatus:审核状态:0审核未通过,1审核通过,2待审核;invalidReason:审核不通过原因;auditBy:审核人用户id", required = true) @PostMapping("/audit") public ResponseJson auditArticle(@RequestBody String params) { JSONObject paramsMap = JSONObject.parseObject(params); Integer articleId = paramsMap.getInteger("articleId"); Integer auditStatus = paramsMap.getInteger("auditStatus"); String invalidReason = paramsMap.getString("invalidReason"); Integer auditBy = paramsMap.getInteger("auditBy"); return articleService.auditArticle(articleId, auditStatus, invalidReason, auditBy); } @ApiOperation("更改查看标记") @ApiImplicitParam(name = "articleId", required = true, value = "文章id") @PostMapping("/check") public ResponseJson checkArticle(Integer articleId) { return articleService.checkArticle(articleId); } }