From e0ff4ee57395015ff20469cd401789bb71772b46 Mon Sep 17 00:00:00 2001 From: liyawei Date: Thu, 16 Jun 2022 14:25:49 +0800 Subject: [PATCH] =?UTF-8?q?cos=E4=B8=8B=E8=BD=BD=E6=B5=81=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ParamsInfoEOServiceImpl.java | 10 +- .../BussDocumentLibraryEOServiceImpl.java | 2 + .../modules/document/utils/ReadPdfUtil.java | 4 +- .../modules/document/utils/ReadWordUtil.java | 2 + .../ocr/controller/OcrRestfulController.java | 15 +- .../split/service/impl/FileSpiltService.java | 294 +++++++++--------- .../impl/FileSplitItemsEOServiceImpl.java | 33 +- 7 files changed, 191 insertions(+), 169 deletions(-) diff --git a/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/template/service/impl/ParamsInfoEOServiceImpl.java b/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/template/service/impl/ParamsInfoEOServiceImpl.java index faaa6d9ca..1ceb2cbf0 100644 --- a/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/template/service/impl/ParamsInfoEOServiceImpl.java +++ b/jero-boot/jero-boot-module-certification/src/main/java/com/jero/modules/cert/template/service/impl/ParamsInfoEOServiceImpl.java @@ -615,13 +615,17 @@ public class ParamsInfoEOServiceImpl extends ServiceImpl fileTemplateList,String fileNowPath) throws IOException { + private void downLoadFileList(List fileTemplateList,String fileNowPath) { for(OSSFile fileExportDto : fileTemplateList){ String oldPath = fileExportDto.getUrl(); String newPath = fileNowPath + File.separator + fileExportDto.getFileName(); if (CosBootUtil.doesObjectExist(oldPath)){ - InputStream in = CosBootUtil.download(oldPath); - copyFile(in, newPath); + try (InputStream in = CosBootUtil.download(oldPath);) { + copyFile(in, newPath); + } catch (IOException e) { + e.printStackTrace(); + log.error(e.getMessage(), e); + } } } } diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/document/service/impl/BussDocumentLibraryEOServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/document/service/impl/BussDocumentLibraryEOServiceImpl.java index 851b075ba..24ddb5449 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/document/service/impl/BussDocumentLibraryEOServiceImpl.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/document/service/impl/BussDocumentLibraryEOServiceImpl.java @@ -4439,6 +4439,8 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper(); - queryWrapper.eq(OSSFile::getConnectId, connectId); - queryWrapper.eq(OSSFile::getFileName, fileName); - queryWrapper.orderByDesc(OSSFile::getCreateTime); - List ossFileList = iossFileService.list(queryWrapper); - if (CollectionUtils.isEmpty(ossFileList)) { - throw new JeroBootException("当前文件未找到,请重新选择!"); - } - OSSFile ossFile = ossFileList.get(0); + //获取文件地址 + String connectId = sarFileSplitInfoEO.getConnectId(); + String fileName = sarFileSplitInfoEO.getFileName(); + if (StringUtils.isEmpty(connectId) || StringUtils.isEmpty(fileName)) { + throw new JeroBootException("当前文件未找到,请重新选择!"); + } + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper(); + queryWrapper.eq(OSSFile::getConnectId, connectId); + queryWrapper.eq(OSSFile::getFileName, fileName); + queryWrapper.orderByDesc(OSSFile::getCreateTime); + List ossFileList = iossFileService.list(queryWrapper); + if (CollectionUtils.isEmpty(ossFileList)) { + throw new JeroBootException("当前文件未找到,请重新选择!"); + } + OSSFile ossFile = ossFileList.get(0); - String readFilePath = ossFile.getUrl(); - if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) { - throw new JeroBootException("当前文件未找到,请重新选择!"); - } + String readFilePath = ossFile.getUrl(); + if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) { + throw new JeroBootException("当前文件未找到,请重新选择!"); + } + try (InputStream is = CosBootUtil.download(readFilePath);) { // AttFileEO attFileEO = attFileEOService.getFileInfo(sarFileSplitInfoEO.getAttId()); // String readFilePath = filePath + "/" + attFileEO.getFilePath() + attFileEO.getFileName(); // String readFilePath = "C:\\Users\\wangc\\Desktop\\蔚来演示数据\\GB 11551-2014 汽车正面碰撞的乘员保护.docx"; // InputStream is = new FileInputStream(readFilePath); //需要将文件路更改为word文档所在路径。 - InputStream is = CosBootUtil.download(readFilePath); //需要将文件路更改为word文档所在路径。 + XWPFDocument doc = new XWPFDocument(is); Pattern ptest = Pattern.compile("^1范围"); @@ -642,27 +642,27 @@ public class FileSpiltService { // } else { // nowStart.add(String.valueOf(sarFileSplitInfoEO.getStartNumber())); // } - try { - //获取文件地址 - String connectId = sarFileSplitInfoEO.getConnectId(); - String fileName = sarFileSplitInfoEO.getFileName(); - if (StringUtils.isEmpty(connectId) || StringUtils.isEmpty(fileName)) { - throw new JeroBootException("当前文件未找到,请重新选择!"); - } - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper(); - queryWrapper.eq(OSSFile::getConnectId, connectId); - queryWrapper.eq(OSSFile::getFileName, fileName); - queryWrapper.orderByDesc(OSSFile::getCreateTime); - List ossFileList = iossFileService.list(queryWrapper); - if (CollectionUtils.isEmpty(ossFileList)) { - throw new JeroBootException("当前文件未找到,请重新选择!"); - } - OSSFile ossFile = ossFileList.get(0); - String readFilePath = ossFile.getUrl(); - if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) { - throw new JeroBootException("当前文件未找到,请重新选择!"); - } - InputStream is = CosBootUtil.download(readFilePath); + //获取文件地址 + String connectId = sarFileSplitInfoEO.getConnectId(); + String fileName = sarFileSplitInfoEO.getFileName(); + if (StringUtils.isEmpty(connectId) || StringUtils.isEmpty(fileName)) { + throw new JeroBootException("当前文件未找到,请重新选择!"); + } + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper(); + queryWrapper.eq(OSSFile::getConnectId, connectId); + queryWrapper.eq(OSSFile::getFileName, fileName); + queryWrapper.orderByDesc(OSSFile::getCreateTime); + List ossFileList = iossFileService.list(queryWrapper); + if (CollectionUtils.isEmpty(ossFileList)) { + throw new JeroBootException("当前文件未找到,请重新选择!"); + } + OSSFile ossFile = ossFileList.get(0); + String readFilePath = ossFile.getUrl(); + if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) { + throw new JeroBootException("当前文件未找到,请重新选择!"); + } + try (InputStream is = CosBootUtil.download(readFilePath);) { + // InputStream is = new FileInputStream(readFilePath); //需要将文件路更改为word文档所在路径。 XWPFDocument doc = new XWPFDocument(is); @@ -824,27 +824,27 @@ public class FileSpiltService { // } else { // nowStart.add(String.valueOf(sarFileSplitInfoEO.getStartNumber())); // } - try { - //获取文件地址 - String connectId = sarFileSplitInfoEO.getConnectId(); - String fileName = sarFileSplitInfoEO.getFileName(); - if (StringUtils.isEmpty(connectId) || StringUtils.isEmpty(fileName)) { - throw new JeroBootException("当前文件未找到,请重新选择!"); - } - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper(); - queryWrapper.eq(OSSFile::getConnectId, connectId); - queryWrapper.eq(OSSFile::getFileName, fileName); - queryWrapper.orderByDesc(OSSFile::getCreateTime); - List ossFileList = iossFileService.list(queryWrapper); - if (CollectionUtils.isEmpty(ossFileList)) { - throw new JeroBootException("当前文件未找到,请重新选择!"); - } - OSSFile ossFile = ossFileList.get(0); - String readFilePath = ossFile.getUrl(); - if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) { - throw new JeroBootException("当前文件未找到,请重新选择!"); - } - InputStream is = CosBootUtil.download(readFilePath); + //获取文件地址 + String connectId = sarFileSplitInfoEO.getConnectId(); + String fileName = sarFileSplitInfoEO.getFileName(); + if (StringUtils.isEmpty(connectId) || StringUtils.isEmpty(fileName)) { + throw new JeroBootException("当前文件未找到,请重新选择!"); + } + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper(); + queryWrapper.eq(OSSFile::getConnectId, connectId); + queryWrapper.eq(OSSFile::getFileName, fileName); + queryWrapper.orderByDesc(OSSFile::getCreateTime); + List ossFileList = iossFileService.list(queryWrapper); + if (CollectionUtils.isEmpty(ossFileList)) { + throw new JeroBootException("当前文件未找到,请重新选择!"); + } + OSSFile ossFile = ossFileList.get(0); + String readFilePath = ossFile.getUrl(); + if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) { + throw new JeroBootException("当前文件未找到,请重新选择!"); + } + try (InputStream is = CosBootUtil.download(readFilePath);) { + // InputStream is = new FileInputStream(readFilePath); //需要将文件路更改为word文档所在路径。 XWPFDocument doc = new XWPFDocument(is); @@ -1013,27 +1013,27 @@ public class FileSpiltService { // } else { // nowStart.add(String.valueOf(sarFileSplitInfoEO.getStartNumber())); // } - try { - //获取文件地址 - String connectId = sarFileSplitInfoEO.getConnectId(); - String fileName = sarFileSplitInfoEO.getFileName(); - if (StringUtils.isEmpty(connectId) || StringUtils.isEmpty(fileName)) { - throw new JeroBootException("当前文件未找到,请重新选择!"); - } - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper(); - queryWrapper.eq(OSSFile::getConnectId, connectId); - queryWrapper.eq(OSSFile::getFileName, fileName); - queryWrapper.orderByDesc(OSSFile::getCreateTime); - List ossFileList = iossFileService.list(queryWrapper); - if (CollectionUtils.isEmpty(ossFileList)) { - throw new JeroBootException("当前文件未找到,请重新选择!"); - } - OSSFile ossFile = ossFileList.get(0); - String readFilePath = ossFile.getUrl(); - if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) { - throw new JeroBootException("当前文件未找到,请重新选择!"); - } - InputStream is = CosBootUtil.download(readFilePath); + //获取文件地址 + String connectId = sarFileSplitInfoEO.getConnectId(); + String fileName = sarFileSplitInfoEO.getFileName(); + if (StringUtils.isEmpty(connectId) || StringUtils.isEmpty(fileName)) { + throw new JeroBootException("当前文件未找到,请重新选择!"); + } + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper(); + queryWrapper.eq(OSSFile::getConnectId, connectId); + queryWrapper.eq(OSSFile::getFileName, fileName); + queryWrapper.orderByDesc(OSSFile::getCreateTime); + List ossFileList = iossFileService.list(queryWrapper); + if (CollectionUtils.isEmpty(ossFileList)) { + throw new JeroBootException("当前文件未找到,请重新选择!"); + } + OSSFile ossFile = ossFileList.get(0); + String readFilePath = ossFile.getUrl(); + if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) { + throw new JeroBootException("当前文件未找到,请重新选择!"); + } + try (InputStream is = CosBootUtil.download(readFilePath);) { + // InputStream is = new FileInputStream(readFilePath); //需要将文件路更改为word文档所在路径。 XWPFDocument doc = new XWPFDocument(is); @@ -1200,27 +1200,27 @@ public class FileSpiltService { // } else { // nowStart.add(String.valueOf(sarFileSplitInfoEO.getStartNumber())); // } - try { - //获取文件地址 - String connectId = sarFileSplitInfoEO.getConnectId(); - String fileName = sarFileSplitInfoEO.getFileName(); - if (StringUtils.isEmpty(connectId) || StringUtils.isEmpty(fileName)) { - throw new JeroBootException("当前文件未找到,请重新选择!"); - } - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper(); - queryWrapper.eq(OSSFile::getConnectId, connectId); - queryWrapper.eq(OSSFile::getFileName, fileName); - queryWrapper.orderByDesc(OSSFile::getCreateTime); - List ossFileList = iossFileService.list(queryWrapper); - if (CollectionUtils.isEmpty(ossFileList)) { - throw new JeroBootException("当前文件未找到,请重新选择!"); - } - OSSFile ossFile = ossFileList.get(0); - String readFilePath = ossFile.getUrl(); - if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) { - throw new JeroBootException("当前文件未找到,请重新选择!"); - } - InputStream is = CosBootUtil.download(readFilePath); + //获取文件地址 + String connectId = sarFileSplitInfoEO.getConnectId(); + String fileName = sarFileSplitInfoEO.getFileName(); + if (StringUtils.isEmpty(connectId) || StringUtils.isEmpty(fileName)) { + throw new JeroBootException("当前文件未找到,请重新选择!"); + } + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper(); + queryWrapper.eq(OSSFile::getConnectId, connectId); + queryWrapper.eq(OSSFile::getFileName, fileName); + queryWrapper.orderByDesc(OSSFile::getCreateTime); + List ossFileList = iossFileService.list(queryWrapper); + if (CollectionUtils.isEmpty(ossFileList)) { + throw new JeroBootException("当前文件未找到,请重新选择!"); + } + OSSFile ossFile = ossFileList.get(0); + String readFilePath = ossFile.getUrl(); + if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) { + throw new JeroBootException("当前文件未找到,请重新选择!"); + } + try (InputStream is = CosBootUtil.download(readFilePath);) { + // InputStream is = new FileInputStream(readFilePath); //需要将文件路更改为word文档所在路径。 XWPFDocument doc = new XWPFDocument(is); @@ -1377,27 +1377,27 @@ public class FileSpiltService { // } else { // nowStart.add(String.valueOf(sarFileSplitInfoEO.getStartNumber())); // } - try { - //获取文件地址 - String connectId = sarFileSplitInfoEO.getConnectId(); - String fileName = sarFileSplitInfoEO.getFileName(); - if (StringUtils.isEmpty(connectId) || StringUtils.isEmpty(fileName)) { - throw new JeroBootException("当前文件未找到,请重新选择!"); - } - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper(); - queryWrapper.eq(OSSFile::getConnectId, connectId); - queryWrapper.eq(OSSFile::getFileName, fileName); - queryWrapper.orderByDesc(OSSFile::getCreateTime); - List ossFileList = iossFileService.list(queryWrapper); - if (CollectionUtils.isEmpty(ossFileList)) { - throw new JeroBootException("当前文件未找到,请重新选择!"); - } - OSSFile ossFile = ossFileList.get(0); - String readFilePath = ossFile.getUrl(); - if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) { - throw new JeroBootException("当前文件未找到,请重新选择!"); - } - InputStream is = CosBootUtil.download(readFilePath); + //获取文件地址 + String connectId = sarFileSplitInfoEO.getConnectId(); + String fileName = sarFileSplitInfoEO.getFileName(); + if (StringUtils.isEmpty(connectId) || StringUtils.isEmpty(fileName)) { + throw new JeroBootException("当前文件未找到,请重新选择!"); + } + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper(); + queryWrapper.eq(OSSFile::getConnectId, connectId); + queryWrapper.eq(OSSFile::getFileName, fileName); + queryWrapper.orderByDesc(OSSFile::getCreateTime); + List ossFileList = iossFileService.list(queryWrapper); + if (CollectionUtils.isEmpty(ossFileList)) { + throw new JeroBootException("当前文件未找到,请重新选择!"); + } + OSSFile ossFile = ossFileList.get(0); + String readFilePath = ossFile.getUrl(); + if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) { + throw new JeroBootException("当前文件未找到,请重新选择!"); + } + try (InputStream is = CosBootUtil.download(readFilePath);){ + // InputStream is = new FileInputStream(readFilePath); //需要将文件路更改为word文档所在路径。 XWPFDocument doc = new XWPFDocument(is); @@ -1565,28 +1565,28 @@ public class FileSpiltService { // } else { // nowStart.add(String.valueOf(sarFileSplitInfoEO.getStartNumber())); // } - try { - //获取文件地址 - String connectId = sarFileSplitInfoEO.getConnectId(); - String fileName = sarFileSplitInfoEO.getFileName(); - if (StringUtils.isEmpty(connectId) || StringUtils.isEmpty(fileName)) { - throw new JeroBootException("当前文件未找到,请重新选择!"); - } - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper(); - queryWrapper.eq(OSSFile::getConnectId, connectId); - queryWrapper.eq(OSSFile::getFileName, fileName); - queryWrapper.orderByDesc(OSSFile::getCreateTime); - List ossFileList = iossFileService.list(queryWrapper); - if (CollectionUtils.isEmpty(ossFileList)) { - throw new JeroBootException("当前文件未找到,请重新选择!"); - } - OSSFile ossFile = ossFileList.get(0); - String readFilePath = ossFile.getUrl(); + //获取文件地址 + String connectId = sarFileSplitInfoEO.getConnectId(); + String fileName = sarFileSplitInfoEO.getFileName(); + if (StringUtils.isEmpty(connectId) || StringUtils.isEmpty(fileName)) { + throw new JeroBootException("当前文件未找到,请重新选择!"); + } + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper(); + queryWrapper.eq(OSSFile::getConnectId, connectId); + queryWrapper.eq(OSSFile::getFileName, fileName); + queryWrapper.orderByDesc(OSSFile::getCreateTime); + List ossFileList = iossFileService.list(queryWrapper); + if (CollectionUtils.isEmpty(ossFileList)) { + throw new JeroBootException("当前文件未找到,请重新选择!"); + } + OSSFile ossFile = ossFileList.get(0); + String readFilePath = ossFile.getUrl(); + + if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) { + throw new JeroBootException("当前文件未找到,请重新选择!"); + } + try (InputStream is = CosBootUtil.download(readFilePath);){ - if (StringUtils.isEmpty(readFilePath) || !CosBootUtil.doesObjectExist(readFilePath)) { - throw new JeroBootException("当前文件未找到,请重新选择!"); - } - InputStream is = CosBootUtil.download(readFilePath); // InputStream is = new FileInputStream(readFilePath); //需要将文件路更改为word文档所在路径。 XWPFDocument doc = new XWPFDocument(is); diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/split/service/impl/FileSplitItemsEOServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/split/service/impl/FileSplitItemsEOServiceImpl.java index 17b066d6f..bb5bd606d 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/split/service/impl/FileSplitItemsEOServiceImpl.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/split/service/impl/FileSplitItemsEOServiceImpl.java @@ -1652,9 +1652,14 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl result = importSplitItems(mFile, cut, menuId, infoId); if(!result.isSuccess()){ @@ -3284,25 +3289,33 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl allImgList, String fileNowPath) throws IOException { + public void downLoadImgList(List allImgList, String fileNowPath) { for(FileSplitValImgExportDto imgExportDto : allImgList){ String oldPath = imgExportDto.getImgPath(); String newPath = fileNowPath + File.separator + imgExportDto.getImgName(); if (CosBootUtil.doesObjectExist(oldPath)){ - InputStream in = CosBootUtil.download(oldPath); - copyFile1(in, newPath); + try (InputStream in = CosBootUtil.download(oldPath);) { + copyFile1(in, newPath); + } catch (IOException e) { + e.printStackTrace(); + log.error(e.getMessage(), e); + } } } } - public void downLoadFileList(List allRelevFileList,String fileNowPath) throws IOException { + public void downLoadFileList(List allRelevFileList,String fileNowPath) { for(OSSFile fileExportDto : allRelevFileList){ String oldPath = fileExportDto.getUrl(); String newPath = fileNowPath + File.separator + fileExportDto.getFileName(); if (CosBootUtil.doesObjectExist(oldPath)){ - InputStream in = CosBootUtil.download(oldPath); - copyFile1(in, newPath); + try (InputStream in = CosBootUtil.download(oldPath);) { + copyFile1(in, newPath); + } catch (IOException e) { + e.printStackTrace(); + log.error(e.getMessage(), e); + } } } @@ -3326,6 +3339,8 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl