FileController.java 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package com.zksy.park.controller;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.zksy.common.annotation.Log;
  4. import com.zksy.common.core.domain.Result;
  5. import com.zksy.park.domain.FileGeneral;
  6. import com.zksy.park.service.FileGeneralService;
  7. import com.zksy.service.MinioFileStorageService;
  8. import io.swagger.annotations.*;
  9. import lombok.SneakyThrows;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.web.bind.annotation.*;
  12. import org.springframework.web.multipart.MultipartFile;
  13. import javax.servlet.http.HttpServletResponse;
  14. @RestController
  15. @RequestMapping("/file")
  16. @Api(value = "文件信息",tags = "文件信息")
  17. public class FileController {
  18. @Autowired
  19. private FileGeneralService service;
  20. @Autowired
  21. private MinioFileStorageService minioFileStorageService;
  22. @Log(title = "文件信息-文件上传")
  23. @RequestMapping(path = "/filePath",method = RequestMethod.POST)
  24. @ApiOperation(value = "文件上传",notes = "文件上传")
  25. // @ApiImplicitParams({
  26. // @ApiImplicitParam(name = "file", value = "文件", required = true, paramType = "path", allowMultiple = false, dataType = "file"),
  27. // @ApiImplicitParam(name = "businessType", value = "文件夹名称", required = true, paramType = "path", allowMultiple = false, dataType = "String")
  28. // })
  29. public Result minioUploadResUrl(MultipartFile file,String businessType) throws Exception {
  30. String result = minioFileStorageService.uploadFile(file,businessType);
  31. return Result.ok(result);
  32. }
  33. @Log(title = "文件信息-文件下载")
  34. @GetMapping("/downLoadFile")
  35. @ApiOperation(value = "文件下载")
  36. @ApiImplicitParam(name = "filePath", value = "文件目录", required = true, paramType = "query", allowMultiple = false, dataType = "String")
  37. @SneakyThrows(Exception.class)
  38. public Result downLoadFile(@RequestParam String filePath,HttpServletResponse response){
  39. try {
  40. minioFileStorageService.downLoadFile(filePath, response);
  41. }catch (Exception e){
  42. return Result.error("文件下载失败");
  43. }
  44. return Result.ok("文件下载成功");
  45. }
  46. @Log(title = "文件信息-文件删除")
  47. @GetMapping("/fileDeleteTP")
  48. @ApiOperation(value = "文件删除")
  49. @ApiImplicitParams({
  50. @ApiImplicitParam(name = "name", value = "文件名", required = true, paramType = "path", allowMultiple = false, dataType = "list"),
  51. @ApiImplicitParam(name = "id", value = "主键id", required = true, paramType = "path", allowMultiple = false, dataType = "Long")
  52. })
  53. public Result fileDelete(@RequestParam String name,@RequestParam String id){
  54. try {
  55. service.removeById(id);
  56. minioFileStorageService.deleteFile(name);
  57. }catch (Exception e){
  58. e.printStackTrace();
  59. }
  60. return Result.ok();
  61. }
  62. @Log(title = "文件信息-查询文件")
  63. @GetMapping("/selectFile")
  64. @ApiOperation(value = "查询文件")
  65. @ApiImplicitParams({
  66. @ApiImplicitParam(name = "formId", value = "对应表单id", required = true, paramType = "path", allowMultiple = false, dataType = "String"),
  67. })
  68. public Result selectFile(@RequestParam String formId){
  69. return Result.ok(service.selectFile(formId));
  70. }
  71. }