FileApi.java 7.7 KB

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