From 98c5978c7a85af72900e7211df6bede29567d085 Mon Sep 17 00:00:00 2001 From: dinggang <2498628697@qq.com> Date: Tue, 26 Apr 2022 15:09:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=8F=91=E6=8C=87=E5=8D=97=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8A=E4=BC=A0=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DevelopmentGuideController.java | 4 ++- .../impl/DevelopmentGuideServiceImpl.java | 26 ++++++++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/renren-admin/src/main/java/io/renren/modules/developmentGuide/controller/DevelopmentGuideController.java b/renren-admin/src/main/java/io/renren/modules/developmentGuide/controller/DevelopmentGuideController.java index c14cbe60..b38aa704 100644 --- a/renren-admin/src/main/java/io/renren/modules/developmentGuide/controller/DevelopmentGuideController.java +++ b/renren-admin/src/main/java/io/renren/modules/developmentGuide/controller/DevelopmentGuideController.java @@ -42,7 +42,9 @@ public class DevelopmentGuideController { @PostMapping("/uploadDevelopmentFile") @ApiOperation("开发指南文件上传") @ApiImplicitParams({ - @ApiImplicitParam(name = "file", value = "开发指南文件", paramType = "file", dataType = "file", required = true) + @ApiImplicitParam(name = "file", value = "开发指南文件", paramType = "file", dataType = "file", required = true), + @ApiImplicitParam(name = "fileName", value = "文件名称", paramType = "query", dataType = "String", required = true), + @ApiImplicitParam(name = "type", value = "能力类型", paramType = "query", dataType = "String", required = true), }) public Result uploadDevelopmentFile(@RequestParam("file") MultipartFile uploadFile, HttpServletRequest request) { try { diff --git a/renren-admin/src/main/java/io/renren/modules/developmentGuide/service/impl/DevelopmentGuideServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/developmentGuide/service/impl/DevelopmentGuideServiceImpl.java index 727d9822..70b96fb3 100644 --- a/renren-admin/src/main/java/io/renren/modules/developmentGuide/service/impl/DevelopmentGuideServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/developmentGuide/service/impl/DevelopmentGuideServiceImpl.java @@ -27,19 +27,28 @@ public class DevelopmentGuideServiceImpl implements DevelopmentGuideService { @Override public void getDevelopmentFile(HttpServletRequest request, HttpServletResponse response) throws Exception { + logger.info("----------------------------------开始上传开发指南--------------------------------------------------"); String type = request.getParameter("type").toString(); Long resourceId = Long.parseLong(request.getParameter("resourceId")); + logger.info("读取文件类型及能力ID:" + type + ";" + resourceId); String url = devModelFilePath + File.separator + type + File.separator + resourceId + ".md"; + String filePath = devModelFilePath + File.separator + type; File file = new File(url); //开发指南未保存过获取默认模板文件 - if (! file.exists()) { - file = new File(devModelFilePath + File.separator + type + File.separator + type + ".md"); + if (new File(filePath).exists()) { + if (! file.exists()) { + file = new File(devModelFilePath + File.separator + type + File.separator + type + ".md"); + } + } else { + logger.info("----------------------------------文件路径不存在--------------------------------------"); + throw new IOException("文件路径不存在!"); } response.setContentType("text/html"); try ( FileInputStream fis = new FileInputStream(file); OutputStream outputStream = response.getOutputStream(); ) { + logger.info("----------------------------------开始获取文件--------------------------------------"); //将读取流拷贝到输出流中 IOUtils.copy(fis, outputStream); //清空缓存的读取流,保证数据完整性 @@ -52,22 +61,27 @@ public class DevelopmentGuideServiceImpl implements DevelopmentGuideService { @Override public void uploadDevelopmentFile(MultipartFile uploadFile, HttpServletRequest request) throws Exception{ + logger.info("----------------------------------开始上传开发指南--------------------------------------------------"); String type = request.getParameter("type").toString(); - File folder = new File(devModelFilePath + File.pathSeparator + type + File.separator + uploadFile.getName()); - File path = new File(devModelFilePath + File.pathSeparator + type); + String fileName = request.getParameter("fileName").toString(); + logger.info("读取文件类型及文件名:" + type + ";" + fileName); + File folder = new File(devModelFilePath + File.pathSeparator + type + File.separator + fileName); + File path = new File(devModelFilePath + File.pathSeparator + type + File.separator); //文件保存过删除后重新保存 if (folder.exists()) { if (folder.isFile()) { if (!folder.delete()) { + logger.info("----------------------------------删除已存在文件失败--------------------------------------"); throw new IOException("保存文件失败!"); } } } try { // 文件保存 - logger.info("读取文件名:" + uploadFile.getName()); - uploadFile.transferTo(new File(path, uploadFile.getName())); + uploadFile.transferTo(new File(path, fileName)); + logger.info("----------------------------------文件上传成功--------------------------------------"); } catch (IOException e) { + logger.info("----------------------------------文件上传失败--------------------------------------"); e.printStackTrace(); } }