ArticleApi.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package com.caimei.controller.admin.data;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.caimei.model.ResponseJson;
  4. import com.caimei.model.vo.ArticleFormVo;
  5. import com.caimei.model.vo.ArticleListVo;
  6. import com.caimei.service.auth.ArticleService;
  7. import com.github.pagehelper.PageInfo;
  8. import io.swagger.annotations.Api;
  9. import io.swagger.annotations.ApiImplicitParam;
  10. import io.swagger.annotations.ApiImplicitParams;
  11. import io.swagger.annotations.ApiOperation;
  12. import lombok.RequiredArgsConstructor;
  13. import lombok.extern.slf4j.Slf4j;
  14. import org.springframework.web.bind.annotation.*;
  15. import java.util.Map;
  16. /**
  17. * 资料库文章API
  18. *
  19. * @author : Aslee
  20. * @date : 2021/7/8
  21. */
  22. @Api(tags = "资料库文章API")
  23. @Slf4j
  24. @RestController
  25. @RequiredArgsConstructor
  26. @RequestMapping("/data/article")
  27. public class ArticleApi {
  28. private final ArticleService articleService;
  29. @ApiOperation("文章列表")
  30. @ApiImplicitParams({
  31. @ApiImplicitParam(name = "listType", required = false, value = "列表类型:1文章列表,2文章审核列表"),
  32. @ApiImplicitParam(name = "authUserId", required = true, value = "供应商用户id"),
  33. @ApiImplicitParam(name = "articleTitle", required = false, value = "文章标题"),
  34. @ApiImplicitParam(name = "auditStatus", required = false, value = "审核状态:0审核未通过,1审核通过,2待审核"),
  35. @ApiImplicitParam(name = "status", required = false, value = "文章状态:0已下线,1已上线,2待上线"),
  36. @ApiImplicitParam(name = "pageNum", required = false, value = "第几页"),
  37. @ApiImplicitParam(name = "pageSize", required = false, value = "一页多少条")
  38. })
  39. @GetMapping("/list")
  40. public ResponseJson<PageInfo<ArticleListVo>> getArticleList(Integer listType, Integer authUserId, String articleTitle, Integer auditStatus, Integer status,
  41. @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
  42. @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
  43. return articleService.getArticleList(listType, authUserId, articleTitle, auditStatus, status, pageNum, pageSize);
  44. }
  45. @ApiOperation("添加/编辑文章")
  46. @ApiImplicitParam(name = "params", value = "articleId:文章id;authUserId:供应商用户id;articleTitle:文章标题;articleImage:文章图片;articleContent:文章内容", required = true)
  47. @PostMapping("/save")
  48. public ResponseJson saveArticle(@RequestBody String params) {
  49. JSONObject paramsMap = JSONObject.parseObject(params);
  50. Integer articleId = paramsMap.getInteger("articleId");
  51. Integer authUserId = paramsMap.getInteger("authUserId");
  52. String articleTitle = paramsMap.getString("articleTitle");
  53. String articleImage = paramsMap.getString("articleImage");
  54. String articleContent = paramsMap.getString("articleContent");
  55. return articleService.saveArticle(articleId, authUserId, articleTitle, articleImage, articleContent);
  56. }
  57. @ApiOperation("文章回显数据")
  58. @ApiImplicitParam(name = "articleId", value = "文章id", required = true)
  59. @GetMapping("/form/data")
  60. public ResponseJson<ArticleFormVo> getArticleFormData(Integer articleId) {
  61. return articleService.getArticleFormData(articleId);
  62. }
  63. @ApiOperation("更新文章状态")
  64. @ApiImplicitParam(name = "params", value = "articleId:文章id;status:文章状态:0停用 1启用;", required = true)
  65. @PostMapping("/update/status")
  66. public ResponseJson updateArticleStatus(@RequestBody Map<String,Integer> params) {
  67. Integer articleId = params.get("articleId");
  68. Integer status = params.get("status");
  69. return articleService.updateArticleStatus(articleId, status);
  70. }
  71. @ApiOperation("删除文章")
  72. @ApiImplicitParam(name = "params", value = "articleId:文章id", required = true)
  73. @PostMapping("/delete")
  74. public ResponseJson deleteArticle(@RequestBody Map<String,Integer> params) {
  75. Integer articleId = params.get("articleId");
  76. return articleService.deleteArticle(articleId);
  77. }
  78. @ApiOperation("审核文章")
  79. @ApiImplicitParam(name = "params", value = "articleId:文章id;auditStatus:审核状态:0审核未通过,1审核通过,2待审核;invalidReason:审核不通过原因;auditBy:审核人用户id", required = true)
  80. @PostMapping("/audit")
  81. public ResponseJson auditArticle(@RequestBody String params) {
  82. JSONObject paramsMap = JSONObject.parseObject(params);
  83. Integer articleId = paramsMap.getInteger("articleId");
  84. Integer auditStatus = paramsMap.getInteger("auditStatus");
  85. String invalidReason = paramsMap.getString("invalidReason");
  86. Integer auditBy = paramsMap.getInteger("auditBy");
  87. return articleService.auditArticle(articleId, auditStatus, invalidReason, auditBy);
  88. }
  89. @ApiOperation("更改查看标记")
  90. @ApiImplicitParam(name = "articleId", required = true, value = "文章id")
  91. @PostMapping("/check")
  92. public ResponseJson checkArticle(Integer articleId) {
  93. return articleService.checkArticle(articleId);
  94. }
  95. }