From 7d64716cb0d406f21cde03976fd273bd07fdc06f Mon Sep 17 00:00:00 2001 From: whycxzp <perryhsu@163.com> Date: 星期二, 28 九月 2021 11:44:28 +0800 Subject: [PATCH] 更新用户-角色-菜单-权限 --- src/main/java/com/whyc/controller/ProjectManageController.java | 94 +++++++++++++++++----------------------------- 1 files changed, 35 insertions(+), 59 deletions(-) diff --git a/src/main/java/com/whyc/controller/ProjectManageController.java b/src/main/java/com/whyc/controller/ProjectManageController.java index 9b8e63c..90deccf 100644 --- a/src/main/java/com/whyc/controller/ProjectManageController.java +++ b/src/main/java/com/whyc/controller/ProjectManageController.java @@ -2,6 +2,7 @@ import com.github.pagehelper.PageInfo; import com.whyc.config.MyProps; +import com.whyc.config.ServerConfig; import com.whyc.dto.Response; import com.whyc.pojo.ProjectArchiveManage; import com.whyc.pojo.ProjectManage; @@ -34,6 +35,9 @@ @Autowired private MyProps myProps; + + @Autowired + private ServerConfig serverConfig; @Autowired private ProjectProcessManageService service; @@ -75,6 +79,7 @@ return response; } + /** * 鏂囦欢瀛樺偍鍚庡湴鍧�鏇存柊鍒板搴旈」鐩紪鍙风殑鍦板潃锛屼竴涓」鐩搴斿涓枃浠� db_experiment.tb_project_archive_manage * 鏄惁闇�瑕佸皢word杞琾df/棰勮鏂囦欢pdf @@ -82,45 +87,6 @@ * @param file * @return */ - @PostMapping("upload") - @ApiOperation(notes = "杩斿洖鏂囦欢鍦板潃锛岀‘璁ゆ椂鎻愪氦淇濆瓨鍒板瓧娈�", value = "椤圭洰杩囩▼绠$悊-鏂囨。鏉愭枡娣诲姞(閫夋嫨鏂囦欢)") - public Response upload(@RequestParam("file") MultipartFile file) { - // 鑾峰彇鍘熷鍚嶅瓧 - String originalFilename = file.getOriginalFilename(); - // 鑾峰彇鍚庣紑鍚� - // String suffixName = fileName.substring(fileName.lastIndexOf(".")); - // 鏂囦欢淇濆瓨璺緞銆佸悗鏈熻�冭檻鎸夋棩鏈熸垨鑰呮湀浠藉缓dir - String filePath = myProps.getFilePath(); - // 鏂囦欢閲嶅懡鍚嶏紝闃叉閲嶅,棰勮鏃堕渶瑕佹樉绀哄師鏂囦欢鍚� _ 鍒囧壊 - String fileName = filePath + UUID.randomUUID() + "_" + originalFilename; - // 鏂囦欢瀵硅薄 - File dest = new File(fileName); - // 鍒ゆ柇璺緞鏄惁瀛樺湪锛屽鏋滀笉瀛樺湪鍒欏垱寤� - if (!dest.getParentFile().exists()) { - dest.getParentFile().mkdirs(); - } - Response<Object> response = new Response<>(); - HashMap<Object, Object> map = new HashMap<>(); - try { - // 淇濆瓨鍒版湇鍔″櫒涓� - file.transferTo(dest); - map.put("fileType", file.getContentType()); - map.put("name", originalFilename); - Double size = file.getSize() * 0.01 / 1024 / 1024 * 100; - String douStr = String.format("%.2f", size); - map.put("fileSize", douStr+" M"); - map.put("url",fileName); - } catch (Exception e) { - e.printStackTrace(); - return response.setMsg(0, "涓婁紶澶辫触"); - } - response.setCode(1); - response.setData(map); - return response; - } - - - @PostMapping("/uploads") @ApiOperation(notes = "杩斿洖鏂囦欢鍦板潃锛岀‘璁ゆ椂鎻愪氦淇濆瓨鍒板瓧娈�", value = "椤圭洰杩囩▼绠$悊-鏂囨。鏉愭枡娣诲姞(澶氶��)") public Response uploads(MultipartFile[] file) throws IOException { @@ -130,26 +96,29 @@ } ArrayList<Object> list = new ArrayList<>(); +// String filePath = myProps.getFilePath(); + String uploadPath = FileUtils.getProjectPath(); +// System.out.println("uploadPath = " + uploadPath); for (MultipartFile multipartFile : file) { if (multipartFile.isEmpty()) { return response.setMsg(0, "璇烽�夋嫨瑕佷笂浼犵殑鏂囦欢"); } byte[] fileBytes = multipartFile.getBytes(); - String filePath = myProps.getFilePath(); //鍙栧緱褰撳墠涓婁紶鏂囦欢鐨勬枃浠跺悕绉� String originalFilename = multipartFile.getOriginalFilename(); //鐢熸垚鏂囦欢鍚� String fileName = UUID.randomUUID() + "_" + originalFilename; HashMap<Object, Object> map = new HashMap<>(); + map.put("name", originalFilename); + String url = serverConfig.getUrl(); + map.put("url", url + "/uploadFile/" + fileName); try { - FileUtils.uploadFile(fileBytes, filePath, fileName); + FileUtils.uploadFile(fileBytes, uploadPath, fileName); } catch (IOException e) { e.printStackTrace(); return response.setMsg(0, "涓婁紶澶辫触"); } - map.put("fileName", originalFilename); - map.put("url", filePath + fileName); list.add(map); } @@ -159,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"); @@ -184,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 { @@ -204,8 +183,9 @@ } } } + }else{ + return "fileDoesNotExist"; } - return result.setMsg(0,"鏂囦欢涓嶅瓨鍦�"); } @@ -307,17 +287,13 @@ /** * @param proNameCode - * @param proNum - * @return 瀹為獙鍚嶇О銆佷笂浼犳棩鏈熴�佸綊妗f棩鏈� (鎿嶄綔TODO) + * @return 瀹為獙鍚嶇О銆佽瘯楠屾棩鏈熴�佺粨璁哄瓧娈� etc */ @GetMapping("archiveExperimentData") - @ApiOperation(notes = "(鎿嶄綔TODO)",value = "椤圭洰褰掓。绠$悊-璇曢獙鏁版嵁") - public Response searchArchiveExperimentData(@ApiParam(value = "椤圭洰鍚嶇О浠g爜", required = true) @RequestParam String proNameCode, - @ApiParam(value = "椤圭洰缂栧彿", required = true) @RequestParam String proNum) { - ProjectArchiveManage pam = new ProjectArchiveManage(); - pam.setProNum(proNum); - pam.setProNameCode(proNameCode); - return archiveManageService.searchArchiveExperimentData(pam); + @ApiOperation(notes = "TODO 鏂囦欢鏍煎紡鍜屼笅杞藉湴鍧�", value = "椤圭洰褰掓。绠$悊-璇曢獙鏁版嵁") + public Response searchArchiveExperimentData(@ApiParam(value = "椤圭洰鍚嶇О浠g爜", required = true) @RequestParam String proNameCode) { + //TODO fileName file + return archiveManageService.searchArchiveExperimentData(proNameCode); } @GetMapping("archiveTechnologicalAchievements") -- Gitblit v1.9.1