From ec24147e3fdd1fd5a89ce04c2a54180330f0cdfe Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Wed, 13 Mar 2024 15:37:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=BA=E5=B7=A5=E4=BA=A4=E4=BA=92=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E4=BF=AE=E6=94=B9=E4=B8=8D=E4=BD=BF=E7=94=A8ftp?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E4=B8=8A=E4=BC=A0=EF=BC=8C=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E8=BF=9C=E7=A8=8B=E6=9C=8D=E5=8A=A1=E6=96=87=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E6=9C=AC=E5=9C=B0=E4=B8=8A=E4=BC=A0=EF=BC=8C?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/jeecg/common/util/FTPUtil.java | 201 +++++++++++------- .../org/jeecg/common/util/GammaFileUtil.java | 16 +- .../org/jeecg/common/util/PHDFileUtil.java | 13 +- .../service/impl/GammaServiceImpl.java | 49 +---- .../impl/SpectrumAnalysisServiceImpl.java | 44 +--- .../org/jeecg/common/util/ReadLineUtil.java | 6 +- .../impl/GardsSampleDataWebServiceImpl.java | 2 +- 7 files changed, 158 insertions(+), 173 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/FTPUtil.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/FTPUtil.java index 0e16b41e..92040c73 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/FTPUtil.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/FTPUtil.java @@ -285,35 +285,70 @@ public class FTPUtil { * @param inputStream 文件输入流 * @return 返回值true/false */ - public synchronized boolean saveFile(String filePath,String fileName,InputStream inputStream){ - final FTPClient ftpClient = this.LoginFTP(); - try{ - final boolean flag = this.checkDirectory(ftpClient,filePath); - if(flag){ - ftpClient.setFileType(FTP.BINARY_FILE_TYPE); - String encodedName = new String(fileName.getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1); - final boolean result = ftpClient.storeFile(encodedName, inputStream); - return result; + public synchronized boolean saveFile(String filePath, InputStream inputStream){ + //声明目标文件 + File targetFile = new File(filePath); + OutputStream outputStream = null; + try { + //获取父级路径 + File directory = targetFile.getParentFile(); + //判断父级路径是否存在 + if (!directory.exists()) { + directory.mkdirs(); } - }catch (IOException e){ - log.error("{}文件创建失败,原因为:{}",filePath+"/"+fileName,e.getMessage()); - e.printStackTrace(); - return false; - }finally { - if(null != inputStream){ - try { - inputStream.close(); - } catch (IOException e) { - e.printStackTrace(); - } + // 创建输出流对象并写入数据到文件 + outputStream = new FileOutputStream(targetFile); + byte[] buffer = new byte[1024]; + int length; + while ((length = inputStream.read(buffer)) > 0) { + outputStream.write(buffer, 0, length); } + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + // 关闭输入流和输出流 try { - ftpClient.disconnect(); + if (Objects.nonNull(inputStream)) { + inputStream.close(); + } + if (Objects.nonNull(outputStream)) { + outputStream.close(); + } } catch (IOException e) { - e.printStackTrace(); + throw new RuntimeException(e); } } - return false; + return true; +// final FTPClient ftpClient = this.LoginFTP(); +// try{ +// final boolean flag = this.checkDirectory(ftpClient,filePath); +// if(flag){ +// ftpClient.setFileType(FTP.BINARY_FILE_TYPE); +// String encodedName = new String(fileName.getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1); +// final boolean result = ftpClient.storeFile(encodedName, inputStream); +// return result; +// } +// }catch (IOException e){ +// log.error("{}文件创建失败,原因为:{}",filePath+"/"+fileName,e.getMessage()); +// e.printStackTrace(); +// return false; +// }finally { +// if(null != inputStream){ +// try { +// inputStream.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } +// try { +// ftpClient.disconnect(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } +// return false; } /** @@ -458,65 +493,85 @@ public class FTPUtil { /* * 将源FTP路径的文件保存为指定路径的临时文件 * */ - public File downloadFile(String fromPath, String toPath) { - FTPClient ftpClient = null; - InputStream inputStream = null; - // 声明一个临时文件 - File tempFile = null; - try { - ftpClient = LoginFTP(); - // 切换被动模式 - ftpClient.enterLocalPassiveMode(); - ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); - // 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项 - ftpClient.setControlEncoding("UTF-8"); - ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE); - inputStream = ftpClient.retrieveFileStream(fromPath); - if (Objects.nonNull(inputStream)) { - tempFile = File.createTempFile(toPath, null); - // 将FTP文件的输入流复制给临时文件 - FileUtils.copyInputStreamToFile(inputStream, tempFile); - } - return tempFile; - } catch (IOException e) { - e.printStackTrace(); - return null; - } finally { - try { - if (ObjectUtil.isNotNull(ftpClient)) - ftpClient.disconnect(); - if (ObjectUtil.isNotNull(inputStream)) - inputStream.close(); - } catch (IOException e) { - e.printStackTrace(); - } + public File downloadFile(String fromPath) { + //获取路径下的文件信息 + File tempFile = new File(fromPath); + //判断文件是否存在 + if (!tempFile.exists()) { + tempFile = null; } + return tempFile; +// FTPClient ftpClient = null; +// InputStream inputStream = null; +// // 声明一个临时文件 +// File tempFile = null; +// try { +// //连接ftp +// ftpClient = LoginFTP(); +// // 切换被动模式 +// ftpClient.enterLocalPassiveMode(); +// ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); +// // 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项 +// ftpClient.setControlEncoding("UTF-8"); +// ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE); +// inputStream = ftpClient.retrieveFileStream(fromPath); +// if (Objects.nonNull(inputStream)) { +// tempFile = File.createTempFile(toPath, null); +// // 将FTP文件的输入流复制给临时文件 +// FileUtils.copyInputStreamToFile(inputStream, tempFile); +// } +// return tempFile; +// } catch (IOException e) { +// e.printStackTrace(); +// return null; +// } finally { +// try { +// if (ObjectUtil.isNotNull(ftpClient)) +// ftpClient.disconnect(); +// if (ObjectUtil.isNotNull(inputStream)) +// inputStream.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } } /* * 将源FTP路径的文件转换为文件流 * */ public InputStream downloadFileStream(String fromPath) { - FTPClient ftpClient = null; + //获取路径下的文件信息 + File tempFile = new File(fromPath); + InputStream inputStream = null; try { - ftpClient = LoginFTP(); - // 切换被动模式 - ftpClient.enterLocalPassiveMode(); - ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); - // 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项 - ftpClient.setControlEncoding("UTF-8"); - ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE); - return ftpClient.retrieveFileStream(fromPath); - } catch (IOException e) { - e.printStackTrace(); - return null; - } finally { - try { - if (ObjectUtil.isNotNull(ftpClient)) - ftpClient.disconnect(); - } catch (IOException e) { - e.printStackTrace(); + //判断文件是否存在 + if (tempFile.exists()) { + inputStream = new FileInputStream(tempFile); } + return inputStream; + } catch (FileNotFoundException e) { + throw new RuntimeException(e); } +// FTPClient ftpClient = null; +// try { +// ftpClient = LoginFTP(); +// // 切换被动模式 +// ftpClient.enterLocalPassiveMode(); +// ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); +// // 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项 +// ftpClient.setControlEncoding("UTF-8"); +// ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE); +// return ftpClient.retrieveFileStream(fromPath); +// } catch (IOException e) { +// e.printStackTrace(); +// return null; +// } finally { +// try { +// if (ObjectUtil.isNotNull(ftpClient)) +// ftpClient.disconnect(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } } } diff --git a/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/common/util/GammaFileUtil.java b/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/common/util/GammaFileUtil.java index 3da16c3f..e97794c3 100644 --- a/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/common/util/GammaFileUtil.java +++ b/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/common/util/GammaFileUtil.java @@ -70,9 +70,9 @@ public class GammaFileUtil extends AbstractLogOrReport { //如果功能是人工交互模块则从ftp获取文件内容 File file = null; if (sysSource.equals("BetaGamma")) { - file = ftpUtil.downloadFile(fromPath, "betaGamma"); + file = ftpUtil.downloadFile(fromPath); if (Objects.isNull(file)) { - result.error500("ftp file can't find"); + result.error500("file can't find"); return false; } } else if (sysSource.equals("AUTO")) {//如果是自动处理则从本地文件中获取文件内容 @@ -265,7 +265,7 @@ public class GammaFileUtil extends AbstractLogOrReport { try { String lcFileName = prefixName+"_"+subFileName + ".lc"; String fromPathLc = pathName + StringPool.SLASH + lcFileName; - lcFile = ftpUtil.downloadFile(fromPathLc, "betaGamma"); + lcFile = ftpUtil.downloadFile(fromPathLc); if (Objects.nonNull(lcFile)) { List readLinesLc = FileUtils.readLines(lcFile, "UTF-8"); //得到行数据处理后的数据结果 @@ -275,7 +275,7 @@ public class GammaFileUtil extends AbstractLogOrReport { } String scacFileName = prefixName+"_"+subFileName + ".scac"; String fromPathScac = pathName + StringPool.SLASH + scacFileName; - scacFile = ftpUtil.downloadFile(fromPathScac, "betaGamma"); + scacFile = ftpUtil.downloadFile(fromPathScac); if (Objects.nonNull(scacFile)) { List readLinesScac = FileUtils.readLines(scacFile, "UTF-8"); //得到行数据处理后的数据结果 @@ -298,10 +298,6 @@ public class GammaFileUtil extends AbstractLogOrReport { try { if (ObjectUtil.isNotNull(inputStreamBase)) inputStreamBase.close(); - if (ObjectUtil.isNotNull(lcFile)) - lcFile.delete(); - if (ObjectUtil.isNotNull(scacFile)) - scacFile.delete(); } catch (IOException e) { e.printStackTrace(); } @@ -3235,7 +3231,7 @@ public class GammaFileUtil extends AbstractLogOrReport { try { sampleTmp = new File(fileAnlyse.getTmpFilePath()); if (Objects.nonNull(sampleTmp)) { - bRet = ftpUtil.saveFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + middleData.analyses_save_filePath.substring(0, middleData.analyses_save_filePath.lastIndexOf(StringPool.SLASH)), middleData.analyses_save_filePath.substring(middleData.analyses_save_filePath.lastIndexOf(StringPool.SLASH)+1), new FileInputStream(sampleTmp)); + bRet = ftpUtil.saveFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + middleData.analyses_save_filePath, new FileInputStream(sampleTmp)); } } catch (FileNotFoundException e) { throw new RuntimeException(e); @@ -4369,7 +4365,7 @@ public class GammaFileUtil extends AbstractLogOrReport { public File analyzeFile(String path, String fileName) { path = path.replace("\\", "/"); String fromPath = path + StringPool.SLASH + fileName; - return ftpUtil.downloadFile(fromPath, "betaGamma"); + return ftpUtil.downloadFile(fromPath); } public List readLine(String filePath) { diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/common/util/PHDFileUtil.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/common/util/PHDFileUtil.java index d7ae8bf9..2b19508d 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/common/util/PHDFileUtil.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/common/util/PHDFileUtil.java @@ -817,7 +817,7 @@ public class PHDFileUtil extends AbstractLogOrReport { File file = null; try { String fromPath = filePath + StringPool.SLASH + sampleFileName; - file = ftpUtil.downloadFile(fromPath, "betaGamma"); + file = ftpUtil.downloadFile(fromPath); //加载sampleFile内容 EnergySpectrumStruct struct = EnergySpectrumHandler.getSourceData(file.getAbsolutePath()); //获取所需要的数据 @@ -841,9 +841,6 @@ public class PHDFileUtil extends AbstractLogOrReport { }catch (Exception e){ e.printStackTrace(); return map; - }finally { - if (ObjectUtil.isNotNull(file)) - file.delete(); } } @@ -852,7 +849,7 @@ public class PHDFileUtil extends AbstractLogOrReport { File file = null; try { String fromPath = filePath + StringPool.SLASH + fileName; - file = ftpUtil.downloadFile(fromPath, "betaGamma"); + file = ftpUtil.downloadFile(fromPath); EnergySpectrumStruct sourceData = EnergySpectrumHandler.getSourceData(file.getAbsolutePath()); String systemType = sourceData.system_type; String dataType = sourceData.data_type; @@ -886,9 +883,6 @@ public class PHDFileUtil extends AbstractLogOrReport { }catch (Exception e){ e.printStackTrace(); return path.toString(); - }finally { - if (ObjectUtil.isNotNull(file)) - file.delete(); } } @@ -1118,9 +1112,6 @@ public class PHDFileUtil extends AbstractLogOrReport { if (Objects.nonNull(inputStream)){ inputStream.close(); } - if (Objects.nonNull(file)) { - file.delete(); - } } catch (IOException e) { throw new RuntimeException(e); } diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GammaServiceImpl.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GammaServiceImpl.java index 54f6cd89..7758cfd4 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GammaServiceImpl.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GammaServiceImpl.java @@ -368,10 +368,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi result.setResult(phd); } catch (JsonProcessingException e) { throw new RuntimeException(e); - } finally { - if (Objects.nonNull(tmpFile)) { - tmpFile.delete(); - } } result.setSuccess(true); return result; @@ -884,12 +880,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi String key = fileName + StrUtil.DASHED + username; Cache phdCache = localCache.getPHDCache(); PHDFile phdFile = phdCache.getIfPresent(key); - if (StringUtils.isNotBlank(phdFile.getTmpFilePath())) { - File file = new File(phdFile.getTmpFilePath()); - if (Objects.nonNull(file)) { - file.delete(); - } - } // 删除指定key的Cache localCache.deletePHDCache(key); } @@ -957,7 +947,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi return result; } compareFilePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + compareFilePath; - File compareFile = ftpUtil.downloadFile(compareFilePath, "betaGamma"); + File compareFile = ftpUtil.downloadFile(compareFilePath); if (Objects.isNull(compareFile)) { result.error500("The comparison file path does not exist"); return result; @@ -969,7 +959,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi result.setSuccess(true); result.setResult(chartDataList); } - compareFile.delete(); return result; } @@ -991,7 +980,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi //加载compare文件 String compareFilePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName; String fromPath = compareFilePath + StringPool.SLASH + compareFileName; - File compareFile = ftpUtil.downloadFile(fromPath, "betaGamma"); + File compareFile = ftpUtil.downloadFile(fromPath); if (Objects.nonNull(compareFile)) { // 获取Compare数据 List m_vecCompare = gammaFileUtil.loadCompareData(compareFile, userName, m_nCount, result); @@ -1000,7 +989,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi result.setSuccess(true); result.setResult(chartDataList); } - compareFile.delete(); } return result; } @@ -1041,7 +1029,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi return result; } stripFilePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + stripFilePath; - File stripFile = ftpUtil.downloadFile(stripFilePath, "betaGamma"); + File stripFile = ftpUtil.downloadFile(stripFilePath); if (Objects.isNull(stripFile)) { result.error500("The comparison file path does not exist"); return result; @@ -1056,7 +1044,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi result.setSuccess(true); result.setResult(stripMap); } - stripFile.delete(); return result; } @@ -1092,7 +1079,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi //加载strip文件 String stripFilePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName; String fromPath = stripFilePath + StringPool.SLASH + stripFileName; - File stripFile = ftpUtil.downloadFile(fromPath, "betaGamma"); + File stripFile = ftpUtil.downloadFile(fromPath); if (Objects.nonNull(stripFile)) { // 获取Compare数据 List m_vecCompare = gammaFileUtil.loadCompareData(stripFile, userName, m_nCount, result); @@ -1104,7 +1091,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi result.setSuccess(true); result.setResult(stripMap); } - stripFile.delete(); } return result; } @@ -3234,9 +3220,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi if (Objects.nonNull(inputStream)) { inputStream.close(); } - if (Objects.nonNull(tmpFile)) { - tmpFile.delete(); - } } catch (IOException e) { throw new RuntimeException(e); } @@ -3508,9 +3491,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi if (Objects.nonNull(inputStream)) { inputStream.close(); } - if (Objects.nonNull(tmpFile)) { - tmpFile.delete(); - } } catch (IOException e) { throw new RuntimeException(e); } @@ -3804,9 +3784,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi if (Objects.nonNull(inputStream)) { inputStream.close(); } - if (Objects.nonNull(tmpFile)) { - tmpFile.delete(); - } } catch (IOException e) { throw new RuntimeException(e); } @@ -5019,46 +4996,39 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi //分析成功后存储日志文件和报告文件 String rootPath = spectrumPathProperties.getRootPath(); { - String baselinePathName = ftpUtil.getFtpRootPath()+middleData.analyses_baseline_absolute_filePath.substring(0, middleData.analyses_baseline_absolute_filePath.lastIndexOf(StringPool.SLASH)); - String baselineFileName = middleData.analyses_baseline_absolute_filePath.substring(middleData.analyses_baseline_absolute_filePath.lastIndexOf(StringPool.SLASH) + 1); File baselineFile = new File(rootPath+middleData.analyses_baseline_absolute_filePath); try { FileInputStream in = new FileInputStream(baselineFile); - ftpUtil.saveFile(baselinePathName, baselineFileName, in); + ftpUtil.saveFile(ftpUtil.getFtpRootPath()+middleData.analyses_baseline_absolute_filePath, in); } catch (FileNotFoundException e) { throw new RuntimeException(e); } } { - String lcPathName = ftpUtil.getFtpRootPath()+middleData.analyses_lc_absolute_filePath.substring(0, middleData.analyses_lc_absolute_filePath.lastIndexOf(StringPool.SLASH)); - String lcFileName = middleData.analyses_lc_absolute_filePath.substring(middleData.analyses_lc_absolute_filePath.lastIndexOf(StringPool.SLASH) + 1); File lcFile = new File(rootPath+middleData.analyses_lc_absolute_filePath); try { FileInputStream in = new FileInputStream(lcFile); - ftpUtil.saveFile(lcPathName, lcFileName, in); + ftpUtil.saveFile(ftpUtil.getFtpRootPath()+middleData.analyses_lc_absolute_filePath, in); } catch (FileNotFoundException e) { throw new RuntimeException(e); } } { - String scacPathName = ftpUtil.getFtpRootPath()+middleData.analyses_scac_absolute_filePath.substring(0, middleData.analyses_scac_absolute_filePath.lastIndexOf(StringPool.SLASH)); - String scacFileName = middleData.analyses_scac_absolute_filePath.substring(middleData.analyses_scac_absolute_filePath.lastIndexOf(StringPool.SLASH) + 1); File scacFile = new File(rootPath+middleData.analyses_scac_absolute_filePath); try { FileInputStream in = new FileInputStream(scacFile); - ftpUtil.saveFile(scacPathName, scacFileName, in); + ftpUtil.saveFile(ftpUtil.getFtpRootPath()+middleData.analyses_scac_absolute_filePath, in); } catch (FileNotFoundException e) { throw new RuntimeException(e); } } { - String logPathName = middleData.analyses_absolute_LogPath.substring(0, middleData.analyses_absolute_LogPath.lastIndexOf(StringPool.SLASH)); String logFileName = middleData.analyses_absolute_LogPath.substring(middleData.analyses_absolute_LogPath.lastIndexOf(StringPool.SLASH)+1); File logFile = new File(logFileName); try { FileUtil.writeString(gammaFileUtil.GetLogContent(middleData), logFile, "UTF-8"); FileInputStream in = new FileInputStream(logFile); - ftpUtil.saveFile(logPathName, logFileName, in); + ftpUtil.saveFile(middleData.analyses_absolute_LogPath, in); } catch (FileNotFoundException e) { throw new RuntimeException(e); } finally { @@ -5066,13 +5036,12 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi } } { - String rptPathName = middleData.analyses_absolute_ReportPath.substring(0, middleData.analyses_absolute_ReportPath.lastIndexOf(StringPool.SLASH)); String rptFileName = middleData.analyses_absolute_ReportPath.substring(middleData.analyses_absolute_ReportPath.lastIndexOf(StringPool.SLASH)+1)+".txt"; File rptFile = new File(rptFileName); try { FileUtil.writeString(gammaFileUtil.GetReportContent(middleData), rptFile, "UTF-8"); FileInputStream in = new FileInputStream(rptFile); - ftpUtil.saveFile(rptPathName, rptFileName, in); + ftpUtil.saveFile(middleData.analyses_absolute_ReportPath+".txt", in); } catch (FileNotFoundException e) { throw new RuntimeException(e); } finally { diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumAnalysisServiceImpl.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumAnalysisServiceImpl.java index 5b7bc57d..a8161b98 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumAnalysisServiceImpl.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumAnalysisServiceImpl.java @@ -473,7 +473,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements if (Objects.nonNull(sample)) { betaDataFile.setSampleFilePathName(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH +dbSpectrumFilePath.getSampleFilePath()); betaDataFile.setSampleFileName(sampleFileName); - sampleTmp = ftpUtil.downloadFile(betaDataFile.getSampleFilePathName(), "betaGamma"); + sampleTmp = ftpUtil.downloadFile(betaDataFile.getSampleFilePathName()); if (Objects.nonNull(sampleTmp)) { //sample临时文件路径存储 betaDataFile.setSampleTmpPath(sampleTmp.getAbsolutePath()); @@ -510,7 +510,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements if (Objects.nonNull(gasBg)) { betaDataFile.setGasFilePathName(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH +dbSpectrumFilePath.getGasBgFilePath()); betaDataFile.setGasFileName(gasFileName); - gasTmp = ftpUtil.downloadFile(betaDataFile.getGasFilePathName(), "betaGamma"); + gasTmp = ftpUtil.downloadFile(betaDataFile.getGasFilePathName()); if (Objects.nonNull(gasTmp)) { //存储gas临时文件路径 betaDataFile.setGasTmpPath(gasTmp.getAbsolutePath()); @@ -547,7 +547,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements if (Objects.nonNull(detBg)) { betaDataFile.setDetFilePathName(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH +dbSpectrumFilePath.getDetBgFilePath()); betaDataFile.setDetFileName(detFileName); - detTmp = ftpUtil.downloadFile(betaDataFile.getDetFilePathName(), "betaGamma"); + detTmp = ftpUtil.downloadFile(betaDataFile.getDetFilePathName()); if (Objects.nonNull(detTmp)) { //存储det临时文件路径 betaDataFile.setDetTmpPath(detTmp.getAbsolutePath()); @@ -584,7 +584,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements if (Objects.nonNull(qc)) { betaDataFile.setQcFilePathName(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH +dbQcFilePath); betaDataFile.setQcFileName(qcFileName); - qcTmp = ftpUtil.downloadFile(betaDataFile.getQcFilePathName(), "betaGamma"); + qcTmp = ftpUtil.downloadFile(betaDataFile.getQcFilePathName()); if (Objects.nonNull(qcTmp)) { betaDataFile.setQcTmpPath(qcTmp.getAbsolutePath()); EnergySpectrumStruct struct = EnergySpectrumHandler.getSourceData(qcTmp.getAbsolutePath()); @@ -773,7 +773,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements File file = null; try { //根据完整的文件路径 获取临时文件 - file = ftpUtil.downloadFile(filePathName, "betaGamma"); + file = ftpUtil.downloadFile(filePathName); if (Objects.nonNull(file)) { if (type.equalsIgnoreCase("sample")) { betaDataFile.setSampleTmpPath(file.getAbsolutePath()); @@ -870,26 +870,6 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements String betaKey = sampleFileName + "-" + userName; Cache cache = betaCache.getBetaCache(); BetaDataFile betaDataFile = cache.getIfPresent(betaKey); - String sampleTmpPath = betaDataFile.getSampleTmpPath(); - if (StringUtils.isNotBlank(sampleTmpPath)) { - File file = new File(sampleTmpPath); - file.delete(); - } - String gasTmpPath = betaDataFile.getGasTmpPath(); - if (StringUtils.isNotBlank(gasTmpPath)) { - File file = new File(gasTmpPath); - file.delete(); - } - String detTmpPath = betaDataFile.getDetTmpPath(); - if (StringUtils.isNotBlank(detTmpPath)) { - File file = new File(detTmpPath); - file.delete(); - } - String qcTmpPath = betaDataFile.getQcTmpPath(); - if (StringUtils.isNotBlank(qcTmpPath)) { - File file = new File(qcTmpPath); - file.delete(); - } betaCache.deleteBetaCache(betaKey); } @@ -4282,23 +4262,22 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements try { if (StringUtils.isNotBlank(betaDataFile.getSampleTmpPath())) { File sampleTmp = new File(betaDataFile.getSampleTmpPath()); - ftpUtil.saveFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + sampleFilePathName.substring(0, sampleFilePathName.lastIndexOf(StringPool.SLASH)), anlyseResultIn.getSampleFileName(), new FileInputStream(sampleTmp)); + ftpUtil.saveFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + sampleFilePathName, new FileInputStream(sampleTmp)); } if (StringUtils.isNotBlank(betaDataFile.getGasTmpPath())) { File gasTmp = new File(betaDataFile.getGasTmpPath()); - ftpUtil.saveFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + gasFilePathName.substring(0, gasFilePathName.lastIndexOf(StringPool.SLASH)), anlyseResultIn.getGasFileName(), new FileInputStream(gasTmp)); + ftpUtil.saveFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + gasFilePathName, new FileInputStream(gasTmp)); } if (StringUtils.isNotBlank(betaDataFile.getDetTmpPath())) { File detTmp = new File(betaDataFile.getDetTmpPath()); - ftpUtil.saveFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + detFilePathName.substring(0, detFilePathName.lastIndexOf(StringPool.SLASH)), anlyseResultIn.getDetFileName(), new FileInputStream(detTmp)); + ftpUtil.saveFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + detFilePathName, new FileInputStream(detTmp)); } if (StringUtils.isNotBlank(betaDataFile.getQcTmpPath())) { File qcTmp = new File(betaDataFile.getQcTmpPath()); - ftpUtil.saveFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + qcFilePathName.substring(0, qcFilePathName.lastIndexOf(StringPool.SLASH)), anlyseResultIn.getQcFileName(), new FileInputStream(qcTmp)); + ftpUtil.saveFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + qcFilePathName, new FileInputStream(qcTmp)); } //分析成功后存储日志文件和报告文件 { - String logPathName = analyses_absolute_LogPath.substring(0, analyses_absolute_LogPath.lastIndexOf(StringPool.SLASH)); String logFileName = analyses_absolute_LogPath.substring(analyses_absolute_LogPath.lastIndexOf(StringPool.SLASH)+1); //获取日志的文件存放路径 String logFilePath = parameterProperties.getLogFilePath() + File.separator + DateUtils.formatDate(new Date(), "yyyy-MM-dd"); @@ -4314,20 +4293,19 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements FileUtil.writeString("", logFile, "UTF-8"); } FileInputStream in = new FileInputStream(logFile); - ftpUtil.saveFile(logPathName, logFileName, in); + ftpUtil.saveFile(analyses_absolute_LogPath, in); } catch (FileNotFoundException e) { throw new RuntimeException(e); } } { String rptContent = phdFileUtil.OutPutRnRpt(betaDataFile); - String rptPathName = analyses_absolute_ReportPath.substring(0, analyses_absolute_ReportPath.lastIndexOf(StringPool.SLASH)); String rptFileName = analyses_absolute_ReportPath.substring(analyses_absolute_ReportPath.lastIndexOf(StringPool.SLASH)+1)+".txt"; File rptFile = new File(rptFileName); try { FileUtil.writeString(rptContent, rptFile, "UTF-8"); FileInputStream in = new FileInputStream(rptFile); - ftpUtil.saveFile(rptPathName, rptFileName, in); + ftpUtil.saveFile(analyses_absolute_ReportPath+".txt", in); } catch (FileNotFoundException e) { throw new RuntimeException(e); } finally { diff --git a/jeecg-module-web-statistics/src/main/java/org/jeecg/common/util/ReadLineUtil.java b/jeecg-module-web-statistics/src/main/java/org/jeecg/common/util/ReadLineUtil.java index 5e8e8c85..dd776e78 100644 --- a/jeecg-module-web-statistics/src/main/java/org/jeecg/common/util/ReadLineUtil.java +++ b/jeecg-module-web-statistics/src/main/java/org/jeecg/common/util/ReadLineUtil.java @@ -34,7 +34,7 @@ public class ReadLineUtil { File file = null; try { filePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + filePath; - file = ftpUtil.downloadFile(filePath, "betaGamma"); + file = ftpUtil.downloadFile(filePath); //判断文件路径是否为空 if (Objects.nonNull(file)){ List allLines = FileUtils.readLines(file, encoding); @@ -52,10 +52,6 @@ public class ReadLineUtil { } } catch (IOException e) { throw new RuntimeException(e); - } finally { - if (Objects.nonNull(file)) { - file.delete(); - } } return Collections.emptyMap(); } diff --git a/jeecg-module-web-statistics/src/main/java/org/jeecg/modules/service/impl/GardsSampleDataWebServiceImpl.java b/jeecg-module-web-statistics/src/main/java/org/jeecg/modules/service/impl/GardsSampleDataWebServiceImpl.java index c64a1e1b..6f3eb318 100644 --- a/jeecg-module-web-statistics/src/main/java/org/jeecg/modules/service/impl/GardsSampleDataWebServiceImpl.java +++ b/jeecg-module-web-statistics/src/main/java/org/jeecg/modules/service/impl/GardsSampleDataWebServiceImpl.java @@ -133,7 +133,7 @@ public class GardsSampleDataWebServiceImpl extends ServiceImpl