ProjectFileController.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package com.hssx.cloudmodel.controller;
  2. import com.hssx.cloudmodel.entity.ProjectFile;
  3. import com.hssx.cloudmodel.entity.vo.UserVO;
  4. import com.hssx.cloudmodel.service.ProjectFileService;
  5. import com.hssx.cloudmodel.util.HttpRespMsg;
  6. import io.swagger.annotations.ApiOperation;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.beans.factory.annotation.Value;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RequestParam;
  11. import org.springframework.web.bind.annotation.ResponseBody;
  12. import org.springframework.web.bind.annotation.RestController;
  13. import org.springframework.web.multipart.MultipartFile;
  14. import javax.servlet.http.HttpServletRequest;
  15. import javax.servlet.http.HttpServletResponse;
  16. import java.io.*;
  17. import java.util.UUID;
  18. /**
  19. * <p>
  20. * 前端控制器
  21. * </p>
  22. *
  23. * @author 吴涛涛
  24. * @since 2019-07-30
  25. */
  26. @RestController
  27. @RequestMapping("/projectfile")
  28. public class ProjectFileController {
  29. @Value("${upload.path}")
  30. private String path;
  31. @Value("${download.path}")
  32. private String downLoadpath;
  33. @Autowired
  34. private ProjectFileService projectFileService;
  35. /**
  36. * 项目文档的上传
  37. * 参数: token 用户身份凭证,projectId 项目id ,file 文件信息
  38. *
  39. * @return
  40. */
  41. @ApiOperation("项目文档的上传")
  42. @RequestMapping("/uploadFile")
  43. @ResponseBody
  44. public HttpRespMsg uploadFile(@RequestParam(required = false) MultipartFile file,
  45. HttpServletResponse response, HttpServletRequest request, UserVO userVO) throws Exception {
  46. System.out.println("开始上传文件" + "file+" + file.getOriginalFilename());
  47. HttpRespMsg msg = new HttpRespMsg();
  48. msg = projectFileService.addFile(userVO,file,path);
  49. return msg;
  50. }
  51. /**
  52. * 项目文档的下载
  53. * 参数: token 用户身份凭证,id 项目id
  54. *
  55. * @return
  56. */
  57. @ApiOperation("项目文档的下载")
  58. @RequestMapping("/dowloadFile")
  59. @ResponseBody
  60. public HttpRespMsg dowloadFile(ProjectFile projectFile,String token,HttpServletResponse response) throws FileNotFoundException, UnsupportedEncodingException {
  61. HttpRespMsg msg = projectFileService.dowloadFile(projectFile,token,downLoadpath,response,path);
  62. return msg;
  63. }
  64. /**
  65. * 项目文档的列表
  66. * 参数: token 用户身份凭证,projectId 项目id
  67. *
  68. * @return
  69. */
  70. @ApiOperation("项目文档的列表")
  71. @RequestMapping("/list")
  72. @ResponseBody
  73. public HttpRespMsg list(UserVO userVO){
  74. HttpRespMsg msg = projectFileService.getFileList(userVO);
  75. return msg;
  76. }
  77. /**
  78. * 项目文档的删除
  79. * 参数: id 文档id
  80. *
  81. * @return
  82. */
  83. @ApiOperation("项目文档的删除")
  84. @RequestMapping("/delFile")
  85. @ResponseBody
  86. public HttpRespMsg delFile(ProjectFile projectFile){
  87. HttpRespMsg msg = projectFileService.delFile(projectFile);
  88. return msg;
  89. }
  90. }