whycrzg
2021-04-07 585ad3e3541a8e83db039df59e42ab640f66c221
更新download接口
1个文件已修改
25 ■■■■ 已修改文件
src/main/java/com/whyc/controller/ProjectManageController.java 25 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/ProjectManageController.java
@@ -128,10 +128,18 @@
    @GetMapping("/download")
    @ApiOperation(notes = "需要在地址栏测试",value = "项目过程管理-文档材料下载")
    public Object download(HttpServletResponse response, @RequestParam String filePath,@RequestParam String fileName) {
        Response<Object> result = new Response<>();
        File file = new File( filePath);
    @ApiOperation(notes = "需要在地址栏测试 http://localhost:8090/projectManage/download?fileName=申请书.pdf",value = "项目过程管理-文档材料下载")
    public String download(HttpServletResponse response, @ApiParam(value = "文件路径",required = true)@RequestParam String filePath) {
        String fileName = "";
        if (filePath.length() > 10&&filePath.contains("/")) {   //IP地址+文件名
            int lastIndexOf = filePath.lastIndexOf("/");
            fileName = filePath.substring(lastIndexOf);
        } else {
            return "filePath is Error";
        }
        String projectPath = FileUtils.getProjectPath();
        File file = new File( projectPath+fileName);
        if (file.exists()) {
            try {
                fileName= new String(fileName.getBytes("gbk"), "ISO8859-1");
@@ -153,10 +161,12 @@
                    outputStream.write(buffer, 0, i);
                    i = bis.read(buffer);
                }
                return result.setMsg(1,"下载成功");
//               return result.setMsg(1,"下载成功");
               return "downloadSuccessful";
            } catch (Exception e) {
                e.printStackTrace();
                return result.setMsg(0,"下载失败");
//                return result.setMsg(0,"下载失败");
                return "downloadFailed";
            } finally {
                if (bis != null) {
                    try {
@@ -173,8 +183,9 @@
                    }
                }
            }
        }else{
            return "fileDoesNotExist";
        }
        return result.setMsg(0,"文件不存在");
    }