ImageApi.java 4.7 KB

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