package com.hssx.cloudmodel.controller; import com.hssx.cloudmodel.entity.ProjectFile; import com.hssx.cloudmodel.entity.vo.UserVO; import com.hssx.cloudmodel.service.ProjectFileService; import com.hssx.cloudmodel.util.HttpRespMsg; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.*; import java.util.UUID; /** *

* 前端控制器 *

* * @author 吴涛涛 * @since 2019-07-30 */ @RestController @RequestMapping("/projectfile") public class ProjectFileController { @Value("${upload.path}") private String path; @Value("${download.path}") private String downLoadpath; @Autowired private ProjectFileService projectFileService; /** * 项目文档的上传 * 参数: token 用户身份凭证,projectId 项目id ,file 文件信息 * * @return */ @ApiOperation("项目文档的上传") @RequestMapping("/uploadFile") @ResponseBody public HttpRespMsg uploadFile(@RequestParam(required = false) MultipartFile file, HttpServletResponse response, HttpServletRequest request, UserVO userVO) throws Exception { System.out.println("开始上传文件" + "file+" + file.getOriginalFilename()); HttpRespMsg msg = new HttpRespMsg(); msg = projectFileService.addFile(userVO,file,path); return msg; } /** * 项目文档的下载 * 参数: token 用户身份凭证,id 项目id * * @return */ @ApiOperation("项目文档的下载") @RequestMapping("/dowloadFile") @ResponseBody public HttpRespMsg dowloadFile(ProjectFile projectFile,String token,HttpServletResponse response) throws FileNotFoundException, UnsupportedEncodingException { HttpRespMsg msg = projectFileService.dowloadFile(projectFile,token,downLoadpath,response,path); return msg; } /** * 项目文档的列表 * 参数: token 用户身份凭证,projectId 项目id * * @return */ @ApiOperation("项目文档的列表") @RequestMapping("/list") @ResponseBody public HttpRespMsg list(UserVO userVO){ HttpRespMsg msg = projectFileService.getFileList(userVO); return msg; } /** * 项目文档的删除 * 参数: id 文档id * * @return */ @ApiOperation("项目文档的删除") @RequestMapping("/delFile") @ResponseBody public HttpRespMsg delFile(ProjectFile projectFile){ HttpRespMsg msg = projectFileService.delFile(projectFile); return msg; } }