FileApi.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package com.caimei.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.caimei.model.ResponseJson;
  4. import com.caimei.model.vo.FileListVo;
  5. import com.caimei.service.FileService;
  6. import com.github.pagehelper.PageInfo;
  7. import io.swagger.annotations.Api;
  8. import io.swagger.annotations.ApiImplicitParam;
  9. import io.swagger.annotations.ApiImplicitParams;
  10. import io.swagger.annotations.ApiOperation;
  11. import lombok.RequiredArgsConstructor;
  12. import lombok.extern.slf4j.Slf4j;
  13. import org.springframework.web.bind.annotation.*;
  14. import java.util.Map;
  15. /**
  16. * 资料库文件API
  17. *
  18. * @author : Aslee
  19. * @date : 2021/7/9
  20. */
  21. @Api(tags = "资料库文件API")
  22. @Slf4j
  23. @RestController
  24. @RequiredArgsConstructor
  25. @RequestMapping("/data/file")
  26. public class FileApi {
  27. private final FileService fileService;
  28. @ApiOperation("文件列表")
  29. @ApiImplicitParams({
  30. @ApiImplicitParam(name = "listType", required = false, value = "列表类型:1文件列表,2文件审核列表"),
  31. @ApiImplicitParam(name = "authUserId", required = true, value = "供应商用户id"),
  32. @ApiImplicitParam(name = "fileTitle", required = false, value = "文件标题"),
  33. @ApiImplicitParam(name = "auditStatus", required = false, value = "审核状态:0审核未通过,1审核通过,2待审核"),
  34. @ApiImplicitParam(name = "status", required = false, value = "文件状态:0已下线,1已上线,2待上线"),
  35. @ApiImplicitParam(name = "pageNum", required = false, value = "第几页"),
  36. @ApiImplicitParam(name = "pageSize", required = false, value = "一页多少条")
  37. })
  38. @GetMapping("/list")
  39. public ResponseJson<PageInfo<FileListVo>> getFileList(Integer listType, Integer authUserId, String fileTitle, Integer auditStatus, Integer status,
  40. @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
  41. @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
  42. return fileService.getFileList(listType, authUserId, fileTitle, auditStatus, status, pageNum, pageSize);
  43. }
  44. @ApiOperation("添加/编辑文件")
  45. @ApiImplicitParam(name = "params", required = false, value = "fileId:文件id;authUserId:供应商用户id;fileTitle:文件标题;fileName:文件名称;filePreviewUrl:文件预览链接;fileDowloadUrl:文件下载链接")
  46. @PostMapping("/save")
  47. public ResponseJson saveFile(@RequestBody String params) {
  48. JSONObject paramsMap = JSONObject.parseObject(params);
  49. Integer fileId = paramsMap.getInteger("fileId");
  50. Integer authUserId = paramsMap.getInteger("authUserId");
  51. String fileTitle = paramsMap.getString("fileTitle");
  52. String fileName = paramsMap.getString("fileName");
  53. String filePreviewUrl = paramsMap.getString("filePreviewUrl");
  54. String fileDownloadUrl = paramsMap.getString("fileDownloadUrl");
  55. return fileService.saveFile(fileId, authUserId, fileTitle, fileName, filePreviewUrl, fileDownloadUrl);
  56. }
  57. @ApiOperation("更新文件状态")
  58. @ApiImplicitParam(name = "params", value = "fileId:文件id;status:文件状态:0停用 1启用;", required = true)
  59. @PostMapping("/update/status")
  60. public ResponseJson updateFileStatus(@RequestBody Map<String,Integer> params) {
  61. Integer fileId = params.get("fileId");
  62. Integer status = params.get("status");
  63. return fileService.updateFileStatus(fileId, status);
  64. }
  65. @ApiOperation("删除文件")
  66. @ApiImplicitParam(name = "params", value = "fileId:文件id", required = true)
  67. @PostMapping("/delete")
  68. public ResponseJson deleteFile(@RequestBody Map<String,Integer> params) {
  69. Integer fileId = params.get("fileId");
  70. return fileService.deleteFile(fileId);
  71. }
  72. @ApiOperation("审核文件")
  73. @ApiImplicitParam(name = "params", value = "fileId:文件id;auditStatus:审核状态:0审核未通过,1审核通过,2待审核;invalidReason:审核不通过原因;auditBy:审核人用户id", required = true)
  74. @PostMapping("/audit")
  75. public ResponseJson auditFile(@RequestBody String params) {
  76. JSONObject paramsMap = JSONObject.parseObject(params);
  77. Integer fileId = paramsMap.getInteger("fileId");
  78. Integer auditStatus = paramsMap.getInteger("auditStatus");
  79. String invalidReason = paramsMap.getString("invalidReason");
  80. Integer auditBy = paramsMap.getInteger("auditBy");
  81. return fileService.auditFile(fileId, auditStatus, invalidReason, auditBy);
  82. }
  83. }