FileApi.java 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package com.caimei.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.caimei.model.ResponseJson;
  4. import com.caimei.model.vo.CourseFileListVo;
  5. import com.caimei.model.vo.FileListVo;
  6. import com.caimei.service.FileService;
  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/9
  21. */
  22. @Api(tags = "资料库文件API")
  23. @Slf4j
  24. @RestController
  25. @RequiredArgsConstructor
  26. @RequestMapping("/data/file")
  27. public class FileApi {
  28. private final FileService fileService;
  29. @ApiOperation("文件列表")
  30. @ApiImplicitParams({
  31. @ApiImplicitParam(name = "listType", required = false, value = "列表类型:1文件列表,2文件审核列表"),
  32. @ApiImplicitParam(name = "authUserId", required = true, value = "供应商用户id"),
  33. @ApiImplicitParam(name = "fileTitle", 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<FileListVo>> getFileList(Integer listType, Integer authUserId, String fileTitle, Integer auditStatus, Integer status,
  41. @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
  42. @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
  43. return fileService.getFileList(listType, authUserId, fileTitle, auditStatus, status, pageNum, pageSize);
  44. }
  45. @ApiOperation("添加/编辑文件")
  46. @ApiImplicitParam(name = "params", required = false, value = "fileId:文件id;authUserId:供应商用户id;fileTitle:文件标题;fileName:文件名称;filePreviewUrl:文件预览链接;fileDownloadUrl:oss名称")
  47. @PostMapping("/save")
  48. public ResponseJson saveFile(@RequestBody String params) {
  49. JSONObject paramsMap = JSONObject.parseObject(params);
  50. Integer fileId = paramsMap.getInteger("fileId");
  51. Integer authUserId = paramsMap.getInteger("authUserId");
  52. String fileTitle = paramsMap.getString("fileTitle");
  53. String fileName = paramsMap.getString("fileName");
  54. String filePreviewUrl = paramsMap.getString("filePreviewUrl");
  55. String fileDownloadUrl = paramsMap.getString("fileDownloadUrl");
  56. return fileService.saveFile(fileId, authUserId, fileTitle, fileName, filePreviewUrl, fileDownloadUrl);
  57. }
  58. @ApiOperation("更新文件状态")
  59. @ApiImplicitParam(name = "params", value = "fileId:文件id;status:文件状态:0停用 1启用;", required = true)
  60. @PostMapping("/update/status")
  61. public ResponseJson updateFileStatus(@RequestBody Map<String,Integer> params) {
  62. Integer fileId = params.get("fileId");
  63. Integer status = params.get("status");
  64. return fileService.updateFileStatus(fileId, status);
  65. }
  66. @ApiOperation("删除文件")
  67. @ApiImplicitParam(name = "params", value = "fileId:文件id", required = true)
  68. @PostMapping("/delete")
  69. public ResponseJson deleteFile(@RequestBody Map<String,Integer> params) {
  70. Integer fileId = params.get("fileId");
  71. return fileService.deleteFile(fileId);
  72. }
  73. @ApiOperation("审核文件")
  74. @ApiImplicitParam(name = "params", value = "fileId:文件id;auditStatus:审核状态:0审核未通过,1审核通过,2待审核;invalidReason:审核不通过原因;auditBy:审核人用户id", required = true)
  75. @PostMapping("/audit")
  76. public ResponseJson auditFile(@RequestBody String params) {
  77. JSONObject paramsMap = JSONObject.parseObject(params);
  78. Integer fileId = paramsMap.getInteger("fileId");
  79. Integer auditStatus = paramsMap.getInteger("auditStatus");
  80. String invalidReason = paramsMap.getString("invalidReason");
  81. Integer auditBy = paramsMap.getInteger("auditBy");
  82. return fileService.auditFile(fileId, auditStatus, invalidReason, auditBy);
  83. }
  84. @ApiOperation("授权牌照图片下载")
  85. @PostMapping("/auth/image/download")
  86. public ResponseJson download(){
  87. fileService.download();
  88. return ResponseJson.success();
  89. }
  90. @ApiOperation("添加/编辑教程文件")
  91. @ApiImplicitParam(name = "params", required = false, value = "fileId:文件id;fileTitle:文件标题;fileName:文件名称;ossName:oss名称;fileType:文件类型:1视频,2文档;fileModule:文件模块:1品牌授权-授权列表,2机构管理-机构列表")
  92. @PostMapping("/course/save")
  93. public ResponseJson saveCourseFile(@RequestBody String params) {
  94. JSONObject paramsMap = JSONObject.parseObject(params);
  95. Integer fileId = paramsMap.getInteger("fileId");
  96. String fileTitle = paramsMap.getString("fileTitle");
  97. String fileName = paramsMap.getString("fileName");
  98. String ossName = paramsMap.getString("ossName");
  99. Integer fileType = paramsMap.getInteger("fileType");
  100. String fileModule = paramsMap.getString("fileModule");
  101. return fileService.saveCourseFile(fileId, fileTitle, fileName, ossName, fileType, fileModule);
  102. }
  103. @ApiOperation("教程文件列表")
  104. @ApiImplicitParams({
  105. @ApiImplicitParam(name = "fileType", required = false, value = "文件类型:1视频,2文档"),
  106. @ApiImplicitParam(name = "fileTitle", required = false, value = "文件标题"),
  107. @ApiImplicitParam(name = "fileModule", required = false, value = "文件模块:1品牌授权-授权列表,2机构管理-机构列表"),
  108. @ApiImplicitParam(name = "pageNum", required = false, value = "第几页"),
  109. @ApiImplicitParam(name = "pageSize", required = false, value = "一页多少条")
  110. })
  111. @GetMapping("/course/list")
  112. public ResponseJson<PageInfo<CourseFileListVo>> getCourseFileList(Integer fileType, String fileModule, String fileTitle,
  113. @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
  114. @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
  115. return fileService.getCourseFileList(fileType, fileModule, fileTitle, pageNum, pageSize);
  116. }
  117. @ApiOperation("删除文件")
  118. @ApiImplicitParam(name = "params", value = "fileId:文件id", required = true)
  119. @PostMapping("/course/delete")
  120. public ResponseJson deleteCourseFile(@RequestBody Map<String,Integer> params) {
  121. Integer fileId = params.get("fileId");
  122. return fileService.deleteCourseFile(fileId);
  123. }
  124. }