From fdb5325e0226c4a9229bd50b65018b547e7624d1 Mon Sep 17 00:00:00 2001 From: gaoxiongzaq Date: Wed, 25 Oct 2023 10:12:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8E=8B=E7=BC=A9=E5=8C=85?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=20cad=E5=88=9B=E5=BB=BA=E5=B8=A6=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=90=8D=E7=9A=84=E6=96=87=E4=BB=B6=E5=A4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/keking/service/FileHandlerService.java | 16 +++++++++------- .../keking/service/impl/CadFilePreviewImpl.java | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/server/src/main/java/cn/keking/service/FileHandlerService.java b/server/src/main/java/cn/keking/service/FileHandlerService.java index a199da8b..08f969ad 100644 --- a/server/src/main/java/cn/keking/service/FileHandlerService.java +++ b/server/src/main/java/cn/keking/service/FileHandlerService.java @@ -323,14 +323,16 @@ public class FileHandlerService implements InitializingBean { * @param outputFilePath pdf输出文件路径 * @return 转换是否成功 */ - public String cadToPdf(String inputFilePath, String outputFilePath ,String cadPreviewType) throws Exception { + public String cadToPdf(String inputFilePath, String outputFilePath ,String cadPreviewType ,String fileKey) throws Exception { final InterruptionTokenSource source = new InterruptionTokenSource();//CAD延时 - int index = outputFilePath.lastIndexOf("."); - String folder = outputFilePath.substring(0, index); - File path = new File(folder); - //目录不存在 创建新的目录 - if (!path.exists()) { - path.mkdirs(); + if (!ObjectUtils.isEmpty(fileKey)) { //判断 是压缩包的创建新的目录 + int index = outputFilePath.lastIndexOf("/"); //截取最后一个斜杠的前面的内容 + String folder = outputFilePath.substring(0, index); + File path = new File(folder); + //目录不存在 创建新的目录 + if (!path.exists()) { + path.mkdirs(); + } } Callable call = () -> { File outputFile = new File(outputFilePath); diff --git a/server/src/main/java/cn/keking/service/impl/CadFilePreviewImpl.java b/server/src/main/java/cn/keking/service/impl/CadFilePreviewImpl.java index f2ec3c18..17c39ec4 100644 --- a/server/src/main/java/cn/keking/service/impl/CadFilePreviewImpl.java +++ b/server/src/main/java/cn/keking/service/impl/CadFilePreviewImpl.java @@ -54,7 +54,7 @@ public class CadFilePreviewImpl implements FilePreview { String imageUrls = null; if (StringUtils.hasText(outFilePath)) { try { - imageUrls = fileHandlerService.cadToPdf(filePath, outFilePath,cadPreviewType); + imageUrls = fileHandlerService.cadToPdf(filePath, outFilePath,cadPreviewType,fileKey); } catch (Exception e) { e.printStackTrace(); }