From ec24147e3fdd1fd5a89ce04c2a54180330f0cdfe Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Wed, 13 Mar 2024 15:37:26 +0800 Subject: [PATCH 01/40] =?UTF-8?q?=E4=BA=BA=E5=B7=A5=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E4=BF=AE=E6=94=B9=E4=B8=8D=E4=BD=BF=E7=94=A8?= =?UTF-8?q?ftp=E6=9C=8D=E5=8A=A1=E4=B8=8A=E4=BC=A0=EF=BC=8C=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E8=BF=9C=E7=A8=8B=E6=9C=8D=E5=8A=A1=E6=96=87=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E6=94=B9=E4=B8=BA=E6=9C=AC=E5=9C=B0=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=EF=BC=8C=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 Date: Wed, 13 Mar 2024 16:37:48 +0800 Subject: [PATCH 02/40] =?UTF-8?q?=E4=BA=BA=E5=B7=A5=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E6=A8=A1=E5=9D=97ftp=E6=9C=8D=E5=8A=A1=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=96=B9=E6=B3=95=E4=BF=AE=E6=94=B9=20?= =?UTF-8?q?=E4=BA=BA=E5=B7=A5=E4=BA=A4=E4=BA=92=E4=BF=9D=E5=AD=98=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E6=96=B9=E6=B3=95=E4=BF=9D=E5=AD=98=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/jeecg/common/util/FTPUtil.java | 6 +- .../service/impl/GammaServiceImpl.java | 58 +++++++------- .../impl/SpectrumAnalysisServiceImpl.java | 4 +- .../service/impl/SpectrumFileServiceImpl.java | 75 +++++++++++++------ 4 files changed, 88 insertions(+), 55 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 92040c73..a4f35ece 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 @@ -281,14 +281,14 @@ public class FTPUtil { /** * 写入文件,若文件或文件目录不存在则自行创建 * @param filePath 文件路径 - * @param fileName 文件名称 * @param inputStream 文件输入流 * @return 返回值true/false */ public synchronized boolean saveFile(String filePath, InputStream inputStream){ //声明目标文件 File targetFile = new File(filePath); - OutputStream outputStream = null; + //创建输出流 + BufferedOutputStream outputStream = null; try { //获取父级路径 File directory = targetFile.getParentFile(); @@ -297,7 +297,7 @@ public class FTPUtil { directory.mkdirs(); } // 创建输出流对象并写入数据到文件 - outputStream = new FileOutputStream(targetFile); + outputStream = new BufferedOutputStream(new FileOutputStream(targetFile)); byte[] buffer = new byte[1024]; int length; while ((length = inputStream.read(buffer)) > 0) { 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 7758cfd4..8671de66 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 @@ -4995,40 +4995,40 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi phd.setStatus("R"); //分析成功后存储日志文件和报告文件 String rootPath = spectrumPathProperties.getRootPath(); - { - File baselineFile = new File(rootPath+middleData.analyses_baseline_absolute_filePath); - try { - FileInputStream in = new FileInputStream(baselineFile); - ftpUtil.saveFile(ftpUtil.getFtpRootPath()+middleData.analyses_baseline_absolute_filePath, in); - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } - } - { - File lcFile = new File(rootPath+middleData.analyses_lc_absolute_filePath); - try { - FileInputStream in = new FileInputStream(lcFile); - ftpUtil.saveFile(ftpUtil.getFtpRootPath()+middleData.analyses_lc_absolute_filePath, in); - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } - } - { - File scacFile = new File(rootPath+middleData.analyses_scac_absolute_filePath); - try { - FileInputStream in = new FileInputStream(scacFile); - ftpUtil.saveFile(ftpUtil.getFtpRootPath()+middleData.analyses_scac_absolute_filePath, in); - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } - } +// { +// File baselineFile = new File(rootPath+middleData.analyses_baseline_absolute_filePath); +// try { +// FileInputStream in = new FileInputStream(baselineFile); +// ftpUtil.saveFile(ftpUtil.getFtpRootPath()+middleData.analyses_baseline_absolute_filePath, in); +// } catch (FileNotFoundException e) { +// throw new RuntimeException(e); +// } +// } +// { +// File lcFile = new File(rootPath+middleData.analyses_lc_absolute_filePath); +// try { +// FileInputStream in = new FileInputStream(lcFile); +// ftpUtil.saveFile(ftpUtil.getFtpRootPath()+middleData.analyses_lc_absolute_filePath, in); +// } catch (FileNotFoundException e) { +// throw new RuntimeException(e); +// } +// } +// { +// File scacFile = new File(rootPath+middleData.analyses_scac_absolute_filePath); +// try { +// FileInputStream in = new FileInputStream(scacFile); +// ftpUtil.saveFile(ftpUtil.getFtpRootPath()+middleData.analyses_scac_absolute_filePath, in); +// } catch (FileNotFoundException e) { +// throw new RuntimeException(e); +// } +// } { 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(middleData.analyses_absolute_LogPath, in); + ftpUtil.saveFile(ftpUtil.getFtpRootPath()+middleData.analyses_absolute_LogPath, in); } catch (FileNotFoundException e) { throw new RuntimeException(e); } finally { @@ -5041,7 +5041,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi try { FileUtil.writeString(gammaFileUtil.GetReportContent(middleData), rptFile, "UTF-8"); FileInputStream in = new FileInputStream(rptFile); - ftpUtil.saveFile(middleData.analyses_absolute_ReportPath+".txt", in); + ftpUtil.saveFile(ftpUtil.getFtpRootPath()+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 a8161b98..c2d98c9a 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 @@ -4293,7 +4293,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements FileUtil.writeString("", logFile, "UTF-8"); } FileInputStream in = new FileInputStream(logFile); - ftpUtil.saveFile(analyses_absolute_LogPath, in); + ftpUtil.saveFile(ftpUtil.getFtpRootPath()+analyses_absolute_LogPath, in); } catch (FileNotFoundException e) { throw new RuntimeException(e); } @@ -4305,7 +4305,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements try { FileUtil.writeString(rptContent, rptFile, "UTF-8"); FileInputStream in = new FileInputStream(rptFile); - ftpUtil.saveFile(analyses_absolute_ReportPath+".txt", in); + ftpUtil.saveFile(ftpUtil.getFtpRootPath()+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/SpectrumFileServiceImpl.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumFileServiceImpl.java index 0d8b0123..9f2306e9 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumFileServiceImpl.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumFileServiceImpl.java @@ -53,31 +53,49 @@ public class SpectrumFileServiceImpl implements ISpectrumFileService { @Override public Result upload(MultipartFile file) { + //压缩包文件名称 String filename = file.getOriginalFilename(); + //判断是否是压缩包文件 boolean isZip = filename.endsWith(FileTypeEnum.zip.getType()); - if (!isZip) return Result.error(Prompt.FILE_TYPE_ERR); + //如果不是压缩包文件 返回错误提示信息 + if (!isZip) { + return Result.error(Prompt.FILE_TYPE_ERR); + } + //获取登陆用户名 LoginUser user = (LoginUser)SecurityUtils.getSubject().getPrincipal(); String username = user.getUsername(); - FTPClient ftpClient = null; +// FTPClient ftpClient = null; + //获取文件输出流 FileOutputStream fos = null; + //获取压缩包文件输入流 ZipInputStream zipInputStream = null; String slash = SymbolConstant.SINGLE_SLASH; //上传文件夹路径 - String filePath = spectrumPathProperties.getUploadPath() + slash + username; + String filePath = ftpUtil.getFtpRootPath() + slash + spectrumPathProperties.getUploadPath() + slash + username; //本地临时文件夹路径 String tempFilePath = System.getProperty("java.io.tmpdir") + username + slash; + //文件名称集合 List fileNames = new ArrayList<>(); + //文件集合 List fileList = new ArrayList<>(); + //正则表达式 String sampleRx = "[a-zA-Z]{3}[0-9]{2}_[0-9]{3}-[0-9]{8}_[0-9]{4}_(S|G|D|Q)_(FULL_|PREL_)\\d+\\.PHD"; Pattern regexPattern = Pattern.compile(sampleRx); String sampleRx1 = "[a-zA-Z]{3}[0-9]{2}_[0-9]{3}-[0-9]{8}_[0-9]{4}_(S|G|D|Q)_(FULL_|PREL_)\\d+\\.\\d+\\.PHD"; Pattern regexPattern1 = Pattern.compile(sampleRx1); try{ + //创建本地临时文件夹 File tempDir = new File(tempFilePath); - if (!tempDir.exists()) tempDir.mkdir(); + //判断本地临时文件夹是否存在 + if (!tempDir.exists()) { + tempDir.mkdir(); + } + //创建输入流 zipInputStream = new ZipInputStream(file.getInputStream()); ZipEntry entry; + //遍历获取压缩包内文件 while (ObjectUtil.isNotNull(entry = zipInputStream.getNextEntry())) { + //文件名称 String fileName = entry.getName(); fileNames.add(fileName); File oneFile = new File(tempFilePath + fileName); @@ -89,46 +107,61 @@ public class SpectrumFileServiceImpl implements ISpectrumFileService { } fileList.add(oneFile); } - if (CollUtil.isEmpty(fileList)) + //判断文件集合是否为空 + if (CollUtil.isEmpty(fileList)) { return Result.error(Prompt.FILE_IS_EMPTY); - ftpClient = ftpUtil.LoginFTP(); - if (ObjectUtil.isNull(ftpClient)) - return Result.error(Prompt.FTP_ERR); - // 如果指定目录不存在,逐级创建目录 - boolean created = FTPUtil.createDirs(ftpClient, filePath); - if (!created) return Result.error(Prompt.DIR_CREATE_FAIL + filePath); + } +// //登陆ftp +// ftpClient = ftpUtil.LoginFTP(); +// if (ObjectUtil.isNull(ftpClient)) { +// return Result.error(Prompt.FTP_ERR); +// } +// // 如果指定目录不存在,逐级创建目录 +// boolean created = FTPUtil.createDirs(ftpClient, filePath); +// if (!created) { +// return Result.error(Prompt.DIR_CREATE_FAIL + filePath); +// } // 上传所有文件 List failList = new ArrayList<>(); for (File oneFile : fileList) { String fileName = oneFile.getName(); // 判断能谱文件名称是否符合规则,不符合则进行重命名 if (!regexPattern.matcher(fileName).find() && !regexPattern1.matcher(fileName).find()) { + //分析文件 EnergySpectrumStruct struct = phdFileUtil.analyzeFileSourceData(oneFile); + //获取文件后缀 String suffix = nameStandUtil.GetSuffix(struct.data_type, struct.spectrum_quantity, String.valueOf(struct.acquisition_live_time)); + //获取文件名称 fileName = nameStandUtil.GetFileNameFromDateTime(struct.measurement_id, suffix); } String fullFilePath = filePath + slash + fileName; FileInputStream local = new FileInputStream(oneFile); - boolean success = ftpClient.storeFile(fileName, local); - if (!success) failList.add(fullFilePath); + boolean success = ftpUtil.saveFile(fullFilePath, local); + if (!success) { + failList.add(fullFilePath); + } } - if (CollUtil.isNotEmpty(failList)) + if (CollUtil.isNotEmpty(failList)) { return Result.error(Prompt.UPLOAD_ERR, failList); + } return Result.OK(Prompt.UPLOAD_SUCC); } catch (IOException e) { e.printStackTrace(); return Result.error(Prompt.UPLOAD_ERR); }finally { try { - if (ObjectUtil.isNotNull(zipInputStream)) + if (ObjectUtil.isNotNull(zipInputStream)) { zipInputStream.close(); - if (ObjectUtil.isNotNull(fos)) + } + if (ObjectUtil.isNotNull(fos)) { fos.close(); - if (ObjectUtil.isNotNull(ftpClient)) - if (ftpClient.isConnected()){ - ftpClient.logout(); - ftpClient.disconnect(); - } + } +// if (ObjectUtil.isNotNull(ftpClient)) { +// if (ftpClient.isConnected()){ +// ftpClient.logout(); +// ftpClient.disconnect(); +// } +// } } catch (IOException e) { e.printStackTrace(); } From fb8077531df4f3a88810fee0b070986f44e25b3c Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Thu, 14 Mar 2024 09:57:21 +0800 Subject: [PATCH 03/40] =?UTF-8?q?=E4=BA=BA=E5=B7=A5=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E6=B5=8B=E8=AF=95=E6=96=B9=E6=B3=95=E5=88=A0?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/controller/GammaController.java | 6 - .../jeecg/modules/service/IGammaService.java | 2 - .../service/impl/GammaServiceImpl.java | 209 ------------------ 3 files changed, 217 deletions(-) diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/GammaController.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/GammaController.java index 2fd05653..0baccfa7 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/GammaController.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/GammaController.java @@ -33,12 +33,6 @@ public class GammaController { gammaService.initValue(sampleId, dbName, analyst, fileName, request); } - - @GetMapping("testFun") - public Result testFun(String fileName,HttpServletRequest request){ - return gammaService.testFun(fileName, request); - } - @GetMapping("gammaByDB") @ApiOperation(value = "gamma页面loadFromDB加载数据", notes = "gamma页面loadFromDB加载数据") public Result gammaByDB(Integer sampleId, String dbName, String analyst, HttpServletRequest request){ diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGammaService.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGammaService.java index 205d57ec..642e9145 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGammaService.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGammaService.java @@ -17,8 +17,6 @@ public interface IGammaService{ void initValue(Integer sampleId, String dbName, String analyst, String fileName, HttpServletRequest request); - Result testFun(String fileName, HttpServletRequest request); - Result gammaByDB(String dbName, Integer sampleId, String analyst, HttpServletRequest request); Result gammaByFile(String fileName, HttpServletRequest request); 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 8671de66..54484465 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 @@ -164,215 +164,6 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi } } - @Override - public Result testFun(String fileName, HttpServletRequest request) { - Result result = new Result(); - String userName = JwtUtil.getUserNameByToken(request); - Cache phdCache = localCache.getPHDCache(); - PHDFile phd = phdCache.getIfPresent(fileName + StringPool.DASH + userName); - phd.setUserId("1"); - phd.setXmlFilePath(parameterProperties.getFilePath()); - String systemType = fileName.substring(2, 3); - if (Objects.isNull(phd)) { - result.error500("Please select the parse file first!"); - return result; - } - Map nuclideLinesMap = (Map) redisUtil.get(userName+StringPool.DASH+phd.getHeader().getSystem_type()); - // 解析获取临时文件信息 - File tmpFile = gammaFileUtil.analyzeFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName, fileName); - ObjectMapper mapper = new ObjectMapper(); - try { - String phdStr = mapper.writeValueAsString(phd); - String mapLines = mapper.writeValueAsString(nuclideLinesMap); - String strValue = CalValuesHandler.analyseSpectrum(phdStr, mapLines, tmpFile.getAbsolutePath(), new AnalysisProcess()); - Map parseMap = JSON.parseObject(strValue, Map.class); - for (Map.Entry entry : parseMap.entrySet()) { - if (entry.getKey().equalsIgnoreCase("bAnalyed")) { - boolean value = JSON.parseObject(JSON.toJSONString(entry.getValue()), Boolean.class); - phd.setBAnalyed(value); - } - if (entry.getKey().equalsIgnoreCase("mapEnerPara")) { - HashMap jsonMap = JSON.parseObject(JSON.toJSONString(entry.getValue()), HashMap.class); - Map value = new HashMap<>(); - for (Map.Entry objectEntry : jsonMap.entrySet()) { - String key = objectEntry.getKey(); - ParameterInfo entryValue = JSON.parseObject(JSON.toJSONString(objectEntry.getValue()), ParameterInfo.class); - value.put(key, entryValue); - } - phd.setMapEnerPara(value); - } - if (entry.getKey().equalsIgnoreCase("mapResoPara")) { - HashMap jsonMap = JSON.parseObject(JSON.toJSONString(entry.getValue()), HashMap.class); - Map value = new HashMap<>(); - for (Map.Entry objectEntry : jsonMap.entrySet()) { - String key = objectEntry.getKey(); - ParameterInfo entryValue = JSON.parseObject(JSON.toJSONString(objectEntry.getValue()), ParameterInfo.class); - value.put(key, entryValue); - } - phd.setMapResoPara(value); - } - if (entry.getKey().equalsIgnoreCase("mapEffiPara")) { - HashMap jsonMap = JSON.parseObject(JSON.toJSONString(entry.getValue()), HashMap.class); - Map value = new HashMap<>(); - for (Map.Entry objectEntry : jsonMap.entrySet()) { - String key = objectEntry.getKey(); - ParameterInfo entryValue = JSON.parseObject(JSON.toJSONString(objectEntry.getValue()), ParameterInfo.class); - value.put(key, entryValue); - } - phd.setMapEffiPara(value); - } - if (entry.getKey().equalsIgnoreCase("mapTotEPara")) { - HashMap jsonMap = JSON.parseObject(JSON.toJSONString(entry.getValue()), HashMap.class); - Map value = new HashMap<>(); - for (Map.Entry objectEntry : jsonMap.entrySet()) { - String key = objectEntry.getKey(); - ParameterInfo entryValue = JSON.parseObject(JSON.toJSONString(objectEntry.getValue()), ParameterInfo.class); - value.put(key, entryValue); - } - phd.setMapTotEPara(value); - } - if (entry.getKey().equalsIgnoreCase("para_stepRatio")) { - ParameterInfo value = JSON.parseObject(JSON.toJSONString(entry.getValue()), ParameterInfo.class); - phd.setPara_stepRatio(value); - } - if (entry.getKey().equalsIgnoreCase("para_tail")) { - ParameterInfo value = JSON.parseObject(JSON.toJSONString(entry.getValue()), ParameterInfo.class); - phd.setPara_tail(value); - } - if (entry.getKey().equalsIgnoreCase("para_tailAlpha")) { - ParameterInfo value = JSON.parseObject(JSON.toJSONString(entry.getValue()), ParameterInfo.class); - phd.setPara_tailAlpha(value); - } - if (entry.getKey().equalsIgnoreCase("para_tailRight")) { - ParameterInfo value = JSON.parseObject(JSON.toJSONString(entry.getValue()), ParameterInfo.class); - phd.setPara_tailRight(value); - } - if (entry.getKey().equalsIgnoreCase("para_tailRightAlpha")) { - ParameterInfo value = JSON.parseObject(JSON.toJSONString(entry.getValue()), ParameterInfo.class); - phd.setPara_tailRightAlpha(value); - } - if (entry.getKey().equalsIgnoreCase("newEner")) { - String value = JSON.parseObject(JSON.toJSONString(entry.getValue()), String.class); - phd.setNewEner(value); - } - if (entry.getKey().equalsIgnoreCase("newReso")) { - String value = JSON.parseObject(JSON.toJSONString(entry.getValue()), String.class); - phd.setNewReso(value); - } - if (entry.getKey().equalsIgnoreCase("mapEnerKD")) { - HashMap jsonMap = JSON.parseObject(JSON.toJSONString(entry.getValue()), HashMap.class); - Map value = new HashMap<>(); - for (Map.Entry objectEntry : jsonMap.entrySet()) { - String key = objectEntry.getKey(); - GEnergyBlock entryValue = JSON.parseObject(JSON.toJSONString(objectEntry.getValue()), GEnergyBlock.class); - value.put(key, entryValue); - } - phd.setMapEnerKD(value); - } - if (entry.getKey().equalsIgnoreCase("mapResoKD")) { - HashMap jsonMap = JSON.parseObject(JSON.toJSONString(entry.getValue()), HashMap.class); - Map value = new HashMap<>(); - for (Map.Entry objectEntry : jsonMap.entrySet()) { - String key = objectEntry.getKey(); - GResolutionBlock entryValue = JSON.parseObject(JSON.toJSONString(objectEntry.getValue()), GResolutionBlock.class); - value.put(key, entryValue); - } - phd.setMapResoKD(value); - } - if (entry.getKey().equalsIgnoreCase("vEnergy")) { - List value = JSON.parseArray(JSON.toJSONString(entry.getValue()), Double.class); - phd.setVEnergy(value); - } - if (entry.getKey().equalsIgnoreCase("vBase")) { - List value = JSON.parseArray(JSON.toJSONString(entry.getValue()), Double.class); - phd.setVBase(value); - } - if (entry.getKey().equalsIgnoreCase("vLc")) { - List value = JSON.parseArray(JSON.toJSONString(entry.getValue()), Double.class); - phd.setVLc(value); - } - if (entry.getKey().equalsIgnoreCase("vScac")) { - List value = JSON.parseArray(JSON.toJSONString(entry.getValue()), Double.class); - phd.setVScac(value); - } - if (entry.getKey().equalsIgnoreCase("vPeak")) { - List value = JSON.parseArray(JSON.toJSONString(entry.getValue()), PeakInfo.class); - phd.setVPeak(value); - } - if (entry.getKey().equalsIgnoreCase("baseCtrls")) { - BaseControls value = JSON.parseObject(JSON.toJSONString(entry.getValue()), BaseControls.class); - phd.setBaseCtrls(value); - } - if (entry.getKey().equalsIgnoreCase("usedEner")) { - String value = JSON.parseObject(JSON.toJSONString(entry.getValue()), String.class); - phd.setUsedEner(value); - } - if (entry.getKey().equalsIgnoreCase("usedEnerKD")) { - GEnergyBlock value = JSON.parseObject(JSON.toJSONString(entry.getValue()), GEnergyBlock.class); - phd.setUsedEnerKD(value); - } - if (entry.getKey().equalsIgnoreCase("usedEnerPara")) { - ParameterInfo value = JSON.parseObject(JSON.toJSONString(entry.getValue()), ParameterInfo.class); - phd.setUsedEnerPara(value); - } - if (entry.getKey().equalsIgnoreCase("usedReso")) { - String value = JSON.parseObject(JSON.toJSONString(entry.getValue()), String.class); - phd.setUsedReso(value); - } - if (entry.getKey().equalsIgnoreCase("usedResoKD")) { - GResolutionBlock value = JSON.parseObject(JSON.toJSONString(entry.getValue()), GResolutionBlock.class); - phd.setUsedResoKD(value); - } - if (entry.getKey().equalsIgnoreCase("usedResoPara")) { - ParameterInfo value = JSON.parseObject(JSON.toJSONString(entry.getValue()), ParameterInfo.class); - phd.setUsedResoPara(value); - } - if (entry.getKey().equalsIgnoreCase("usedEffi")) { - String value = JSON.parseObject(JSON.toJSONString(entry.getValue()), String.class); - phd.setUsedEffi(value); - } - if (entry.getKey().equalsIgnoreCase("usedEffiKD")) { - GEfficiencyBlock value = JSON.parseObject(JSON.toJSONString(entry.getValue()), GEfficiencyBlock.class); - phd.setUsedEffiKD(value); - } - if (entry.getKey().equalsIgnoreCase("usedEffiPara")) { - ParameterInfo value = JSON.parseObject(JSON.toJSONString(entry.getValue()), ParameterInfo.class); - phd.setUsedEffiPara(value); - } - if (entry.getKey().equalsIgnoreCase("usedTotE")) { - String value = JSON.parseObject(JSON.toJSONString(entry.getValue()), String.class); - phd.setUsedTotE(value); - } - if (entry.getKey().equalsIgnoreCase("usedTotEKD")) { - TotaleffBlock value = JSON.parseObject(JSON.toJSONString(entry.getValue()), TotaleffBlock.class); - phd.setUsedTotEKD(value); - } - if (entry.getKey().equalsIgnoreCase("usedTotEPara")) { - ParameterInfo value = JSON.parseObject(JSON.toJSONString(entry.getValue()), ParameterInfo.class); - phd.setUsedTotEPara(value); - } - } - BeanUtils.copyProperties(phd.getSetting(), phd.getUsedSetting()); - - for (PeakInfo info:phd.getVPeak()) { - if (Objects.isNull(info.recoilBetaChan)) { - info.recoilBetaChan = "nan"; - } - if (Objects.isNull(info.recoilDeltaChan)) { - info.recoilDeltaChan = "nan"; - } - } - // 重新分析各峰值对应的核素信息 - gammaFileUtil.NuclidesIdent(phd, nuclideLinesMap); - gammaFileUtil.RunQC(phd); - result.setResult(phd); - } catch (JsonProcessingException e) { - throw new RuntimeException(e); - } - result.setSuccess(true); - return result; - } - @Override public Result gammaByDB(String dbName, Integer sampleId, String analyst, HttpServletRequest request) { Result result = new Result(); From 17c487ca327860407d43625e8b16996fb8ed873f Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Fri, 15 Mar 2024 10:24:51 +0800 Subject: [PATCH 04/40] =?UTF-8?q?=E4=BA=BA=E5=B7=A5=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E5=AD=98=E5=82=A8=E6=96=B9=E6=B3=95=EF=BC=8C?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E6=95=B0=E6=8D=AE=E5=88=B0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E6=96=87=E4=BB=B6=E5=B7=B2=E7=BB=8F=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E7=9A=84=E6=83=85=E5=86=B5=E4=B8=8B=EF=BC=8C=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=8F=90=E4=BA=A4=E5=AF=BC=E8=87=B4=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=A7=E5=B0=8F=E5=8F=98=E6=88=900=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jeecg/common/util/GammaFileUtil.java | 6 ++- .../impl/SpectrumAnalysisServiceImpl.java | 40 +++++++++++++------ 2 files changed, 32 insertions(+), 14 deletions(-) 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 e97794c3..0d77da9e 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 @@ -3230,8 +3230,10 @@ public class GammaFileUtil extends AbstractLogOrReport { File sampleTmp = null; try { sampleTmp = new File(fileAnlyse.getTmpFilePath()); - if (Objects.nonNull(sampleTmp)) { - bRet = ftpUtil.saveFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + middleData.analyses_save_filePath, new FileInputStream(sampleTmp)); + //sample文件的存储路径 + String saveSamplePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + middleData.analyses_save_filePath; + if (Objects.nonNull(sampleTmp) && !saveSamplePath.equals(fileAnlyse.getTmpFilePath())) { + bRet = ftpUtil.saveFile(saveSamplePath, new FileInputStream(sampleTmp)); } } catch (FileNotFoundException e) { throw new RuntimeException(e); 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 c2d98c9a..692c512a 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 @@ -4260,21 +4260,37 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements } //上传本次文件到ftp人工交互存储路径下 try { - if (StringUtils.isNotBlank(betaDataFile.getSampleTmpPath())) { - File sampleTmp = new File(betaDataFile.getSampleTmpPath()); - ftpUtil.saveFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + sampleFilePathName, new FileInputStream(sampleTmp)); + { + //sample文件的saveFile存储路径 + String saveSamplePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + sampleFilePathName; + if (StringUtils.isNotBlank(betaDataFile.getSampleTmpPath()) && !saveSamplePath.equals(betaDataFile.getSampleTmpPath())) { + File sampleTmp = new File(betaDataFile.getSampleTmpPath()); + ftpUtil.saveFile(saveSamplePath, new FileInputStream(sampleTmp)); + } } - if (StringUtils.isNotBlank(betaDataFile.getGasTmpPath())) { - File gasTmp = new File(betaDataFile.getGasTmpPath()); - ftpUtil.saveFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + gasFilePathName, new FileInputStream(gasTmp)); + { + //gas文件的saveFile存储路径 + String saveGasPath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + gasFilePathName; + if (StringUtils.isNotBlank(betaDataFile.getGasTmpPath()) && !saveGasPath.equals(betaDataFile.getGasTmpPath())) { + File gasTmp = new File(betaDataFile.getGasTmpPath()); + ftpUtil.saveFile(saveGasPath, new FileInputStream(gasTmp)); + } } - if (StringUtils.isNotBlank(betaDataFile.getDetTmpPath())) { - File detTmp = new File(betaDataFile.getDetTmpPath()); - ftpUtil.saveFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + detFilePathName, new FileInputStream(detTmp)); + { + //det文件的saveFile存储路径 + String saveDetPath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + detFilePathName; + if (StringUtils.isNotBlank(betaDataFile.getDetTmpPath()) && !saveDetPath.equals(betaDataFile.getDetTmpPath())) { + File detTmp = new File(betaDataFile.getDetTmpPath()); + ftpUtil.saveFile(saveDetPath, new FileInputStream(detTmp)); + } } - if (StringUtils.isNotBlank(betaDataFile.getQcTmpPath())) { - File qcTmp = new File(betaDataFile.getQcTmpPath()); - ftpUtil.saveFile(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + qcFilePathName, new FileInputStream(qcTmp)); + { + //qc文件的saveFile存储路径 + String saveQcPath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + qcFilePathName; + if (StringUtils.isNotBlank(betaDataFile.getQcTmpPath()) && !saveQcPath.equals(betaDataFile.getQcTmpPath())) { + File qcTmp = new File(betaDataFile.getQcTmpPath()); + ftpUtil.saveFile(saveQcPath, new FileInputStream(qcTmp)); + } } //分析成功后存储日志文件和报告文件 { From 70f3d172b6cd4f1127b7cf025a6f4f830e769806 Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Fri, 15 Mar 2024 10:27:53 +0800 Subject: [PATCH 05/40] =?UTF-8?q?=E4=BA=BA=E5=B7=A5=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E5=AD=98=E5=82=A8=E6=96=B9=E6=B3=95=EF=BC=8C?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E6=95=B0=E6=8D=AE=E5=88=B0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E6=96=87=E4=BB=B6=E5=B7=B2=E7=BB=8F=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E7=9A=84=E6=83=85=E5=86=B5=E4=B8=8B=EF=BC=8C=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=8F=90=E4=BA=A4=E5=AF=BC=E8=87=B4=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=A7=E5=B0=8F=E5=8F=98=E6=88=900=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/service/impl/SpectrumAnalysisServiceImpl.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 692c512a..d35c6227 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 @@ -4260,7 +4260,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements } //上传本次文件到ftp人工交互存储路径下 try { - { + if (StringUtils.isNotBlank(sampleFilePathName)) { //sample文件的saveFile存储路径 String saveSamplePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + sampleFilePathName; if (StringUtils.isNotBlank(betaDataFile.getSampleTmpPath()) && !saveSamplePath.equals(betaDataFile.getSampleTmpPath())) { @@ -4268,7 +4268,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements ftpUtil.saveFile(saveSamplePath, new FileInputStream(sampleTmp)); } } - { + if (StringUtils.isNotBlank(gasFilePathName)) { //gas文件的saveFile存储路径 String saveGasPath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + gasFilePathName; if (StringUtils.isNotBlank(betaDataFile.getGasTmpPath()) && !saveGasPath.equals(betaDataFile.getGasTmpPath())) { @@ -4276,7 +4276,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements ftpUtil.saveFile(saveGasPath, new FileInputStream(gasTmp)); } } - { + if (StringUtils.isNotBlank(detFilePathName)) { //det文件的saveFile存储路径 String saveDetPath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + detFilePathName; if (StringUtils.isNotBlank(betaDataFile.getDetTmpPath()) && !saveDetPath.equals(betaDataFile.getDetTmpPath())) { @@ -4284,7 +4284,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements ftpUtil.saveFile(saveDetPath, new FileInputStream(detTmp)); } } - { + if (StringUtils.isNotBlank(qcFilePathName)) { //qc文件的saveFile存储路径 String saveQcPath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + qcFilePathName; if (StringUtils.isNotBlank(betaDataFile.getQcTmpPath()) && !saveQcPath.equals(betaDataFile.getQcTmpPath())) { From 14084248932ce6f655383e0eba698ec7b2cfd85f Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Fri, 15 Mar 2024 10:57:57 +0800 Subject: [PATCH 06/40] =?UTF-8?q?=E4=BA=BA=E5=B7=A5=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E6=A8=A1=E5=9D=97Beta=E5=88=86=E6=9E=90=E7=AE=97=E6=B3=95?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=86=85=E5=AE=B9=E5=A2=9E=E5=8A=A0message?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E6=8F=90=E7=A4=BA=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/jeecg/common/util/PHDFileUtil.java | 2 ++ .../impl/SpectrumAnalysisServiceImpl.java | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) 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 2b19508d..4f7d35cb 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 @@ -1002,6 +1002,7 @@ public class PHDFileUtil extends AbstractLogOrReport { } map.put("DetBoundary", boundaryList); } + map.put("message", analyseResult.error_log); bRet = false; return bRet; } else { @@ -1088,6 +1089,7 @@ public class PHDFileUtil extends AbstractLogOrReport { } map.put("DetBoundary", boundaryList); } + map.put("message", "analyse Success."); return bRet; } } 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 d35c6227..c32d3aa3 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 @@ -3811,7 +3811,22 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements map.put("savedAnalysisResult", true); } } else { - map.clear(); + List sampleBoundary = (List) map.get("SampleBoundary"); + if(CollectionUtils.isNotEmpty(sampleBoundary)) { + betaDataFile.setSampleBoundary(sampleBoundary); + } + List gasBoundary = (List) map.get("GasBoundary"); + if(CollectionUtils.isNotEmpty(gasBoundary)) { + betaDataFile.setGasBoundary(gasBoundary); + } + List detBoundary = (List) map.get("DetBoundary"); + if(CollectionUtils.isNotEmpty(detBoundary)) { + betaDataFile.setDetBoundary(detBoundary); + } + List qcBoundary = (List) map.get("QCBoundary"); + if(CollectionUtils.isNotEmpty(qcBoundary)) { + betaDataFile.setQcBoundary(qcBoundary); + } map.put("XeData", Collections.EMPTY_LIST); } } catch (Exception e) { From 29821e708d14ef94d624d11ee272b8832c398fc7 Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Fri, 15 Mar 2024 11:12:57 +0800 Subject: [PATCH 07/40] =?UTF-8?q?=E4=BA=BA=E5=B7=A5=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E4=BF=9D=E5=AD=98=E6=96=87=E4=BB=B6=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/org/jeecg/common/util/FTPUtil.java | 4 ++-- 1 file changed, 2 insertions(+), 2 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 a4f35ece..c5c85095 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 @@ -288,7 +288,7 @@ public class FTPUtil { //声明目标文件 File targetFile = new File(filePath); //创建输出流 - BufferedOutputStream outputStream = null; + FileOutputStream outputStream = null; try { //获取父级路径 File directory = targetFile.getParentFile(); @@ -297,7 +297,7 @@ public class FTPUtil { directory.mkdirs(); } // 创建输出流对象并写入数据到文件 - outputStream = new BufferedOutputStream(new FileOutputStream(targetFile)); + outputStream = new FileOutputStream(targetFile); byte[] buffer = new byte[1024]; int length; while ((length = inputStream.read(buffer)) > 0) { From 8d7bee473509c792e15bf6c560099475d7c45441 Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Fri, 15 Mar 2024 11:20:21 +0800 Subject: [PATCH 08/40] =?UTF-8?q?=E4=BA=BA=E5=B7=A5=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E4=BF=9D=E5=AD=98=E6=96=87=E4=BB=B6=E4=BB=A3?= =?UTF-8?q?=E7=A0=81,=E6=96=87=E4=BB=B6=E8=B7=AF=E5=BE=84\=E6=94=B9?= =?UTF-8?q?=E4=B8=BA/=E5=8C=B9=E9=85=8D=EF=BC=8C=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=A2=AB=E8=A6=86=E7=9B=96=E4=B8=BA0KB?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/org/jeecg/common/util/GammaFileUtil.java | 2 +- .../modules/service/impl/SpectrumAnalysisServiceImpl.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) 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 0d77da9e..97b7889c 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 @@ -3232,7 +3232,7 @@ public class GammaFileUtil extends AbstractLogOrReport { sampleTmp = new File(fileAnlyse.getTmpFilePath()); //sample文件的存储路径 String saveSamplePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + middleData.analyses_save_filePath; - if (Objects.nonNull(sampleTmp) && !saveSamplePath.equals(fileAnlyse.getTmpFilePath())) { + if (Objects.nonNull(sampleTmp) && !saveSamplePath.equals(fileAnlyse.getTmpFilePath().replace(StringPool.BACK_SLASH, StringPool.SLASH))) { bRet = ftpUtil.saveFile(saveSamplePath, new FileInputStream(sampleTmp)); } } catch (FileNotFoundException e) { 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 c32d3aa3..b34dfe34 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 @@ -4278,7 +4278,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements if (StringUtils.isNotBlank(sampleFilePathName)) { //sample文件的saveFile存储路径 String saveSamplePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + sampleFilePathName; - if (StringUtils.isNotBlank(betaDataFile.getSampleTmpPath()) && !saveSamplePath.equals(betaDataFile.getSampleTmpPath())) { + if (StringUtils.isNotBlank(betaDataFile.getSampleTmpPath()) && !saveSamplePath.equals(betaDataFile.getSampleTmpPath().replace(StringPool.BACK_SLASH, StringPool.SLASH))) { File sampleTmp = new File(betaDataFile.getSampleTmpPath()); ftpUtil.saveFile(saveSamplePath, new FileInputStream(sampleTmp)); } @@ -4286,7 +4286,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements if (StringUtils.isNotBlank(gasFilePathName)) { //gas文件的saveFile存储路径 String saveGasPath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + gasFilePathName; - if (StringUtils.isNotBlank(betaDataFile.getGasTmpPath()) && !saveGasPath.equals(betaDataFile.getGasTmpPath())) { + if (StringUtils.isNotBlank(betaDataFile.getGasTmpPath()) && !saveGasPath.equals(betaDataFile.getGasTmpPath().replace(StringPool.BACK_SLASH, StringPool.SLASH))) { File gasTmp = new File(betaDataFile.getGasTmpPath()); ftpUtil.saveFile(saveGasPath, new FileInputStream(gasTmp)); } @@ -4294,7 +4294,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements if (StringUtils.isNotBlank(detFilePathName)) { //det文件的saveFile存储路径 String saveDetPath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + detFilePathName; - if (StringUtils.isNotBlank(betaDataFile.getDetTmpPath()) && !saveDetPath.equals(betaDataFile.getDetTmpPath())) { + if (StringUtils.isNotBlank(betaDataFile.getDetTmpPath()) && !saveDetPath.equals(betaDataFile.getDetTmpPath().replace(StringPool.BACK_SLASH, StringPool.SLASH))) { File detTmp = new File(betaDataFile.getDetTmpPath()); ftpUtil.saveFile(saveDetPath, new FileInputStream(detTmp)); } @@ -4302,7 +4302,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements if (StringUtils.isNotBlank(qcFilePathName)) { //qc文件的saveFile存储路径 String saveQcPath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + qcFilePathName; - if (StringUtils.isNotBlank(betaDataFile.getQcTmpPath()) && !saveQcPath.equals(betaDataFile.getQcTmpPath())) { + if (StringUtils.isNotBlank(betaDataFile.getQcTmpPath()) && !saveQcPath.equals(betaDataFile.getQcTmpPath().replace(StringPool.BACK_SLASH, StringPool.SLASH))) { File qcTmp = new File(betaDataFile.getQcTmpPath()); ftpUtil.saveFile(saveQcPath, new FileInputStream(qcTmp)); } From f8da6c3aaea3bbb864c11c05fa3f68582275afa5 Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Fri, 15 Mar 2024 11:34:57 +0800 Subject: [PATCH 09/40] =?UTF-8?q?=E4=BA=BA=E5=B7=A5=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E6=A8=A1=E5=9D=97Beta=E9=83=A8=E5=88=86=E5=88=86=E6=9E=90?= =?UTF-8?q?=E7=AE=97=E6=B3=95=EF=BC=8C=E5=A4=B1=E8=B4=A5=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5=E4=B8=8BBProcessd=E5=8F=82=E6=95=B0=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=B8=BAfalse=E5=B9=B6=E4=BC=A0=E9=80=92=E7=BB=99=E5=89=8D?= =?UTF-8?q?=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/SpectrumAnalysisServiceImpl.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) 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 b34dfe34..f64d9503 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 @@ -3248,17 +3248,11 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements return result; } map = BetaGammaAnalyzeCurrentProcess(analyseData, betaDataFile); - map.put("bProcessed", true); - map.put("savedAnalysisResult", true); result.setSuccess(true); result.setResult(map); } else if ("AllSpectrum".equals(analyseData.getApplyType())) { //获取当前选中的文件名称 map = BetaGammaAnalyzeAllProcess(analyseData, userName, currentFileName); - if (CollectionUtils.isNotEmpty(map)) { - map.put("bProcessed", true); - map.put("savedAnalysisResult", true); - } result.setSuccess(true); result.setResult(map); } @@ -3450,9 +3444,9 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements } betaDataFile.setXeResultsSpectrumList(xeResultsSpectrumList); betaDataFile.setBProcessed(true); - betaDataFile.setSaveAnalysisResult(true); betaDataFile.setBgPara(spectrum_group.BgCalPara); } + xeMap.put("bProcessed", true); } else { List sampleBoundary = (List) xeMap.get("SampleBoundary"); if(CollectionUtils.isNotEmpty(sampleBoundary)) { @@ -3470,7 +3464,9 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements if(CollectionUtils.isNotEmpty(qcBoundary)) { betaDataFile.setQcBoundary(qcBoundary); } + betaDataFile.setBProcessed(false); xeMap.put("XeData", Collections.EMPTY_LIST); + xeMap.put("bProcessed", false); } } } catch (Exception e) { @@ -3681,9 +3677,9 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements } sampleBetaData.setXeResultsSpectrumList(xeResultsSpectrumList); sampleBetaData.setBProcessed(true); - sampleBetaData.setSaveAnalysisResult(true); sampleBetaData.setBgPara(spectrum_group.BgCalPara); } + xeMap.put("bProcessed", true); analyseResultMap.put(sampleFileName, xeMap); } else { List sampleBoundary = (List) xeMap.get("SampleBoundary"); @@ -3702,7 +3698,9 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements if(CollectionUtils.isNotEmpty(qcBoundary)) { sampleBetaData.setQcBoundary(qcBoundary); } + sampleBetaData.setBProcessed(false); xeMap.put("XeData", Collections.EMPTY_LIST); + xeMap.put("bProcessed", false); analyseResultMap.put(sampleFileName, xeMap); } } @@ -3806,9 +3804,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements betaDataFile.setXeResultsSpectrumList(xeDataList); } betaDataFile.setBProcessed(true); - betaDataFile.setSaveAnalysisResult(true); map.put("bProcessed", true); - map.put("savedAnalysisResult", true); } } else { List sampleBoundary = (List) map.get("SampleBoundary"); @@ -3828,6 +3824,8 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements betaDataFile.setQcBoundary(qcBoundary); } map.put("XeData", Collections.EMPTY_LIST); + betaDataFile.setBProcessed(false); + map.put("bProcessed", false); } } catch (Exception e) { e.printStackTrace(); @@ -3927,9 +3925,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements betaDataFile.setXeResultsSpectrumList(xeDataList); } betaDataFile.setBProcessed(true); - betaDataFile.setSaveAnalysisResult(true); map.put("bProcessed", true); - map.put("savedAnalysisResult", true); mapList.put(sampleFileName, map); } else { List sampleBoundary = (List) map.get("SampleBoundary"); @@ -3949,6 +3945,8 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements betaDataFile.setQcBoundary(qcBoundary); } map.put("XeData", Collections.EMPTY_LIST); + betaDataFile.setBProcessed(false); + map.put("bProcessed", false); mapList.put(sampleFileName, map); } } From 953dd61988a289107ec69d342b0b1494e2493b86 Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Fri, 15 Mar 2024 11:47:50 +0800 Subject: [PATCH 10/40] =?UTF-8?q?=E4=BA=BA=E5=B7=A5=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E6=A8=A1=E5=9D=97Beta=E9=83=A8=E5=88=86=E5=88=86=E6=9E=90?= =?UTF-8?q?=E7=AE=97=E6=B3=95=EF=BC=8C=E5=A4=B1=E8=B4=A5=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5=E4=B8=8BBProcessd,savedAnalysisResult=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E4=BF=AE=E6=94=B9=E4=B8=BAfalse=E5=B9=B6=E4=BC=A0?= =?UTF-8?q?=E9=80=92=E7=BB=99=E5=89=8D=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/SpectrumAnalysisServiceImpl.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 f64d9503..e557f635 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 @@ -3444,9 +3444,11 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements } betaDataFile.setXeResultsSpectrumList(xeResultsSpectrumList); betaDataFile.setBProcessed(true); + betaDataFile.setSaveAnalysisResult(true); betaDataFile.setBgPara(spectrum_group.BgCalPara); } xeMap.put("bProcessed", true); + xeMap.put("savedAnalysisResult", true); } else { List sampleBoundary = (List) xeMap.get("SampleBoundary"); if(CollectionUtils.isNotEmpty(sampleBoundary)) { @@ -3465,8 +3467,10 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements betaDataFile.setQcBoundary(qcBoundary); } betaDataFile.setBProcessed(false); + betaDataFile.setSaveAnalysisResult(false); xeMap.put("XeData", Collections.EMPTY_LIST); xeMap.put("bProcessed", false); + xeMap.put("savedAnalysisResult", false); } } } catch (Exception e) { @@ -3677,9 +3681,11 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements } sampleBetaData.setXeResultsSpectrumList(xeResultsSpectrumList); sampleBetaData.setBProcessed(true); + sampleBetaData.setSaveAnalysisResult(true); sampleBetaData.setBgPara(spectrum_group.BgCalPara); } xeMap.put("bProcessed", true); + xeMap.put("savedAnalysisResult", true); analyseResultMap.put(sampleFileName, xeMap); } else { List sampleBoundary = (List) xeMap.get("SampleBoundary"); @@ -3699,8 +3705,10 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements sampleBetaData.setQcBoundary(qcBoundary); } sampleBetaData.setBProcessed(false); + sampleBetaData.setSaveAnalysisResult(false); xeMap.put("XeData", Collections.EMPTY_LIST); xeMap.put("bProcessed", false); + xeMap.put("savedAnalysisResult", false); analyseResultMap.put(sampleFileName, xeMap); } } @@ -3804,7 +3812,9 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements betaDataFile.setXeResultsSpectrumList(xeDataList); } betaDataFile.setBProcessed(true); + betaDataFile.setSaveAnalysisResult(true); map.put("bProcessed", true); + map.put("savedAnalysisResult", true); } } else { List sampleBoundary = (List) map.get("SampleBoundary"); @@ -3825,7 +3835,9 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements } map.put("XeData", Collections.EMPTY_LIST); betaDataFile.setBProcessed(false); + betaDataFile.setSaveAnalysisResult(false); map.put("bProcessed", false); + map.put("savedAnalysisResult", false); } } catch (Exception e) { e.printStackTrace(); @@ -3925,7 +3937,9 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements betaDataFile.setXeResultsSpectrumList(xeDataList); } betaDataFile.setBProcessed(true); + betaDataFile.setSaveAnalysisResult(true); map.put("bProcessed", true); + map.put("savedAnalysisResult", true); mapList.put(sampleFileName, map); } else { List sampleBoundary = (List) map.get("SampleBoundary"); @@ -3946,7 +3960,9 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements } map.put("XeData", Collections.EMPTY_LIST); betaDataFile.setBProcessed(false); + betaDataFile.setSaveAnalysisResult(false); map.put("bProcessed", false); + map.put("savedAnalysisResult", false); mapList.put(sampleFileName, map); } } From 0654872c3b18487b127fe7ca9f23847dd5c26f84 Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Fri, 15 Mar 2024 15:54:47 +0800 Subject: [PATCH 11/40] =?UTF-8?q?=E4=BA=BA=E5=B7=A5=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E5=88=86=E6=9E=90=E6=A8=A1=E5=9D=97Beta=E5=9C=A8=E5=88=86?= =?UTF-8?q?=E6=9E=90=E5=A4=B1=E8=B4=A5=E7=9A=84=E6=83=85=E5=86=B5=E4=B8=8B?= =?UTF-8?q?=E4=B8=8D=E8=BF=9B=E8=A1=8C=E5=AD=98=E5=82=A8=EF=BC=8C=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E6=AD=A3=E7=A1=AE=E9=9C=80=E8=A6=81=E5=88=86=E6=9E=90?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/service/impl/SpectrumAnalysisServiceImpl.java | 5 +++++ 1 file changed, 5 insertions(+) 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 e557f635..0702af0e 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 @@ -4066,6 +4066,11 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements //从本地缓存获取beta gamma的数组 Cache cache = betaCache.getBetaCache(); BetaDataFile betaDataFile = cache.getIfPresent(anlyseResultIn.getSampleFileName() + "-" + userName); + //判断保存分析结果标识 + if (!betaDataFile.isSaveAnalysisResult()) { + result.error500("Please first Analyse File!"); + return result; + } List betaList = new LinkedList<>(); List betaFittingPara = new LinkedList<>(); List gammaList = new LinkedList<>(); From 765ea99ad84fcd9afbb6175cc977d567af2d945f Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Fri, 15 Mar 2024 16:00:36 +0800 Subject: [PATCH 12/40] =?UTF-8?q?=E4=BA=BA=E5=B7=A5=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E5=88=86=E6=9E=90=E6=A8=A1=E5=9D=97Beta=E5=9C=A8=E5=88=86?= =?UTF-8?q?=E6=9E=90=E5=A4=B1=E8=B4=A5=E7=9A=84=E6=83=85=E5=86=B5=E4=B8=8B?= =?UTF-8?q?=E4=B8=8D=E8=BF=9B=E8=A1=8C=E5=AD=98=E5=82=A8=EF=BC=8C=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E6=AD=A3=E7=A1=AE=E9=9C=80=E8=A6=81=E5=88=86=E6=9E=90?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jeecg/modules/service/impl/SpectrumAnalysisServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 0702af0e..4ed12286 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 @@ -4067,7 +4067,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements Cache cache = betaCache.getBetaCache(); BetaDataFile betaDataFile = cache.getIfPresent(anlyseResultIn.getSampleFileName() + "-" + userName); //判断保存分析结果标识 - if (!betaDataFile.isSaveAnalysisResult()) { + if (Objects.nonNull(betaDataFile) && !betaDataFile.isSaveAnalysisResult()) { result.error500("Please first Analyse File!"); return result; } From 0c5eadbb2c807c33604975d9eb450acdbe9ec838 Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Fri, 15 Mar 2024 16:51:49 +0800 Subject: [PATCH 13/40] =?UTF-8?q?=E4=BA=BA=E5=B7=A5=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E5=88=86=E6=9E=90=E6=A8=A1=E5=9D=97=E4=BF=9D=E5=AD=98=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=88=B0=E6=95=B0=E6=8D=AE=E5=BA=93=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=96=87=E4=BB=B6=E6=97=B6=EF=BC=8C=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=96=87=E4=BB=B6=E5=90=8D=E7=A7=B0=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jeecg/modules/service/impl/SpectrumAnalysisServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 4ed12286..4929c8b4 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 @@ -4328,7 +4328,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements } //分析成功后存储日志文件和报告文件 { - String logFileName = analyses_absolute_LogPath.substring(analyses_absolute_LogPath.lastIndexOf(StringPool.SLASH)+1); + String logFileName = betaDataFile.getSampleFileName().replace("PHD", "log"); //获取日志的文件存放路径 String logFilePath = parameterProperties.getLogFilePath() + File.separator + DateUtils.formatDate(new Date(), "yyyy-MM-dd"); //判断文件路径是否存在 From 924cddb1f2d4c700d0bb64f12e174b47e029775b Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Tue, 19 Mar 2024 17:00:16 +0800 Subject: [PATCH 14/40] =?UTF-8?q?=E4=BA=BA=E5=B7=A5=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E5=88=86=E6=9E=90=E6=A8=A1=E5=9D=97Beta=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96=EF=BC=8C?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E5=89=8D=E7=9A=84=E5=88=86=E6=9E=90=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E7=A7=BB=E9=99=A4=EF=BC=8C=E6=A0=B9=E6=8D=AE=E5=88=86?= =?UTF-8?q?=E6=9E=90=E7=BB=93=E6=9E=9C=E6=95=B0=E6=8D=AE=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GardsCalibrationSpectrumMapper.java | 3 + .../xml/GardsCalibrationSpectrumMapper.xml | 28 + ...IGardsCalibrationPairsSpectrumService.java | 3 +- .../IGardsCalibrationSpectrumService.java | 3 +- .../IGardsROIChannelsSpectrumService.java | 3 +- .../IGardsROIResultsSpectrumService.java | 3 +- .../IGardsXeResultsSpectrumService.java | 3 +- ...dsCalibrationPairsSpectrumServiceImpl.java | 91 +- .../GardsCalibrationSpectrumServiceImpl.java | 121 ++- .../GardsROIChannelsSpectrumServiceImpl.java | 50 +- .../GardsROIResultsSpectrumServiceImpl.java | 26 +- .../GardsXeResultsSpectrumServiceImpl.java | 8 +- .../impl/SpectrumAnalysisServiceImpl.java | 987 +++++------------- 13 files changed, 584 insertions(+), 745 deletions(-) diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/mapper/GardsCalibrationSpectrumMapper.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/mapper/GardsCalibrationSpectrumMapper.java index 3f24e6f8..a411196d 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/mapper/GardsCalibrationSpectrumMapper.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/mapper/GardsCalibrationSpectrumMapper.java @@ -7,6 +7,9 @@ import org.jeecg.modules.base.entity.rnman.GardsCalibration; public interface GardsCalibrationSpectrumMapper extends BaseMapper { + @InterceptorIgnore(tenantLine = "true") + void insertCalibration(@Param(value = "calibration") GardsCalibration calibration); + @InterceptorIgnore(tenantLine = "true") void insertCalibrationGamma(@Param(value = "calibration") GardsCalibration calibration); diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/mapper/xml/GardsCalibrationSpectrumMapper.xml b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/mapper/xml/GardsCalibrationSpectrumMapper.xml index 5f18eb40..58da4e85 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/mapper/xml/GardsCalibrationSpectrumMapper.xml +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/mapper/xml/GardsCalibrationSpectrumMapper.xml @@ -2,6 +2,34 @@ + + INSERT INTO + RNMAN.GARDS_CALIBRATION( + SAMPLE_ID, + IDANALYSIS, + SAMPLE_TYPE, + CALTYPE, + FUNCTION, + FUNCTIONDEF, + STARTOFRANGE, + ENDOFRANGE, + COEFF1, + COEFF2, + COEFF3) + VALUES(#{calibration.sampleId}, + #{calibration.idAnalysis}, + #{calibration.sampleType}, + #{calibration.calType}, + #{calibration.function}, + #{calibration.functionDef}, + #{calibration.startOfRange}, + #{calibration.endOfRange}, + #{calibration.coeff1}, + #{calibration.coeff2}, + #{calibration.coeff3}) + + + INSERT INTO RNMAN.GARDS_CALIBRATION( diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGardsCalibrationPairsSpectrumService.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGardsCalibrationPairsSpectrumService.java index 508e5d9b..69a96631 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGardsCalibrationPairsSpectrumService.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGardsCalibrationPairsSpectrumService.java @@ -2,6 +2,7 @@ package org.jeecg.modules.service; import com.baomidou.mybatisplus.extension.service.IService; import org.jeecg.modules.base.entity.rnman.GardsCalibrationPairs; +import org.jeecg.modules.entity.vo.BgDataAnlyseResultIn; import org.jeecg.modules.entity.vo.GStoreMiddleProcessData; import org.jeecg.modules.entity.vo.PHDFile; @@ -9,7 +10,7 @@ import java.util.List; public interface IGardsCalibrationPairsSpectrumService extends IService { - int saveGardsCalibrationPairs(List calibrationPairsList); + int saveGardsCalibrationPairs(BgDataAnlyseResultIn anlyseResultIn, Integer sampleId, Integer gasId, Integer detId, Integer idAnalysis); int saveGardsCalibrationPairsGamma(GStoreMiddleProcessData middleData, Integer sampleId, String idAnalysis); diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGardsCalibrationSpectrumService.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGardsCalibrationSpectrumService.java index c76067b0..f4e2a2f7 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGardsCalibrationSpectrumService.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGardsCalibrationSpectrumService.java @@ -2,13 +2,14 @@ package org.jeecg.modules.service; import com.baomidou.mybatisplus.extension.service.IService; import org.jeecg.modules.base.entity.rnman.GardsCalibration; +import org.jeecg.modules.entity.vo.BgDataAnlyseResultIn; import org.jeecg.modules.entity.vo.GStoreMiddleProcessData; import java.util.List; public interface IGardsCalibrationSpectrumService extends IService { - int saveGardsCalibration(List calibrationPairsList); + int saveGardsCalibration(BgDataAnlyseResultIn anlyseResultIn, Integer sampleId, Integer gasId, Integer detId, Integer idAnalysis); int saveCalibrationGamma(GStoreMiddleProcessData middleData, Integer sampleId, String idAnalysis); diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGardsROIChannelsSpectrumService.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGardsROIChannelsSpectrumService.java index 90b781d4..a94e6f63 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGardsROIChannelsSpectrumService.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGardsROIChannelsSpectrumService.java @@ -2,11 +2,12 @@ package org.jeecg.modules.service; import com.baomidou.mybatisplus.extension.service.IService; import org.jeecg.modules.base.entity.rnman.GardsRoiChannels; +import org.jeecg.modules.entity.vo.BgDataAnlyseResultIn; import java.util.List; public interface IGardsROIChannelsSpectrumService extends IService { - int saveGardsROIChannels(List roiChannelsList); + int saveGardsROIChannels(BgDataAnlyseResultIn anlyseResultIn, Integer sampleId, Integer gasId, Integer detId, Integer idAnalysis); } diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGardsROIResultsSpectrumService.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGardsROIResultsSpectrumService.java index eed0f3d2..9a583e07 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGardsROIResultsSpectrumService.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGardsROIResultsSpectrumService.java @@ -2,11 +2,12 @@ package org.jeecg.modules.service; import com.baomidou.mybatisplus.extension.service.IService; import org.jeecg.modules.base.entity.rnman.GardsRoiResults; +import org.jeecg.modules.entity.vo.BgDataAnlyseResultIn; import java.util.List; public interface IGardsROIResultsSpectrumService extends IService { - int saveGardsROIResults(List roiResultsList); + int saveGardsROIResults(BgDataAnlyseResultIn anlyseResultIn, Integer sampleId, Integer idAnalysis); } diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGardsXeResultsSpectrumService.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGardsXeResultsSpectrumService.java index 800d3726..a6cfecae 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGardsXeResultsSpectrumService.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGardsXeResultsSpectrumService.java @@ -2,11 +2,12 @@ package org.jeecg.modules.service; import com.baomidou.mybatisplus.extension.service.IService; import org.jeecg.modules.base.entity.rnman.GardsXeResults; +import org.jeecg.modules.entity.vo.BgDataAnlyseResultIn; import java.util.List; public interface IGardsXeResultsSpectrumService extends IService { - int saveGardsXeResults(List xeResultsList); + int saveGardsXeResults(BgDataAnlyseResultIn anlyseResultIn, Integer sampleId, Integer idAnalysis); } diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GardsCalibrationPairsSpectrumServiceImpl.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GardsCalibrationPairsSpectrumServiceImpl.java index 0f70be56..210e7cc2 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GardsCalibrationPairsSpectrumServiceImpl.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GardsCalibrationPairsSpectrumServiceImpl.java @@ -4,6 +4,10 @@ import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.jeecg.modules.base.entity.rnman.GardsCalibrationPairs; +import org.jeecg.modules.base.enums.CalName; +import org.jeecg.modules.base.enums.CalType; +import org.jeecg.modules.base.enums.SystemType; +import org.jeecg.modules.entity.vo.BgDataAnlyseResultIn; import org.jeecg.modules.entity.vo.GStoreMiddleProcessData; import org.jeecg.modules.entity.vo.PHDFile; import org.jeecg.modules.entity.GardsCalibrationPairsSpectrum; @@ -22,7 +26,92 @@ public class GardsCalibrationPairsSpectrumServiceImpl extends ServiceImpl calibrationPairsList) { + public int saveGardsCalibrationPairs(BgDataAnlyseResultIn anlyseResultIn, Integer sampleId, Integer gasId, Integer detId, Integer idAnalysis) { + List calibrationPairsList = new LinkedList<>(); + if (CollectionUtils.isNotEmpty(anlyseResultIn.getB_channel_sample())) { + for (int i=0; i< anlyseResultIn.getB_channel_sample().size(); i++){ + GardsCalibrationPairs calibrationPairs = new GardsCalibrationPairs(); + calibrationPairs.setSampleId(sampleId); + calibrationPairs.setIdAnalysis(idAnalysis); + calibrationPairs.setSampleType(SystemType.BETA.getType()); + calibrationPairs.setCaltype(CalType.ENERGY_CAL.getType()); + calibrationPairs.setInput(CalName.CalPHD.getType()); + calibrationPairs.setIdCalPoint(i); + calibrationPairs.setXValue(anlyseResultIn.getB_channel_sample().get(i)); + calibrationPairs.setYValue(anlyseResultIn.getB_energy_sample().get(i)); + calibrationPairsList.add(calibrationPairs); + } + } + if (CollectionUtils.isNotEmpty(anlyseResultIn.getG_channel_sample())) { + for (int i=0; i< anlyseResultIn.getG_channel_sample().size(); i++){ + GardsCalibrationPairs calibrationPairs = new GardsCalibrationPairs(); + calibrationPairs.setSampleId(sampleId); + calibrationPairs.setIdAnalysis(idAnalysis); + calibrationPairs.setSampleType(SystemType.GAMMA.getType()); + calibrationPairs.setCaltype(CalType.ENERGY_CAL.getType()); + calibrationPairs.setInput(CalName.CalPHD.getType()); + calibrationPairs.setIdCalPoint(i); + calibrationPairs.setXValue(anlyseResultIn.getG_channel_sample().get(i)); + calibrationPairs.setYValue(anlyseResultIn.getG_energy_sample().get(i)); + calibrationPairsList.add(calibrationPairs); + } + } + if (CollectionUtils.isNotEmpty(anlyseResultIn.getB_channel_gas())) { + for (int i=0; i< anlyseResultIn.getB_channel_gas().size(); i++){ + GardsCalibrationPairs calibrationPairs = new GardsCalibrationPairs(); + calibrationPairs.setSampleId(gasId); + calibrationPairs.setIdAnalysis(idAnalysis); + calibrationPairs.setSampleType(SystemType.BETA.getType()); + calibrationPairs.setCaltype(CalType.ENERGY_CAL.getType()); + calibrationPairs.setInput(CalName.CalPHD.getType()); + calibrationPairs.setIdCalPoint(i); + calibrationPairs.setXValue(anlyseResultIn.getB_channel_gas().get(i)); + calibrationPairs.setYValue(anlyseResultIn.getB_energy_gas().get(i)); + calibrationPairsList.add(calibrationPairs); + } + } + if (CollectionUtils.isNotEmpty(anlyseResultIn.getG_channel_gas())) { + for (int i=0; i< anlyseResultIn.getG_channel_gas().size(); i++){ + GardsCalibrationPairs calibrationPairs = new GardsCalibrationPairs(); + calibrationPairs.setSampleId(gasId); + calibrationPairs.setIdAnalysis(idAnalysis); + calibrationPairs.setSampleType(SystemType.GAMMA.getType()); + calibrationPairs.setCaltype(CalType.ENERGY_CAL.getType()); + calibrationPairs.setInput(CalName.CalPHD.getType()); + calibrationPairs.setIdCalPoint(i); + calibrationPairs.setXValue(anlyseResultIn.getG_channel_gas().get(i)); + calibrationPairs.setYValue(anlyseResultIn.getG_energy_gas().get(i)); + calibrationPairsList.add(calibrationPairs); + } + } + if (CollectionUtils.isNotEmpty(anlyseResultIn.getB_channel_det())) { + for (int i=0; i< anlyseResultIn.getB_channel_det().size(); i++){ + GardsCalibrationPairs calibrationPairs = new GardsCalibrationPairs(); + calibrationPairs.setSampleId(detId); + calibrationPairs.setIdAnalysis(idAnalysis); + calibrationPairs.setSampleType(SystemType.BETA.getType()); + calibrationPairs.setCaltype(CalType.ENERGY_CAL.getType()); + calibrationPairs.setInput(CalName.CalPHD.getType()); + calibrationPairs.setIdCalPoint(i); + calibrationPairs.setXValue(anlyseResultIn.getB_channel_det().get(i)); + calibrationPairs.setYValue(anlyseResultIn.getB_energy_det().get(i)); + calibrationPairsList.add(calibrationPairs); + } + } + if (CollectionUtils.isNotEmpty(anlyseResultIn.getG_channel_det())) { + for (int i=0; i< anlyseResultIn.getG_channel_det().size(); i++){ + GardsCalibrationPairs calibrationPairs = new GardsCalibrationPairs(); + calibrationPairs.setSampleId(detId); + calibrationPairs.setIdAnalysis(idAnalysis); + calibrationPairs.setSampleType(SystemType.GAMMA.getType()); + calibrationPairs.setCaltype(CalType.ENERGY_CAL.getType()); + calibrationPairs.setInput(CalName.CalPHD.getType()); + calibrationPairs.setIdCalPoint(i); + calibrationPairs.setXValue(anlyseResultIn.getG_channel_det().get(i)); + calibrationPairs.setYValue(anlyseResultIn.getG_energy_det().get(i)); + calibrationPairsList.add(calibrationPairs); + } + } if (CollectionUtils.isNotEmpty(calibrationPairsList)) { this.saveBatch(calibrationPairsList); } diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GardsCalibrationSpectrumServiceImpl.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GardsCalibrationSpectrumServiceImpl.java index ba21ac82..dd4f6f30 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GardsCalibrationSpectrumServiceImpl.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GardsCalibrationSpectrumServiceImpl.java @@ -4,6 +4,12 @@ import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.jeecg.modules.base.entity.rnman.GardsCalibration; +import org.jeecg.modules.base.enums.CalType; +import org.jeecg.modules.base.enums.DataTypeAbbr; +import org.jeecg.modules.base.enums.FittingType; +import org.jeecg.modules.base.enums.SystemType; +import org.jeecg.modules.entity.GardsCalibrationSpectrum; +import org.jeecg.modules.entity.vo.BgDataAnlyseResultIn; import org.jeecg.modules.entity.vo.GStoreMiddleProcessData; import org.jeecg.modules.mapper.GardsCalibrationSpectrumMapper; import org.jeecg.modules.service.IGardsCalibrationSpectrumService; @@ -12,6 +18,8 @@ import org.springframework.transaction.annotation.Transactional; import java.util.LinkedList; import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; @Service("gardsCalibrationSpectrumService") @DS("ora") @@ -20,11 +28,116 @@ public class GardsCalibrationSpectrumServiceImpl extends ServiceImpl calibrationPairsList) { - if (CollectionUtils.isNotEmpty(calibrationPairsList)) { - this.saveBatch(calibrationPairsList); + public int saveGardsCalibration(BgDataAnlyseResultIn anlyseResultIn, Integer sampleId, Integer gasId, Integer detId, Integer idAnalysis) { + List calibrationSpectrumList = new LinkedList<>(); + if (Objects.nonNull(sampleId)) { + GardsCalibration calibrationB = new GardsCalibration(); + calibrationB.setSampleId(sampleId); + calibrationB.setIdAnalysis(idAnalysis); + calibrationB.setSampleType(SystemType.BETA.getType()); + calibrationB.setCalType(CalType.ENERGY_CAL.getType()); + calibrationB.setFunction(FittingType.POLY2.getCode()); + calibrationB.setFunctionDef(FittingType.POLY2.getDescription()); + calibrationB.setStartOfRange(0); + calibrationB.setEndOfRange(1); + List betaCollect = anlyseResultIn.getBetaCalibrationSpectrumList().stream().filter(item -> item.getDataType().equals(DataTypeAbbr.SAMPLEPHD.getType())).collect(Collectors.toList()); + GardsCalibrationSpectrum betaCalibrationSpectrum = betaCollect.get(0); + calibrationB.setCoeff1(Double.valueOf(betaCalibrationSpectrum.getCoeff1())); + calibrationB.setCoeff2(Double.valueOf(betaCalibrationSpectrum.getCoeff2())); + calibrationB.setCoeff3(Double.valueOf(betaCalibrationSpectrum.getCoeff3())); + calibrationSpectrumList.add(calibrationB); + + GardsCalibration calibrationG = new GardsCalibration(); + calibrationG.setSampleId(sampleId); + calibrationG.setIdAnalysis(idAnalysis); + calibrationG.setSampleType(SystemType.GAMMA.getType()); + calibrationG.setCalType(CalType.ENERGY_CAL.getType()); + calibrationG.setFunction(FittingType.POLY2.getCode()); + calibrationG.setFunctionDef(FittingType.POLY2.getDescription()); + calibrationG.setStartOfRange(0); + calibrationG.setEndOfRange(1); + List gammaCollect = anlyseResultIn.getGammaCalibrationSpectrumList().stream().filter(item -> item.getDataType().equals(DataTypeAbbr.SAMPLEPHD.getType())).collect(Collectors.toList()); + GardsCalibrationSpectrum gammaCalibrationSpectrum = gammaCollect.get(0); + calibrationG.setCoeff1(Double.valueOf(gammaCalibrationSpectrum.getCoeff1())); + calibrationG.setCoeff2(Double.valueOf(gammaCalibrationSpectrum.getCoeff2())); + calibrationG.setCoeff3(Double.valueOf(gammaCalibrationSpectrum.getCoeff3())); + calibrationSpectrumList.add(calibrationG); } - return calibrationPairsList.size(); + + if (Objects.nonNull(gasId)) { + //gas文件 Beta部分 + GardsCalibration calibrationB = new GardsCalibration(); + calibrationB.setSampleId(gasId); + calibrationB.setIdAnalysis(idAnalysis); + calibrationB.setSampleType(SystemType.BETA.getType()); + calibrationB.setCalType(CalType.ENERGY_CAL.getType()); + calibrationB.setFunction(FittingType.POLY2.getCode()); + calibrationB.setFunctionDef(FittingType.POLY2.getDescription()); + calibrationB.setStartOfRange(0); + calibrationB.setEndOfRange(1); + List betaCollect = anlyseResultIn.getBetaCalibrationSpectrumList().stream().filter(item -> item.getDataType().equals(DataTypeAbbr.GASBKPHD.getType())).collect(Collectors.toList()); + GardsCalibrationSpectrum betaCalibrationSpectrum = betaCollect.get(0); + calibrationB.setCoeff1(Double.valueOf(betaCalibrationSpectrum.getCoeff1())); + calibrationB.setCoeff2(Double.valueOf(betaCalibrationSpectrum.getCoeff2())); + calibrationB.setCoeff3(Double.valueOf(betaCalibrationSpectrum.getCoeff3())); + calibrationSpectrumList.add(calibrationB); + //gas文件 gamma部分 + GardsCalibration calibrationG = new GardsCalibration(); + calibrationG.setSampleId(gasId); + calibrationG.setIdAnalysis(idAnalysis); + calibrationG.setSampleType(SystemType.GAMMA.getType()); + calibrationG.setCalType(CalType.ENERGY_CAL.getType()); + calibrationG.setFunction(FittingType.POLY2.getCode()); + calibrationG.setFunctionDef(FittingType.POLY2.getDescription()); + calibrationG.setStartOfRange(0); + calibrationG.setEndOfRange(1); + List gammaCollect = anlyseResultIn.getGammaCalibrationSpectrumList().stream().filter(item -> item.getDataType().equals(DataTypeAbbr.GASBKPHD.getType())).collect(Collectors.toList()); + GardsCalibrationSpectrum gammaCalibrationSpectrum = gammaCollect.get(0); + calibrationG.setCoeff1(Double.valueOf(gammaCalibrationSpectrum.getCoeff1())); + calibrationG.setCoeff2(Double.valueOf(gammaCalibrationSpectrum.getCoeff2())); + calibrationG.setCoeff3(Double.valueOf(gammaCalibrationSpectrum.getCoeff3())); + calibrationSpectrumList.add(calibrationG); + } + + if (Objects.nonNull(detId)) { + GardsCalibration calibrationB = new GardsCalibration(); + calibrationB.setSampleId(detId); + calibrationB.setIdAnalysis(idAnalysis); + calibrationB.setSampleType(SystemType.BETA.getType()); + calibrationB.setCalType(CalType.ENERGY_CAL.getType()); + calibrationB.setFunction(FittingType.POLY2.getCode()); + calibrationB.setFunctionDef(FittingType.POLY2.getDescription()); + calibrationB.setStartOfRange(0); + calibrationB.setEndOfRange(1); + List betaCollect = anlyseResultIn.getBetaCalibrationSpectrumList().stream().filter(item -> item.getDataType().equals(DataTypeAbbr.DETBKPHD.getType())).collect(Collectors.toList()); + GardsCalibrationSpectrum betaCalibrationSpectrum = betaCollect.get(0); + calibrationB.setCoeff1(Double.valueOf(betaCalibrationSpectrum.getCoeff1())); + calibrationB.setCoeff2(Double.valueOf(betaCalibrationSpectrum.getCoeff2())); + calibrationB.setCoeff3(Double.valueOf(betaCalibrationSpectrum.getCoeff3())); + calibrationSpectrumList.add(calibrationB); + GardsCalibration calibrationG = new GardsCalibration(); + calibrationG.setSampleId(detId); + calibrationG.setIdAnalysis(idAnalysis); + calibrationG.setSampleType(SystemType.GAMMA.getType()); + calibrationG.setCalType(CalType.ENERGY_CAL.getType()); + calibrationG.setFunction(FittingType.POLY2.getCode()); + calibrationG.setFunctionDef(FittingType.POLY2.getDescription()); + calibrationG.setStartOfRange(0); + calibrationG.setEndOfRange(1); + List gammaCollect = anlyseResultIn.getGammaCalibrationSpectrumList().stream().filter(item -> item.getDataType().equals(DataTypeAbbr.DETBKPHD.getType())).collect(Collectors.toList()); + GardsCalibrationSpectrum gammaCalibrationSpectrum = gammaCollect.get(0); + calibrationG.setCoeff1(Double.valueOf(gammaCalibrationSpectrum.getCoeff1())); + calibrationG.setCoeff2(Double.valueOf(gammaCalibrationSpectrum.getCoeff2())); + calibrationG.setCoeff3(Double.valueOf(gammaCalibrationSpectrum.getCoeff3())); + calibrationSpectrumList.add(calibrationG); + } + + if (CollectionUtils.isNotEmpty(calibrationSpectrumList)) { + for (GardsCalibration calibration:calibrationSpectrumList) { + this.baseMapper.insertCalibration(calibration); + } + } + return calibrationSpectrumList.size(); } @Override diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GardsROIChannelsSpectrumServiceImpl.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GardsROIChannelsSpectrumServiceImpl.java index 3ef84935..6cf29d63 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GardsROIChannelsSpectrumServiceImpl.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GardsROIChannelsSpectrumServiceImpl.java @@ -4,12 +4,18 @@ import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.jeecg.modules.base.entity.rnman.GardsRoiChannels; +import org.jeecg.modules.base.enums.DataType; +import org.jeecg.modules.base.enums.DataTypeAbbr; +import org.jeecg.modules.entity.GardsROIChannelsSpectrum; +import org.jeecg.modules.entity.vo.BgDataAnlyseResultIn; import org.jeecg.modules.mapper.GardsROIChannelsSpectrumMapper; import org.jeecg.modules.service.IGardsROIChannelsSpectrumService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.LinkedList; import java.util.List; +import java.util.stream.Collectors; @Service("roiChannelsService") @DS("ora") @@ -17,7 +23,49 @@ public class GardsROIChannelsSpectrumServiceImpl extends ServiceImpl roiChannelsList) { + public int saveGardsROIChannels(BgDataAnlyseResultIn anlyseResultIn, Integer sampleId, Integer gasId, Integer detId, Integer idAnalysis) { + List roiChannelsList = new LinkedList<>(); + List roiChannelsSpectrumList = anlyseResultIn.getRoiChannelsSpectrumList(); + //过滤出sample相关的数据 + List sampleRoiChannelsSpectrumList = roiChannelsSpectrumList.stream().filter(item-> item.getDataType().equals(DataTypeAbbr.SAMPLEPHD.getType())).collect(Collectors.toList()); + for (int i=0; i gasRoiChannelsSpectrumList = roiChannelsSpectrumList.stream().filter(item-> item.getDataType().equals(DataTypeAbbr.GASBKPHD.getType())).collect(Collectors.toList()); + for (int i=0; i detRoiChannelsSpectrumList = roiChannelsSpectrumList.stream().filter(item-> item.getDataType().equals(DataTypeAbbr.DETBKPHD.getType())).collect(Collectors.toList()); + for (int i=0; i implements IGardsROIResultsSpectrumService { @Override - public int saveGardsROIResults(List roiResultsList) { + public int saveGardsROIResults(BgDataAnlyseResultIn anlyseResultIn, Integer sampleId, Integer idAnalysis) { + List roiResultsList = new LinkedList<>(); + List roiResultsSpectrumList = anlyseResultIn.getRoiResultsSpectrumList(); + for (int i=0; i xeResultsList) { + public int saveGardsXeResults(BgDataAnlyseResultIn anlyseResultIn, Integer sampleId, Integer idAnalysis) { + List xeResultsList = anlyseResultIn.getXeData(); + for (GardsXeResults xeResults:xeResultsList) { + xeResults.setIdAnalysis(idAnalysis); + xeResults.setSampleId(sampleId); + } if (CollectionUtils.isNotEmpty(xeResultsList)) { this.saveBatch(xeResultsList); } 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 4929c8b4..12421e5e 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 @@ -122,6 +122,17 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements private NameStandUtil nameStandUtil; @Autowired private IDataService dataService; + @Autowired + private IGardsCalibrationPairsSpectrumService gardsCalibrationPairsSpectrumService; + @Autowired + private IGardsCalibrationSpectrumService gardsCalibrationSpectrumService; + @Autowired + private IGardsROIChannelsSpectrumService gardsROIChannelsSpectrumService; + @Autowired + private IGardsXeResultsSpectrumService gardsXeResultsSpectrumService; + @Autowired + private IGardsROIResultsSpectrumService gardsROIResultsSpectrumService; + @Override @@ -4102,8 +4113,6 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements if (userStation.contains(String.valueOf(stationId))) { bAnalysisResultWriteAuthority = true; } - //获取ROI Limit数据 -// getROILimit(anlyseResultIn); //根据sample文件名称模糊查询sampleId if (StringUtils.isNotBlank(betaDataFile.getSampleFilePathName())) { anlyseResultIn.setSampleFilePath(betaDataFile.getSampleFilePathName().substring(0, betaDataFile.getSampleFilePathName().lastIndexOf(StringPool.SLASH))); @@ -4144,7 +4153,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements //处理数据 获取对应的channel/energy值 getChannelAndEnergy(anlyseResultIn, betaList, gammaList, betaDataFile); //分析文件内容 - analyzePHDFile(anlyseResultIn, BgCalPara, betaFittingPara, gammaFittingPara, betaDataFile); + analyzePHDFile(anlyseResultIn, betaDataFile); //判断文件是否存储过 如果没有则解析文件并进行存储 if ( !OriginalDataStore(betaDataFile, "gas", gasFilePathName) ){ result.error500("gasFile save failed"); @@ -4212,87 +4221,60 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements GardsAnalysesSpectrum analysis = spectrumAnalysisMapper.getAnalysis("RNMAN.GARDS_ANALYSES", sampleId, userName); Integer idAnalysis = analysis.getIdAnalysis(); //获取sample,gas,det三个文件分别对应的beta,gamma数据集合 - List calibrationPairsList = getCalibrationPairs(anlyseResultIn, sampleId, gasId, detId, idAnalysis); //如果分析过--删除GARDS_CALIBRATION_PAIRS表数据 新增GARDS_CALIBRATION_PAIRS表数据 if (Objects.nonNull(isExist)){ //根据idAnalysis删除GARDS_CALIBRATION_PAIRS表数据 spectrumAnalysisMapper.deleteCalibrationPairs(idAnalysis); //遍历新增GARDS_CALIBRATION_PAIRS表数据 - for (GardsCalibrationPairs calibrationPairs:calibrationPairsList) { - spectrumAnalysisMapper.insertCalibrationPairs(calibrationPairs); - } + gardsCalibrationPairsSpectrumService.saveGardsCalibrationPairs(anlyseResultIn, sampleId, gasId, detId, idAnalysis); }else {//如果没有分析过--新增GARDS_CALIBRATION_PAIRS表数据 //遍历新增GARDS_CALIBRATION_PAIRS表数据 - for (GardsCalibrationPairs calibrationPairs:calibrationPairsList) { - spectrumAnalysisMapper.insertCalibrationPairs(calibrationPairs); - } + gardsCalibrationPairsSpectrumService.saveGardsCalibrationPairs(anlyseResultIn, sampleId, gasId, detId, idAnalysis); } //gards_calibration 数据表 - List calibrationList = getCalibration(anlyseResultIn, sampleId, gasId, detId, idAnalysis); //判断是否分析过 - if (Objects.nonNull(isExist)) { + if (Objects.nonNull(isExist)) { //删除Gards_Calibration表数据 spectrumAnalysisMapper.deleteCalibration(idAnalysis); //新增Gards_Calibration表数据数据 - for (GardsCalibration calibration:calibrationList) { - spectrumAnalysisMapper.insertCalibration(calibration); - } + gardsCalibrationSpectrumService.saveGardsCalibration(anlyseResultIn, sampleId, gasId, detId, idAnalysis); } else { //新增Gards_Calibration表数据数据 - for (GardsCalibration calibration:calibrationList) { - spectrumAnalysisMapper.insertCalibration(calibration); - } + gardsCalibrationSpectrumService.saveGardsCalibration(anlyseResultIn, sampleId, gasId, detId, idAnalysis); } //gards_roi_channels数据表 - List roiChannelsList = new LinkedList<>(); - getROIChannel(sampleId, idAnalysis, anlyseResultIn.getRoiChannelsSpectrumList(), roiChannelsList, DataTypeAbbr.SAMPLEPHD.getType()); - getROIChannel(gasId, idAnalysis, anlyseResultIn.getRoiChannelsSpectrumList(), roiChannelsList, DataTypeAbbr.GASBKPHD.getType()); - getROIChannel(detId, idAnalysis, anlyseResultIn.getRoiChannelsSpectrumList(), roiChannelsList, DataTypeAbbr.DETBKPHD.getType()); //如果分析过数据 if (Objects.nonNull(isExist)){ //删除gards_roi_channels数据表数据 spectrumAnalysisMapper.deleteROIChannels(idAnalysis); //新增gards_roi_channels数据表数据 - for (GardsRoiChannels roiChannels:roiChannelsList) { - spectrumAnalysisMapper.insertROIChannels(roiChannels); - } + gardsROIChannelsSpectrumService.saveGardsROIChannels(anlyseResultIn, sampleId, gasId, detId, idAnalysis); }else {//没有分析过 //新增gards_roi_channels数据表数据 - for (GardsRoiChannels roiChannels:roiChannelsList) { - spectrumAnalysisMapper.insertROIChannels(roiChannels); - } + gardsROIChannelsSpectrumService.saveGardsROIChannels(anlyseResultIn, sampleId, gasId, detId, idAnalysis); } //gards_Xe_results数据表 - List xeResultsList = getXeResults(anlyseResultIn, sampleId, idAnalysis); if(Objects.nonNull(isExist)) { //删除gards_Xe_results数据表数据 spectrumAnalysisMapper.deleteXeResult(idAnalysis); //新增gards_Xe_results数据表数据 - for (GardsXeResults xeResults:xeResultsList) { - spectrumAnalysisMapper.insertXeResult(xeResults); - } + gardsXeResultsSpectrumService.saveGardsXeResults(anlyseResultIn, sampleId, idAnalysis); } else { //新增gards_Xe_results数据表数据 - for (GardsXeResults xeResults:xeResultsList) { - spectrumAnalysisMapper.insertXeResult(xeResults); - } + gardsXeResultsSpectrumService.saveGardsXeResults(anlyseResultIn, sampleId, idAnalysis); } //gards_roi_results数据表 - List roiResultsSpectrumList = getROIResult(anlyseResultIn.getRoiResultsSpectrumList(), sampleId, idAnalysis); if(Objects.nonNull(isExist)) { //删除gards_roi_results数据表数据 spectrumAnalysisMapper.deleteROIResults(idAnalysis); //新增gards_roi_results数据表数据 - for (GardsRoiResults roiResults:roiResultsSpectrumList) { - spectrumAnalysisMapper.insertROIResults(roiResults); - } + gardsROIResultsSpectrumService.saveGardsROIResults(anlyseResultIn, sampleId, idAnalysis); } else { //新增gards_roi_results数据表数据 - for (GardsRoiResults roiResults:roiResultsSpectrumList) { - spectrumAnalysisMapper.insertROIResults(roiResults); - } + gardsROIResultsSpectrumService.saveGardsROIResults(anlyseResultIn, sampleId, idAnalysis); } //上传本次文件到ftp人工交互存储路径下 + long uploadStartTime = System.currentTimeMillis(); try { if (StringUtils.isNotBlank(sampleFilePathName)) { //sample文件的saveFile存储路径 @@ -4392,6 +4374,191 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements return result; } + @Transactional + public boolean OriginalDataStore(BetaDataFile betaDataFile, String type, String filePathName) { + //根据新的文件路径名称查询数据是否存在 + GardsSampleData isExist = spectrumAnalysisMapper.findSampleByFile(filePathName); + //如果数据已经存入过数据库 则 修改状态后返回 + if (Objects.nonNull(isExist)){ + //如果文件已经存入过数据库则修改状态 + spectrumAnalysisMapper.updateAnalysesStatus(filePathName); + return true; + } + //读取文件内容 + EnergySpectrumStruct sourceData = null; + File file = null; + try { + if (Objects.nonNull(betaDataFile)){ + + if (type.equalsIgnoreCase("sample")) { + file = new File(betaDataFile.getSampleTmpPath()); + sourceData = betaDataFile.getSampleStruct(); + } else if (type.equalsIgnoreCase("gas")) { + file = new File(betaDataFile.getGasTmpPath()); + sourceData = betaDataFile.getGasStruct(); + } else if (type.equalsIgnoreCase("det")) { + file = new File(betaDataFile.getDetTmpPath()); + sourceData = betaDataFile.getDetStruct(); + } else if (type.equalsIgnoreCase("qc")) { + file = new File(betaDataFile.getQcTmpPath()); + sourceData = betaDataFile.getQcStruct(); + } + //获取文件中块名信息 + List readLines = getFileBlockList(file); + //查询台站id + Integer stationId = spectrumAnalysisMapper.getStationId(sourceData.site_code); + Integer detectorId = spectrumAnalysisMapper.getDetectorId(sourceData.detector_code); + if(Objects.isNull(stationId) || Objects.isNull(detectorId)) { + String error = "get station_id or detect_id error"; + return false; + } + //新增Gards_Sample_Data表数据 + sampleDataSpectrumService.saveSampleData(sourceData, stationId, detectorId, filePathName, readLines); + //获取sampleId + Integer sampleId = spectrumAnalysisMapper.getSampleId(filePathName); + //存储Gards_Sample_Aux表数据 + sampleAuxSpectrumService.saveSampleAux(sourceData, sampleId, readLines); + //判断文件是否包含Comment块 新增Gards_Description数据 + if (readLines.contains(SampleFileHeader.COMMENT.getMessage())){ + sampleDescriptionSpectrumService.saveSampleDescription(sourceData, sampleId); + } + //判断文件是否包含Certificate块 新增Gards_Sample_Cert数据 + if (readLines.contains(SampleFileHeader.CERTIFICATE.getMessage())){ + sampleCertSpectrumService.saveSampleCert(sourceData, sampleId); + sampleCertLineSpectrumService.saveSampleCertLine(sourceData, sampleId); + } + //新增Gards_Calibration_Pairs_Orig数据 + calibrationPairsOrigSpectrumService.saveGardsCalibrationPairsOrig(sourceData, sampleId, readLines); + //判断文件是否包含b-gEfficiency块 新增Gards_Sample_Cert数据 + if (readLines.contains(SampleFileHeader.BGEFFICIENCY.getMessage())){ + bgEfficiencyPairsSpectrumService.saveBgEfficiencyPairs(sourceData, sampleId); + } + //判断文件是否包含TotalEff块 新增Gards_Sample_Cert数据 + if (readLines.contains(SampleFileHeader.TOTALEFF.getMessage())){ + totalEfficiencyPairsSpectrumService.saveTotalEfficiencyPairs(sourceData, sampleId); + } + //判断文件是否包含Ratios块 新增Gards_Sample_Ratios数据 + if (readLines.contains(SampleFileHeader.RATIOS.getMessage())){ + sampleRatiosSpectrumService.saveSampleRatios(sourceData, sampleId); + } + //判断是否包含ROI_Limits块 新增Gards_ROI_Limits数据 + if (readLines.contains(SampleFileHeader.ROILIMITS.getMessage())){ + roiLimitsSpectrumService.saveRoiLimits(sourceData, sampleId); + } + //新增Gards_Spectrum数据 + spectrumService.saveSpectrum(sourceData, sampleId, readLines, filePathName); + //判断是否包含Histogram块 新增Gards_Histogram数据 + if (readLines.contains(SampleFileHeader.HISTOGRAM.getMessage())){ + histogramService.saveHistogram(sourceData, sampleId, filePathName); + } + } + return true; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public List getFileBlockList(File file) { + List readLines = new LinkedList<>(); + try { + List allLines = FileUtils.readLines(file, "UTF-8"); + for (String line:allLines) { + if (line.contains("#")){ + readLines.add(line); + } + } + } catch (IOException e) { + throw new RuntimeException(e); + } + return readLines; + } + + public SpectrumData getSpectrumData(Integer sampleId, BetaDataFile betaDataFile, String type) { + //根据 sampleId获取sampleData的数据内容 + GardsSampleDataSpectrum sampleData = spectrumAnalysisMapper.getSampleData(sampleId); + File file = null; + EnergySpectrumStruct struct = null; + if (type.equalsIgnoreCase("sample")) { + file = new File(betaDataFile.getSampleTmpPath()); + struct = betaDataFile.getSampleStruct(); + } else if (type.equalsIgnoreCase("gas")) { + file = new File(betaDataFile.getGasTmpPath()); + struct = betaDataFile.getGasStruct(); + } else if (type.equalsIgnoreCase("det")) { + file = new File(betaDataFile.getDetTmpPath()); + struct = betaDataFile.getDetStruct(); + } else if (type.equalsIgnoreCase("qc")) { + file = new File(betaDataFile.getQcTmpPath()); + struct = betaDataFile.getQcStruct(); + } + SpectrumData spectrumData = new SpectrumData(); + try { + //封装散点图下的基础数据信息 + //Station Code + String stationCode = struct.site_code; + //Detector Code + String detectorCode = struct.detector_code; + //Data Type + String dataType = struct.data_type; + //Collection Start + Date CollectionStart = null; + if ( StringUtils.isNotBlank(struct.collection_start_date) && StringUtils.isNotBlank(struct.collection_start_time) ){ + CollectionStart = DateUtils.parseDate(struct.collection_start_date + StringPool.SPACE + struct.collection_start_time); + } + //Collection Stop + Date CollectionStop = null; + if ( StringUtils.isNotBlank(struct.collection_stop_date) && StringUtils.isNotBlank(struct.collection_stop_time) ){ + CollectionStop = DateUtils.parseDate(struct.collection_stop_date + StringPool.SPACE + struct.collection_stop_time); + } + //Collection Time + String CollectionTime = ""; + if ( Objects.nonNull(CollectionStart) && Objects.nonNull(CollectionStop) ){ + CollectionTime = String.format ("%.2f",Double.valueOf(CollectionStop.getTime()/1000 - CollectionStart.getTime()/ 1000)); + } + //Acquisition Start + Date AcquisitionStart = null; + if ( StringUtils.isNotBlank(struct.collection_start_date) && StringUtils.isNotBlank(struct.collection_start_time) ){ + AcquisitionStart = DateUtils.parseDate(struct.acquisition_start_date + StringPool.SPACE + struct.acquisition_start_time); + } + //Acq Real Time + double AcquisitionRealTime = struct.acquisition_real_time; + //Acq live Time + double AcquisitionLiveTime = struct.acquisition_live_time; + //Air Volume[m3] + double airVolume = struct.air_volume; + //Xe Volume[m3] + double xeVolume = struct.sample_volume_of_Xe; + //xeCollectionYield + double xeCollectionYield = struct.Xe_collection_yield; + //gasBkMeasurementId + String gasBkMeasurementId = struct.gas_bk_measurement_id; + //detectorBkMeasurementId + String detectorBkMeasurementId = struct.detector_bk_measurement_id; + //measurementId + String measurementId = struct.measurement_id; + spectrumData.setSampleId(sampleId); + spectrumData.setStatus(sampleData.getStatus()); + spectrumData.setStationCode(stationCode); + spectrumData.setDetectorCode(detectorCode); + spectrumData.setDataType(dataType); + spectrumData.setCollectionStart(CollectionStart); + spectrumData.setCollectionStop(CollectionStop); + spectrumData.setCollectionTime(CollectionTime); + spectrumData.setAcquisitionStart(AcquisitionStart); + spectrumData.setAcquisitionRealTime(String.format("%.2f", AcquisitionRealTime)); + spectrumData.setAcquisitionLiveTime(String.format("%.2f", AcquisitionLiveTime)); + spectrumData.setAirVolume(String.format("%.5f", airVolume)); + spectrumData.setXeVolume(String.format("%.5f", xeVolume)); + spectrumData.setYield(xeCollectionYield); + spectrumData.setGasBkMeasurementId(gasBkMeasurementId); + spectrumData.setDetectorBkMeasurementId(detectorBkMeasurementId); + spectrumData.setMeasurementId(measurementId); + } catch (ParseException e) { + throw new RuntimeException(e); + } + return spectrumData; + } + /** * 分析成功数据发送到Redis */ @@ -5038,7 +5205,6 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements ExportUtil.exportXls(response, template, analyze, export); } - public void saveToTxtOld(BgDataAnlyseResultIn anlyseResultIn, HttpServletRequest request, HttpServletResponse response) { String userName = JwtUtil.getUserNameByToken(request); // 解析文件,生成导出数据 @@ -5610,701 +5776,58 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements } } - public void analyzePHDFile(BgDataAnlyseResultIn anlyseResultIn, BgCalibratePara BgCalPara, List betaFittingPara, List gammaFittingPara, BetaDataFile betaDataFile) { - File sampleTmp = null; - File gasTmp = null; - File detTmp = null; - try { - //根据文件路径 文件名称获取对应的临时文件 - sampleTmp = new File(betaDataFile.getSampleTmpPath()); - gasTmp = new File(betaDataFile.getGasTmpPath()); - detTmp = new File(betaDataFile.getDetTmpPath()); - //调用动态库解析文件 - //Gamma Energy Calibration页面 如果点击过fitting使BGammaEnergyValid并且有勾选 - //如果三个sampleData,GasData,DetData数据都是被勾选状态 则需要传递新的参数重新分析 否则不需要改变数据分析当前文件内容 - BgAnalyseResult bgAnalyseResult = null; - if (Objects.nonNull(sampleTmp) && Objects.nonNull(gasTmp) && Objects.nonNull(detTmp)) { - if (Objects.isNull(BgCalPara)) { - bgAnalyseResult = EnergySpectrumHandler.bgAnalyse(sampleTmp.getAbsolutePath(), gasTmp.getAbsolutePath(), detTmp.getAbsolutePath()); - } else { - bgAnalyseResult = EnergySpectrumHandler.bgReAnalyse(sampleTmp.getAbsolutePath(), gasTmp.getAbsolutePath(), detTmp.getAbsolutePath(), BgCalPara); - } - if (StringUtils.isBlank(bgAnalyseResult.error_log) || bgAnalyseResult.error_log.equalsIgnoreCase("no error.")) { - //处理XeData的数据 - List xeResultsSpectrumList = new LinkedList<>(); - GardsXeResults xe131m = new GardsXeResults(); - xe131m.setNuclideName(XeNuclideName.XE_131m.getType()); - xe131m.setConc(bgAnalyseResult.Xe131m_con); - xe131m.setConcErr(bgAnalyseResult.Xe131m_uncer); - xe131m.setLc(bgAnalyseResult.LC_Xe131m); - xe131m.setMdc(bgAnalyseResult.MDC_Xe131m); - xe131m.setNidFlag(anlyseResultIn.getXe131mFlag()); - xeResultsSpectrumList.add(xe131m); - GardsXeResults xe133 = new GardsXeResults(); - xe133.setNuclideName(XeNuclideName.XE_133.getType()); - xe133.setConc(bgAnalyseResult.Xe133_con); - xe133.setConcErr(bgAnalyseResult.Xe133_uncer); - xe133.setLc(bgAnalyseResult.LC_Xe133); - xe133.setMdc(bgAnalyseResult.MDC_Xe133); - xe133.setNidFlag(anlyseResultIn.getXe133Flag()); - xeResultsSpectrumList.add(xe133); - GardsXeResults xe133m = new GardsXeResults(); - xe133m.setNuclideName(XeNuclideName.XE_133m.getType()); - xe133m.setConc(bgAnalyseResult.Xe133m_con); - xe133m.setConcErr(bgAnalyseResult.Xe133m_uncer); - xe133m.setLc(bgAnalyseResult.LC_Xe133m); - xe133m.setMdc(bgAnalyseResult.MDC_Xe133m); - xe133m.setNidFlag(anlyseResultIn.getXe133mFlag()); - xeResultsSpectrumList.add(xe133m); - GardsXeResults xe135 = new GardsXeResults(); - xe135.setNuclideName(XeNuclideName.XE_135.getType()); - xe135.setConc(bgAnalyseResult.Xe135_con); - xe135.setConcErr(bgAnalyseResult.Xe135_uncer); - xe135.setLc(bgAnalyseResult.LC_Xe135); - xe135.setMdc(bgAnalyseResult.MDC_Xe135); - xe135.setNidFlag(anlyseResultIn.getXe135Flag()); - xeResultsSpectrumList.add(xe135); - anlyseResultIn.setXeData(xeResultsSpectrumList); - //处理GammaCalibration的数据 - List gammaCalibrationSpectrumList = new LinkedList<>(); - if (anlyseResultIn.isBGammaEnergyValidSample()) { - GardsCalibrationSpectrum gammaCalibrationS = new GardsCalibrationSpectrum(); - gammaCalibrationS.setDataType(DataTypeAbbr.SAMPLEPHD.getType()); - gammaCalibrationS.setCoeff1(Double.valueOf(gammaFittingPara.get(0))); - gammaCalibrationS.setCoeff2(Double.valueOf(gammaFittingPara.get(1))); - gammaCalibrationS.setCoeff3(Double.valueOf(gammaFittingPara.get(2))); - gammaCalibrationSpectrumList.add(gammaCalibrationS); - } else { - GardsCalibrationSpectrum gammaCalibrationS = new GardsCalibrationSpectrum(); - gammaCalibrationS.setDataType(DataTypeAbbr.SAMPLEPHD.getType()); - gammaCalibrationS.setCoeff1(bgAnalyseResult.s_g_fitting_e_c.get(0)); - gammaCalibrationS.setCoeff2(bgAnalyseResult.s_g_fitting_e_c.get(1)); - gammaCalibrationS.setCoeff3(bgAnalyseResult.s_g_fitting_e_c.get(2)); - gammaCalibrationSpectrumList.add(gammaCalibrationS); - } - if (anlyseResultIn.isBGammaEnergyValidGas()) { - GardsCalibrationSpectrum gammaCalibrationG = new GardsCalibrationSpectrum(); - gammaCalibrationG.setDataType(DataTypeAbbr.GASBKPHD.getType()); - gammaCalibrationG.setCoeff1(Double.valueOf(gammaFittingPara.get(0))); - gammaCalibrationG.setCoeff2(Double.valueOf(gammaFittingPara.get(1))); - gammaCalibrationG.setCoeff3(Double.valueOf(gammaFittingPara.get(2))); - gammaCalibrationSpectrumList.add(gammaCalibrationG); - } else { - GardsCalibrationSpectrum gammaCalibrationG = new GardsCalibrationSpectrum(); - gammaCalibrationG.setDataType(DataTypeAbbr.GASBKPHD.getType()); - gammaCalibrationG.setCoeff1(bgAnalyseResult.g_g_fitting_e_c.get(0)); - gammaCalibrationG.setCoeff2(bgAnalyseResult.g_g_fitting_e_c.get(1)); - gammaCalibrationG.setCoeff3(bgAnalyseResult.g_g_fitting_e_c.get(2)); - gammaCalibrationSpectrumList.add(gammaCalibrationG); - } - if (anlyseResultIn.isBGammaEnergyValidDet()) { - GardsCalibrationSpectrum gammaCalibrationD = new GardsCalibrationSpectrum(); - gammaCalibrationD.setDataType(DataTypeAbbr.DETBKPHD.getType()); - gammaCalibrationD.setCoeff1(Double.valueOf(gammaFittingPara.get(0))); - gammaCalibrationD.setCoeff2(Double.valueOf(gammaFittingPara.get(1))); - gammaCalibrationD.setCoeff3(Double.valueOf(gammaFittingPara.get(2))); - gammaCalibrationSpectrumList.add(gammaCalibrationD); - } else { - GardsCalibrationSpectrum gammaCalibrationD = new GardsCalibrationSpectrum(); - gammaCalibrationD.setDataType(DataTypeAbbr.DETBKPHD.getType()); - gammaCalibrationD.setCoeff1(bgAnalyseResult.d_g_fitting_e_c.get(0)); - gammaCalibrationD.setCoeff2(bgAnalyseResult.d_g_fitting_e_c.get(1)); - gammaCalibrationD.setCoeff3(bgAnalyseResult.d_g_fitting_e_c.get(2)); - gammaCalibrationSpectrumList.add(gammaCalibrationD); - } - anlyseResultIn.setGammaCalibrationSpectrumList(gammaCalibrationSpectrumList); - //处理BetaCalibration数据 - List betaCalibrationSpectrumList = new LinkedList<>(); - if (anlyseResultIn.isBBetaEnergyValidSample()) { - GardsCalibrationSpectrum betaCalibrationS = new GardsCalibrationSpectrum(); - betaCalibrationS.setDataType(DataTypeAbbr.SAMPLEPHD.getType()); - betaCalibrationS.setCoeff1(Double.valueOf(betaFittingPara.get(0))); - betaCalibrationS.setCoeff2(Double.valueOf(betaFittingPara.get(1))); - betaCalibrationS.setCoeff3(Double.valueOf(betaFittingPara.get(2))); - betaCalibrationSpectrumList.add(betaCalibrationS); - } else { - GardsCalibrationSpectrum betaCalibrationS = new GardsCalibrationSpectrum(); - betaCalibrationS.setDataType(DataTypeAbbr.SAMPLEPHD.getType()); - betaCalibrationS.setCoeff1(bgAnalyseResult.s_b_fitting_e_c.get(0)); - betaCalibrationS.setCoeff2(bgAnalyseResult.s_b_fitting_e_c.get(1)); - betaCalibrationS.setCoeff3(bgAnalyseResult.s_b_fitting_e_c.get(2)); - betaCalibrationSpectrumList.add(betaCalibrationS); - } - if (anlyseResultIn.isBBetaEnergyValidGas()) { - GardsCalibrationSpectrum betaCalibrationG = new GardsCalibrationSpectrum(); - betaCalibrationG.setDataType(DataTypeAbbr.GASBKPHD.getType()); - betaCalibrationG.setCoeff1(Double.valueOf(betaFittingPara.get(0))); - betaCalibrationG.setCoeff2(Double.valueOf(betaFittingPara.get(1))); - betaCalibrationG.setCoeff3(Double.valueOf(betaFittingPara.get(2))); - betaCalibrationSpectrumList.add(betaCalibrationG); - } else { - GardsCalibrationSpectrum betaCalibrationG = new GardsCalibrationSpectrum(); - betaCalibrationG.setDataType(DataTypeAbbr.GASBKPHD.getType()); - betaCalibrationG.setCoeff1(bgAnalyseResult.g_b_fitting_e_c.get(0)); - betaCalibrationG.setCoeff2(bgAnalyseResult.g_b_fitting_e_c.get(1)); - betaCalibrationG.setCoeff3(bgAnalyseResult.g_b_fitting_e_c.get(2)); - betaCalibrationSpectrumList.add(betaCalibrationG); - } - if (anlyseResultIn.isBBetaEnergyValidDet()) { - GardsCalibrationSpectrum betaCalibrationD = new GardsCalibrationSpectrum(); - betaCalibrationD.setDataType(DataTypeAbbr.DETBKPHD.getType()); - betaCalibrationD.setCoeff1(Double.valueOf(betaFittingPara.get(0))); - betaCalibrationD.setCoeff2(Double.valueOf(betaFittingPara.get(1))); - betaCalibrationD.setCoeff3(Double.valueOf(betaFittingPara.get(2))); - betaCalibrationSpectrumList.add(betaCalibrationD); - } else { - GardsCalibrationSpectrum betaCalibrationD = new GardsCalibrationSpectrum(); - betaCalibrationD.setDataType(DataTypeAbbr.DETBKPHD.getType()); - betaCalibrationD.setCoeff1(bgAnalyseResult.d_b_fitting_e_c.get(0)); - betaCalibrationD.setCoeff2(bgAnalyseResult.d_b_fitting_e_c.get(1)); - betaCalibrationD.setCoeff3(bgAnalyseResult.d_b_fitting_e_c.get(2)); - betaCalibrationSpectrumList.add(betaCalibrationD); - } - anlyseResultIn.setBetaCalibrationSpectrumList(betaCalibrationSpectrumList); - //存储roiChannel数据 - List roiChannelsSpectrumList = new LinkedList<>(); - for (int i=0; i roiResultsSpectrumList = new LinkedList<>(); - for (int i=0; ibgAnalyseResult.MDC.get(i)) { - roiResults.setNidFlag(1); - } else { - roiResults.setNidFlag(0); - } - roiResultsSpectrumList.add(roiResults); - } - anlyseResultIn.setRoiResultsSpectrumList(roiResultsSpectrumList); - betaDataFile.getXeResultsSpectrumList().forEach(item -> { - if (item.getNuclideName().equals(XeNuclideName.XE_131m.getType())) { - item.setNidFlag(anlyseResultIn.getXe131mFlag()); - } else if (item.getNuclideName().equals(XeNuclideName.XE_133.getType())) { - item.setNidFlag(anlyseResultIn.getXe133Flag()); - } else if (item.getNuclideName().equals(XeNuclideName.XE_133m.getType())) { - item.setNidFlag(anlyseResultIn.getXe133mFlag()); - } else if (item.getNuclideName().equals(XeNuclideName.XE_135.getType())) { - item.setNidFlag(anlyseResultIn.getXe135Flag()); - } - }); - } + public void analyzePHDFile(BgDataAnlyseResultIn anlyseResultIn, BetaDataFile betaDataFile) { + //处理XeData表数据 + List xeDataList = betaDataFile.getXeDataList(); + if (CollectionUtils.isEmpty(xeDataList)) { + List xeResultsSpectrumList = betaDataFile.getXeResultsSpectrumList(); + xeDataList = getXeDataList(xeResultsSpectrumList); + } + for (GardsXeResults xeData :xeDataList) { + if (xeData.getNuclideName().equals(XeNuclideName.XE_131m)) { + xeData.setNidFlag(anlyseResultIn.getXe131mFlag()); + } else if (xeData.getNuclideName().equals(XeNuclideName.XE_133)) { + xeData.setNidFlag(anlyseResultIn.getXe133Flag()); + } else if (xeData.getNuclideName().equals(XeNuclideName.XE_133m)) { + xeData.setNidFlag(anlyseResultIn.getXe133mFlag()); + } else if (xeData.getNuclideName().equals(XeNuclideName.XE_135)) { + xeData.setNidFlag(anlyseResultIn.getXe135Flag()); } - } catch (Exception e) { - e.printStackTrace(); } - } - - public List getCalibrationPairs(BgDataAnlyseResultIn anlyseResultIn, Integer sampleId, Integer gasId, Integer detId, Integer idAnalysis) { - List calibrationPairsList = new LinkedList<>(); - for (int i=0; i< anlyseResultIn.getB_channel_sample().size(); i++){ - GardsCalibrationPairs calibrationPairs = new GardsCalibrationPairs(); - calibrationPairs.setSampleId(sampleId); - calibrationPairs.setIdAnalysis(idAnalysis); - calibrationPairs.setSampleType(SystemType.BETA.getType()); - calibrationPairs.setCaltype(CalType.ENERGY_CAL.getType()); - calibrationPairs.setInput(CalName.CalPHD.getType()); - calibrationPairs.setIdCalPoint(i); - calibrationPairs.setXValue(anlyseResultIn.getB_channel_sample().get(i)); - calibrationPairs.setYValue(anlyseResultIn.getB_energy_sample().get(i)); - calibrationPairsList.add(calibrationPairs); - } - for (int i=0; i< anlyseResultIn.getG_channel_sample().size(); i++){ - GardsCalibrationPairs calibrationPairs = new GardsCalibrationPairs(); - calibrationPairs.setSampleId(sampleId); - calibrationPairs.setIdAnalysis(idAnalysis); - calibrationPairs.setSampleType(SystemType.GAMMA.getType()); - calibrationPairs.setCaltype(CalType.ENERGY_CAL.getType()); - calibrationPairs.setInput(CalName.CalPHD.getType()); - calibrationPairs.setIdCalPoint(i); - calibrationPairs.setXValue(anlyseResultIn.getG_channel_sample().get(i)); - calibrationPairs.setYValue(anlyseResultIn.getG_energy_sample().get(i)); - calibrationPairsList.add(calibrationPairs); - } - - for (int i=0; i< anlyseResultIn.getB_channel_gas().size(); i++){ - GardsCalibrationPairs calibrationPairs = new GardsCalibrationPairs(); - calibrationPairs.setSampleId(gasId); - calibrationPairs.setIdAnalysis(idAnalysis); - calibrationPairs.setSampleType(SystemType.BETA.getType()); - calibrationPairs.setCaltype(CalType.ENERGY_CAL.getType()); - calibrationPairs.setInput(CalName.CalPHD.getType()); - calibrationPairs.setIdCalPoint(i); - calibrationPairs.setXValue(anlyseResultIn.getB_channel_gas().get(i)); - calibrationPairs.setYValue(anlyseResultIn.getB_energy_gas().get(i)); - calibrationPairsList.add(calibrationPairs); - } - - for (int i=0; i< anlyseResultIn.getG_channel_gas().size(); i++){ - GardsCalibrationPairs calibrationPairs = new GardsCalibrationPairs(); - calibrationPairs.setSampleId(gasId); - calibrationPairs.setIdAnalysis(idAnalysis); - calibrationPairs.setSampleType(SystemType.GAMMA.getType()); - calibrationPairs.setCaltype(CalType.ENERGY_CAL.getType()); - calibrationPairs.setInput(CalName.CalPHD.getType()); - calibrationPairs.setIdCalPoint(i); - calibrationPairs.setXValue(anlyseResultIn.getG_channel_gas().get(i)); - calibrationPairs.setYValue(anlyseResultIn.getG_energy_gas().get(i)); - calibrationPairsList.add(calibrationPairs); - } - - for (int i=0; i< anlyseResultIn.getB_channel_det().size(); i++){ - GardsCalibrationPairs calibrationPairs = new GardsCalibrationPairs(); - calibrationPairs.setSampleId(detId); - calibrationPairs.setIdAnalysis(idAnalysis); - calibrationPairs.setSampleType(SystemType.BETA.getType()); - calibrationPairs.setCaltype(CalType.ENERGY_CAL.getType()); - calibrationPairs.setInput(CalName.CalPHD.getType()); - calibrationPairs.setIdCalPoint(i); - calibrationPairs.setXValue(anlyseResultIn.getB_channel_det().get(i)); - calibrationPairs.setYValue(anlyseResultIn.getB_energy_det().get(i)); - calibrationPairsList.add(calibrationPairs); - } - - for (int i=0; i< anlyseResultIn.getG_channel_det().size(); i++){ - GardsCalibrationPairs calibrationPairs = new GardsCalibrationPairs(); - calibrationPairs.setSampleId(detId); - calibrationPairs.setIdAnalysis(idAnalysis); - calibrationPairs.setSampleType(SystemType.GAMMA.getType()); - calibrationPairs.setCaltype(CalType.ENERGY_CAL.getType()); - calibrationPairs.setInput(CalName.CalPHD.getType()); - calibrationPairs.setIdCalPoint(i); - calibrationPairs.setXValue(anlyseResultIn.getG_channel_det().get(i)); - calibrationPairs.setYValue(anlyseResultIn.getG_energy_det().get(i)); - calibrationPairsList.add(calibrationPairs); - } - return calibrationPairsList; - } - - public List getCalibration(BgDataAnlyseResultIn anlyseResultIn, Integer sampleId, Integer gasId, Integer detId, Integer idAnalysis) { - List calibrationSpectrumList = new LinkedList<>(); - if (Objects.nonNull(sampleId)) { - GardsCalibration calibrationB = new GardsCalibration(); - calibrationB.setSampleId(sampleId); - calibrationB.setIdAnalysis(idAnalysis); - calibrationB.setSampleType(SystemType.BETA.getType()); - calibrationB.setCalType(CalType.ENERGY_CAL.getType()); - calibrationB.setFunction(FittingType.POLY2.getCode()); - calibrationB.setFunctionDef(FittingType.POLY2.getDescription()); - calibrationB.setStartOfRange(0); - calibrationB.setEndOfRange(1); - List betaCollect = anlyseResultIn.getBetaCalibrationSpectrumList().stream().filter(item -> item.getDataType().equals(DataTypeAbbr.SAMPLEPHD.getType())).collect(Collectors.toList()); - GardsCalibrationSpectrum betaCalibrationSpectrum = betaCollect.get(0); - calibrationB.setCoeff1(Double.valueOf(betaCalibrationSpectrum.getCoeff1())); - calibrationB.setCoeff2(Double.valueOf(betaCalibrationSpectrum.getCoeff2())); - calibrationB.setCoeff3(Double.valueOf(betaCalibrationSpectrum.getCoeff3())); - calibrationSpectrumList.add(calibrationB); - - GardsCalibration calibrationG = new GardsCalibration(); - calibrationG.setSampleId(sampleId); - calibrationG.setIdAnalysis(idAnalysis); - calibrationG.setSampleType(SystemType.GAMMA.getType()); - calibrationG.setCalType(CalType.ENERGY_CAL.getType()); - calibrationG.setFunction(FittingType.POLY2.getCode()); - calibrationG.setFunctionDef(FittingType.POLY2.getDescription()); - calibrationG.setStartOfRange(0); - calibrationG.setEndOfRange(1); - List gammaCollect = anlyseResultIn.getGammaCalibrationSpectrumList().stream().filter(item -> item.getDataType().equals(DataTypeAbbr.SAMPLEPHD.getType())).collect(Collectors.toList()); - GardsCalibrationSpectrum gammaCalibrationSpectrum = gammaCollect.get(0); - calibrationG.setCoeff1(Double.valueOf(gammaCalibrationSpectrum.getCoeff1())); - calibrationG.setCoeff2(Double.valueOf(gammaCalibrationSpectrum.getCoeff2())); - calibrationG.setCoeff3(Double.valueOf(gammaCalibrationSpectrum.getCoeff3())); - calibrationSpectrumList.add(calibrationG); - } - - if (Objects.nonNull(gasId)) { - //gas文件 Beta部分 - GardsCalibration calibrationB = new GardsCalibration(); - calibrationB.setSampleId(gasId); - calibrationB.setIdAnalysis(idAnalysis); - calibrationB.setSampleType(SystemType.BETA.getType()); - calibrationB.setCalType(CalType.ENERGY_CAL.getType()); - calibrationB.setFunction(FittingType.POLY2.getCode()); - calibrationB.setFunctionDef(FittingType.POLY2.getDescription()); - calibrationB.setStartOfRange(0); - calibrationB.setEndOfRange(1); - List betaCollect = anlyseResultIn.getBetaCalibrationSpectrumList().stream().filter(item -> item.getDataType().equals(DataTypeAbbr.GASBKPHD.getType())).collect(Collectors.toList()); - GardsCalibrationSpectrum betaCalibrationSpectrum = betaCollect.get(0); - calibrationB.setCoeff1(Double.valueOf(betaCalibrationSpectrum.getCoeff1())); - calibrationB.setCoeff2(Double.valueOf(betaCalibrationSpectrum.getCoeff2())); - calibrationB.setCoeff3(Double.valueOf(betaCalibrationSpectrum.getCoeff3())); - calibrationSpectrumList.add(calibrationB); - //gas文件 gamma部分 - GardsCalibration calibrationG = new GardsCalibration(); - calibrationG.setSampleId(gasId); - calibrationG.setIdAnalysis(idAnalysis); - calibrationG.setSampleType(SystemType.GAMMA.getType()); - calibrationG.setCalType(CalType.ENERGY_CAL.getType()); - calibrationG.setFunction(FittingType.POLY2.getCode()); - calibrationG.setFunctionDef(FittingType.POLY2.getDescription()); - calibrationG.setStartOfRange(0); - calibrationG.setEndOfRange(1); - List gammaCollect = anlyseResultIn.getGammaCalibrationSpectrumList().stream().filter(item -> item.getDataType().equals(DataTypeAbbr.GASBKPHD.getType())).collect(Collectors.toList()); - GardsCalibrationSpectrum gammaCalibrationSpectrum = gammaCollect.get(0); - calibrationG.setCoeff1(Double.valueOf(gammaCalibrationSpectrum.getCoeff1())); - calibrationG.setCoeff2(Double.valueOf(gammaCalibrationSpectrum.getCoeff2())); - calibrationG.setCoeff3(Double.valueOf(gammaCalibrationSpectrum.getCoeff3())); - calibrationSpectrumList.add(calibrationG); - } - - if (Objects.nonNull(detId)) { - GardsCalibration calibrationB = new GardsCalibration(); - calibrationB.setSampleId(detId); - calibrationB.setIdAnalysis(idAnalysis); - calibrationB.setSampleType(SystemType.BETA.getType()); - calibrationB.setCalType(CalType.ENERGY_CAL.getType()); - calibrationB.setFunction(FittingType.POLY2.getCode()); - calibrationB.setFunctionDef(FittingType.POLY2.getDescription()); - calibrationB.setStartOfRange(0); - calibrationB.setEndOfRange(1); - List betaCollect = anlyseResultIn.getBetaCalibrationSpectrumList().stream().filter(item -> item.getDataType().equals(DataTypeAbbr.DETBKPHD.getType())).collect(Collectors.toList()); - GardsCalibrationSpectrum betaCalibrationSpectrum = betaCollect.get(0); - calibrationB.setCoeff1(Double.valueOf(betaCalibrationSpectrum.getCoeff1())); - calibrationB.setCoeff2(Double.valueOf(betaCalibrationSpectrum.getCoeff2())); - calibrationB.setCoeff3(Double.valueOf(betaCalibrationSpectrum.getCoeff3())); - calibrationSpectrumList.add(calibrationB); - GardsCalibration calibrationG = new GardsCalibration(); - calibrationG.setSampleId(detId); - calibrationG.setIdAnalysis(idAnalysis); - calibrationG.setSampleType(SystemType.GAMMA.getType()); - calibrationG.setCalType(CalType.ENERGY_CAL.getType()); - calibrationG.setFunction(FittingType.POLY2.getCode()); - calibrationG.setFunctionDef(FittingType.POLY2.getDescription()); - calibrationG.setStartOfRange(0); - calibrationG.setEndOfRange(1); - List gammaCollect = anlyseResultIn.getGammaCalibrationSpectrumList().stream().filter(item -> item.getDataType().equals(DataTypeAbbr.DETBKPHD.getType())).collect(Collectors.toList()); - GardsCalibrationSpectrum gammaCalibrationSpectrum = gammaCollect.get(0); - calibrationG.setCoeff1(Double.valueOf(gammaCalibrationSpectrum.getCoeff1())); - calibrationG.setCoeff2(Double.valueOf(gammaCalibrationSpectrum.getCoeff2())); - calibrationG.setCoeff3(Double.valueOf(gammaCalibrationSpectrum.getCoeff3())); - calibrationSpectrumList.add(calibrationG); - } - return calibrationSpectrumList; - } - - public void getROIChannel(Integer sampleId, Integer idAnalysis, List roiChannelsSpectrumList, List roiChannelsList, String dataType) { - roiChannelsSpectrumList = roiChannelsSpectrumList.stream().filter(item-> item.getDataType().equals(dataType)).collect(Collectors.toList()); - for (int i=0; i getXeDataList(BgDataAnlyseResultIn anlyseResultIn, Integer sampleId, Integer idAnalysis) { - List xeResultsList = new LinkedList<>(); - //Xe131m - GardsXeResultsSpectrum xe131m = new GardsXeResultsSpectrum(); - xe131m.setSampleId(sampleId); - xe131m.setIdAnalysis(idAnalysis); - xe131m.setNuclideName(XeNuclideName.XE_131m.getType()); - xe131m.setConc(anlyseResultIn.getXe131m_con()); - xe131m.setConcErr(anlyseResultIn.getXe131m_uncer()); - xe131m.setMdc(anlyseResultIn.getMdc_Xe131m()); - xe131m.setLc(anlyseResultIn.getLc_Xe131m()); - xe131m.setNidFlag(anlyseResultIn.getXe131mFlag()); - xeResultsList.add(xe131m); - //Xe133 - GardsXeResultsSpectrum xe133 = new GardsXeResultsSpectrum(); - xe133.setSampleId(sampleId); - xe133.setIdAnalysis(idAnalysis); - xe133.setNuclideName(XeNuclideName.XE_133.getType()); - xe133.setConc(anlyseResultIn.getXe133_con()); - xe133.setConcErr(anlyseResultIn.getXe133_uncer()); - xe133.setMdc(anlyseResultIn.getMdc_Xe133()); - xe133.setLc(anlyseResultIn.getLc_Xe133()); - xe133.setNidFlag(anlyseResultIn.getXe133Flag()); - xeResultsList.add(xe133); - //Xe133m - GardsXeResultsSpectrum xe133m = new GardsXeResultsSpectrum(); - xe133m.setSampleId(sampleId); - xe133m.setIdAnalysis(idAnalysis); - xe133m.setNuclideName(XeNuclideName.XE_133m.getType()); - xe133m.setConc(anlyseResultIn.getXe133m_con()); - xe133m.setConcErr(anlyseResultIn.getXe133m_uncer()); - xe133m.setMdc(anlyseResultIn.getMdc_Xe133m()); - xe133m.setLc(anlyseResultIn.getLc_Xe133m()); - xe133m.setNidFlag(anlyseResultIn.getXe133mFlag()); - xeResultsList.add(xe133m); - //Xe135 - GardsXeResultsSpectrum xe135 = new GardsXeResultsSpectrum(); - xe135.setSampleId(sampleId); - xe135.setIdAnalysis(idAnalysis); - xe135.setNuclideName(XeNuclideName.XE_135.getType()); - xe135.setConc(anlyseResultIn.getXe135_con()); - xe135.setConcErr(anlyseResultIn.getXe135_uncer()); - xe135.setMdc(anlyseResultIn.getMdc_Xe135()); - xe135.setLc(anlyseResultIn.getLc_Xe135()); - xe135.setNidFlag(anlyseResultIn.getXe135Flag()); - xeResultsList.add(xe135); - return xeResultsList; - } - - public List getXeResults(BgDataAnlyseResultIn anlyseResultIn, Integer sampleId, Integer idAnalysis) { - List xeResultsList = anlyseResultIn.getXeData(); - for (GardsXeResults xeResults:xeResultsList) { - xeResults.setIdAnalysis(idAnalysis); - xeResults.setSampleId(sampleId); - } - return xeResultsList; - } - - @Transactional - public boolean OriginalDataStore(BetaDataFile betaDataFile, String type, String filePathName) { - //根据新的文件路径名称查询数据是否存在 - GardsSampleData isExist = spectrumAnalysisMapper.findSampleByFile(filePathName); - //如果数据已经存入过数据库 则 修改状态后返回 - if (Objects.nonNull(isExist)){ - //如果文件已经存入过数据库则修改状态 - spectrumAnalysisMapper.updateAnalysesStatus(filePathName); - return true; - } - //读取文件内容 - EnergySpectrumStruct sourceData = null; - File file = null; - try { - if (Objects.nonNull(betaDataFile)){ - - if (type.equalsIgnoreCase("sample")) { - file = new File(betaDataFile.getSampleTmpPath()); - sourceData = betaDataFile.getSampleStruct(); - } else if (type.equalsIgnoreCase("gas")) { - file = new File(betaDataFile.getGasTmpPath()); - sourceData = betaDataFile.getGasStruct(); - } else if (type.equalsIgnoreCase("det")) { - file = new File(betaDataFile.getDetTmpPath()); - sourceData = betaDataFile.getDetStruct(); - } else if (type.equalsIgnoreCase("qc")) { - file = new File(betaDataFile.getQcTmpPath()); - sourceData = betaDataFile.getQcStruct(); - } - //获取文件中块名信息 - List readLines = getFileBlockList(file); - //查询台站id - Integer stationId = spectrumAnalysisMapper.getStationId(sourceData.site_code); - Integer detectorId = spectrumAnalysisMapper.getDetectorId(sourceData.detector_code); - if(Objects.isNull(stationId) || Objects.isNull(detectorId)) { - String error = "get station_id or detect_id error"; - return false; - } - //新增Gards_Sample_Data表数据 - sampleDataSpectrumService.saveSampleData(sourceData, stationId, detectorId, filePathName, readLines); - //获取sampleId - Integer sampleId = spectrumAnalysisMapper.getSampleId(filePathName); - //存储Gards_Sample_Aux表数据 - sampleAuxSpectrumService.saveSampleAux(sourceData, sampleId, readLines); - //判断文件是否包含Comment块 新增Gards_Description数据 - if (readLines.contains(SampleFileHeader.COMMENT.getMessage())){ - sampleDescriptionSpectrumService.saveSampleDescription(sourceData, sampleId); - } - //判断文件是否包含Certificate块 新增Gards_Sample_Cert数据 - if (readLines.contains(SampleFileHeader.CERTIFICATE.getMessage())){ - sampleCertSpectrumService.saveSampleCert(sourceData, sampleId); - sampleCertLineSpectrumService.saveSampleCertLine(sourceData, sampleId); - } - //新增Gards_Calibration_Pairs_Orig数据 - calibrationPairsOrigSpectrumService.saveGardsCalibrationPairsOrig(sourceData, sampleId, readLines); - //判断文件是否包含b-gEfficiency块 新增Gards_Sample_Cert数据 - if (readLines.contains(SampleFileHeader.BGEFFICIENCY.getMessage())){ - bgEfficiencyPairsSpectrumService.saveBgEfficiencyPairs(sourceData, sampleId); - } - //判断文件是否包含TotalEff块 新增Gards_Sample_Cert数据 - if (readLines.contains(SampleFileHeader.TOTALEFF.getMessage())){ - totalEfficiencyPairsSpectrumService.saveTotalEfficiencyPairs(sourceData, sampleId); - } - //判断文件是否包含Ratios块 新增Gards_Sample_Ratios数据 - if (readLines.contains(SampleFileHeader.RATIOS.getMessage())){ - sampleRatiosSpectrumService.saveSampleRatios(sourceData, sampleId); - } - //判断是否包含ROI_Limits块 新增Gards_ROI_Limits数据 - if (readLines.contains(SampleFileHeader.ROILIMITS.getMessage())){ - roiLimitsSpectrumService.saveRoiLimits(sourceData, sampleId); - } - //新增Gards_Spectrum数据 - spectrumService.saveSpectrum(sourceData, sampleId, readLines, filePathName); - //判断是否包含Histogram块 新增Gards_Histogram数据 - if (readLines.contains(SampleFileHeader.HISTOGRAM.getMessage())){ - histogramService.saveHistogram(sourceData, sampleId, filePathName); - } + anlyseResultIn.setXeData(xeDataList); + betaDataFile.getXeResultsSpectrumList().forEach(item -> { + if (item.getNuclideName().equals(XeNuclideName.XE_131m.getType())) { + item.setNidFlag(anlyseResultIn.getXe131mFlag()); + } else if (item.getNuclideName().equals(XeNuclideName.XE_133.getType())) { + item.setNidFlag(anlyseResultIn.getXe133Flag()); + } else if (item.getNuclideName().equals(XeNuclideName.XE_133m.getType())) { + item.setNidFlag(anlyseResultIn.getXe133mFlag()); + } else if (item.getNuclideName().equals(XeNuclideName.XE_135.getType())) { + item.setNidFlag(anlyseResultIn.getXe135Flag()); } - return true; - } catch (Exception e) { - throw new RuntimeException(e); - } + }); + //处理GammaCalibration的数据 + List gammaCalibrationSpectrumList = betaDataFile.getGammaCalibrationSpectrumEList(); + anlyseResultIn.setGammaCalibrationSpectrumList(gammaCalibrationSpectrumList); + //处理BetaCalibration数据 + List betaCalibrationSpectrumList = betaDataFile.getBetaCalibrationSpectrumEList(); + anlyseResultIn.setBetaCalibrationSpectrumList(betaCalibrationSpectrumList); + //存储roiChannel数据 + List roiChannelsSpectrumList = betaDataFile.getRoiChannelsSpectrumList(); + anlyseResultIn.setRoiChannelsSpectrumList(roiChannelsSpectrumList); + //存储roiResult的数据 + List roiResultsSpectrumList = betaDataFile.getRoiResultsSpectrumList(); + anlyseResultIn.setRoiResultsSpectrumList(roiResultsSpectrumList); } - public List getFileBlockList(File file) { - List readLines = new LinkedList<>(); - try { - List allLines = FileUtils.readLines(file, "UTF-8"); - for (String line:allLines) { - if (line.contains("#")){ - readLines.add(line); - } - } - } catch (IOException e) { - throw new RuntimeException(e); + public List getXeDataList(List xeResultsSpectrumList) { + List xeDataList = new LinkedList<>(); + for (GardsXeResultsSpectrum xeResultsSpectrum:xeResultsSpectrumList) { + GardsXeResults xeResults = new GardsXeResults(); + BeanUtil.copyProperties(xeResultsSpectrum, xeResults); + xeDataList.add(xeResults); } - return readLines; - } - - public List getROIResult(List roiResultsSpectrumList, Integer sampleId, Integer idAnalysis) { - List roiResultsList = new LinkedList<>(); - for (int i=0; i Date: Tue, 19 Mar 2024 17:16:45 +0800 Subject: [PATCH 15/40] =?UTF-8?q?=E4=BA=BA=E5=B7=A5=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E5=88=86=E6=9E=90=E6=A8=A1=E5=9D=97Beta=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=BE=93=E5=87=BA=E8=AF=AD=E5=8F=A5=E7=A7=BB?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jeecg/modules/service/impl/SpectrumAnalysisServiceImpl.java | 1 - 1 file changed, 1 deletion(-) 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 12421e5e..930294d8 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 @@ -4274,7 +4274,6 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements gardsROIResultsSpectrumService.saveGardsROIResults(anlyseResultIn, sampleId, idAnalysis); } //上传本次文件到ftp人工交互存储路径下 - long uploadStartTime = System.currentTimeMillis(); try { if (StringUtils.isNotBlank(sampleFilePathName)) { //sample文件的saveFile存储路径 From c9ee863667a900fedfd8f0ffdd9096600893d350 Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Wed, 20 Mar 2024 14:02:54 +0800 Subject: [PATCH 16/40] =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=B9=E5=88=86=E6=94=AF=E4=BA=BA=E5=B7=A5?= =?UTF-8?q?=E4=BA=A4=E4=BA=92=E6=A8=A1=E5=9D=97=EF=BC=8C=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=B9=E7=9A=84=E5=89=8D=E7=BC=80=E8=B7=AF=E5=BE=84=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E4=B8=8D=E5=86=8D=E4=BD=BF=E7=94=A8FTP=E7=9A=84?= =?UTF-8?q?=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/GammaServiceImpl.java | 28 +++++++++---------- .../impl/SpectrumAnalysisServiceImpl.java | 28 +++++++++---------- .../service/impl/SpectrumFileServiceImpl.java | 4 +-- 3 files changed, 30 insertions(+), 30 deletions(-) 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 54484465..01a77634 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 @@ -180,7 +180,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi return result; } // 切割数据库存储的文件路径获取路径信息 - String pathName = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + sampleFilePath.substring(0, sampleFilePath.lastIndexOf(StringPool.SLASH)); + String pathName = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + sampleFilePath.substring(0, sampleFilePath.lastIndexOf(StringPool.SLASH)); // 切割数据库存储的文件路径获取文件名称 String fileName = sampleFilePath.substring(sampleFilePath.lastIndexOf(StringPool.SLASH) + 1); // 声明phd实体类 @@ -598,7 +598,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi Map map = new HashMap<>(); Cache phdCache = localCache.getPHDCache(); // 上传文件路径 - String path = ftpUtil.getFtpRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName; + String path = spectrumPathProperties.getRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName; // 获取当前角色的颜色配置 Map colorMap = sysUserColorService.initColor(userName); PHDFile phd = phdCache.getIfPresent(fileName + StringPool.DASH + userName); @@ -737,7 +737,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi result.error500("The comparison file path does not exist"); return result; } - compareFilePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + compareFilePath; + compareFilePath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + compareFilePath; File compareFile = ftpUtil.downloadFile(compareFilePath); if (Objects.isNull(compareFile)) { result.error500("The comparison file path does not exist"); @@ -769,7 +769,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi long m_nCount = phd.getSpec().getNum_g_channel(); List vEnergy = phd.getVEnergy(); //加载compare文件 - String compareFilePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName; + String compareFilePath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName; String fromPath = compareFilePath + StringPool.SLASH + compareFileName; File compareFile = ftpUtil.downloadFile(fromPath); if (Objects.nonNull(compareFile)) { @@ -819,7 +819,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi result.error500("The comparison file path does not exist"); return result; } - stripFilePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + stripFilePath; + stripFilePath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + stripFilePath; File stripFile = ftpUtil.downloadFile(stripFilePath); if (Objects.isNull(stripFile)) { result.error500("The comparison file path does not exist"); @@ -868,7 +868,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi m_vCount.add(0L); } //加载strip文件 - String stripFilePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName; + String stripFilePath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName; String fromPath = stripFilePath + StringPool.SLASH + stripFileName; File stripFile = ftpUtil.downloadFile(fromPath); if (Objects.nonNull(stripFile)) { @@ -3937,7 +3937,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi if (StringUtils.isBlank(reportPath)) { throw new RuntimeException("The automatic handler generated report does not exist!"); } - String pathFileName = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + reportPath + ".txt"; + String pathFileName = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + reportPath + ".txt"; InputStream inputStream = null; ServletOutputStream outputStream = null; try { @@ -3971,7 +3971,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi public void exportARR(Integer sampleId, HttpServletResponse response) { // 获取自动处理生成的报告地址 String reportPath = spectrumAnalysisMapper.viewARR(sampleId); - String pathFileName = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + reportPath + ".txt"; + String pathFileName = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + reportPath + ".txt"; InputStream inputStream = null; ServletOutputStream outputStream = null; try { @@ -4571,7 +4571,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi if (StringUtils.isBlank(logPath)) { throw new RuntimeException("The log generated by the automatic processor does not exist!"); } - String pathFileName = ftpUtil.getFtpRootPath() + spectrumPathProperties.getLogPath() + StringPool.SLASH + logPath; + String pathFileName = spectrumPathProperties.getRootPath() + spectrumPathProperties.getLogPath() + StringPool.SLASH + logPath; InputStream inputStream = null; ServletOutputStream outputStream = null; try { @@ -4790,7 +4790,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi // File baselineFile = new File(rootPath+middleData.analyses_baseline_absolute_filePath); // try { // FileInputStream in = new FileInputStream(baselineFile); -// ftpUtil.saveFile(ftpUtil.getFtpRootPath()+middleData.analyses_baseline_absolute_filePath, in); +// ftpUtil.saveFile(spectrumPathProperties.getRootPath()+middleData.analyses_baseline_absolute_filePath, in); // } catch (FileNotFoundException e) { // throw new RuntimeException(e); // } @@ -4799,7 +4799,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi // File lcFile = new File(rootPath+middleData.analyses_lc_absolute_filePath); // try { // FileInputStream in = new FileInputStream(lcFile); -// ftpUtil.saveFile(ftpUtil.getFtpRootPath()+middleData.analyses_lc_absolute_filePath, in); +// ftpUtil.saveFile(spectrumPathProperties.getRootPath()+middleData.analyses_lc_absolute_filePath, in); // } catch (FileNotFoundException e) { // throw new RuntimeException(e); // } @@ -4808,7 +4808,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi // File scacFile = new File(rootPath+middleData.analyses_scac_absolute_filePath); // try { // FileInputStream in = new FileInputStream(scacFile); -// ftpUtil.saveFile(ftpUtil.getFtpRootPath()+middleData.analyses_scac_absolute_filePath, in); +// ftpUtil.saveFile(spectrumPathProperties.getRootPath()+middleData.analyses_scac_absolute_filePath, in); // } catch (FileNotFoundException e) { // throw new RuntimeException(e); // } @@ -4819,7 +4819,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi try { FileUtil.writeString(gammaFileUtil.GetLogContent(middleData), logFile, "UTF-8"); FileInputStream in = new FileInputStream(logFile); - ftpUtil.saveFile(ftpUtil.getFtpRootPath()+middleData.analyses_absolute_LogPath, in); + ftpUtil.saveFile(spectrumPathProperties.getRootPath()+middleData.analyses_absolute_LogPath, in); } catch (FileNotFoundException e) { throw new RuntimeException(e); } finally { @@ -4832,7 +4832,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi try { FileUtil.writeString(gammaFileUtil.GetReportContent(middleData), rptFile, "UTF-8"); FileInputStream in = new FileInputStream(rptFile); - ftpUtil.saveFile(ftpUtil.getFtpRootPath()+middleData.analyses_absolute_ReportPath+".txt", in); + ftpUtil.saveFile(spectrumPathProperties.getRootPath()+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 930294d8..cf20f059 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 @@ -301,7 +301,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements Result result = new Result(); List> resultList = new LinkedList<>(); String userName = JwtUtil.getUserNameByToken(request); - String filePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH +userName; + String filePath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH +userName; String sampleRx = "[a-zA-Z]{3}[0-9]{2}_[0-9]{3}-[0-9]{8}_[0-9]{4}_S_(FULL_|PREL_)\\d+\\.PHD"; Pattern regexPattern = Pattern.compile(sampleRx); String sampleRx1 = "[a-zA-Z]{3}[0-9]{2}_[0-9]{3}-[0-9]{8}_[0-9]{4}_S_(FULL_|PREL_)\\d+\\.\\d+\\.PHD"; @@ -482,7 +482,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements betaDataFile.setSampleId(String.valueOf(sampleId)); //判断sample信息是否存在 if (Objects.nonNull(sample)) { - betaDataFile.setSampleFilePathName(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH +dbSpectrumFilePath.getSampleFilePath()); + betaDataFile.setSampleFilePathName(spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH +dbSpectrumFilePath.getSampleFilePath()); betaDataFile.setSampleFileName(sampleFileName); sampleTmp = ftpUtil.downloadFile(betaDataFile.getSampleFilePathName()); if (Objects.nonNull(sampleTmp)) { @@ -519,7 +519,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements } //判断gas信息是否存在 if (Objects.nonNull(gasBg)) { - betaDataFile.setGasFilePathName(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH +dbSpectrumFilePath.getGasBgFilePath()); + betaDataFile.setGasFilePathName(spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH +dbSpectrumFilePath.getGasBgFilePath()); betaDataFile.setGasFileName(gasFileName); gasTmp = ftpUtil.downloadFile(betaDataFile.getGasFilePathName()); if (Objects.nonNull(gasTmp)) { @@ -556,7 +556,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements } //判断det信息是否存在 if (Objects.nonNull(detBg)) { - betaDataFile.setDetFilePathName(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH +dbSpectrumFilePath.getDetBgFilePath()); + betaDataFile.setDetFilePathName(spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH +dbSpectrumFilePath.getDetBgFilePath()); betaDataFile.setDetFileName(detFileName); detTmp = ftpUtil.downloadFile(betaDataFile.getDetFilePathName()); if (Objects.nonNull(detTmp)) { @@ -593,7 +593,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements } //判断qc信息是否存在 if (Objects.nonNull(qc)) { - betaDataFile.setQcFilePathName(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH +dbQcFilePath); + betaDataFile.setQcFilePathName(spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH +dbQcFilePath); betaDataFile.setQcFileName(qcFileName); qcTmp = ftpUtil.downloadFile(betaDataFile.getQcFilePathName()); if (Objects.nonNull(qcTmp)) { @@ -672,7 +672,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements //获取用户名 String userName = JwtUtil.getUserNameByToken(request); //上传文件路径 - String path = ftpUtil.getFtpRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName; + String path = spectrumPathProperties.getRootPath() + spectrumPathProperties.getUploadPath() + StringPool.SLASH + userName; Map resultMap = new HashMap<>(); Map sampleMap = new HashMap<>(); Map gasBgMap = new HashMap<>(); @@ -929,7 +929,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements InputStream inputStream = null; ServletOutputStream outputStream = null; try { - inputStream = ftpUtil.downloadFileStream(ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + reportPath + ".txt"); + inputStream = ftpUtil.downloadFileStream(spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + reportPath + ".txt"); if (Objects.nonNull(inputStream)){ outputStream = response.getOutputStream(); byte[] buffer = new byte[1024]; @@ -3996,7 +3996,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements InputStream inputStream = null; ServletOutputStream outputStream = null; try { - inputStream = ftpUtil.downloadFileStream(ftpUtil.getFtpRootPath() + spectrumPathProperties.getLogPath() + StringPool.SLASH + logPath); + inputStream = ftpUtil.downloadFileStream(spectrumPathProperties.getRootPath() + spectrumPathProperties.getLogPath() + StringPool.SLASH + logPath); if (Objects.nonNull(inputStream)){ outputStream = response.getOutputStream(); byte[] buffer = new byte[1024]; @@ -4277,7 +4277,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements try { if (StringUtils.isNotBlank(sampleFilePathName)) { //sample文件的saveFile存储路径 - String saveSamplePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + sampleFilePathName; + String saveSamplePath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + sampleFilePathName; if (StringUtils.isNotBlank(betaDataFile.getSampleTmpPath()) && !saveSamplePath.equals(betaDataFile.getSampleTmpPath().replace(StringPool.BACK_SLASH, StringPool.SLASH))) { File sampleTmp = new File(betaDataFile.getSampleTmpPath()); ftpUtil.saveFile(saveSamplePath, new FileInputStream(sampleTmp)); @@ -4285,7 +4285,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements } if (StringUtils.isNotBlank(gasFilePathName)) { //gas文件的saveFile存储路径 - String saveGasPath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + gasFilePathName; + String saveGasPath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + gasFilePathName; if (StringUtils.isNotBlank(betaDataFile.getGasTmpPath()) && !saveGasPath.equals(betaDataFile.getGasTmpPath().replace(StringPool.BACK_SLASH, StringPool.SLASH))) { File gasTmp = new File(betaDataFile.getGasTmpPath()); ftpUtil.saveFile(saveGasPath, new FileInputStream(gasTmp)); @@ -4293,7 +4293,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements } if (StringUtils.isNotBlank(detFilePathName)) { //det文件的saveFile存储路径 - String saveDetPath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + detFilePathName; + String saveDetPath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + detFilePathName; if (StringUtils.isNotBlank(betaDataFile.getDetTmpPath()) && !saveDetPath.equals(betaDataFile.getDetTmpPath().replace(StringPool.BACK_SLASH, StringPool.SLASH))) { File detTmp = new File(betaDataFile.getDetTmpPath()); ftpUtil.saveFile(saveDetPath, new FileInputStream(detTmp)); @@ -4301,7 +4301,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements } if (StringUtils.isNotBlank(qcFilePathName)) { //qc文件的saveFile存储路径 - String saveQcPath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + qcFilePathName; + String saveQcPath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + qcFilePathName; if (StringUtils.isNotBlank(betaDataFile.getQcTmpPath()) && !saveQcPath.equals(betaDataFile.getQcTmpPath().replace(StringPool.BACK_SLASH, StringPool.SLASH))) { File qcTmp = new File(betaDataFile.getQcTmpPath()); ftpUtil.saveFile(saveQcPath, new FileInputStream(qcTmp)); @@ -4324,7 +4324,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements FileUtil.writeString("", logFile, "UTF-8"); } FileInputStream in = new FileInputStream(logFile); - ftpUtil.saveFile(ftpUtil.getFtpRootPath()+analyses_absolute_LogPath, in); + ftpUtil.saveFile(spectrumPathProperties.getRootPath()+analyses_absolute_LogPath, in); } catch (FileNotFoundException e) { throw new RuntimeException(e); } @@ -4336,7 +4336,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements try { FileUtil.writeString(rptContent, rptFile, "UTF-8"); FileInputStream in = new FileInputStream(rptFile); - ftpUtil.saveFile(ftpUtil.getFtpRootPath()+analyses_absolute_ReportPath+".txt", in); + ftpUtil.saveFile(spectrumPathProperties.getRootPath()+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/SpectrumFileServiceImpl.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumFileServiceImpl.java index 9f2306e9..f758432a 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumFileServiceImpl.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumFileServiceImpl.java @@ -71,7 +71,7 @@ public class SpectrumFileServiceImpl implements ISpectrumFileService { ZipInputStream zipInputStream = null; String slash = SymbolConstant.SINGLE_SLASH; //上传文件夹路径 - String filePath = ftpUtil.getFtpRootPath() + slash + spectrumPathProperties.getUploadPath() + slash + username; + String filePath = spectrumPathProperties.getRootPath() + slash + spectrumPathProperties.getUploadPath() + slash + username; //本地临时文件夹路径 String tempFilePath = System.getProperty("java.io.tmpdir") + username + slash; //文件名称集合 @@ -176,7 +176,7 @@ public class SpectrumFileServiceImpl implements ISpectrumFileService { String username = user.getUsername(); String slash = SymbolConstant.SINGLE_SLASH; String comma = SymbolConstant.COMMA; - String filePath = ftpUtil.getFtpRootPath() + spectrumPathProperties.getUploadPath() + slash + username; + String filePath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getUploadPath() + slash + username; FTPClient ftpClient = null; List fileDtos = new ArrayList<>(); Page page = new Page<>(pageNo, pageSize); From 89075bef6d4c935760ceb44f8473b97bf0cd61cb Mon Sep 17 00:00:00 2001 From: nieziyan Date: Thu, 21 Mar 2024 18:08:11 +0800 Subject: [PATCH 17/40] =?UTF-8?q?feat=EF=BC=9A1.=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E6=A8=A1=E5=9D=97FTP=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E4=B8=BA=E6=9C=AC=E5=9C=B0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=9C=8D=E5=8A=A12.=E6=97=A5=E5=BF=97=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=A2=9E=E5=8A=A0=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/comparator/FileComparator.java | 4 +- .../controller/LogManageController.java | 19 +- .../modules/service/ILogManageService.java | 12 +- .../service/impl/LogManageServiceImpl.java | 263 ++++++++---------- .../src/main/resources/application.yml | 3 +- 5 files changed, 132 insertions(+), 169 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/comparator/FileComparator.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/comparator/FileComparator.java index 28626188..4250675b 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/comparator/FileComparator.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/comparator/FileComparator.java @@ -6,8 +6,8 @@ import java.util.Comparator; public class FileComparator implements Comparator { - private String field; - private String order; + private final String field; + private final String order; public FileComparator(String field, String order) { this.field = field; diff --git a/jeecg-module-log-manage/src/main/java/org/jeecg/modules/controller/LogManageController.java b/jeecg-module-log-manage/src/main/java/org/jeecg/modules/controller/LogManageController.java index bf783238..9b2ff809 100644 --- a/jeecg-module-log-manage/src/main/java/org/jeecg/modules/controller/LogManageController.java +++ b/jeecg-module-log-manage/src/main/java/org/jeecg/modules/controller/LogManageController.java @@ -2,7 +2,9 @@ package org.jeecg.modules.controller; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.jeecg.common.api.vo.Result; import org.jeecg.common.util.FTPUtil; +import org.jeecg.modules.base.bizVo.FileVo; import org.jeecg.modules.entity.FileInfo; import org.jeecg.modules.entity.LogManage; import org.jeecg.modules.service.ILogManageService; @@ -20,31 +22,24 @@ import java.util.List; @Api(value = "日志管理", tags = "日志管理") public class LogManageController { - @Autowired - private FTPUtil ftpUtil; @Autowired private ILogManageService logManageService; @GetMapping("findFtpFolders") @ApiOperation(value = "查询日志文件夹树形结构", notes = "查询日志文件夹树形结构") public List findFtpFolders(String workPath) { - return logManageService.findFtpFolders(workPath); + return logManageService.fileTree(workPath); } - /** - * 查询目录下文件内容 - * @param path - * @return - */ @GetMapping("findFiles") @ApiOperation(value = "查询目录下文件内容", notes = "查询目录下文件内容") - public List findFiles(String path) { - return logManageService.findFiles(path); + public Result findFiles(String path, FileVo fileVo) { + return logManageService.findFiles(path, fileVo); } @PostMapping("downloadFile") @ApiOperation(value = "ftp文件下载", notes = "ftp文件下载") - public void downloadFile(String localPath, String fileName, HttpServletResponse response) { - ftpUtil.downloadFTPFile(localPath, response); + public void downloadFile(String localPath, HttpServletResponse response) { + logManageService.downloadFile(localPath, response); } } diff --git a/jeecg-module-log-manage/src/main/java/org/jeecg/modules/service/ILogManageService.java b/jeecg-module-log-manage/src/main/java/org/jeecg/modules/service/ILogManageService.java index bab2dce0..5a073fc1 100644 --- a/jeecg-module-log-manage/src/main/java/org/jeecg/modules/service/ILogManageService.java +++ b/jeecg-module-log-manage/src/main/java/org/jeecg/modules/service/ILogManageService.java @@ -1,24 +1,24 @@ package org.jeecg.modules.service; +import org.jeecg.common.api.vo.Result; +import org.jeecg.modules.base.bizVo.FileVo; import org.jeecg.modules.entity.FileInfo; import org.jeecg.modules.entity.LogManage; +import javax.servlet.http.HttpServletResponse; import java.util.List; public interface ILogManageService { /** * 查询日志文件夹树形结构 - * @param workPath - * @return */ - List findFtpFolders(String workPath); + List fileTree(String workPath); /** * 查询目录下文件内容 - * @param path - * @return */ - List findFiles(String path); + Result findFiles(String path, FileVo fileVo); + void downloadFile(String localPath, HttpServletResponse response); } diff --git a/jeecg-module-log-manage/src/main/java/org/jeecg/modules/service/impl/LogManageServiceImpl.java b/jeecg-module-log-manage/src/main/java/org/jeecg/modules/service/impl/LogManageServiceImpl.java index 3138b956..33fc1c18 100644 --- a/jeecg-module-log-manage/src/main/java/org/jeecg/modules/service/impl/LogManageServiceImpl.java +++ b/jeecg-module-log-manage/src/main/java/org/jeecg/modules/service/impl/LogManageServiceImpl.java @@ -1,192 +1,159 @@ package org.jeecg.modules.service.impl; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.ListUtil; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.ArrayUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.StringPool; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPFile; +import org.jeecg.common.api.vo.Result; +import org.jeecg.common.constant.Prompt; +import org.jeecg.common.properties.SpectrumPathProperties; import org.jeecg.common.util.DateUtils; -import org.jeecg.common.util.FTPUtil; +import org.jeecg.common.util.ExportUtil; +import org.jeecg.common.util.PageUtil; +import org.jeecg.modules.base.bizVo.FileVo; import org.jeecg.modules.entity.FileInfo; import org.jeecg.modules.entity.LogManage; import org.jeecg.modules.service.ILogManageService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import javax.servlet.http.HttpServletResponse; +import java.io.File; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.util.*; +import java.util.stream.Collectors; -@Service("logManageService") +@Slf4j +@Service public class LogManageServiceImpl implements ILogManageService { @Autowired - private FTPUtil ftpUtil; + private SpectrumPathProperties spectrumPath; @Override - public List findFtpFolders(String workPath) { + public List fileTree(String workPath) { List result = new ArrayList<>(); - FTPClient ftpClient = ftpUtil.LoginFTP(); - if(Objects.isNull(ftpClient)){ - throw new RuntimeException("ftp connection failed!"); + workPath = spectrumPath.getRootPath() + StringPool.SLASH + workPath; + List files = ListUtil.toList(FileUtil.ls(workPath)); + if (CollUtil.isEmpty(files)) return result; + int num = 1; + for (File file : files) { + LogManage logManage = new LogManage(); + logManage.setName(file.getName()); + logManage.setOrderNum(num++); + logManage.setPath(workPath + StringPool.SLASH + file.getName()); + List children = this.getChildren(logManage); + logManage.setHashChild(CollUtil.isNotEmpty(children)); + logManage.setChildren(children); + result.add(logManage); } - try { - //切换被动模式 - ftpClient.enterLocalPassiveMode(); - ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); - // 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项 - ftpClient.setControlEncoding("UTF-8"); - ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE); - //切换工作文件路径 - workPath = ftpUtil.getFtpRootPath()+StringPool.SLASH+workPath; - ftpClient.changeWorkingDirectory(workPath); - List ftpFiles = Arrays.asList(ftpClient.listDirectories()); - if (CollectionUtils.isNotEmpty(ftpFiles)){ - int num =1; - for (FTPFile ftpFile:ftpFiles) { - LogManage logManage = new LogManage(); - logManage.setName(ftpFile.getName()); - logManage.setOrderNum(num); - logManage.setParentNum(0); - logManage.setPath(workPath + StringPool.SLASH + ftpFile.getName()); - result.add(logManage); - num++; - } - } - if (CollectionUtils.isNotEmpty(result)){ - List list = new LinkedList<>(); - for (LogManage logManage:result) { - list = this.findDirectory(ftpClient, list, logManage.getOrderNum(), workPath + StringPool.SLASH + logManage.getName() , logManage.getName()); - ftpClient.changeToParentDirectory(); - } - result.addAll(list); - } - - } catch (IOException e) { - throw new RuntimeException(e); - } finally { - try { - if (ftpClient != null){ - ftpClient.disconnect(); - } - } catch (IOException e) { - throw new RuntimeException(e); - } - } - result = this.LogManageTree(result); return result; } @Override - public List findFiles(String path) { - List result = new ArrayList<>(); - FTPClient ftpClient = ftpUtil.LoginFTP(); - if (Objects.isNull(ftpClient)){ - throw new RuntimeException("ftp connection failed!"); + public Result findFiles(String path, FileVo fileVo) { + String name = fileVo.getName(); + Integer pageNo = fileVo.getPageNo(); + Integer pageSize = fileVo.getPageSize(); + Page page = new Page<>(pageNo, pageSize); + List files = CollUtil.toList(FileUtil.ls(path)); + // 文件名过滤 + if (StrUtil.isNotBlank(name)) + files = files.stream().filter(file -> StrUtil.containsIgnoreCase(file.getName(), name)) + .collect(Collectors.toList()); + page.setTotal(files.size()); + // 分页 + files = PageUtil.page(pageNo, pageSize, files); + List records = new ArrayList<>(); + for (File file : files) { + if (FileUtil.isDirectory(file)) continue; + FileInfo fileInfo = new FileInfo(); + fileInfo.setFileName(file.getName()); + fileInfo.setFilePath(path + StringPool.SLASH + file.getName()); + fileInfo.setFileSize(FileUtil.readableFileSize(file)); + fileInfo.setFileDate(DateUtil.formatDateTime(FileUtil.lastModifiedTime(file))); + records.add(fileInfo); } + page.setRecords(records); + return Result.OK(page); + } + + @Override + public void downloadFile(String localPath, HttpServletResponse response) { + OutputStream outputStream = null; + InputStream inputStream = null; try { - //切换被动模式 - ftpClient.enterLocalPassiveMode(); - ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); - // 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项 - ftpClient.setControlEncoding("UTF-8"); - ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE); - //切换工作文件路径 - ftpClient.changeWorkingDirectory(path); - List ftpFiles = Arrays.asList(ftpClient.listFiles()); - if (CollectionUtils.isNotEmpty(ftpFiles)){ - for (FTPFile ftpFile:ftpFiles) { - if (ftpFile.isFile()){ - FileInfo fileInfo = new FileInfo(); - fileInfo.setFileName(ftpFile.getName()); - fileInfo.setFilePath(path + StringPool.SLASH + ftpFile.getName()); - fileInfo.setFileSize(String.format("%.2f", Double.valueOf(Double.valueOf(ftpFile.getSize())/1024)) + "KB"); - fileInfo.setFileDate(DateUtils.formatDate(ftpFile.getTimestamp(),"yyyy-MM-dd")); - result.add(fileInfo); - } - } + // 如果是目录 则直接退出方法 + if (FileUtil.isDirectory(localPath)) return; + + // 判断是否存在此文件 + if (!FileUtil.exist(localPath)) return; + + // 获取文件名 + String fileName = FileUtil.getName(localPath); + + inputStream = FileUtil.getInputStream(localPath); + outputStream = ExportUtil.stream(response, fileName); + + // 缓冲区大小 + byte[] buffer = new byte[4096]; + int bytesRead; + + // 将文件输出流写入到输出流中 + while ((bytesRead = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); } } catch (IOException e) { - throw new RuntimeException(e); + log.error("文件{}下载失败 :{}", localPath, e.getMessage()); } finally { try { - if (ftpClient != null){ - ftpClient.disconnect(); - } + if (ObjectUtil.isNotNull(inputStream))inputStream.close(); + if (ObjectUtil.isNotNull(outputStream))outputStream.close(); } catch (IOException e) { - throw new RuntimeException(e); + e.printStackTrace(); } } - return result; } /** - * 遍历查询当前路径下的文件夹信息 - * @param ftpClient - * @param list - * @param filePath 以"/"开始和结束 - * @return + * 获取当前目录节点所有子孙节点Tree */ - public List findDirectory(FTPClient ftpClient, List list, Integer parentNum, String filePath, String fileName){ - try { - //切换被动模式 - ftpClient.enterLocalPassiveMode(); - ftpClient.changeWorkingDirectory(fileName); - List ftpFiles = Arrays.asList(ftpClient.listDirectories()); - if (CollectionUtils.isNotEmpty(ftpFiles)){ - int num = 1; - for (FTPFile file : ftpFiles) { - if (file.isDirectory()) { - LogManage logManage = new LogManage(); - logManage.setName(file.getName()); - logManage.setOrderNum(parentNum*10+num); - logManage.setParentNum(parentNum); - logManage.setPath(filePath + StringPool.SLASH + file.getName()); - list.add(logManage); - // 需要加此判断。否则,ftp默认将‘项目文件所在目录之下的目录(./)’与‘项目文件所在目录向上一级目录下的目录(../)’都纳入递归,这样下去就陷入一个死循环了。需将其过滤掉。 - if (!".".equals(file.getName()) && !"..".equals(file.getName())) { - findDirectory(ftpClient, list, parentNum*10+num, filePath + StringPool.SLASH + file.getName(), file.getName()); - ftpClient.changeToParentDirectory(); - } - num++; - } - } - } - } catch (IOException e) { - throw new RuntimeException(e); - } - return list; - } - - /** - * 将当前的文件夹转换成树形结构 - * @param logManages - * @return - */ - public List LogManageTree(List logManages){ - if (logManages == null) { - return null; - } + private List getChildren(LogManage parent){ List result = new LinkedList<>(); - Integer TOP_NODE_ID = 0; - logManages.forEach(logManage -> { - Integer pid = logManage.getParentNum(); - if (pid == null || TOP_NODE_ID.equals(pid)) { - result.add(logManage); - return; - } - for (LogManage manage : logManages) { - Integer id = manage.getOrderNum(); - if (id != null && id.equals(pid)) { - if (manage.getChildren() == null) { - manage.initChildren(); - } - logManage.setHashParent(true); - manage.getChildren().add(logManage); - manage.setHashChild(true); - return; - } - } - }); + String parentPath = parent.getPath(); + // 如果是文件 则直接返回空集合 + if (FileUtil.isFile(parentPath)) return result; + List files = ListUtil.toList(FileUtil.ls(parentPath)); + // 如果当前目录不存在子文件 则返回空集合 + if (CollUtil.isEmpty(files)) return result; + int parentOrderNum = parent.getOrderNum(); + int num = parentOrderNum * 10 + 1; + for (File file : files) { + // 过滤掉文件 只收集目录 + if (FileUtil.isFile(file)) continue; + LogManage logManage = new LogManage(); + logManage.setName(file.getName()); + logManage.setOrderNum(num++); + logManage.setHashParent(true); + logManage.setParentNum(parentOrderNum); + logManage.setPath(parentPath + StringPool.SLASH + file.getName()); + List children = getChildren(logManage); + logManage.setHashChild(CollUtil.isNotEmpty(children)); + logManage.setChildren(children); + result.add(logManage); + } return result; } - } diff --git a/jeecg-server-cloud/armd-log-manage-start/src/main/resources/application.yml b/jeecg-server-cloud/armd-log-manage-start/src/main/resources/application.yml index a6d71a86..4ba3ba15 100644 --- a/jeecg-server-cloud/armd-log-manage-start/src/main/resources/application.yml +++ b/jeecg-server-cloud/armd-log-manage-start/src/main/resources/application.yml @@ -15,4 +15,5 @@ spring: config: import: - optional:nacos:armd.yaml - - optional:nacos:armd-@profile.name@.yaml \ No newline at end of file + - optional:nacos:armd-@profile.name@.yaml + - optional:nacos:armd-analysis-@profile.name@.yaml \ No newline at end of file From 83017ee87752f1e4a0656f81697e3d37c3dd575c Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Fri, 22 Mar 2024 09:24:55 +0800 Subject: [PATCH 18/40] =?UTF-8?q?=E4=BA=BA=E5=B7=A5=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E5=88=86=E6=9E=90beta=E9=83=A8=E5=88=86=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E6=95=B0=E6=8D=AE=E6=97=B6=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E7=9A=84=E5=B1=9E=E4=BA=8E=E5=9B=A0=E4=B8=BA?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E5=B7=B2=E7=BB=8F=E5=AD=98=E5=9C=A8=E7=9A=84?= =?UTF-8?q?=E6=83=85=E5=86=B5=E5=AF=BC=E8=87=B4=E6=95=B0=E6=8D=AE=E8=A2=AB?= =?UTF-8?q?=E9=87=8D=E7=BD=AE=EF=BC=8C=E5=AD=98=E5=82=A8=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E6=97=B6=E4=B8=8B=E6=A0=87=E8=B6=8A=E7=95=8C=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/SpectrumAnalysisServiceImpl.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) 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 cf20f059..0004f64a 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 @@ -607,6 +607,13 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements } //更新缓存数据对应的缓存数据 phdFileUtil.createBgCalPara(betaDataFile, gammaCalibrationSpectrumList, betaCalibrationSpectrumList, gammaCalibrationPairsList, betaCalibrationPairsList); + //第一次加载时初始化数据库数据 + betaDataFile.setGammaCalibrationSpectrumEList(gammaCalibrationSpectrumList); + betaDataFile.setBetaCalibrationSpectrumEList(betaCalibrationSpectrumList); + betaDataFile.setRoiChannelsSpectrumList(roiChannelsSpectrumList); + betaDataFile.setRoiResultsSpectrumList(roiResultsSpectrumList); + betaDataFile.setGammaCalibrationPairsList(gammaCalibrationPairsList); + betaDataFile.setBetaCalibrationPairsList(betaCalibrationPairsList); } else { xeResultsSpectrumList = betaDataFile.getXeResultsSpectrumList(); sampleMap = loadData("sample", betaDataFile); @@ -641,12 +648,6 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements xeData.setConcErr(Double.valueOf(NumberFormatUtil.numberSixLen(String.valueOf(xeData.getConcErr())))); } } - betaDataFile.setGammaCalibrationSpectrumEList(gammaCalibrationSpectrumList); - betaDataFile.setBetaCalibrationSpectrumEList(betaCalibrationSpectrumList); - betaDataFile.setRoiChannelsSpectrumList(roiChannelsSpectrumList); - betaDataFile.setRoiResultsSpectrumList(roiResultsSpectrumList); - betaDataFile.setGammaCalibrationPairsList(gammaCalibrationPairsList); - betaDataFile.setBetaCalibrationPairsList(betaCalibrationPairsList); betaDataFile.setXeResultsSpectrumList(xeResultsSpectrumList); betaDataFile.setSaveAnalysisResult(true); resultMap.put("XeData", phdFileUtil.viewXeData(xeResultsSpectrumList)); From 2a99fabe53e0bbbe65c4050b8d7b1f9eb5a7aad2 Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Thu, 11 Apr 2024 11:03:22 +0800 Subject: [PATCH 19/40] =?UTF-8?q?=E4=BA=BA=E5=B7=A5=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E6=A8=A1=E5=9D=97Beta=E4=BF=9D=E5=AD=98=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=88=B0=E6=95=B0=E6=8D=AE=E5=BA=93=E6=97=B6=EF=BC=8C=E5=A4=84?= =?UTF-8?q?=E7=90=86=E6=95=B0=E6=8D=AE=E6=A0=B8=E7=B4=A0=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E6=97=B6=E5=A4=A7=E5=B0=8F=E5=86=99=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/service/impl/SpectrumAnalysisServiceImpl.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 0004f64a..55ea50b6 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 @@ -5784,13 +5784,13 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements xeDataList = getXeDataList(xeResultsSpectrumList); } for (GardsXeResults xeData :xeDataList) { - if (xeData.getNuclideName().equals(XeNuclideName.XE_131m)) { + if (xeData.getNuclideName().equals(XeNuclideName.XE_131m.getType())) { xeData.setNidFlag(anlyseResultIn.getXe131mFlag()); - } else if (xeData.getNuclideName().equals(XeNuclideName.XE_133)) { + } else if (xeData.getNuclideName().equals(XeNuclideName.XE_133.getType())) { xeData.setNidFlag(anlyseResultIn.getXe133Flag()); - } else if (xeData.getNuclideName().equals(XeNuclideName.XE_133m)) { + } else if (xeData.getNuclideName().equals(XeNuclideName.XE_133m.getType())) { xeData.setNidFlag(anlyseResultIn.getXe133mFlag()); - } else if (xeData.getNuclideName().equals(XeNuclideName.XE_135)) { + } else if (xeData.getNuclideName().equals(XeNuclideName.XE_135.getType())) { xeData.setNidFlag(anlyseResultIn.getXe135Flag()); } } From 3343412516b3434c2aa7decbe9b38b23d20904ad Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Thu, 11 Apr 2024 16:51:26 +0800 Subject: [PATCH 20/40] =?UTF-8?q?=E4=BA=BA=E5=B7=A5=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E6=A8=A1=E5=9D=97Gamma=E9=83=A8=E5=88=86=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E9=80=BB=E8=BE=91=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=B3=B0?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E4=BD=BF=E7=94=A8=E7=BC=93=E5=AD=98=E7=9A=84?= =?UTF-8?q?=E6=A0=B8=E7=B4=A0=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/jeecg/modules/service/impl/GammaServiceImpl.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 01a77634..64014b69 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 @@ -1302,7 +1302,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi HashMap map = new HashMap<>(); // 根据boolean 决定是否保留本次数据 如果保留则不需要操作vPeak 并重新拟合线 if (accept) { - Map nuclideLinesMap = (Map) redisUtil.get(userName+StringPool.DASH+phd.getHeader().getSystem_type()); + Map nuclideLinesMap = phd.getPhdNuclideMap();//(Map) redisUtil.get(userName+StringPool.DASH+phd.getHeader().getSystem_type()); if (flag.equalsIgnoreCase("insert")) {// 如果传递的flag标识 是 Insert则进行峰值的插入 //重新赋值index for (int k=0; k vPeak = gammaFileUtil.InitPeakTable(phd.getVPeak()); map.put("table", vPeak); //如果当前缓存的谱核素信息不包含当前核素 From 9f9466b52998856e4f250fd092b7e98e5a5e995c Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Fri, 12 Apr 2024 10:50:23 +0800 Subject: [PATCH 21/40] =?UTF-8?q?=E4=BA=BA=E5=B7=A5=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E6=A8=A1=E5=9D=97Gamma=E9=83=A8=E5=88=86=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=A0=B8=E7=B4=A0=E6=96=B9=E6=B3=95=E5=A2=9E=E5=8A=A0=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E6=A0=B8=E7=B4=A0=E5=AD=98=E5=9C=A8=E4=B8=8D=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E6=B7=BB=E5=8A=A0=E6=A0=B8=E7=B4=A0=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=20=E4=BA=BA=E5=B7=A5=E4=BA=A4=E4=BA=92=E6=A8=A1=E5=9D=97Beta?= =?UTF-8?q?=E9=83=A8=E5=88=86=E9=87=8D=E6=96=B0=E5=88=86=E6=9E=90=E5=85=A8?= =?UTF-8?q?=E9=83=A8=E8=B0=B1=E4=BF=A1=E6=81=AF=EF=BC=8C=E8=B5=8B=E5=80=BC?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/service/impl/GammaServiceImpl.java | 5 ++++- .../impl/SpectrumAnalysisServiceImpl.java | 16 ++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) 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 64014b69..05fd4687 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 @@ -1685,7 +1685,10 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi // 用户当前的核素信息新增核素名称 list_identify.add(nuclideName); // 根据要进行修改的列的数据下标 操作Vpeak数据 - phd.getVPeak().get(curRow).nuclides.add(nuclideName); + List peakNuclides = phd.getVPeak().get(curRow).nuclides; + if (peakNuclides.indexOf(nuclideName) < 0 ) { + peakNuclides.add(nuclideName); + } // 查询当前用户所关心的核素名称 Map mapNucLines = (Map) redisUtil.get(userName+StringPool.DASH+phd.getHeader().getSystem_type()); //用户当前缓存的核素信息 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 55ea50b6..95940b2f 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 @@ -3523,15 +3523,15 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements betaDataFile.setBetaFittingPara(betaDataFile.getBetaFittingParaNow()); betaDataFile.setBetaFittingParaToUi(betaDataFile.getBetaFittingParaToUiNow()); betaDataFile.setBetaNewEnergyList(betaDataFile.getBetaNewEnergyListNow()); + //将新的数组封装到各自的数组中 + betaList = betaDataFile.getBetaList(); + betaFittingPara = betaDataFile.getBetaFittingPara(); + betaFittingParaToUi = betaDataFile.getBetaFittingParaToUi(); //将当前文件用到的计算数据同步到需要计算的文件缓存 sampleBetaData.setBetaList(betaList); sampleBetaData.setBetaFittingPara(betaFittingPara); sampleBetaData.setBetaFittingParaToUi(betaFittingParaToUi); sampleBetaData.setBetaNewEnergyList(betaDataFile.getBetaNewEnergyListNow()); - //将新的数组封装到各自的数组中 - betaList = betaDataFile.getBetaList(); - betaFittingPara = betaDataFile.getBetaFittingPara(); - betaFittingParaToUi = betaDataFile.getBetaFittingParaToUi(); } List beCal = new LinkedList<>(); beCal.add(Double.valueOf(betaFittingParaToUi.get(0))); @@ -3580,15 +3580,15 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements betaDataFile.setGammaFittingPara(betaDataFile.getGammaFittingParaNow()); betaDataFile.setGammaFittingParaToUi(betaDataFile.getGammaFittingParaToUiNow()); betaDataFile.setGammaNewEnergyList(betaDataFile.getGammaNewEnergyListNow()); + //将新的数组封装到各自的数组中 + gammaList = betaDataFile.getGammaList(); + gammaFittingPara = betaDataFile.getGammaFittingPara(); + gammaFittingParaToUi = betaDataFile.getGammaFittingParaToUi(); //将当前文件用到的计算数据同步到需要计算的文件缓存 sampleBetaData.setGammaList(gammaList); sampleBetaData.setGammaFittingPara(gammaFittingPara); sampleBetaData.setGammaFittingParaToUi(gammaFittingParaToUi); sampleBetaData.setGammaNewEnergyList(betaDataFile.getGammaNewEnergyListNow()); - //将新的数组封装到各自的数组中 - gammaList = betaDataFile.getGammaList(); - gammaFittingPara = betaDataFile.getGammaFittingPara(); - gammaFittingParaToUi = betaDataFile.getGammaFittingParaToUi(); } List geCal = new LinkedList<>(); geCal.add(Double.valueOf(gammaFittingParaToUi.get(0))); From ea3cc4ea0edab46d12f293d0ae2e3455820cb2ba Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Fri, 12 Apr 2024 11:50:02 +0800 Subject: [PATCH 22/40] =?UTF-8?q?=E4=BA=BA=E5=B7=A5=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E6=A8=A1=E5=9D=97Gamma=E9=83=A8=E5=88=86=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=A0=B8=E7=B4=A0=E6=96=B9=E6=B3=95=E5=A2=9E=E5=8A=A0=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E6=A0=B8=E7=B4=A0=E5=AD=98=E5=9C=A8=E4=B8=8D=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E6=B7=BB=E5=8A=A0=E6=A0=B8=E7=B4=A0=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=20=E4=BA=BA=E5=B7=A5=E4=BA=A4=E4=BA=92=E6=A8=A1=E5=9D=97Beta?= =?UTF-8?q?=E9=83=A8=E5=88=86=E9=87=8D=E6=96=B0=E5=88=86=E6=9E=90=E5=85=A8?= =?UTF-8?q?=E9=83=A8=E8=B0=B1=E4=BF=A1=E6=81=AF=EF=BC=8C=E8=B5=8B=E5=80=BC?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/SpectrumAnalysisServiceImpl.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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 95940b2f..158eb10d 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 @@ -3505,10 +3505,12 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements List betaList = new LinkedList<>(); List betaFittingPara = new LinkedList<>(); List betaFittingParaToUi = new LinkedList<>(); + List> betaNewEnergyListNow = new LinkedList<>(); List gammaList = new LinkedList<>(); List gammaFittingPara = new LinkedList<>(); List gammaFittingParaToUi = new LinkedList<>(); - //根据sample文件名称获取当前文件的缓存信息 + List> gammaNewEnergyListNow = new LinkedList<>(); + //根据sample文件名称获取当前文件的缓存信息 BetaDataFile sampleBetaData = cache.getIfPresent(sampleFileName + "-" + userName); //存储重新分析字段的实体类 SpectrumGroup spectrum_group = new SpectrumGroup(); @@ -3527,11 +3529,12 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements betaList = betaDataFile.getBetaList(); betaFittingPara = betaDataFile.getBetaFittingPara(); betaFittingParaToUi = betaDataFile.getBetaFittingParaToUi(); + betaNewEnergyListNow = betaDataFile.getBetaNewEnergyListNow(); //将当前文件用到的计算数据同步到需要计算的文件缓存 sampleBetaData.setBetaList(betaList); sampleBetaData.setBetaFittingPara(betaFittingPara); sampleBetaData.setBetaFittingParaToUi(betaFittingParaToUi); - sampleBetaData.setBetaNewEnergyList(betaDataFile.getBetaNewEnergyListNow()); + sampleBetaData.setBetaNewEnergyList(betaNewEnergyListNow); } List beCal = new LinkedList<>(); beCal.add(Double.valueOf(betaFittingParaToUi.get(0))); @@ -3584,11 +3587,12 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements gammaList = betaDataFile.getGammaList(); gammaFittingPara = betaDataFile.getGammaFittingPara(); gammaFittingParaToUi = betaDataFile.getGammaFittingParaToUi(); + gammaNewEnergyListNow = betaDataFile.getGammaNewEnergyListNow(); //将当前文件用到的计算数据同步到需要计算的文件缓存 sampleBetaData.setGammaList(gammaList); sampleBetaData.setGammaFittingPara(gammaFittingPara); sampleBetaData.setGammaFittingParaToUi(gammaFittingParaToUi); - sampleBetaData.setGammaNewEnergyList(betaDataFile.getGammaNewEnergyListNow()); + sampleBetaData.setGammaNewEnergyList(gammaNewEnergyListNow); } List geCal = new LinkedList<>(); geCal.add(Double.valueOf(gammaFittingParaToUi.get(0))); @@ -3984,7 +3988,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements e.printStackTrace(); } result.setSuccess(true); - result.setResult(mapList.get(currentFileName)); + result.setResult(mapList); return result; } From a025eb5098a9ec107c41b53ee2bee1c64ce2e7df Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Fri, 12 Apr 2024 15:34:00 +0800 Subject: [PATCH 23/40] =?UTF-8?q?=E4=BA=BA=E5=B7=A5=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E6=A8=A1=E5=9D=97Beta=E9=83=A8=E5=88=86=E5=88=86=E6=9E=90?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E5=90=8E=E5=B0=86=E6=A0=B8=E7=B4=A0=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=88=97=E8=A1=A8=E6=B8=85=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/SpectrumAnalysisServiceImpl.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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 158eb10d..f44a2ec7 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 @@ -3480,6 +3480,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements } betaDataFile.setBProcessed(false); betaDataFile.setSaveAnalysisResult(false); + betaDataFile.setXeResultsSpectrumList(Collections.EMPTY_LIST); xeMap.put("XeData", Collections.EMPTY_LIST); xeMap.put("bProcessed", false); xeMap.put("savedAnalysisResult", false); @@ -3722,6 +3723,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements } sampleBetaData.setBProcessed(false); sampleBetaData.setSaveAnalysisResult(false); + sampleBetaData.setXeResultsSpectrumList(Collections.EMPTY_LIST); xeMap.put("XeData", Collections.EMPTY_LIST); xeMap.put("bProcessed", false); xeMap.put("savedAnalysisResult", false); @@ -3852,6 +3854,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements map.put("XeData", Collections.EMPTY_LIST); betaDataFile.setBProcessed(false); betaDataFile.setSaveAnalysisResult(false); + betaDataFile.setXeResultsSpectrumList(Collections.EMPTY_LIST); map.put("bProcessed", false); map.put("savedAnalysisResult", false); } @@ -3977,6 +3980,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements map.put("XeData", Collections.EMPTY_LIST); betaDataFile.setBProcessed(false); betaDataFile.setSaveAnalysisResult(false); + betaDataFile.setXeResultsSpectrumList(Collections.EMPTY_LIST); map.put("bProcessed", false); map.put("savedAnalysisResult", false); mapList.put(sampleFileName, map); @@ -5826,10 +5830,12 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport implements public List getXeDataList(List xeResultsSpectrumList) { List xeDataList = new LinkedList<>(); - for (GardsXeResultsSpectrum xeResultsSpectrum:xeResultsSpectrumList) { - GardsXeResults xeResults = new GardsXeResults(); - BeanUtil.copyProperties(xeResultsSpectrum, xeResults); - xeDataList.add(xeResults); + if (CollectionUtils.isNotEmpty(xeResultsSpectrumList)) { + for (GardsXeResultsSpectrum xeResultsSpectrum:xeResultsSpectrumList) { + GardsXeResults xeResults = new GardsXeResults(); + BeanUtil.copyProperties(xeResultsSpectrum, xeResults); + xeDataList.add(xeResults); + } } return xeDataList; } From a38a242e038f7ebbffa0d846d8a49ae946ec2f5b Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Thu, 18 Apr 2024 15:09:54 +0800 Subject: [PATCH 24/40] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/email/EmailServiceManager.java | 27 ++++++++++++------- .../common/properties/TaskProperties.java | 5 ++++ .../jeecg/modules/EmailParsingActuator.java | 24 +++++++++-------- .../spectrum/SpectrumParsingActuator.java | 5 +++- 4 files changed, 40 insertions(+), 21 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java index 45018aca..3b3c2f39 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java @@ -7,6 +7,7 @@ import cn.hutool.core.util.StrUtil; import com.google.common.collect.Lists; import com.sun.mail.imap.IMAPStore; import com.sun.mail.smtp.SMTPAddressFailedException; +import io.swagger.models.auth.In; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.jeecg.common.api.dto.message.MessageDTO; @@ -16,6 +17,7 @@ import org.jeecg.common.constant.SymbolConstant; import org.jeecg.common.email.emuns.MailContentType; import org.jeecg.common.exception.DownloadEmailException; import org.jeecg.common.properties.SpectrumPathProperties; +import org.jeecg.common.properties.TaskProperties; import org.jeecg.common.util.DateUtils; import org.jeecg.common.util.Md5Util; import org.jeecg.common.util.RedisUtil; @@ -47,6 +49,8 @@ public class EmailServiceManager { private SysEmail email; private SpectrumPathProperties spectrumPathProperties; + + private TaskProperties taskProperties; /** * 系统启动时间 */ @@ -80,13 +84,14 @@ public class EmailServiceManager { * @param email 邮件属性 */ public void init(SysEmail email, Integer receiveNum, String temporaryStoragePath, - Date systemStartupTime, SpectrumPathProperties pathProperties, + Date systemStartupTime, SpectrumPathProperties pathProperties,TaskProperties taskProperties, RedisUtil redisUtil){ this.email = email; this.receiveNum = receiveNum; this.temporaryStoragePath = temporaryStoragePath; this.systemStartupTime = systemStartupTime; this.spectrumPathProperties = pathProperties; + this.taskProperties = taskProperties; this.redisUtil = redisUtil; } @@ -328,8 +333,9 @@ public class EmailServiceManager { props.put("mail.smtp.host", email.getEmailServerAddress()); props.put("mail.smtp.port", email.getPort()); props.put("mail.smtp.auth", "true"); - /*props.put("mail.smtp.socketFactory.port", email.getPort()); - props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");*/ + props.put("mail.smtp.starttls.enable", "true"); + props.put("mail.smtp.socketFactory.port", email.getPort()); + props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); Session session = Session.getInstance(props); @@ -629,10 +635,10 @@ public class EmailServiceManager { if(null != store){ store.close(); } - for(String messageId : messageIds){ - String key = RedisConstant.EMAIL_MSG_ID+StringConstant.COLON+messageId; - redisUtil.del(key); - } +// for(String messageId : messageIds){ +// String key = RedisConstant.EMAIL_MSG_ID+StringConstant.COLON+messageId; +// redisUtil.del(key); +// } } catch (MessagingException e) { log.error("Email closure failed, email address is: {}, reason is: {}",email.getUsername(),e.getMessage()); e.printStackTrace(); @@ -648,10 +654,13 @@ public class EmailServiceManager { boolean exist = false; try { String key = RedisConstant.EMAIL_MSG_ID+StringConstant.COLON+messageId; - exist = redisUtil.hasKey(key); - if(exist){ + int numberKey = redisUtil.get(key) != null? (int) redisUtil.get(key):0; +// exist = redisUtil.hasKey(key); + if(numberKey > taskProperties.getForceDeletedNumber()){ + exist = true; log.info("Check: Remove Email:{},receiveTime:{}",message.getSubject(), DateUtils.formatDate(message.getReceivedDate(),"yyyy-MM-dd HH:mm:ss")); message.setFlag(Flags.Flag.DELETED,true); + redisUtil.del(key); } return exist; } catch (MessagingException e) { diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/TaskProperties.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/TaskProperties.java index 34f9e294..3a9122b7 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/TaskProperties.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/TaskProperties.java @@ -41,6 +41,11 @@ public class TaskProperties implements Serializable { */ private Integer mailThreadExecCycle; + /** + * 线程获取失败邮件次数 + */ + private Integer forceDeletedNumber; + /** * 监测需删除的邮件线程执行周期(毫秒) */ diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java index 8abbeb06..737b53c8 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java @@ -74,23 +74,23 @@ public class EmailParsingActuator extends Thread{ long start = System.currentTimeMillis(); final EmailServiceManager emailServiceManager = EmailServiceManager.getInstance(); emailServiceManager.init(this.emailProperties,this.taskProperties.getReceiveNum(),this.taskProperties.getTemporaryStoragePath(), - this.systemStartupTime, spectrumServiceQuotes.getSpectrumPathProperties(),spectrumServiceQuotes.getRedisUtil()); + this.systemStartupTime, spectrumServiceQuotes.getSpectrumPathProperties(), spectrumServiceQuotes.getTaskProperties(), spectrumServiceQuotes.getRedisUtil()); List messageIds = new ArrayList<>(); try { Message[] messages = emailServiceManager.receiveMail(); if(ArrayUtils.isNotEmpty(messages)){ log.info("EmailParsingActuator本次获取邮件数量为:{}",messages.length); //检验获取的邮件是否在之前删除失败列表中,若在直接调用邮件API删除,并且此次数组里元素也删除 -// for(int i=messages.length-1;i>=0;i--){ -// if (!messages[i].isExpunged()){ -// String messageId = ((MimeMessage) messages[i]).getMessageID(); -// final boolean exist = emailServiceManager.check(messages[i],messageId); -// messageIds.add(messageId); -// if(exist){ -// messages = ArrayUtils.remove(messages,i); -// } -// } -// } + for(int i=messages.length-1;i>=0;i--){ + if (!messages[i].isExpunged()){ + String messageId = ((MimeMessage) messages[i]).getMessageID(); + final boolean exist = emailServiceManager.check(messages[i],messageId); + messageIds.add(messageId); + if(exist){ + messages = ArrayUtils.remove(messages,i); + } + } + } log.info("EmailParsingActuator本次真实执行邮件数量为:{}",messages.length); if(messages.length > 0){ //本批次邮件号 @@ -107,6 +107,8 @@ public class EmailParsingActuator extends Thread{ } }catch (InterruptedException e) { e.printStackTrace(); + } catch (MessagingException e) { + throw new RuntimeException(e); } finally { //清除本批次邮件日志缓存 EmailLogManager.getInstance().clear(); diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java index 53f17107..22861fd2 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java @@ -96,7 +96,10 @@ public class SpectrumParsingActuator implements Runnable{ receiveDate = DateUtils.formatDate(message.getReceivedDate(),"yyyy-MM-dd HH:mm:ss"); String emlName = subject+ StringConstant.UNDER_LINE+ receiveDate; String key = RedisConstant.EMAIL_MSG_ID+StringConstant.COLON+messageId; - spectrumServiceQuotes.getRedisUtil().set(key,emlName,expiryTime); +// spectrumServiceQuotes.getRedisUtil().set(key,emlName,expiryTime); + //判断当前key的下载次数是否超过限制次数 + spectrumServiceQuotes.getRedisUtil().incr(key, 1L); + spectrumServiceQuotes.getRedisUtil().expire(key, expiryTime); //线程开始初始化时,初始本线程负责的能谱日志事件 SpectrumLogManager.mailSpectrumLogManager.offer(Thread.currentThread().getId(),null); From 85987985a11f2b58eb0f6b056f3f7916de76f752 Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Fri, 19 Apr 2024 14:14:51 +0800 Subject: [PATCH 25/40] =?UTF-8?q?=E9=82=AE=E7=AE=B1=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E9=82=AE=E4=BB=B6=E9=83=A8=E5=88=86=E5=A2=9E=E5=8A=A0=E9=94=81?= =?UTF-8?q?=E5=8F=96=E6=B6=88=E5=BC=82=E6=AD=A5=E4=B8=8B=E8=BD=BD=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=85=B3=E9=97=AD=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/email/EmailServiceManager.java | 115 ++++++++++-------- 1 file changed, 64 insertions(+), 51 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java index 3b3c2f39..25b7094a 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java @@ -66,6 +66,8 @@ public class EmailServiceManager { private RedisUtil redisUtil; + private Object downloadEmlLocal = new Object(); + @NotNull public static EmailServiceManager getInstance(){ return new EmailServiceManager(); @@ -525,44 +527,47 @@ public class EmailServiceManager { * 当计数大于10000后从0开始,服务重启后也从0开始 */ public File downloadEmailToEmlDir(@NotNull Message message,Integer emailCounter,Integer batchesCounter) throws MessagingException { - String subject = ""; - File emlFile = null; - String status = EmailLogManager.STATUS_SUCCESS; - Date receivedDate = null; - try { - //获取发件人 - final String address = ((InternetAddress) message.getFrom()[0]).getAddress(); - final String from = address.substring(0,address.indexOf(StringConstant.AT)); - //获取主题 - subject = MimeUtility.decodeText(message.getSubject()); - if(subject.indexOf(StringConstant.SLASH) != -1){ - subject = StringUtils.replace(subject,StringConstant.SLASH,""); - } - if(subject.indexOf(StringConstant.COLON) != -1){ - subject = StringUtils.replace(subject,StringConstant.COLON,""); - } - receivedDate = message.getReceivedDate(); - StringBuilder fileName = new StringBuilder(); - fileName.append(from); - fileName.append(StringConstant.UNDER_LINE); - fileName.append(subject); - fileName.append(StringConstant.UNDER_LINE); - fileName.append(DateUtils.formatDate(new Date(),"YYMMdd")); - fileName.append(StringConstant.UNDER_LINE); - fileName.append(DateUtils.formatDate(new Date(),"HHmmssSSS")); - fileName.append(StringConstant.UNDER_LINE); - fileName.append("receive"); - fileName.append(StringConstant.UNDER_LINE); - fileName.append(DateUtils.formatDate(receivedDate,"YYMMdd")); - fileName.append(StringConstant.UNDER_LINE); - fileName.append(DateUtils.formatDate(receivedDate,"HHmmssSSS")); - fileName.append(StringConstant.UNDER_LINE); - fileName.append(emailCounter); - fileName.append(SAVE_EML_SUFFIX); - final String rootPath = spectrumPathProperties.getRootPath(); - final String emlPath = spectrumPathProperties.getEmlPath(); - emlFile = new File(rootPath+emlPath+File.separator+fileName); - message.writeTo(new FileOutputStream(emlFile)); + synchronized (downloadEmlLocal) { + String subject = ""; + File emlFile = null; + String status = EmailLogManager.STATUS_SUCCESS; + Date receivedDate = null; + FileOutputStream outputStream = null; + try { + //获取发件人 + final String address = ((InternetAddress) message.getFrom()[0]).getAddress(); + final String from = address.substring(0,address.indexOf(StringConstant.AT)); + //获取主题 + subject = MimeUtility.decodeText(message.getSubject()); + if(subject.indexOf(StringConstant.SLASH) != -1){ + subject = StringUtils.replace(subject,StringConstant.SLASH,""); + } + if(subject.indexOf(StringConstant.COLON) != -1){ + subject = StringUtils.replace(subject,StringConstant.COLON,""); + } + receivedDate = message.getReceivedDate(); + StringBuilder fileName = new StringBuilder(); + fileName.append(from); + fileName.append(StringConstant.UNDER_LINE); + fileName.append(subject); + fileName.append(StringConstant.UNDER_LINE); + fileName.append(DateUtils.formatDate(new Date(),"YYMMdd")); + fileName.append(StringConstant.UNDER_LINE); + fileName.append(DateUtils.formatDate(new Date(),"HHmmssSSS")); + fileName.append(StringConstant.UNDER_LINE); + fileName.append("receive"); + fileName.append(StringConstant.UNDER_LINE); + fileName.append(DateUtils.formatDate(receivedDate,"YYMMdd")); + fileName.append(StringConstant.UNDER_LINE); + fileName.append(DateUtils.formatDate(receivedDate,"HHmmssSSS")); + fileName.append(StringConstant.UNDER_LINE); + fileName.append(emailCounter); + fileName.append(SAVE_EML_SUFFIX); + final String rootPath = spectrumPathProperties.getRootPath(); + final String emlPath = spectrumPathProperties.getEmlPath(); + emlFile = new File(rootPath+emlPath+File.separator+fileName); + outputStream = new FileOutputStream(emlFile); + message.writeTo(outputStream); // int bufferSize = 1024 * 1024; // 1M // InputStream inputStream = message.getInputStream(); @@ -580,20 +585,28 @@ public class EmailServiceManager { // // 关闭流 // bufferedInputStream.close(); // bufferedOutputStream.close(); - } catch (MessagingException | IOException e) { - // 下载邮件失败 抛出自定义邮件下载异常 - status = EmailLogManager.STATUS_ERROR; - String errorMsg = StrUtil.format("The email download failed, the subject of the email is {}, the reason is {}.", subject, e.getMessage()); - log.error(errorMsg); - throw new DownloadEmailException(errorMsg); - }catch (Exception e) { - log.error("",e); - }finally { - EmailLogEvent event = new EmailLogEvent(batchesCounter,Thread.currentThread().getId(),EmailLogManager.GS_TYPE_GET,status,EmailLogManager.GETIDEML,subject,DateUtils.formatDate(receivedDate,"yyyy-MM-dd HH:mm:ss:SSS"), - (Objects.isNull(emlFile)?" ":emlFile.getAbsolutePath())); - EmailLogManager.getInstance().offer(Thread.currentThread().getId(),event); + } catch (MessagingException | IOException e) { + // 下载邮件失败 抛出自定义邮件下载异常 + status = EmailLogManager.STATUS_ERROR; + String errorMsg = StrUtil.format("The email download failed, the subject of the email is {}, the reason is {}.", subject, e.getMessage()); + log.error(errorMsg); + throw new DownloadEmailException(errorMsg); + }catch (Exception e) { + log.error("",e); + }finally { + EmailLogEvent event = new EmailLogEvent(batchesCounter,Thread.currentThread().getId(),EmailLogManager.GS_TYPE_GET,status,EmailLogManager.GETIDEML,subject,DateUtils.formatDate(receivedDate,"yyyy-MM-dd HH:mm:ss:SSS"), + (Objects.isNull(emlFile)?" ":emlFile.getAbsolutePath())); + EmailLogManager.getInstance().offer(Thread.currentThread().getId(),event); + try { + if (Objects.nonNull(outputStream)) { + outputStream.close(); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + return emlFile; } - return emlFile; } /** From 01122e6daa5721bb2046344dcd3b8bf1953cc8d4 Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Fri, 19 Apr 2024 16:08:45 +0800 Subject: [PATCH 26/40] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jeecg/common/constant/RedisConstant.java | 6 -- .../org/jeecg/common/util/TemplateUtil.java | 55 +++++++++++++++++++ .../base/comparator/FileComparator.java | 4 +- .../jeecg/modules/base/dto/NuclideInfo.java | 8 +++ .../jeecg/modules/base/enums/Condition.java | 2 +- .../org/jeecg/modules/base/enums/DSType.java | 16 ++++-- .../spectrum/SpectrumParsingActuator.java | 4 +- 7 files changed, 80 insertions(+), 15 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/RedisConstant.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/RedisConstant.java index 8a1fa80f..2e885a34 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/RedisConstant.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/RedisConstant.java @@ -13,16 +13,10 @@ public interface RedisConstant { */ String PREFIX_SILENCE = "SilenceCycle:"; - String STREAM_ALARM = "Stream:Alarm"; - String STREAM_ANALYSIS = "Stream:Analysis"; - String GROUP_ALARM = "Group_Alarm"; - String GROUP_ANALYSIS = "Group_Analysis"; - String CONSUMER_ALARM = "Consumer_Alarm"; - String CONSUMER_ANALYSIS = "Consumer_Analysis"; String NUCLIDE_LINES_LIB = "Nuclide_Lines_Lib:"; diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/TemplateUtil.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/TemplateUtil.java index d61f655c..f3a902c0 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/TemplateUtil.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/TemplateUtil.java @@ -1,13 +1,20 @@ package org.jeecg.common.util; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.ReUtil; import cn.hutool.core.util.StrUtil; import org.jeecg.common.api.dto.message.MessageDTO; import org.jeecg.common.util.dynamic.db.FreemarkerParseFactory; import org.jeecg.modules.base.entity.postgre.SysMessageTemplate; import org.jeecg.modules.base.service.ISysMessageTemplateService; + +import java.util.ArrayList; +import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; /* * 模板工具类 @@ -37,6 +44,30 @@ public class TemplateUtil { return messageDTO; } + public static MessageDTO parse1(String code, Map data){ + MessageDTO messageDTO = new MessageDTO(); + SysMessageTemplate template = templateService.getOne(code); + // 如果没有消息模板 + if(ObjectUtil.isNull(template)) + return messageDTO; + String templateName = template.getTemplateName(); + String templateContent = template.getTemplateContent(); + messageDTO.setTitle(templateName); + if (MapUtil.isEmpty(data)) + return messageDTO; + Set keys = data.keySet(); + String pattern = "\\<([^<>]*{}[^<>]*)\\>"; + List contents = new ArrayList<>(); + for (String key : keys) { + contents.add(ReUtil.getGroup1(StrUtil.format(pattern, key), templateContent)); + } + templateContent = CollUtil.join(contents, "#"); + String content = FreemarkerParseFactory + .parseTemplateContent(templateContent, data, true); + messageDTO.setContent(content); + return messageDTO; + } + public static MessageDTO parse(String title, String code, Map data) { MessageDTO messageDTO = new MessageDTO(); SysMessageTemplate template = templateService.getOne(code); @@ -53,4 +84,28 @@ public class TemplateUtil { messageDTO.setContent(content); return messageDTO; } + + public static MessageDTO parse1(String title, String code, Map data) { + MessageDTO messageDTO = new MessageDTO(); + SysMessageTemplate template = templateService.getOne(code); + // 如果没有消息模板 + if(ObjectUtil.isNull(template)) + return messageDTO; + String templateName = template.getTemplateName(); + String templateContent = template.getTemplateContent(); + messageDTO.setTitle(StrUtil.isBlank(title) ? templateName : title); + if (MapUtil.isEmpty(data)) + return messageDTO; + Set keys = data.keySet(); + String pattern = "\\<([^<>]*{}[^<>]*)\\>"; + List contents = new ArrayList<>(); + for (String key : keys) { + contents.add(ReUtil.getGroup1(StrUtil.format(pattern, key), templateContent)); + } + templateContent = CollUtil.join(contents, "#"); + String content = FreemarkerParseFactory + .parseTemplateContent(templateContent, data, true); + messageDTO.setContent(content); + return messageDTO; + } } diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/comparator/FileComparator.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/comparator/FileComparator.java index 4250675b..28626188 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/comparator/FileComparator.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/comparator/FileComparator.java @@ -6,8 +6,8 @@ import java.util.Comparator; public class FileComparator implements Comparator { - private final String field; - private final String order; + private String field; + private String order; public FileComparator(String field, String order) { this.field = field; diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/NuclideInfo.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/NuclideInfo.java index 77a23fac..cac153bc 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/NuclideInfo.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/NuclideInfo.java @@ -3,8 +3,12 @@ package org.jeecg.modules.base.dto; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; +import org.jeecg.common.util.NumUtil; + import java.io.Serializable; import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; @Data @JsonIgnoreProperties(ignoreUnknown = true) @@ -17,4 +21,8 @@ public class NuclideInfo implements Serializable { private String datasource; private String value; + + public void keepSix(){ + this.value = NumUtil.keepStr(this.value, 6); + } } diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/enums/Condition.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/enums/Condition.java index 7ce3278a..587c8923 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/enums/Condition.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/enums/Condition.java @@ -9,7 +9,7 @@ import lombok.Getter; public enum Condition { FIRST_FOUND("1"), ABOVE_AVERAGE("2"), MEANWHILE("3"); - private String value; + private final String value; public static Condition valueOf1(String value){ for (Condition condition : Condition.values()) { diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/enums/DSType.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/enums/DSType.java index 25ac6382..de9f309d 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/enums/DSType.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/enums/DSType.java @@ -1,10 +1,14 @@ package org.jeecg.modules.base.enums; +import cn.hutool.core.util.StrUtil; +import lombok.Getter; + /** * @author nieziyan * 数据源类型 */ +@Getter public enum DSType { /* ARMD自动处理库 */ ARMDARR("1"), @@ -15,13 +19,17 @@ public enum DSType { /* IDC人工交互库 */ IDCRRR("4"); - DSType(java.lang.String type) { + DSType(String type) { this.type = type; } - private String type; + private final String type; - public String getType() { - return type; + public static String typeOf(String type){ + for (DSType dsType : DSType.values()) { + if (StrUtil.equals(type, dsType.getType())) + return dsType.name(); + } + return null; } } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java index 22861fd2..a88f07ad 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java @@ -126,6 +126,7 @@ public class SpectrumParsingActuator implements Runnable{ try { //开始解析 spectrumHandler.handler(); + spectrumServiceQuotes.getRedisUtil().del(key); } catch (Exception e) { //如果是gamma谱的分析异常 if (e instanceof AnalySpectrumException) { @@ -139,7 +140,6 @@ public class SpectrumParsingActuator implements Runnable{ throw e; } } - }else{ log.warn("This email {} parsing failed and is not listed in the Met, Alert, SOH, Sample, Detbkphd, QC, Gasbkphd spectra.",subject); } @@ -207,7 +207,7 @@ public class SpectrumParsingActuator implements Runnable{ final String finalPath = rootPath+emlErrorPath; FileOperation.moveFile(emlFile,finalPath,true); // 删除 key,防止下次线程执行删除邮件 - spectrumServiceQuotes.getRedisUtil().del(key); +// spectrumServiceQuotes.getRedisUtil().del(key); } } From b0529f0f3d093a48ef2520168e7cdfe5cefd42ea Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Fri, 19 Apr 2024 16:53:17 +0800 Subject: [PATCH 27/40] =?UTF-8?q?=E5=90=8C=E6=AD=A5mdc=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/email/EmailServiceManager.java | 2 +- .../modules/redisStream/AnalysisConsumer.java | 160 +++++++++--------- .../redisStream/RedisStreamConfig.java | 36 ++-- .../IAlarmAnalysisNuclideAvgService.java | 4 +- .../impl/AlarmAnalysisLogServiceImpl.java | 1 + .../AlarmAnalysisNuclideAvgServiceImpl.java | 13 +- .../jeecg/modules/feignclient/ManageUtil.java | 34 ++-- .../jeecg/modules/message/SendMessage.java | 50 +++--- .../jeecg/modules/quartz/job/DatabaseJob.java | 10 +- .../jeecg/modules/quartz/job/ServerJob.java | 8 +- .../modules/quartz/jobs/DatabaseJob.java | 9 +- .../jeecg/modules/quartz/jobs/EmailJob.java | 1 - .../jeecg/modules/quartz/jobs/ServerJob.java | 9 +- .../modules/quartz/jobs/TableSpaceJob.java | 3 +- 14 files changed, 189 insertions(+), 151 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java index 25b7094a..f4f8b334 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java @@ -669,7 +669,7 @@ public class EmailServiceManager { String key = RedisConstant.EMAIL_MSG_ID+StringConstant.COLON+messageId; int numberKey = redisUtil.get(key) != null? (int) redisUtil.get(key):0; // exist = redisUtil.hasKey(key); - if(numberKey > taskProperties.getForceDeletedNumber()){ + if(numberKey >= taskProperties.getForceDeletedNumber()){ exist = true; log.info("Check: Remove Email:{},receiveTime:{}",message.getSubject(), DateUtils.formatDate(message.getReceivedDate(),"yyyy-MM-dd HH:mm:ss")); message.setFlag(Flags.Flag.DELETED,true); diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/redisStream/AnalysisConsumer.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/redisStream/AnalysisConsumer.java index 1165b97e..7bf3492c 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/redisStream/AnalysisConsumer.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/redisStream/AnalysisConsumer.java @@ -5,8 +5,10 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.ListUtil; import cn.hutool.core.map.MapUtil; +import cn.hutool.core.text.StrBuilder; import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.ReUtil; import cn.hutool.core.util.StrUtil; import lombok.Data; import lombok.NoArgsConstructor; @@ -16,14 +18,15 @@ import org.jeecg.common.config.mqtoken.UserTokenContext; import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.constant.SymbolConstant; import org.jeecg.common.constant.enums.SampleType; -import org.jeecg.common.util.RedisStreamUtil; -import org.jeecg.common.util.SpringContextUtils; +import org.jeecg.common.util.*; +import org.jeecg.common.util.dynamic.db.FreemarkerParseFactory; import org.jeecg.modules.base.dto.NuclideInfo; import org.jeecg.modules.base.dto.Info; import org.jeecg.modules.base.entity.postgre.AlarmAnalysisLog; import org.jeecg.modules.base.entity.postgre.AlarmAnalysisNuclideAvg; import org.jeecg.modules.base.entity.postgre.AlarmAnalysisRule; import org.jeecg.modules.base.enums.Condition; +import org.jeecg.modules.base.enums.DSType; import org.jeecg.modules.feignclient.SystemClient; import org.jeecg.modules.service.AnalysisResultService; import org.jeecg.modules.service.IAlarmAnalysisLogService; @@ -36,9 +39,14 @@ import org.springframework.stereotype.Component; import static org.jeecg.common.constant.enums.MessageTypeEnum.*; import static org.jeecg.common.util.TokenUtils.getTempToken; +import static org.jeecg.modules.base.enums.Template.ANALYSIS_NUCLIDE; +import static org.jeecg.modules.base.enums.Template.MONITOR_EMAIL; import java.math.BigDecimal; +import java.time.LocalDate; import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.stream.Collectors; @Data @@ -71,7 +79,7 @@ public class AnalysisConsumer implements StreamListener nuclidesCross){ Set nuclideNames = nuclidesCross.keySet(); - StringBuilder alarmInfo = new StringBuilder(); - List firstDetected; - List moreThanAvg = new ArrayList<>(); String conditionStr = info.getConditions(); String betaOrGamma = info.getBetaOrGamma(); String datasource = info.getDatasource(); + String stationId = info.getStationId(); + // 获取谱文件采样日期 如果为null 则默认为LocalDate.now() + LocalDate collDate = ObjectUtil.isNull(info.getCollectionDate()) ? LocalDate.now() : + info.getCollectionDate().toLocalDate(); + List conditions = ListUtil.toList(conditionStr.split(COMMA)); + List firstDetected = new ArrayList<>(); // 首次发现 + List moreThanAvg = new ArrayList<>(); // 超浓度均值 + List meanwhile = new ArrayList<>(); // 同时出现两种及以上核素 for (String con : conditions) { Condition condition = Condition.valueOf1(con); - if (ObjectUtil.isNotNull(condition)){ - switch (condition){ - case FIRST_FOUND: // 首次发现该元素 - firstDetected = firstDetected(betaOrGamma,datasource,nuclideNames); - if (CollUtil.isNotEmpty(firstDetected)){ - String message = "First discovery of nuclides: [" + StrUtil.join(COMMA,firstDetected) + "]"; - alarmInfo.append(message); - } - break; - case ABOVE_AVERAGE: // 元素浓度高于均值 - moreThanAvg = moreThanAvg(datasource,nuclidesCross); - if (CollUtil.isNotEmpty(moreThanAvg)){ - for (NuclideInfo nuclideInfo : moreThanAvg) { - String nuclide = nuclideInfo.getNuclide(); - String threshold = nuclideInfo.getThreshold(); - String message = "Nuclide " + nuclide + "is above average: " + threshold; - alarmInfo.append(COMMA).append(message); - } - } - break; - case MEANWHILE: // 同时出现两种及以上核素 - if (nuclideNames.size() >= 2){ - String message = "Simultaneously detecting nuclides: [" + StrUtil.join(COMMA,nuclideNames) + "]"; - alarmInfo.append(COMMA).append(message); - } - break; - default: - break; - } + if (ObjectUtil.isNull(condition)) continue; + switch (condition){ + case FIRST_FOUND: // 首次发现该元素 + firstDetected = firstDetected(betaOrGamma, datasource, nuclideNames); + break; + case ABOVE_AVERAGE: // 元素浓度高于均值 + moreThanAvg = moreThanAvg(datasource, stationId, collDate, nuclidesCross); + break; + case MEANWHILE: // 同时出现两种及以上核素 + if (CollUtil.isNotEmpty(nuclideNames) && nuclideNames.size() >= 2) + meanwhile.addAll(nuclideNames); + break; + default: + break; } } - if (StrUtil.isNotBlank(alarmInfo.toString())){ - // 保存报警日志 - AlarmAnalysisLog logInfo = new AlarmAnalysisLog(); - BeanUtil.copyProperties(info,logInfo); - SampleType sampleType = SampleType.typeOf(betaOrGamma); - if (ObjectUtil.isNotNull(sampleType)) - logInfo.setSampleType(sampleType.getValue()); - if (alarmInfo.toString().startsWith(COMMA)) - alarmInfo = new StringBuilder(StrUtil.sub(alarmInfo.toString(), 1, alarmInfo.length())); - logInfo.setAlarmInfo(alarmInfo.toString()); - if (CollUtil.isNotEmpty(moreThanAvg)) - logInfo.setNuclideInfoList(moreThanAvg); - logService.saveLog(logInfo); - // 发送报警信息 - String groupId = info.getGroupId(); - MessageDTO messageDTO = new MessageDTO(); - messageDTO.setTitle("Nuclied Warn Info").setContent(alarmInfo.toString()); - if (StrUtil.isNotBlank(groupId)) { - systemClient.sendMessage(messageDTO, groupId, ALL.getValue()); - systemClient.pushMessageToSingle(messageDTO, groupId); - } + // 构建预警信息 + DataTool dataTool = DataTool.getInstance(); + if (CollUtil.isNotEmpty(firstDetected)) + dataTool.put("firstDetected", CollUtil.join(firstDetected, StrUtil.COMMA + StrUtil.SPACE)); + if (CollUtil.isNotEmpty(moreThanAvg)){ + String above = moreThanAvg.stream() + .map(item -> item.getNuclide() + "(" + item.getValue() + ")" + " > " + item.getThreshold()) + .collect(Collectors.joining(StrUtil.COMMA + StrUtil.SPACE)); + dataTool.put("moreThanAvg", above); } + if (CollUtil.isNotEmpty(meanwhile)) + dataTool.put("meanwhile", CollUtil.join(meanwhile, StrUtil.COMMA + StrUtil.SPACE)); + // 如果报警数据为空 则不需要发送报警信息和生成报警日志 + if (MapUtil.isEmpty(dataTool.get())) return; + MessageDTO messageDTO = TemplateUtil.parse1(ANALYSIS_NUCLIDE.getCode(), dataTool.get()); + // 保存报警日志 + AlarmAnalysisLog logInfo = new AlarmAnalysisLog(); + BeanUtil.copyProperties(info, logInfo); + SampleType sampleType = SampleType.typeOf(betaOrGamma); + if (ObjectUtil.isNotNull(sampleType)) + logInfo.setSampleType(sampleType.getValue()); + logInfo.setAlarmInfo(messageDTO.getContent()); + if (CollUtil.isNotEmpty(moreThanAvg)) + logInfo.setNuclideInfoList(moreThanAvg); + logService.saveLog(logInfo); + // 发送报警信息 + String groupId = info.getGroupId(); + systemClient.sendMessage(messageDTO, groupId, ALL.getValue()); + systemClient.pushMessageToSingle(messageDTO, groupId); } /** @@ -222,12 +228,12 @@ public class AnalysisConsumer implements StreamListener moreThanAvg(String dataSourceType, - Map nuclidesCross){ + private List moreThanAvg(String dataSourceType, String stationId, + LocalDate collDate, Map nuclidesCross){ List nuclideInfos = new ArrayList<>(); Set nuclideNames = nuclidesCross.keySet(); Map nuclideAvgs = nuclideAvgService - .list(nuclideNames, dataSourceType).stream() + .list(nuclideNames, dataSourceType, stationId, collDate).stream() .collect(Collectors.toMap(AlarmAnalysisNuclideAvg::getNuclide, AlarmAnalysisNuclideAvg::getVal)); for (Map.Entry nuclide : nuclidesCross.entrySet()) { @@ -246,41 +252,27 @@ public class AnalysisConsumer implements StreamListener readA1 = StreamMessageListenerContainer + /* 1.需要手动确认消费消息 */ + // 1.1 使用 register 方式 + StreamMessageListenerContainer.ConsumerStreamReadRequest readRequest = StreamMessageListenerContainer .StreamReadRequest - .builder(StreamOffset.create(warnKey, ReadOffset.lastConsumed())) - .consumer(Consumer.from(groupWarnA, consumerWarnA1)) + .builder(StreamOffset.create(analysisKey, ReadOffset.lastConsumed())) + .consumer(Consumer.from(analysisGroup, analysisConsumer)) + // 手动确认消费了消息 默认为自动确认消息 .autoAcknowledge(false) - // 如果消费者发生了异常,是否禁止消费者消费 + // 如果消费者发生了异常 不禁止消费者消费 默认为禁止 .cancelOnError(throwable -> false) .build(); - ConsumeA1 consumeA1 = new ConsumeA1(groupWarnA, consumerWarnA1); - streamMessageListenerContainer.register(readA1, consumeA1);*/ - AnalysisConsumer analysis = new AnalysisConsumer(analysisGroup,analysisConsumer); + AnalysisConsumer analysis = new AnalysisConsumer(analysisGroup, analysisConsumer); + streamMessageListenerContainer.register(readRequest, analysis); + // 1.2 使用 receive 方式 + /*AnalysisConsumer analysis = new AnalysisConsumer(analysisGroup, analysisConsumer); streamMessageListenerContainer.receive(Consumer.from(analysisGroup, analysisConsumer), - StreamOffset.create(analysisKey, ReadOffset.lastConsumed()), analysis); - // 创建消费组A中的消费者A2,自动ACK - /* ConsumeA2 consumeA2 = new ConsumeA2(consumerWarnA2); - streamMessageListenerContainer.receiveAutoAck(Consumer.from(groupWarnA, consumerWarnA2), - StreamOffset.create(warnKey, ReadOffset.lastConsumed()), consumeA2);*/ + StreamOffset.create(analysisKey, ReadOffset.lastConsumed()), analysis);*/ + /* 2.自动确认消费消息 */ + // 2.1 使用 receive 方式 + /*AnalysisConsumer analysis = new AnalysisConsumer(analysisGroup,analysisConsumer); + streamMessageListenerContainer.receiveAutoAck(Consumer.from(analysisGroup, analysisConsumer), + StreamOffset.create(analysisKey, ReadOffset.lastConsumed()), analysis);*/ return streamMessageListenerContainer; } } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/IAlarmAnalysisNuclideAvgService.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/IAlarmAnalysisNuclideAvgService.java index 70199b04..a9afd7a9 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/IAlarmAnalysisNuclideAvgService.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/IAlarmAnalysisNuclideAvgService.java @@ -6,12 +6,14 @@ import org.jeecg.modules.base.entity.postgre.AlarmAnalysisNuclideAvg; import com.baomidou.mybatisplus.extension.service.IService; import org.jeecg.modules.base.bizVo.NuclideAvgVo; +import java.time.LocalDate; import java.util.List; import java.util.Set; public interface IAlarmAnalysisNuclideAvgService extends IService { - List list(Set nuclideNames,String dataSourceType); + List list(Set nuclideNames, String dataSourceType, + String stationId, LocalDate collDate); Page findPage(NuclideAvgVo nuclideAvgVo); } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmAnalysisLogServiceImpl.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmAnalysisLogServiceImpl.java index af13f2a3..47f34b54 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmAnalysisLogServiceImpl.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmAnalysisLogServiceImpl.java @@ -75,6 +75,7 @@ public class AlarmAnalysisLogServiceImpl extends ServiceImpl nuclideInfos = mapper.readValue(nuclideInfo, new TypeReference>() {}); + nuclideInfos.forEach(NuclideInfo::keepSix); logDto.setNuclideList(nuclideInfos); } catch (JsonProcessingException e) { log.error("NuclideInfo解析异常: {}", e.getMessage()); diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmAnalysisNuclideAvgServiceImpl.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmAnalysisNuclideAvgServiceImpl.java index 2659c56d..71d23713 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmAnalysisNuclideAvgServiceImpl.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmAnalysisNuclideAvgServiceImpl.java @@ -15,6 +15,7 @@ import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.List; import java.util.Map; import java.util.Set; @@ -27,13 +28,15 @@ public class AlarmAnalysisNuclideAvgServiceImpl extends ServiceImpl list(Set nuclideNames,String dataSourceType) { - LocalDate dayAgo = LocalDate.now().minusDays(1); + public List list(Set nuclideNames, String dataSourceType, + String stationId, LocalDate collDate) { + LocalDate dayAgo = collDate.minusDays(1); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(AlarmAnalysisNuclideAvg::getDataSourceType,dataSourceType); - wrapper.eq(AlarmAnalysisNuclideAvg::getCaclDate,dayAgo); + wrapper.eq(AlarmAnalysisNuclideAvg::getStationId, stationId); + wrapper.eq(AlarmAnalysisNuclideAvg::getDataSourceType, dataSourceType); + wrapper.eq(AlarmAnalysisNuclideAvg::getCaclDate, dayAgo); wrapper.in(AlarmAnalysisNuclideAvg::getNuclide,nuclideNames); - return list(wrapper); + return this.list(wrapper); } @Override diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/feignclient/ManageUtil.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/feignclient/ManageUtil.java index 17b8ed10..7f68d45c 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/feignclient/ManageUtil.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/feignclient/ManageUtil.java @@ -1,5 +1,6 @@ package org.jeecg.modules.feignclient; +import lombok.extern.slf4j.Slf4j; import org.jeecg.common.api.vo.Result; import org.jeecg.common.constant.RedisConstant; import org.jeecg.common.system.util.JwtUtil; @@ -9,6 +10,7 @@ import org.jeecg.modules.base.dto.LoginResult; import org.jeecg.modules.base.dto.LoginVo; import org.springframework.core.env.Environment; +@Slf4j public class ManageUtil { private static RedisUtil redisUtil; @@ -31,20 +33,28 @@ public class ManageUtil { * 登录运管系统 获取Token * */ public static String getToken(){ - if (redisUtil.hasKey(RedisConstant.MANAGE_TOKEN)) - return (String) redisUtil.get(RedisConstant.MANAGE_TOKEN); - - LoginVo loginVo = new LoginVo(username, password); - Result loginRes = monitorSystem.login(loginVo); - String token = loginRes.getResult().getToken(); - redisUtil.set(RedisConstant.MANAGE_TOKEN, token, JwtUtil.EXPIRE_TIME / 1000 - 10); - return token; + String token = null; + try { + if (redisUtil.hasKey(RedisConstant.MANAGE_TOKEN)) + return (String) redisUtil.get(RedisConstant.MANAGE_TOKEN); + LoginVo loginVo = new LoginVo(username, password); + Result loginRes = monitorSystem.login(loginVo); + token = loginRes.getResult().getToken(); + redisUtil.set(RedisConstant.MANAGE_TOKEN, token, JwtUtil.EXPIRE_TIME / 1000 - 10); + return token; + }catch (RuntimeException e){ + return token; + } } public static void refreshToken(){ - LoginVo loginVo = new LoginVo(username, password); - Result loginRes = monitorSystem.login(loginVo); - String token = loginRes.getResult().getToken(); - redisUtil.set(RedisConstant.MANAGE_TOKEN, token, JwtUtil.EXPIRE_TIME / 1000 - 10); + try { + LoginVo loginVo = new LoginVo(username, password); + Result loginRes = monitorSystem.login(loginVo); + String token = loginRes.getResult().getToken(); + redisUtil.set(RedisConstant.MANAGE_TOKEN, token, JwtUtil.EXPIRE_TIME / 1000 - 10); + }catch (RuntimeException e){ + log.error("运管系统登录异常, Token刷新失败: {}", e.getMessage()); + } } } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/SendMessage.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/SendMessage.java index 698fa427..d3e39205 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/SendMessage.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/SendMessage.java @@ -4,6 +4,7 @@ import cn.hutool.core.collection.ListUtil; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import lombok.extern.slf4j.Slf4j; import org.jeecg.common.api.dto.message.MessageDTO; import org.jeecg.common.constant.SymbolConstant; import org.jeecg.common.constant.enums.MessageTypeEnum; @@ -27,6 +28,7 @@ import static org.jeecg.common.constant.enums.MessageTypeEnum.*; * @author nieziyan * @date 2023-06-21 */ +@Slf4j @Component public class SendMessage { @@ -50,6 +52,7 @@ public class SendMessage { */ public void send(MessageDTO messageDTO, String groupId, String notific){ Map contact = getContact(groupId); + if (MapUtil.isEmpty(contact)) return; if (StrUtil.isBlank(notific)) return; List ways = ListUtil.toList(StrUtil.split(notific, COMMA)); if (ways.contains(ALL.getValue())) @@ -96,26 +99,33 @@ public class SendMessage { * @param groupId */ private Map getContact(String groupId){ - List userIds = abnormalAlarmClient.userIds(groupId).getResult(); - // 查询用户信息 - List sysUsers = sysUserService.listByIds(userIds); - // 用户名 - String usernameList = sysUsers.stream().map(SysUser::getUsername).filter(StrUtil::isNotBlank) - .collect(Collectors.joining(COMMA)); - // 邮箱 - String emailList = sysUsers.stream().map(SysUser::getEmail).filter(StrUtil::isNotBlank) - .collect(Collectors.joining(COMMA)); - // 用户名-邮箱Map - Map userEmail = sysUsers.stream() - .collect(Collectors.toMap(SysUser::getUsername, SysUser::getEmail)); - // 手机号码 - String phoneList = sysUsers.stream().map(SysUser::getPhone).filter(StrUtil::isNotBlank) - .collect(Collectors.joining(COMMA)); Map result = new HashMap<>(); - result.put(SYSTEM, usernameList); - result.put(EMAIL, emailList); - result.put(SMS, phoneList); - result.putAll(userEmail); - return result; + try { + List userIds = abnormalAlarmClient.userIds(groupId).getResult(); + // 查询用户信息 + List sysUsers = sysUserService.listByIds(userIds); + // 用户名 + String usernameList = sysUsers.stream().map(SysUser::getUsername).filter(StrUtil::isNotBlank) + .collect(Collectors.joining(COMMA)); + // 邮箱 + String emailList = sysUsers.stream().map(SysUser::getEmail).filter(StrUtil::isNotBlank) + .collect(Collectors.joining(COMMA)); + // 用户名-邮箱Map + Map userEmail = sysUsers.stream() + .filter(item -> StrUtil.isNotBlank(item.getEmail())) + .collect(Collectors.toMap(SysUser::getUsername, SysUser::getEmail)); + // 手机号码 + String phoneList = sysUsers.stream().map(SysUser::getPhone).filter(StrUtil::isNotBlank) + .collect(Collectors.joining(COMMA)); + + result.put(SYSTEM, usernameList); + result.put(EMAIL, emailList); + result.put(SMS, phoneList); + result.putAll(userEmail); + return result; + }catch (Exception e) { + log.error("获取收件人联系信息异常: {}", e.getMessage()); + return result; + } } } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/DatabaseJob.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/DatabaseJob.java index 9753f15a..5da9a25a 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/DatabaseJob.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/DatabaseJob.java @@ -6,6 +6,7 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import feign.FeignException; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.api.dto.message.MessageDTO; @@ -102,6 +103,10 @@ public class DatabaseJob extends Monitor implements Job{ }*/ // 向运管查询监控项数据 String token = ManageUtil.getToken(); + if(StrUtil.isBlank(token)){ + log.error("运管系统登录异常, Token获取失败"); + continue; + } Result result = getMonitorSystem().itemBack(itemId, itemType, start, end, token); ItemHistory itemHistory = result.getResult(); if (ObjectUtil.isNull(itemHistory)){ @@ -141,9 +146,12 @@ public class DatabaseJob extends Monitor implements Job{ getSendMessage().send(messageDTO, groupId, notific); getPushAppUtil().pushToSingle(messageDTO, groupId); } + } catch (FeignException.Unauthorized e){ + ManageUtil.refreshToken(); + log.warn("向运管系统查询ItemHistory信息异常: Token失效,已刷新Token"); } catch (JsonProcessingException e) { log.error("Database预警规则: {}解析失败,失败原因: {}", operator, e.getMessage()); - }catch (Exception e){ + } catch (Exception e){ log.error("Database监控异常: {}", e.getMessage()); } } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/ServerJob.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/ServerJob.java index 5d5c8a89..2c544195 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/ServerJob.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/ServerJob.java @@ -85,6 +85,10 @@ public class ServerJob extends Monitor implements Job { // 向运管查询监控项数据 String token = ManageUtil.getToken(); + if(StrUtil.isBlank(token)){ + log.error("运管系统登录异常, Token获取失败"); + continue; + } Result result = getMonitorSystem().itemBack(itemId, itemType, start, end, token); ItemHistory itemHistory = result.getResult(); if (ObjectUtil.isNull(itemHistory)){ @@ -124,12 +128,12 @@ public class ServerJob extends Monitor implements Job { getSendMessage().send(messageDTO, groupId, notific); getPushAppUtil().pushToSingle(messageDTO, groupId); } - }catch (FeignException.Unauthorized e){ + } catch (FeignException.Unauthorized e){ ManageUtil.refreshToken(); log.warn("向运管系统查询ItemHistory信息异常: Token失效,已刷新Token"); } catch (JsonProcessingException e) { log.error("Server预警规则: {}解析失败,失败原因: {}", operator, e.getMessage()); - }catch (Exception e){ + } catch (Exception e){ log.error("Server监控异常: {}", e.getMessage()); } } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/jobs/DatabaseJob.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/jobs/DatabaseJob.java index 2c8d7036..5f76098c 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/jobs/DatabaseJob.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/jobs/DatabaseJob.java @@ -6,6 +6,7 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import feign.FeignException; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.api.dto.message.MessageDTO; @@ -86,6 +87,10 @@ public class DatabaseJob extends Monitor { // 向运管查询监控项数据 String token = ManageUtil.getToken(); + if(StrUtil.isBlank(token)){ + log.error("运管系统登录异常, Token获取失败"); + continue; + } Result result = getMonitorSystem().itemBack(itemId, itemType, start, end, token); ItemHistory itemHistory = result.getResult(); if (ObjectUtil.isNull(itemHistory)){ @@ -125,11 +130,13 @@ public class DatabaseJob extends Monitor { getSendMessage().send(messageDTO, groupId, notific); getPushAppUtil().pushToSingle(messageDTO, groupId); } + }catch (FeignException.Unauthorized e){ + ManageUtil.refreshToken(); + log.warn("向运管系统查询ItemHistory信息异常: Token失效,已刷新Token"); } catch (JsonProcessingException e) { log.error("Database预警规则: {}解析失败,失败原因: {}", operator, e.getMessage()); }catch (Exception e){ log.error("Database监控异常: {}", e.getMessage()); - e.printStackTrace(); } } destroy(); diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/jobs/EmailJob.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/jobs/EmailJob.java index 2259aa4c..ef51c991 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/jobs/EmailJob.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/jobs/EmailJob.java @@ -111,7 +111,6 @@ public class EmailJob extends Monitor{ log.error("Email预警规则: {}解析失败,失败原因: {}", operator, e.getMessage()); }catch (Exception e){ log.error("Email监控异常: {}", e.getMessage()); - e.printStackTrace(); } } destroy(); diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/jobs/ServerJob.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/jobs/ServerJob.java index 9bfe5b86..42182ba7 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/jobs/ServerJob.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/jobs/ServerJob.java @@ -84,6 +84,10 @@ public class ServerJob extends Monitor{ // 向运管查询监控项数据 String token = ManageUtil.getToken(); + if(StrUtil.isBlank(token)){ + log.error("运管系统登录异常, Token获取失败"); + continue; + } Result result = getMonitorSystem().itemBack(itemId, itemType, start, end, token); ItemHistory itemHistory = result.getResult(); if (ObjectUtil.isNull(itemHistory)){ @@ -123,14 +127,13 @@ public class ServerJob extends Monitor{ getSendMessage().send(messageDTO, groupId, notific); getPushAppUtil().pushToSingle(messageDTO, groupId); } - }catch (FeignException.Unauthorized e){ + } catch (FeignException.Unauthorized e){ ManageUtil.refreshToken(); log.warn("向运管系统查询ItemHistory信息异常: Token失效,已刷新Token"); } catch (JsonProcessingException e) { log.error("Server预警规则: {}解析失败,失败原因: {}", operator, e.getMessage()); - }catch (Exception e){ + } catch (Exception e){ log.error("Server监控异常: {}", e.getMessage()); - e.printStackTrace(); } } destroy(); diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/jobs/TableSpaceJob.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/jobs/TableSpaceJob.java index 441b344f..9705aceb 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/jobs/TableSpaceJob.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/jobs/TableSpaceJob.java @@ -44,7 +44,7 @@ public class TableSpaceJob extends Monitor { /** * 解析Oracle 表空间预警规则 **/ - @Scheduled(cron = "${task.period-space:0 0 */1 * * ?}") + @Scheduled(cron = "${task.period-space:0 0/1 * * * ?}") public void execute(){ init(); @@ -124,7 +124,6 @@ public class TableSpaceJob extends Monitor { log.error("Database-TableSpace预警规则: {}解析失败,失败原因: {}", operator, e.getMessage()); }catch (Exception e){ log.error("Database-TableSpace监控异常: {}", e.getMessage()); - e.printStackTrace(); } } destroy(); From df16ed12a81254a32a1d4fccecb5c628c88d324f Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Wed, 24 Apr 2024 16:45:49 +0800 Subject: [PATCH 28/40] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=88=B0=E6=96=B0=E7=9A=84=E5=88=86=E6=94=AF?= =?UTF-8?q?onlyDownload=EF=BC=8C=E6=B5=8B=E8=AF=95=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E9=82=AE=E4=BB=B6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/email/EmailServiceManager.java | 144 +++++++++--------- .../org/jeecg/modules/AutoProcessManager.java | 6 +- .../jeecg/modules/EmailParsingActuator.java | 14 +- .../spectrum/SpectrumParsingActuator.java | 82 +++++----- .../jeecg/JeecgAutoProcessApplication.java | 4 +- 5 files changed, 131 insertions(+), 119 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java index f4f8b334..c5a1be52 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java @@ -66,6 +66,8 @@ public class EmailServiceManager { private RedisUtil redisUtil; + private Object receive; + private Object downloadEmlLocal = new Object(); @NotNull @@ -87,7 +89,7 @@ public class EmailServiceManager { */ public void init(SysEmail email, Integer receiveNum, String temporaryStoragePath, Date systemStartupTime, SpectrumPathProperties pathProperties,TaskProperties taskProperties, - RedisUtil redisUtil){ + RedisUtil redisUtil, Object receive){ this.email = email; this.receiveNum = receiveNum; this.temporaryStoragePath = temporaryStoragePath; @@ -95,6 +97,7 @@ public class EmailServiceManager { this.spectrumPathProperties = pathProperties; this.taskProperties = taskProperties; this.redisUtil = redisUtil; + this.receive = receive; } /** @@ -125,77 +128,79 @@ public class EmailServiceManager { * 接收邮件 */ public Message[] receiveMail() { - String status = EmailLogManager.STATUS_SUCCESS; - try{ - //配置邮件服务属性 - Properties properties = new Properties(); - properties.put("mail.store.protocol", "imap"); - properties.put("mail.imap.host", email.getEmailServerAddress()); - properties.put("mail.imap.port",email.getPort()); - if (email.getIsQiye() == 1) { - properties.put("mail.imap.ssl.enable", "true"); - } else { - properties.put("mail.imap.ssl.enable", "false"); - } - - HashMap IAM = new HashMap(); - //带上IMAP ID信息,由key和value组成,例如name,version,vendor,support-email等。 - IAM.put("name","myname"); - IAM.put("version","1.0.0"); - IAM.put("vendor","myclient"); - IAM.put("support-email","testmail@test.com"); - - //获取邮件回话 - final Session session = Session.getDefaultInstance(properties); - - - //获取smtp协议的存储对象 - store = (IMAPStore) session.getStore(); - //连接 - store.connect(email.getUsername(),email.getPassword()); - // 解决163普通邮箱无法建立连接问题 - store.id(IAM); - //获取收件箱 - folder = store.getFolder("INBOX");//INBOX - folder.open(Folder.READ_WRITE); - //如果邮箱邮件数量 > 0 - final int messageCount = folder.getMessageCount(); - if(messageCount > 0){ - Message[] messages = null; - if(Objects.isNull(this.systemStartupTime)){ - int finalNum = messageCount > this.receiveNum?this.receiveNum:messageCount; - //邮箱邮件下标是从1开始的 - return folder.getMessages(1,finalNum); + synchronized (receive) { + String status = EmailLogManager.STATUS_SUCCESS; + try{ + //配置邮件服务属性 + Properties properties = new Properties(); + properties.put("mail.store.protocol", "imap"); + properties.put("mail.imap.host", email.getEmailServerAddress()); + properties.put("mail.imap.port",email.getPort()); + if (email.getIsQiye() == 1) { + properties.put("mail.imap.ssl.enable", "true"); + } else { + properties.put("mail.imap.ssl.enable", "false"); } - SearchTerm searchTerm = new ReceivedDateTerm(ComparisonTerm.GE,this.systemStartupTime); - messages = folder.search(searchTerm); - Arrays.sort(messages, (o1, o2) -> { - try { - return o1.getReceivedDate().compareTo(o2.getReceivedDate()); - } catch (MessagingException e) { - e.printStackTrace(); + + HashMap IAM = new HashMap(); + //带上IMAP ID信息,由key和value组成,例如name,version,vendor,support-email等。 + IAM.put("name","myname"); + IAM.put("version","1.0.0"); + IAM.put("vendor","myclient"); + IAM.put("support-email","testmail@test.com"); + + //获取邮件回话 + final Session session = Session.getDefaultInstance(properties); + + + //获取smtp协议的存储对象 + store = (IMAPStore) session.getStore(); + //连接 + store.connect(email.getUsername(),email.getPassword()); + // 解决163普通邮箱无法建立连接问题 + store.id(IAM); + //获取收件箱 + folder = store.getFolder("INBOX");//INBOX + folder.open(Folder.READ_WRITE); + //如果邮箱邮件数量 > 0 + final int messageCount = folder.getMessageCount(); + if(messageCount > 0){ + Message[] messages = null; + if(Objects.isNull(this.systemStartupTime)){ + int finalNum = messageCount > this.receiveNum?this.receiveNum:messageCount; + //邮箱邮件下标是从1开始的 + return folder.getMessages(1,finalNum); + } + SearchTerm searchTerm = new ReceivedDateTerm(ComparisonTerm.GE,this.systemStartupTime); + messages = folder.search(searchTerm); + Arrays.sort(messages, (o1, o2) -> { + try { + return o1.getReceivedDate().compareTo(o2.getReceivedDate()); + } catch (MessagingException e) { + e.printStackTrace(); + } + return 0; + }); + if(this.receiveNum >= messages.length){ + return messages; + }else{ + return Arrays.copyOfRange(messages,0,this.receiveNum-1); } - return 0; - }); - if(this.receiveNum >= messages.length){ - return messages; - }else{ - return Arrays.copyOfRange(messages,0,this.receiveNum-1); } + }catch (MessagingException e){ + status = EmailLogManager.STATUS_ERROR; + log.error("Email connection is abnormal, account is {}, service is {},the reason is {}.",email.getName(),email.getEmailServerAddress(),e.getMessage()); + e.printStackTrace(); + return null; + }finally { + EmailLogEvent connectEvent = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,email,status,EmailLogManager.CONNECT); + EmailLogManager.getInstance().setConnectLogEvent(connectEvent); + //GetAllId C++原业务是把远程邮箱邮件同步到C++,本次java编写没有这一步,所以和Connect绑定,若Connect成功则GetAllId成功 + EmailLogEvent getAllEvent = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,status,EmailLogManager.GETALLID); + EmailLogManager.getInstance().setGetAllIdLogEvent(getAllEvent); } - }catch (MessagingException e){ - status = EmailLogManager.STATUS_ERROR; - log.error("Email connection is abnormal, account is {}, service is {},the reason is {}.",email.getName(),email.getEmailServerAddress(),e.getMessage()); - e.printStackTrace(); return null; - }finally { - EmailLogEvent connectEvent = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,email,status,EmailLogManager.CONNECT); - EmailLogManager.getInstance().setConnectLogEvent(connectEvent); - //GetAllId C++原业务是把远程邮箱邮件同步到C++,本次java编写没有这一步,所以和Connect绑定,若Connect成功则GetAllId成功 - EmailLogEvent getAllEvent = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,status,EmailLogManager.GETALLID); - EmailLogManager.getInstance().setGetAllIdLogEvent(getAllEvent); } - return null; } /* @@ -532,7 +537,7 @@ public class EmailServiceManager { File emlFile = null; String status = EmailLogManager.STATUS_SUCCESS; Date receivedDate = null; - FileOutputStream outputStream = null; + BufferedOutputStream outputStream = null; try { //获取发件人 final String address = ((InternetAddress) message.getFrom()[0]).getAddress(); @@ -566,9 +571,10 @@ public class EmailServiceManager { final String rootPath = spectrumPathProperties.getRootPath(); final String emlPath = spectrumPathProperties.getEmlPath(); emlFile = new File(rootPath+emlPath+File.separator+fileName); - outputStream = new FileOutputStream(emlFile); + outputStream = new BufferedOutputStream(new FileOutputStream(emlFile)); message.writeTo(outputStream); - + // 刷新缓冲区内容存入内存 + outputStream.flush(); // int bufferSize = 1024 * 1024; // 1M // InputStream inputStream = message.getInputStream(); // BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream, bufferSize); diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java index 3a0880dd..9fea1237 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java @@ -37,6 +37,10 @@ public class AutoProcessManager{ * 邮件Map数据锁 */ private final Object lock = new Object(); + /** + * 邮箱接收邮件锁 + */ + private final Object receive = new Object(); /** * 以邮件Id为key,邮件信息为value */ @@ -99,7 +103,7 @@ public class AutoProcessManager{ boolean testFlag = emailServiceManager.testConnectEmailServer(); if(testFlag){ EmailParsingActuator emailParsingActuator = new EmailParsingActuator(); - emailParsingActuator.init(next,spectrumServiceQuotes,emailCounter,systemStartupTime); + emailParsingActuator.init(next,spectrumServiceQuotes,emailCounter,systemStartupTime, receive); emailParsingActuator.setName(next.getUsername()+"-email-monitor"); emailParsingActuator.start(); //把邮件监测执行线程加入管理队列 diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java index 737b53c8..fd8ae856 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java @@ -36,18 +36,20 @@ public class EmailParsingActuator extends Thread{ private SpectrumServiceQuotes spectrumServiceQuotes; private EmailCounter emailCounter; private Date systemStartupTime; + private Object receive; @Setter @Getter private boolean isStop; @Setter @Getter private Date stopTime; public void init(EmailProperties emailProperties,SpectrumServiceQuotes spectrumServiceQuotes, - EmailCounter emailCounter,Date systemStartupTime){ + EmailCounter emailCounter,Date systemStartupTime, Object receive){ this.emailProperties = emailProperties; this.spectrumServiceQuotes = spectrumServiceQuotes; this.taskProperties = spectrumServiceQuotes.getTaskProperties(); this.emailCounter = emailCounter; this.systemStartupTime = systemStartupTime; + this.receive = receive; //获取机器可用核心数 int systemCores = spectrumServiceQuotes.getMaximumPoolSizeProperties().getAuto(); @@ -74,7 +76,7 @@ public class EmailParsingActuator extends Thread{ long start = System.currentTimeMillis(); final EmailServiceManager emailServiceManager = EmailServiceManager.getInstance(); emailServiceManager.init(this.emailProperties,this.taskProperties.getReceiveNum(),this.taskProperties.getTemporaryStoragePath(), - this.systemStartupTime, spectrumServiceQuotes.getSpectrumPathProperties(), spectrumServiceQuotes.getTaskProperties(), spectrumServiceQuotes.getRedisUtil()); + this.systemStartupTime, spectrumServiceQuotes.getSpectrumPathProperties(), spectrumServiceQuotes.getTaskProperties(), spectrumServiceQuotes.getRedisUtil(), receive); List messageIds = new ArrayList<>(); try { Message[] messages = emailServiceManager.receiveMail(); @@ -84,11 +86,11 @@ public class EmailParsingActuator extends Thread{ for(int i=messages.length-1;i>=0;i--){ if (!messages[i].isExpunged()){ String messageId = ((MimeMessage) messages[i]).getMessageID(); - final boolean exist = emailServiceManager.check(messages[i],messageId); +// final boolean exist = emailServiceManager.check(messages[i],messageId); messageIds.add(messageId); - if(exist){ - messages = ArrayUtils.remove(messages,i); - } +// if(exist){ +// messages = ArrayUtils.remove(messages,i); +// } } } log.info("EmailParsingActuator本次真实执行邮件数量为:{}",messages.length); diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java index a88f07ad..aa9ba619 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java @@ -110,47 +110,47 @@ public class SpectrumParsingActuator implements Runnable{ //保存邮件日志到PG数据库 this.spectrumServiceQuotes.getMailLogService().create(message,emailProperties); - //获取邮件内容 - StringBuilder mailContent = new StringBuilder(); - if(Objects.nonNull(emlFile) && emlFile.length() > 0){ - mailContent.append(FileUtil.readUtf8String(emlFile)); - } - - //判断是否是IMS2.0协议文件 - // 如果邮件内容校验成功 将文件保存到eml目录 并删除邮件对象 - if(checkMailContent(mailContent,subject)){ - AbstractSpectrumHandler spectrumHandler = new SamplephdSpectrum(); - spectrumHandler.init(mailContent.toString(),emlFile.getName(),spectrumServiceQuotes,new StringBuilder(),SpectrumSource.FORM_EMAIL_SERVICE.getSourceType(),batchesCounter); - final boolean matchResult = spectrumHandler.saveEmailToLocal(); - if(matchResult){ - try { - //开始解析 - spectrumHandler.handler(); - spectrumServiceQuotes.getRedisUtil().del(key); - } catch (Exception e) { - //如果是gamma谱的分析异常 - if (e instanceof AnalySpectrumException) { - // 如果邮件内容校验失败(邮件内容不完整) 将错误邮件从eml移动到emlError - if (Objects.nonNull(emlFile) && emlFile.exists()){ - moveEmail(emlFile, key); - } - //删除邮件 - emailServiceManager.removeMail(message,batchesCounter); - } else { - throw e; - } - } - }else{ - log.warn("This email {} parsing failed and is not listed in the Met, Alert, SOH, Sample, Detbkphd, QC, Gasbkphd spectra.",subject); - } - emailServiceManager.removeMail(message,batchesCounter); - }else { - // 如果邮件内容校验失败(邮件内容不完整) 将错误邮件从eml移动到emlError - if (Objects.nonNull(emlFile) && emlFile.exists()){ - moveEmail(emlFile, key); - throw new DownloadEmailException("邮件移走后手动抛出DownloadEmailException"); - } - } +// //获取邮件内容 +// StringBuilder mailContent = new StringBuilder(); +// if(Objects.nonNull(emlFile) && emlFile.length() > 0){ +// mailContent.append(FileUtil.readUtf8String(emlFile)); +// } +// +// //判断是否是IMS2.0协议文件 +// // 如果邮件内容校验成功 将文件保存到eml目录 并删除邮件对象 +// if(checkMailContent(mailContent,subject)){ +// AbstractSpectrumHandler spectrumHandler = new SamplephdSpectrum(); +// spectrumHandler.init(mailContent.toString(),emlFile.getName(),spectrumServiceQuotes,new StringBuilder(),SpectrumSource.FORM_EMAIL_SERVICE.getSourceType(),batchesCounter); +// final boolean matchResult = spectrumHandler.saveEmailToLocal(); +// if(matchResult){ +// try { +// //开始解析 +// spectrumHandler.handler(); +// spectrumServiceQuotes.getRedisUtil().del(key); +// } catch (Exception e) { +// //如果是gamma谱的分析异常 +// if (e instanceof AnalySpectrumException) { +// // 如果邮件内容校验失败(邮件内容不完整) 将错误邮件从eml移动到emlError +// if (Objects.nonNull(emlFile) && emlFile.exists()){ +// moveEmail(emlFile, key); +// } +// //删除邮件 +// emailServiceManager.removeMail(message,batchesCounter); +// } else { +// throw e; +// } +// } +// }else{ +// log.warn("This email {} parsing failed and is not listed in the Met, Alert, SOH, Sample, Detbkphd, QC, Gasbkphd spectra.",subject); +// } +// emailServiceManager.removeMail(message,batchesCounter); +// }else { +// // 如果邮件内容校验失败(邮件内容不完整) 将错误邮件从eml移动到emlError +// if (Objects.nonNull(emlFile) && emlFile.exists()){ +// moveEmail(emlFile, key); +// throw new DownloadEmailException("邮件移走后手动抛出DownloadEmailException"); +// } +// } } catch (Exception e) { // 如果不是下载导致的失败 并且 下载成功,则删除下载的邮件对象 if(!(e instanceof DownloadEmailException) && downloadFlag){ diff --git a/jeecg-server-cloud/armd-auto-process-start/src/main/java/org/jeecg/JeecgAutoProcessApplication.java b/jeecg-server-cloud/armd-auto-process-start/src/main/java/org/jeecg/JeecgAutoProcessApplication.java index 853ac505..f989894e 100644 --- a/jeecg-server-cloud/armd-auto-process-start/src/main/java/org/jeecg/JeecgAutoProcessApplication.java +++ b/jeecg-server-cloud/armd-auto-process-start/src/main/java/org/jeecg/JeecgAutoProcessApplication.java @@ -93,8 +93,8 @@ public class JeecgAutoProcessApplication extends SpringBootServletInitializer im //校验存储目录是否存在,不存在则创建,存在无操作 checkStorageDirectory(); autoProcessManager.start(systemStartupTime); - undealHandleManager.start(); - fileSourceHandleManager.start(); +// undealHandleManager.start(); +// fileSourceHandleManager.start(); // 删除过期的文件 delFileManager.start(); //统计报告执行线程 From 7da8eeb921aee1b9763a309294a4ce3dc06ec57d Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Thu, 25 Apr 2024 14:26:00 +0800 Subject: [PATCH 29/40] =?UTF-8?q?onlyDownload=E6=94=BE=E5=BC=80=E5=90=8E?= =?UTF-8?q?=E7=BB=AD=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jeecg/modules/EmailParsingActuator.java | 8 +- .../spectrum/SpectrumParsingActuator.java | 82 +++++++++---------- .../jeecg/JeecgAutoProcessApplication.java | 4 +- 3 files changed, 47 insertions(+), 47 deletions(-) diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java index fd8ae856..11c83e4c 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java @@ -86,11 +86,11 @@ public class EmailParsingActuator extends Thread{ for(int i=messages.length-1;i>=0;i--){ if (!messages[i].isExpunged()){ String messageId = ((MimeMessage) messages[i]).getMessageID(); -// final boolean exist = emailServiceManager.check(messages[i],messageId); + final boolean exist = emailServiceManager.check(messages[i],messageId); messageIds.add(messageId); -// if(exist){ -// messages = ArrayUtils.remove(messages,i); -// } + if(exist){ + messages = ArrayUtils.remove(messages,i); + } } } log.info("EmailParsingActuator本次真实执行邮件数量为:{}",messages.length); diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java index aa9ba619..a88f07ad 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java @@ -110,47 +110,47 @@ public class SpectrumParsingActuator implements Runnable{ //保存邮件日志到PG数据库 this.spectrumServiceQuotes.getMailLogService().create(message,emailProperties); -// //获取邮件内容 -// StringBuilder mailContent = new StringBuilder(); -// if(Objects.nonNull(emlFile) && emlFile.length() > 0){ -// mailContent.append(FileUtil.readUtf8String(emlFile)); -// } -// -// //判断是否是IMS2.0协议文件 -// // 如果邮件内容校验成功 将文件保存到eml目录 并删除邮件对象 -// if(checkMailContent(mailContent,subject)){ -// AbstractSpectrumHandler spectrumHandler = new SamplephdSpectrum(); -// spectrumHandler.init(mailContent.toString(),emlFile.getName(),spectrumServiceQuotes,new StringBuilder(),SpectrumSource.FORM_EMAIL_SERVICE.getSourceType(),batchesCounter); -// final boolean matchResult = spectrumHandler.saveEmailToLocal(); -// if(matchResult){ -// try { -// //开始解析 -// spectrumHandler.handler(); -// spectrumServiceQuotes.getRedisUtil().del(key); -// } catch (Exception e) { -// //如果是gamma谱的分析异常 -// if (e instanceof AnalySpectrumException) { -// // 如果邮件内容校验失败(邮件内容不完整) 将错误邮件从eml移动到emlError -// if (Objects.nonNull(emlFile) && emlFile.exists()){ -// moveEmail(emlFile, key); -// } -// //删除邮件 -// emailServiceManager.removeMail(message,batchesCounter); -// } else { -// throw e; -// } -// } -// }else{ -// log.warn("This email {} parsing failed and is not listed in the Met, Alert, SOH, Sample, Detbkphd, QC, Gasbkphd spectra.",subject); -// } -// emailServiceManager.removeMail(message,batchesCounter); -// }else { -// // 如果邮件内容校验失败(邮件内容不完整) 将错误邮件从eml移动到emlError -// if (Objects.nonNull(emlFile) && emlFile.exists()){ -// moveEmail(emlFile, key); -// throw new DownloadEmailException("邮件移走后手动抛出DownloadEmailException"); -// } -// } + //获取邮件内容 + StringBuilder mailContent = new StringBuilder(); + if(Objects.nonNull(emlFile) && emlFile.length() > 0){ + mailContent.append(FileUtil.readUtf8String(emlFile)); + } + + //判断是否是IMS2.0协议文件 + // 如果邮件内容校验成功 将文件保存到eml目录 并删除邮件对象 + if(checkMailContent(mailContent,subject)){ + AbstractSpectrumHandler spectrumHandler = new SamplephdSpectrum(); + spectrumHandler.init(mailContent.toString(),emlFile.getName(),spectrumServiceQuotes,new StringBuilder(),SpectrumSource.FORM_EMAIL_SERVICE.getSourceType(),batchesCounter); + final boolean matchResult = spectrumHandler.saveEmailToLocal(); + if(matchResult){ + try { + //开始解析 + spectrumHandler.handler(); + spectrumServiceQuotes.getRedisUtil().del(key); + } catch (Exception e) { + //如果是gamma谱的分析异常 + if (e instanceof AnalySpectrumException) { + // 如果邮件内容校验失败(邮件内容不完整) 将错误邮件从eml移动到emlError + if (Objects.nonNull(emlFile) && emlFile.exists()){ + moveEmail(emlFile, key); + } + //删除邮件 + emailServiceManager.removeMail(message,batchesCounter); + } else { + throw e; + } + } + }else{ + log.warn("This email {} parsing failed and is not listed in the Met, Alert, SOH, Sample, Detbkphd, QC, Gasbkphd spectra.",subject); + } + emailServiceManager.removeMail(message,batchesCounter); + }else { + // 如果邮件内容校验失败(邮件内容不完整) 将错误邮件从eml移动到emlError + if (Objects.nonNull(emlFile) && emlFile.exists()){ + moveEmail(emlFile, key); + throw new DownloadEmailException("邮件移走后手动抛出DownloadEmailException"); + } + } } catch (Exception e) { // 如果不是下载导致的失败 并且 下载成功,则删除下载的邮件对象 if(!(e instanceof DownloadEmailException) && downloadFlag){ diff --git a/jeecg-server-cloud/armd-auto-process-start/src/main/java/org/jeecg/JeecgAutoProcessApplication.java b/jeecg-server-cloud/armd-auto-process-start/src/main/java/org/jeecg/JeecgAutoProcessApplication.java index f989894e..853ac505 100644 --- a/jeecg-server-cloud/armd-auto-process-start/src/main/java/org/jeecg/JeecgAutoProcessApplication.java +++ b/jeecg-server-cloud/armd-auto-process-start/src/main/java/org/jeecg/JeecgAutoProcessApplication.java @@ -93,8 +93,8 @@ public class JeecgAutoProcessApplication extends SpringBootServletInitializer im //校验存储目录是否存在,不存在则创建,存在无操作 checkStorageDirectory(); autoProcessManager.start(systemStartupTime); -// undealHandleManager.start(); -// fileSourceHandleManager.start(); + undealHandleManager.start(); + fileSourceHandleManager.start(); // 删除过期的文件 delFileManager.start(); //统计报告执行线程 From f62158a721519750a02474f510f1fcc6457a2ade Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Fri, 26 Apr 2024 10:31:59 +0800 Subject: [PATCH 30/40] =?UTF-8?q?onlyDownload=E4=BF=AE=E6=94=B9=E9=82=AE?= =?UTF-8?q?=E7=AE=B1=E5=A4=84=E7=90=86=E7=A8=8B=E5=BA=8F=E9=A2=91=E7=B9=81?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BA=BF=E7=A8=8B=E9=97=AE=E9=A2=98=20onlyDo?= =?UTF-8?q?wnload=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E9=83=A8=E5=88=86=E9=95=BF=E6=9C=9F=E5=A0=B5=E5=A1=9E=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/email/EmailServiceManager.java | 183 +++++++++--------- .../org/jeecg/modules/AutoProcessManager.java | 16 +- .../jeecg/modules/EmailParsingActuator.java | 19 +- .../spectrum/SpectrumParsingActuator.java | 82 ++++---- 4 files changed, 148 insertions(+), 152 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java index c5a1be52..e63fbd5d 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java @@ -9,6 +9,8 @@ import com.sun.mail.imap.IMAPStore; import com.sun.mail.smtp.SMTPAddressFailedException; import io.swagger.models.auth.In; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.io.Charsets; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.jeecg.common.api.dto.message.MessageDTO; import org.jeecg.common.constant.RedisConstant; @@ -66,8 +68,6 @@ public class EmailServiceManager { private RedisUtil redisUtil; - private Object receive; - private Object downloadEmlLocal = new Object(); @NotNull @@ -89,7 +89,7 @@ public class EmailServiceManager { */ public void init(SysEmail email, Integer receiveNum, String temporaryStoragePath, Date systemStartupTime, SpectrumPathProperties pathProperties,TaskProperties taskProperties, - RedisUtil redisUtil, Object receive){ + RedisUtil redisUtil){ this.email = email; this.receiveNum = receiveNum; this.temporaryStoragePath = temporaryStoragePath; @@ -97,7 +97,6 @@ public class EmailServiceManager { this.spectrumPathProperties = pathProperties; this.taskProperties = taskProperties; this.redisUtil = redisUtil; - this.receive = receive; } /** @@ -128,79 +127,77 @@ public class EmailServiceManager { * 接收邮件 */ public Message[] receiveMail() { - synchronized (receive) { - String status = EmailLogManager.STATUS_SUCCESS; - try{ - //配置邮件服务属性 - Properties properties = new Properties(); - properties.put("mail.store.protocol", "imap"); - properties.put("mail.imap.host", email.getEmailServerAddress()); - properties.put("mail.imap.port",email.getPort()); - if (email.getIsQiye() == 1) { - properties.put("mail.imap.ssl.enable", "true"); - } else { - properties.put("mail.imap.ssl.enable", "false"); - } - - HashMap IAM = new HashMap(); - //带上IMAP ID信息,由key和value组成,例如name,version,vendor,support-email等。 - IAM.put("name","myname"); - IAM.put("version","1.0.0"); - IAM.put("vendor","myclient"); - IAM.put("support-email","testmail@test.com"); - - //获取邮件回话 - final Session session = Session.getDefaultInstance(properties); - - - //获取smtp协议的存储对象 - store = (IMAPStore) session.getStore(); - //连接 - store.connect(email.getUsername(),email.getPassword()); - // 解决163普通邮箱无法建立连接问题 - store.id(IAM); - //获取收件箱 - folder = store.getFolder("INBOX");//INBOX - folder.open(Folder.READ_WRITE); - //如果邮箱邮件数量 > 0 - final int messageCount = folder.getMessageCount(); - if(messageCount > 0){ - Message[] messages = null; - if(Objects.isNull(this.systemStartupTime)){ - int finalNum = messageCount > this.receiveNum?this.receiveNum:messageCount; - //邮箱邮件下标是从1开始的 - return folder.getMessages(1,finalNum); - } - SearchTerm searchTerm = new ReceivedDateTerm(ComparisonTerm.GE,this.systemStartupTime); - messages = folder.search(searchTerm); - Arrays.sort(messages, (o1, o2) -> { - try { - return o1.getReceivedDate().compareTo(o2.getReceivedDate()); - } catch (MessagingException e) { - e.printStackTrace(); - } - return 0; - }); - if(this.receiveNum >= messages.length){ - return messages; - }else{ - return Arrays.copyOfRange(messages,0,this.receiveNum-1); - } - } - }catch (MessagingException e){ - status = EmailLogManager.STATUS_ERROR; - log.error("Email connection is abnormal, account is {}, service is {},the reason is {}.",email.getName(),email.getEmailServerAddress(),e.getMessage()); - e.printStackTrace(); - return null; - }finally { - EmailLogEvent connectEvent = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,email,status,EmailLogManager.CONNECT); - EmailLogManager.getInstance().setConnectLogEvent(connectEvent); - //GetAllId C++原业务是把远程邮箱邮件同步到C++,本次java编写没有这一步,所以和Connect绑定,若Connect成功则GetAllId成功 - EmailLogEvent getAllEvent = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,status,EmailLogManager.GETALLID); - EmailLogManager.getInstance().setGetAllIdLogEvent(getAllEvent); + String status = EmailLogManager.STATUS_SUCCESS; + try{ + //配置邮件服务属性 + Properties properties = new Properties(); + properties.put("mail.store.protocol", "imap"); + properties.put("mail.imap.host", email.getEmailServerAddress()); + properties.put("mail.imap.port",email.getPort()); + if (email.getIsQiye() == 1) { + properties.put("mail.imap.ssl.enable", "true"); + } else { + properties.put("mail.imap.ssl.enable", "false"); } + + HashMap IAM = new HashMap(); + //带上IMAP ID信息,由key和value组成,例如name,version,vendor,support-email等。 + IAM.put("name","myname"); + IAM.put("version","1.0.0"); + IAM.put("vendor","myclient"); + IAM.put("support-email","testmail@test.com"); + + //获取邮件回话 + final Session session = Session.getDefaultInstance(properties); + + + //获取smtp协议的存储对象 + store = (IMAPStore) session.getStore(); + //连接 + store.connect(email.getUsername(),email.getPassword()); + // 解决163普通邮箱无法建立连接问题 + store.id(IAM); + //获取收件箱 + folder = store.getFolder("INBOX");//INBOX + folder.open(Folder.READ_WRITE); + //如果邮箱邮件数量 > 0 + final int messageCount = folder.getMessageCount(); + if(messageCount > 0){ + Message[] messages = null; + if(Objects.isNull(this.systemStartupTime)){ + int finalNum = messageCount > this.receiveNum?this.receiveNum:messageCount; + //邮箱邮件下标是从1开始的 + return folder.getMessages(1,finalNum); + } + SearchTerm searchTerm = new ReceivedDateTerm(ComparisonTerm.GE,this.systemStartupTime); + messages = folder.search(searchTerm); + Arrays.sort(messages, (o1, o2) -> { + try { + return o1.getReceivedDate().compareTo(o2.getReceivedDate()); + } catch (MessagingException e) { + e.printStackTrace(); + } + return 0; + }); + if(this.receiveNum >= messages.length){ + return messages; + }else{ + return Arrays.copyOfRange(messages,0,this.receiveNum-1); + } + } + }catch (MessagingException e){ + status = EmailLogManager.STATUS_ERROR; + log.error("Email connection is abnormal, account is {}, service is {},the reason is {}.",email.getName(),email.getEmailServerAddress(),e.getMessage()); + e.printStackTrace(); return null; + }finally { + EmailLogEvent connectEvent = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,email,status,EmailLogManager.CONNECT); + EmailLogManager.getInstance().setConnectLogEvent(connectEvent); + //GetAllId C++原业务是把远程邮箱邮件同步到C++,本次java编写没有这一步,所以和Connect绑定,若Connect成功则GetAllId成功 + EmailLogEvent getAllEvent = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,status,EmailLogManager.GETALLID); + EmailLogManager.getInstance().setGetAllIdLogEvent(getAllEvent); } + return null; } /* @@ -537,6 +534,7 @@ public class EmailServiceManager { File emlFile = null; String status = EmailLogManager.STATUS_SUCCESS; Date receivedDate = null; + InputStream inputStream = null; BufferedOutputStream outputStream = null; try { //获取发件人 @@ -571,26 +569,19 @@ public class EmailServiceManager { final String rootPath = spectrumPathProperties.getRootPath(); final String emlPath = spectrumPathProperties.getEmlPath(); emlFile = new File(rootPath+emlPath+File.separator+fileName); - outputStream = new BufferedOutputStream(new FileOutputStream(emlFile)); - message.writeTo(outputStream); - // 刷新缓冲区内容存入内存 - outputStream.flush(); -// int bufferSize = 1024 * 1024; // 1M -// InputStream inputStream = message.getInputStream(); -// BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream, bufferSize); -// // 或者使用 BufferedOutputStream -// OutputStream outputStream = new FileOutputStream(emlFile); -// BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream, bufferSize); -// // 从邮件的输入流读取内容,并写入到本地文件 -// byte[] buffer = new byte[bufferSize]; -// int bytesRead; -// while ((bytesRead = bufferedInputStream.read(buffer)) != -1) { -// bufferedOutputStream.write(buffer, 0, bytesRead); -// } -// -// // 关闭流 -// bufferedInputStream.close(); -// bufferedOutputStream.close(); +// outputStream = new FileOutputStream(emlFile); +// message.writeTo(outputStream); + + int bufferSize = 1024 * 1024; // 1M + inputStream = message.getInputStream(); + outputStream = new BufferedOutputStream(new FileOutputStream(emlFile), bufferSize); + // 从邮件的输入流读取内容,并写入到本地文件 + byte[] buffer = new byte[bufferSize]; + int bytesRead; + while ((bytesRead = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); + } + } catch (MessagingException | IOException e) { // 下载邮件失败 抛出自定义邮件下载异常 status = EmailLogManager.STATUS_ERROR; @@ -604,7 +595,11 @@ public class EmailServiceManager { (Objects.isNull(emlFile)?" ":emlFile.getAbsolutePath())); EmailLogManager.getInstance().offer(Thread.currentThread().getId(),event); try { + if (Objects.nonNull(inputStream)) { + inputStream.close(); + } if (Objects.nonNull(outputStream)) { + outputStream.flush(); outputStream.close(); } } catch (IOException e) { diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java index 9fea1237..c9593dbf 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java @@ -37,10 +37,6 @@ public class AutoProcessManager{ * 邮件Map数据锁 */ private final Object lock = new Object(); - /** - * 邮箱接收邮件锁 - */ - private final Object receive = new Object(); /** * 以邮件Id为key,邮件信息为value */ @@ -103,7 +99,7 @@ public class AutoProcessManager{ boolean testFlag = emailServiceManager.testConnectEmailServer(); if(testFlag){ EmailParsingActuator emailParsingActuator = new EmailParsingActuator(); - emailParsingActuator.init(next,spectrumServiceQuotes,emailCounter,systemStartupTime, receive); + emailParsingActuator.init(next,spectrumServiceQuotes,emailCounter,systemStartupTime); emailParsingActuator.setName(next.getUsername()+"-email-monitor"); emailParsingActuator.start(); //把邮件监测执行线程加入管理队列 @@ -237,9 +233,15 @@ public class AutoProcessManager{ if(databaseEmail.getEnabled().equals(SysMailEnableType.ENABLE.getMailEnableType())){ final boolean testFlag = testConnectEmailServer(databaseEmail); if(testFlag){ - databaseEmail.setNewEmailFlag(true); + if (emailExecThreadMap.containsKey(databaseEmail.getId())) { + EmailParsingActuator actuator = emailExecThreadMap.get(databaseEmail.getId()); + actuator.setStop(false); + log.info("{}邮箱重新加入监测队列",databaseEmail.getUsername()); + } else { + databaseEmail.setNewEmailFlag(true); + log.info("{}邮箱加入监测队列,设置新增标记",databaseEmail.getUsername()); + } emailMap.put(databaseEmail.getId(),databaseEmail); - log.info("{}邮箱加入监测队列,设置新增标记",databaseEmail.getUsername()); } } } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java index 11c83e4c..6097a1c3 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java @@ -36,20 +36,18 @@ public class EmailParsingActuator extends Thread{ private SpectrumServiceQuotes spectrumServiceQuotes; private EmailCounter emailCounter; private Date systemStartupTime; - private Object receive; @Setter @Getter private boolean isStop; @Setter @Getter private Date stopTime; public void init(EmailProperties emailProperties,SpectrumServiceQuotes spectrumServiceQuotes, - EmailCounter emailCounter,Date systemStartupTime, Object receive){ + EmailCounter emailCounter,Date systemStartupTime){ this.emailProperties = emailProperties; this.spectrumServiceQuotes = spectrumServiceQuotes; this.taskProperties = spectrumServiceQuotes.getTaskProperties(); this.emailCounter = emailCounter; this.systemStartupTime = systemStartupTime; - this.receive = receive; //获取机器可用核心数 int systemCores = spectrumServiceQuotes.getMaximumPoolSizeProperties().getAuto(); @@ -76,21 +74,21 @@ public class EmailParsingActuator extends Thread{ long start = System.currentTimeMillis(); final EmailServiceManager emailServiceManager = EmailServiceManager.getInstance(); emailServiceManager.init(this.emailProperties,this.taskProperties.getReceiveNum(),this.taskProperties.getTemporaryStoragePath(), - this.systemStartupTime, spectrumServiceQuotes.getSpectrumPathProperties(), spectrumServiceQuotes.getTaskProperties(), spectrumServiceQuotes.getRedisUtil(), receive); + this.systemStartupTime, spectrumServiceQuotes.getSpectrumPathProperties(), spectrumServiceQuotes.getTaskProperties(), spectrumServiceQuotes.getRedisUtil()); List messageIds = new ArrayList<>(); try { Message[] messages = emailServiceManager.receiveMail(); if(ArrayUtils.isNotEmpty(messages)){ - log.info("EmailParsingActuator本次获取邮件数量为:{}",messages.length); + log.info("EmailParsingActuator本次{}获取邮件数量为:{}", Thread.currentThread().getName(), messages.length); //检验获取的邮件是否在之前删除失败列表中,若在直接调用邮件API删除,并且此次数组里元素也删除 for(int i=messages.length-1;i>=0;i--){ if (!messages[i].isExpunged()){ String messageId = ((MimeMessage) messages[i]).getMessageID(); - final boolean exist = emailServiceManager.check(messages[i],messageId); +// final boolean exist = emailServiceManager.check(messages[i],messageId); messageIds.add(messageId); - if(exist){ - messages = ArrayUtils.remove(messages,i); - } +// if(exist){ +// messages = ArrayUtils.remove(messages,i); +// } } } log.info("EmailParsingActuator本次真实执行邮件数量为:{}",messages.length); @@ -107,11 +105,12 @@ public class EmailParsingActuator extends Thread{ taskLatch.await(); } } - }catch (InterruptedException e) { + } catch (InterruptedException e) { e.printStackTrace(); } catch (MessagingException e) { throw new RuntimeException(e); } finally { + log.info(Thread.currentThread().getName() +"执行完毕!!!!"); //清除本批次邮件日志缓存 EmailLogManager.getInstance().clear(); //保存本批次所有能谱日志 diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java index a88f07ad..aa9ba619 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java @@ -110,47 +110,47 @@ public class SpectrumParsingActuator implements Runnable{ //保存邮件日志到PG数据库 this.spectrumServiceQuotes.getMailLogService().create(message,emailProperties); - //获取邮件内容 - StringBuilder mailContent = new StringBuilder(); - if(Objects.nonNull(emlFile) && emlFile.length() > 0){ - mailContent.append(FileUtil.readUtf8String(emlFile)); - } - - //判断是否是IMS2.0协议文件 - // 如果邮件内容校验成功 将文件保存到eml目录 并删除邮件对象 - if(checkMailContent(mailContent,subject)){ - AbstractSpectrumHandler spectrumHandler = new SamplephdSpectrum(); - spectrumHandler.init(mailContent.toString(),emlFile.getName(),spectrumServiceQuotes,new StringBuilder(),SpectrumSource.FORM_EMAIL_SERVICE.getSourceType(),batchesCounter); - final boolean matchResult = spectrumHandler.saveEmailToLocal(); - if(matchResult){ - try { - //开始解析 - spectrumHandler.handler(); - spectrumServiceQuotes.getRedisUtil().del(key); - } catch (Exception e) { - //如果是gamma谱的分析异常 - if (e instanceof AnalySpectrumException) { - // 如果邮件内容校验失败(邮件内容不完整) 将错误邮件从eml移动到emlError - if (Objects.nonNull(emlFile) && emlFile.exists()){ - moveEmail(emlFile, key); - } - //删除邮件 - emailServiceManager.removeMail(message,batchesCounter); - } else { - throw e; - } - } - }else{ - log.warn("This email {} parsing failed and is not listed in the Met, Alert, SOH, Sample, Detbkphd, QC, Gasbkphd spectra.",subject); - } - emailServiceManager.removeMail(message,batchesCounter); - }else { - // 如果邮件内容校验失败(邮件内容不完整) 将错误邮件从eml移动到emlError - if (Objects.nonNull(emlFile) && emlFile.exists()){ - moveEmail(emlFile, key); - throw new DownloadEmailException("邮件移走后手动抛出DownloadEmailException"); - } - } +// //获取邮件内容 +// StringBuilder mailContent = new StringBuilder(); +// if(Objects.nonNull(emlFile) && emlFile.length() > 0){ +// mailContent.append(FileUtil.readUtf8String(emlFile)); +// } +// +// //判断是否是IMS2.0协议文件 +// // 如果邮件内容校验成功 将文件保存到eml目录 并删除邮件对象 +// if(checkMailContent(mailContent,subject)){ +// AbstractSpectrumHandler spectrumHandler = new SamplephdSpectrum(); +// spectrumHandler.init(mailContent.toString(),emlFile.getName(),spectrumServiceQuotes,new StringBuilder(),SpectrumSource.FORM_EMAIL_SERVICE.getSourceType(),batchesCounter); +// final boolean matchResult = spectrumHandler.saveEmailToLocal(); +// if(matchResult){ +// try { +// //开始解析 +// spectrumHandler.handler(); +// spectrumServiceQuotes.getRedisUtil().del(key); +// } catch (Exception e) { +// //如果是gamma谱的分析异常 +// if (e instanceof AnalySpectrumException) { +// // 如果邮件内容校验失败(邮件内容不完整) 将错误邮件从eml移动到emlError +// if (Objects.nonNull(emlFile) && emlFile.exists()){ +// moveEmail(emlFile, key); +// } +// //删除邮件 +// emailServiceManager.removeMail(message,batchesCounter); +// } else { +// throw e; +// } +// } +// }else{ +// log.warn("This email {} parsing failed and is not listed in the Met, Alert, SOH, Sample, Detbkphd, QC, Gasbkphd spectra.",subject); +// } +// emailServiceManager.removeMail(message,batchesCounter); +// }else { +// // 如果邮件内容校验失败(邮件内容不完整) 将错误邮件从eml移动到emlError +// if (Objects.nonNull(emlFile) && emlFile.exists()){ +// moveEmail(emlFile, key); +// throw new DownloadEmailException("邮件移走后手动抛出DownloadEmailException"); +// } +// } } catch (Exception e) { // 如果不是下载导致的失败 并且 下载成功,则删除下载的邮件对象 if(!(e instanceof DownloadEmailException) && downloadFlag){ From f94b6ca9fa2342bbbbf4f6a0cdb6a3dc1a550f69 Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Fri, 26 Apr 2024 10:33:21 +0800 Subject: [PATCH 31/40] =?UTF-8?q?onlyDownload=E4=BF=AE=E6=94=B9=E9=82=AE?= =?UTF-8?q?=E7=AE=B1=E5=A4=84=E7=90=86=E7=A8=8B=E5=BA=8F=E9=A2=91=E7=B9=81?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BA=BF=E7=A8=8B=E9=97=AE=E9=A2=98=20onlyDo?= =?UTF-8?q?wnload=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E9=83=A8=E5=88=86=E9=95=BF=E6=9C=9F=E5=A0=B5=E5=A1=9E=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/org/jeecg/modules/EmailParsingActuator.java | 1 - 1 file changed, 1 deletion(-) diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java index 6097a1c3..107a0558 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java @@ -110,7 +110,6 @@ public class EmailParsingActuator extends Thread{ } catch (MessagingException e) { throw new RuntimeException(e); } finally { - log.info(Thread.currentThread().getName() +"执行完毕!!!!"); //清除本批次邮件日志缓存 EmailLogManager.getInstance().clear(); //保存本批次所有能谱日志 From 1e0d499b7a345c4891cc52d2e8085a9c342f3767 Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Mon, 29 Apr 2024 18:24:15 +0800 Subject: [PATCH 32/40] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=A4=84=E7=90=86?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=BA=BF=E7=A8=8B=E5=B7=B2=E5=81=9C=E6=AD=A2?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E7=A7=BB=E9=99=A4emailMap=E4=B8=AD=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E7=9A=84=E9=82=AE=E7=AE=B1=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/org/jeecg/modules/AutoProcessManager.java | 1 + 1 file changed, 1 insertion(+) diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java index c9593dbf..9460d44d 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java @@ -285,6 +285,7 @@ public class AutoProcessManager{ if(next.getValue().getState() == State.TERMINATED){ log.info("{}邮箱执行线程已停止,emailExecThreadMap删除此邮箱数据",next.getValue().getEmailProperties().getUsername()); checkStopThreads.remove(); + emailMap.remove(next.getKey()); } } From f58d629bd7c2609f20390e2a7b23a34fa800b48c Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Mon, 29 Apr 2024 18:29:23 +0800 Subject: [PATCH 33/40] =?UTF-8?q?onlyDownload=E5=90=8E=E7=BB=AD=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=94=BE=E5=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spectrum/SpectrumParsingActuator.java | 82 +++++++++---------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java index aa9ba619..a88f07ad 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java @@ -110,47 +110,47 @@ public class SpectrumParsingActuator implements Runnable{ //保存邮件日志到PG数据库 this.spectrumServiceQuotes.getMailLogService().create(message,emailProperties); -// //获取邮件内容 -// StringBuilder mailContent = new StringBuilder(); -// if(Objects.nonNull(emlFile) && emlFile.length() > 0){ -// mailContent.append(FileUtil.readUtf8String(emlFile)); -// } -// -// //判断是否是IMS2.0协议文件 -// // 如果邮件内容校验成功 将文件保存到eml目录 并删除邮件对象 -// if(checkMailContent(mailContent,subject)){ -// AbstractSpectrumHandler spectrumHandler = new SamplephdSpectrum(); -// spectrumHandler.init(mailContent.toString(),emlFile.getName(),spectrumServiceQuotes,new StringBuilder(),SpectrumSource.FORM_EMAIL_SERVICE.getSourceType(),batchesCounter); -// final boolean matchResult = spectrumHandler.saveEmailToLocal(); -// if(matchResult){ -// try { -// //开始解析 -// spectrumHandler.handler(); -// spectrumServiceQuotes.getRedisUtil().del(key); -// } catch (Exception e) { -// //如果是gamma谱的分析异常 -// if (e instanceof AnalySpectrumException) { -// // 如果邮件内容校验失败(邮件内容不完整) 将错误邮件从eml移动到emlError -// if (Objects.nonNull(emlFile) && emlFile.exists()){ -// moveEmail(emlFile, key); -// } -// //删除邮件 -// emailServiceManager.removeMail(message,batchesCounter); -// } else { -// throw e; -// } -// } -// }else{ -// log.warn("This email {} parsing failed and is not listed in the Met, Alert, SOH, Sample, Detbkphd, QC, Gasbkphd spectra.",subject); -// } -// emailServiceManager.removeMail(message,batchesCounter); -// }else { -// // 如果邮件内容校验失败(邮件内容不完整) 将错误邮件从eml移动到emlError -// if (Objects.nonNull(emlFile) && emlFile.exists()){ -// moveEmail(emlFile, key); -// throw new DownloadEmailException("邮件移走后手动抛出DownloadEmailException"); -// } -// } + //获取邮件内容 + StringBuilder mailContent = new StringBuilder(); + if(Objects.nonNull(emlFile) && emlFile.length() > 0){ + mailContent.append(FileUtil.readUtf8String(emlFile)); + } + + //判断是否是IMS2.0协议文件 + // 如果邮件内容校验成功 将文件保存到eml目录 并删除邮件对象 + if(checkMailContent(mailContent,subject)){ + AbstractSpectrumHandler spectrumHandler = new SamplephdSpectrum(); + spectrumHandler.init(mailContent.toString(),emlFile.getName(),spectrumServiceQuotes,new StringBuilder(),SpectrumSource.FORM_EMAIL_SERVICE.getSourceType(),batchesCounter); + final boolean matchResult = spectrumHandler.saveEmailToLocal(); + if(matchResult){ + try { + //开始解析 + spectrumHandler.handler(); + spectrumServiceQuotes.getRedisUtil().del(key); + } catch (Exception e) { + //如果是gamma谱的分析异常 + if (e instanceof AnalySpectrumException) { + // 如果邮件内容校验失败(邮件内容不完整) 将错误邮件从eml移动到emlError + if (Objects.nonNull(emlFile) && emlFile.exists()){ + moveEmail(emlFile, key); + } + //删除邮件 + emailServiceManager.removeMail(message,batchesCounter); + } else { + throw e; + } + } + }else{ + log.warn("This email {} parsing failed and is not listed in the Met, Alert, SOH, Sample, Detbkphd, QC, Gasbkphd spectra.",subject); + } + emailServiceManager.removeMail(message,batchesCounter); + }else { + // 如果邮件内容校验失败(邮件内容不完整) 将错误邮件从eml移动到emlError + if (Objects.nonNull(emlFile) && emlFile.exists()){ + moveEmail(emlFile, key); + throw new DownloadEmailException("邮件移走后手动抛出DownloadEmailException"); + } + } } catch (Exception e) { // 如果不是下载导致的失败 并且 下载成功,则删除下载的邮件对象 if(!(e instanceof DownloadEmailException) && downloadFlag){ From 23bf9ee271f708569fdf2082c96e541bfe7fbdd9 Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Tue, 30 Apr 2024 08:56:52 +0800 Subject: [PATCH 34/40] =?UTF-8?q?onlyDownload=E5=90=8E=E7=BB=AD=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=94=BE=E5=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/org/jeecg/modules/EmailParsingActuator.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java index 107a0558..67983395 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java @@ -84,11 +84,11 @@ public class EmailParsingActuator extends Thread{ for(int i=messages.length-1;i>=0;i--){ if (!messages[i].isExpunged()){ String messageId = ((MimeMessage) messages[i]).getMessageID(); -// final boolean exist = emailServiceManager.check(messages[i],messageId); + final boolean exist = emailServiceManager.check(messages[i],messageId); messageIds.add(messageId); -// if(exist){ -// messages = ArrayUtils.remove(messages,i); -// } + if(exist){ + messages = ArrayUtils.remove(messages,i); + } } } log.info("EmailParsingActuator本次真实执行邮件数量为:{}",messages.length); From 72dbf2ba80d0de1f5d5322534a7b422161d09129 Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Thu, 9 May 2024 09:34:21 +0800 Subject: [PATCH 35/40] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=A4=84=E7=90=86?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E4=BF=AE=E6=94=B9=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/email/EmailServiceManager.java | 9 ++++----- .../jeecg/modules/EmailParsingActuator.java | 18 ++++++++++++------ .../spectrum/SpectrumParsingActuator.java | 8 ++++---- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java index e63fbd5d..a3ac56f3 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java @@ -126,7 +126,7 @@ public class EmailServiceManager { /** * 接收邮件 */ - public Message[] receiveMail() { + public Message[] receiveMail() throws MessagingException { String status = EmailLogManager.STATUS_SUCCESS; try{ //配置邮件服务属性 @@ -185,12 +185,11 @@ public class EmailServiceManager { return Arrays.copyOfRange(messages,0,this.receiveNum-1); } } - }catch (MessagingException e){ + } catch (MessagingException e){ status = EmailLogManager.STATUS_ERROR; log.error("Email connection is abnormal, account is {}, service is {},the reason is {}.",email.getName(),email.getEmailServerAddress(),e.getMessage()); - e.printStackTrace(); - return null; - }finally { + throw e; + } finally { EmailLogEvent connectEvent = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,email,status,EmailLogManager.CONNECT); EmailLogManager.getInstance().setConnectLogEvent(connectEvent); //GetAllId C++原业务是把远程邮箱邮件同步到C++,本次java编写没有这一步,所以和Connect绑定,若Connect成功则GetAllId成功 diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java index 67983395..2f85fe4f 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java @@ -17,10 +17,7 @@ import org.springframework.scheduling.concurrent.CustomizableThreadFactory; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.internet.MimeMessage; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Objects; +import java.util.*; import java.util.concurrent.*; /** @@ -82,8 +79,14 @@ public class EmailParsingActuator extends Thread{ log.info("EmailParsingActuator本次{}获取邮件数量为:{}", Thread.currentThread().getName(), messages.length); //检验获取的邮件是否在之前删除失败列表中,若在直接调用邮件API删除,并且此次数组里元素也删除 for(int i=messages.length-1;i>=0;i--){ + if (null == messages[i].getHeader("Message-ID")) { + System.out.println("Message ID是空值信息!!!!!!!"); + messages = ArrayUtils.remove(messages, i); + continue; + } if (!messages[i].isExpunged()){ String messageId = ((MimeMessage) messages[i]).getMessageID(); + System.out.println("正常获取到的Message ID是:"+messageId); final boolean exist = emailServiceManager.check(messages[i],messageId); messageIds.add(messageId); if(exist){ @@ -105,10 +108,13 @@ public class EmailParsingActuator extends Thread{ taskLatch.await(); } } - } catch (InterruptedException e) { - e.printStackTrace(); } catch (MessagingException e) { + System.out.println("捕获MessagingException!!!!!!!!"); + closeResource(); throw new RuntimeException(e); + } catch (Exception e) { + closeResource(); + log.error(""+e); } finally { //清除本批次邮件日志缓存 EmailLogManager.getInstance().clear(); diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java index a88f07ad..5548ba1e 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java @@ -97,9 +97,6 @@ public class SpectrumParsingActuator implements Runnable{ String emlName = subject+ StringConstant.UNDER_LINE+ receiveDate; String key = RedisConstant.EMAIL_MSG_ID+StringConstant.COLON+messageId; // spectrumServiceQuotes.getRedisUtil().set(key,emlName,expiryTime); - //判断当前key的下载次数是否超过限制次数 - spectrumServiceQuotes.getRedisUtil().incr(key, 1L); - spectrumServiceQuotes.getRedisUtil().expire(key, expiryTime); //线程开始初始化时,初始本线程负责的能谱日志事件 SpectrumLogManager.mailSpectrumLogManager.offer(Thread.currentThread().getId(),null); @@ -144,7 +141,10 @@ public class SpectrumParsingActuator implements Runnable{ log.warn("This email {} parsing failed and is not listed in the Met, Alert, SOH, Sample, Detbkphd, QC, Gasbkphd spectra.",subject); } emailServiceManager.removeMail(message,batchesCounter); - }else { + } else { + //判断当前key的下载次数是否超过限制次数 + spectrumServiceQuotes.getRedisUtil().incr(key, 1L); + spectrumServiceQuotes.getRedisUtil().expire(key, expiryTime); // 如果邮件内容校验失败(邮件内容不完整) 将错误邮件从eml移动到emlError if (Objects.nonNull(emlFile) && emlFile.exists()){ moveEmail(emlFile, key); From 9151233f115cd9075c14634ebd3be0d5a963c81a Mon Sep 17 00:00:00 2001 From: orgin Date: Thu, 30 May 2024 16:48:46 +0800 Subject: [PATCH 36/40] =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E8=B6=85=E6=97=B6?= =?UTF-8?q?=E4=B9=8B=E5=90=8E=E4=B8=8D=E4=B8=AD=E6=96=AD=E7=BA=BF=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/jeecg/common/email/EmailServiceManager.java | 4 ++-- .../src/main/java/org/jeecg/modules/AutoProcessManager.java | 4 ++-- .../main/java/org/jeecg/modules/EmailParsingActuator.java | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java index a3ac56f3..257b0b26 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java @@ -621,7 +621,7 @@ public class EmailServiceManager { try { subject = MimeUtility.decodeText(message.getSubject()); receivedDate = message.getReceivedDate(); - message.setFlag(Flags.Flag.DELETED,true); +// message.setFlag(Flags.Flag.DELETED,true); // log.info("EmailServiceManager: Remove Email:{},receiveTime:{}",message.getSubject(), DateUtils.formatDate(message.getReceivedDate(),"yyyy-MM-dd HH:mm:ss")); } catch (MessagingException | UnsupportedEncodingException e) { status = EmailLogManager.STATUS_ERROR; @@ -672,7 +672,7 @@ public class EmailServiceManager { if(numberKey >= taskProperties.getForceDeletedNumber()){ exist = true; log.info("Check: Remove Email:{},receiveTime:{}",message.getSubject(), DateUtils.formatDate(message.getReceivedDate(),"yyyy-MM-dd HH:mm:ss")); - message.setFlag(Flags.Flag.DELETED,true); +// message.setFlag(Flags.Flag.DELETED,true); redisUtil.del(key); } return exist; diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java index 9460d44d..d62ad50e 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java @@ -290,7 +290,7 @@ public class AutoProcessManager{ } //遍历邮箱执行线程,如果邮箱执行线程stop属性已被设置为true则关闭资源停止线程 - final Iterator> iterator = emailExecThreadMap.entrySet().iterator(); + /*final Iterator> iterator = emailExecThreadMap.entrySet().iterator(); emailExecThreadMap.forEach((emailId,emailExecThread)->{ try{ if(emailExecThread.getState() != State.TERMINATED && emailExecThread.isStop()){ @@ -315,7 +315,7 @@ public class AutoProcessManager{ } } } - }); + });*/ } long end = System.currentTimeMillis(); long sleepTime = taskProperties.getDeletedMailThreadExecCycle() - (end-start); diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java index 2f85fe4f..2b46d2bc 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java @@ -65,7 +65,7 @@ public class EmailParsingActuator extends Thread{ if (isStop) { String nowDate = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"); log.info(nowDate + " " +this.emailProperties.getName()+" EmailParsingActuator is Stop!"); - closeResource(); +// closeResource(); return; } long start = System.currentTimeMillis(); @@ -110,10 +110,10 @@ public class EmailParsingActuator extends Thread{ } } catch (MessagingException e) { System.out.println("捕获MessagingException!!!!!!!!"); - closeResource(); +// closeResource(); throw new RuntimeException(e); } catch (Exception e) { - closeResource(); +// closeResource(); log.error(""+e); } finally { //清除本批次邮件日志缓存 From 11681f12dbf88c45780fdba9577e36921dcd3f7f Mon Sep 17 00:00:00 2001 From: orgin Date: Fri, 31 May 2024 09:15:57 +0800 Subject: [PATCH 37/40] =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E8=B6=85=E6=97=B6?= =?UTF-8?q?=E4=B9=8B=E5=90=8E=E4=B8=8D=E4=B8=AD=E6=96=AD=E7=BA=BF=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/org/jeecg/modules/EmailParsingActuator.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java index 2b46d2bc..975626fa 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java @@ -65,8 +65,13 @@ public class EmailParsingActuator extends Thread{ if (isStop) { String nowDate = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"); log.info(nowDate + " " +this.emailProperties.getName()+" EmailParsingActuator is Stop!"); + try { + Thread.sleep(1000L); + } catch (InterruptedException e) { + log.error("Thread sleep error"); + } // closeResource(); - return; + continue; } long start = System.currentTimeMillis(); final EmailServiceManager emailServiceManager = EmailServiceManager.getInstance(); From 97f4aae3ab84b584d83314b8cb7422276899111b Mon Sep 17 00:00:00 2001 From: nieziyan Date: Tue, 4 Jun 2024 09:23:21 +0800 Subject: [PATCH 38/40] =?UTF-8?q?fix=EF=BC=9A=E8=87=AA=E5=8A=A8=E5=A4=84?= =?UTF-8?q?=E7=90=86debug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/email/EmailServiceManager.java | 116 ++++++++++++++++-- .../org/jeecg/modules/AutoProcessManager.java | 23 ++-- .../jeecg/modules/EmailParsingActuator.java | 16 ++- 3 files changed, 135 insertions(+), 20 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java index 257b0b26..49f02b82 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java @@ -1,16 +1,13 @@ package org.jeecg.common.email; -import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.StrUtil; import com.google.common.collect.Lists; import com.sun.mail.imap.IMAPStore; import com.sun.mail.smtp.SMTPAddressFailedException; -import io.swagger.models.auth.In; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.io.Charsets; -import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.jeecg.common.api.dto.message.MessageDTO; import org.jeecg.common.constant.RedisConstant; @@ -21,7 +18,6 @@ import org.jeecg.common.exception.DownloadEmailException; import org.jeecg.common.properties.SpectrumPathProperties; import org.jeecg.common.properties.TaskProperties; import org.jeecg.common.util.DateUtils; -import org.jeecg.common.util.Md5Util; import org.jeecg.common.util.RedisUtil; import org.jeecg.modules.base.entity.postgre.SysEmail; import org.jetbrains.annotations.NotNull; @@ -36,6 +32,9 @@ import java.io.*; import java.net.InetSocketAddress; import java.net.Socket; import java.util.*; +import java.util.concurrent.*; +import java.util.concurrent.atomic.AtomicReference; +import java.util.concurrent.locks.ReentrantLock; import java.util.stream.Collectors; /** @@ -70,6 +69,8 @@ public class EmailServiceManager { private Object downloadEmlLocal = new Object(); + private final ReentrantLock lock = new ReentrantLock(); + @NotNull public static EmailServiceManager getInstance(){ return new EmailServiceManager(); @@ -155,6 +156,8 @@ public class EmailServiceManager { store = (IMAPStore) session.getStore(); //连接 store.connect(email.getUsername(),email.getPassword()); + if (RandomUtil.randomInt(1, 5) == 3) + throw new MessagingException(); // 解决163普通邮箱无法建立连接问题 store.id(IAM); //获取收件箱 @@ -609,6 +612,105 @@ public class EmailServiceManager { } } + /*public File downloadEmailToEmlDir(@NotNull Message message, Integer emailCounter, Integer batchesCounter) throws MessagingException, IOException { + AtomicReference outputStream = new AtomicReference<>(); + CompletableFuture future = CompletableFuture.supplyAsync(() -> { + try { + lock.lock(); // 获取锁 + // 执行需要获取锁才能进行的操作 + // return executeWithLock(message, emailCounter, batchesCounter); + File file = executeWithLock(message, emailCounter, batchesCounter); + outputStream.set(new FileOutputStream(file)); + a(outputStream,message); + return null; + } catch (MessagingException e) { + throw new RuntimeException(e); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + // 如果成功拿到锁 释放锁 + lock.unlock(); + } + }); + + try { + return future.get(5, TimeUnit.SECONDS); + // return future.get(5, TimeUnit.SECONDS);// 等待任务执行,超过5秒则抛出TimeoutException + } catch (InterruptedException | ExecutionException | TimeoutException e) { + future.cancel(true); // 取消任务执行 + if (ObjectUtil.isNotNull(outputStream) && ObjectUtil.isNotNull(outputStream.get())) + outputStream.get().close(); + log.error("下载 eml 执行超时", e); + throw new RuntimeException("下载 eml 执行超时"); + } + }*/ + public File executeWithLock(Message message,Integer emailCounter,Integer batchesCounter) throws MessagingException { + + String subject = ""; + File emlFile = null; + String status = EmailLogManager.STATUS_SUCCESS; + Date receivedDate = null; + try { + // 获取锁 设置超时 + //获取发件人 + final String address = ((InternetAddress) message.getFrom()[0]).getAddress(); + final String from = address.substring(0,address.indexOf(StringConstant.AT)); + //获取主题 + subject = MimeUtility.decodeText(message.getSubject()); + if(subject.contains(StringConstant.SLASH)){ + subject = StringUtils.replace(subject,StringConstant.SLASH,""); + } + if(subject.contains(StringConstant.COLON)){ + subject = StringUtils.replace(subject,StringConstant.COLON,""); + } + receivedDate = message.getReceivedDate(); + StringBuilder fileName = new StringBuilder(); + fileName.append(from); + fileName.append(StringConstant.UNDER_LINE); + fileName.append(subject); + fileName.append(StringConstant.UNDER_LINE); + fileName.append(DateUtils.formatDate(new Date(),"YYMMdd")); + fileName.append(StringConstant.UNDER_LINE); + fileName.append(DateUtils.formatDate(new Date(),"HHmmssSSS")); + fileName.append(StringConstant.UNDER_LINE); + fileName.append("receive"); + fileName.append(StringConstant.UNDER_LINE); + fileName.append(DateUtils.formatDate(receivedDate,"YYMMdd")); + fileName.append(StringConstant.UNDER_LINE); + fileName.append(DateUtils.formatDate(receivedDate,"HHmmssSSS")); + fileName.append(StringConstant.UNDER_LINE); + fileName.append(emailCounter); + fileName.append(SAVE_EML_SUFFIX); + final String rootPath = spectrumPathProperties.getRootPath(); + final String emlPath = spectrumPathProperties.getEmlPath(); + emlFile = new File(rootPath+emlPath+File.separator+fileName); + // Thread.sleep(6000l); + // try(FileOutputStream outputStream = new FileOutputStream(emlFile)) { + // message.writeTo(outputStream); + // } catch (IOException e) { + // throw new RuntimeException(e); + // } + } catch (MessagingException | IOException e) { + // 下载邮件失败 抛出自定义邮件下载异常 + status = EmailLogManager.STATUS_ERROR; + String errorMsg = StrUtil.format("The email download failed, the subject of the email is {}, the reason is {}.", subject, e.getMessage()); + log.error(errorMsg); + throw new DownloadEmailException(errorMsg); + } catch (Exception e) { + log.error("",e); + } finally { + EmailLogEvent event = new EmailLogEvent(batchesCounter,Thread.currentThread().getId(),EmailLogManager.GS_TYPE_GET,status,EmailLogManager.GETIDEML,subject,DateUtils.formatDate(receivedDate,"yyyy-MM-dd HH:mm:ss:SSS"), + (Objects.isNull(emlFile)?" ":emlFile.getAbsolutePath())); + EmailLogManager.getInstance().offer(Thread.currentThread().getId(),event); + } + return emlFile; + } + + public void a(AtomicReference outputStream, Message message) throws MessagingException, IOException { + message.writeTo(outputStream.get()); + } /** * 删除邮件 * @param message @@ -621,7 +723,7 @@ public class EmailServiceManager { try { subject = MimeUtility.decodeText(message.getSubject()); receivedDate = message.getReceivedDate(); -// message.setFlag(Flags.Flag.DELETED,true); + // message.setFlag(Flags.Flag.DELETED,true); // log.info("EmailServiceManager: Remove Email:{},receiveTime:{}",message.getSubject(), DateUtils.formatDate(message.getReceivedDate(),"yyyy-MM-dd HH:mm:ss")); } catch (MessagingException | UnsupportedEncodingException e) { status = EmailLogManager.STATUS_ERROR; @@ -672,7 +774,7 @@ public class EmailServiceManager { if(numberKey >= taskProperties.getForceDeletedNumber()){ exist = true; log.info("Check: Remove Email:{},receiveTime:{}",message.getSubject(), DateUtils.formatDate(message.getReceivedDate(),"yyyy-MM-dd HH:mm:ss")); -// message.setFlag(Flags.Flag.DELETED,true); + // message.setFlag(Flags.Flag.DELETED,true); redisUtil.del(key); } return exist; diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java index d62ad50e..19bf67d0 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java @@ -1,5 +1,6 @@ package org.jeecg.modules; +import cn.hutool.core.util.RandomUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.constant.RedisConstant; @@ -15,7 +16,6 @@ import org.jeecg.modules.spectrum.SpectrumServiceQuotes; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; -import java.io.*; import java.util.*; import java.util.concurrent.TimeUnit; @@ -47,6 +47,8 @@ public class AutoProcessManager{ */ private Map emailExecThreadMap = new HashMap<>(); + private boolean flag = true; + /** * 启动自动处理 */ @@ -145,9 +147,14 @@ public class AutoProcessManager{ if(!email.isDelFlag()){ final EmailServiceManager emailServiceManager = EmailServiceManager.getInstance(); emailServiceManager.init(email); - boolean testFlag = emailServiceManager.testConnectEmailServer(); + /*boolean testFlag = emailServiceManager.testConnectEmailServer(); if(!testFlag){ emails.add(email); + }*/ + int i = RandomUtil.randomInt(1, 5); + flag = i == 3; + if(flag){ + emails.add(email); } } }); @@ -158,7 +165,7 @@ public class AutoProcessManager{ //如果这时邮箱线程里已有执行的线程则设置停止标记 if(emailExecThreadMap.containsKey(email.getId())){ EmailParsingActuator actuator = emailExecThreadMap.get(email.getId()); - actuator.setStop(true); + actuator.setThreadSleep(true); actuator.setStopTime(new Date()); } log.info("{}邮箱测试连接失败,emailMap删除此邮箱数据,emailExecThreadMap设置线程停止标记",email.getUsername()); @@ -231,11 +238,11 @@ public class AutoProcessManager{ }else{ //如果不包含邮箱id 并且 邮箱处于启用状态 将邮箱对象存入到map中 并将新邮箱标识设置为true if(databaseEmail.getEnabled().equals(SysMailEnableType.ENABLE.getMailEnableType())){ - final boolean testFlag = testConnectEmailServer(databaseEmail); - if(testFlag){ + // final boolean testFlag = testConnectEmailServer(databaseEmail); + if(flag){ if (emailExecThreadMap.containsKey(databaseEmail.getId())) { EmailParsingActuator actuator = emailExecThreadMap.get(databaseEmail.getId()); - actuator.setStop(false); + actuator.setThreadSleep(false); log.info("{}邮箱重新加入监测队列",databaseEmail.getUsername()); } else { databaseEmail.setNewEmailFlag(true); @@ -290,7 +297,7 @@ public class AutoProcessManager{ } //遍历邮箱执行线程,如果邮箱执行线程stop属性已被设置为true则关闭资源停止线程 - /*final Iterator> iterator = emailExecThreadMap.entrySet().iterator(); + final Iterator> iterator = emailExecThreadMap.entrySet().iterator(); emailExecThreadMap.forEach((emailId,emailExecThread)->{ try{ if(emailExecThread.getState() != State.TERMINATED && emailExecThread.isStop()){ @@ -315,7 +322,7 @@ public class AutoProcessManager{ } } } - });*/ + }); } long end = System.currentTimeMillis(); long sleepTime = taskProperties.getDeletedMailThreadExecCycle() - (end-start); diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java index 975626fa..c53a70d8 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java @@ -36,6 +36,8 @@ public class EmailParsingActuator extends Thread{ @Setter @Getter private boolean isStop; @Setter @Getter + private boolean threadSleep; + @Setter @Getter private Date stopTime; public void init(EmailProperties emailProperties,SpectrumServiceQuotes spectrumServiceQuotes, @@ -62,17 +64,21 @@ public class EmailParsingActuator extends Thread{ @Override public void run() { for(;;){ - if (isStop) { - String nowDate = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"); - log.info(nowDate + " " +this.emailProperties.getName()+" EmailParsingActuator is Stop!"); + String nowDate = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"); + if (threadSleep) { + log.info(nowDate + " " +this.emailProperties.getName()+" EmailParsingActuator is sleep!"); try { Thread.sleep(1000L); } catch (InterruptedException e) { log.error("Thread sleep error"); } -// closeResource(); continue; } + if (isStop) { + log.info(nowDate + " " +this.emailProperties.getName()+" EmailParsingActuator is Stop!"); + closeResource(); + return; + } long start = System.currentTimeMillis(); final EmailServiceManager emailServiceManager = EmailServiceManager.getInstance(); emailServiceManager.init(this.emailProperties,this.taskProperties.getReceiveNum(),this.taskProperties.getTemporaryStoragePath(), @@ -115,7 +121,7 @@ public class EmailParsingActuator extends Thread{ } } catch (MessagingException e) { System.out.println("捕获MessagingException!!!!!!!!"); -// closeResource(); + // closeResource(); throw new RuntimeException(e); } catch (Exception e) { // closeResource(); From 3d5080c1d85713886f49484e380814cc5c46f815 Mon Sep 17 00:00:00 2001 From: nieziyan Date: Wed, 5 Jun 2024 09:42:20 +0800 Subject: [PATCH 39/40] =?UTF-8?q?fix=EF=BC=9AAutoProcess=E5=A4=9A=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jeecg/common/email/EmailServiceManager.java | 11 +++++------ .../java/org/jeecg/modules/AutoProcessManager.java | 13 +++---------- .../org/jeecg/modules/EmailParsingActuator.java | 13 +++++-------- 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java index 49f02b82..ad7795fb 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java @@ -156,8 +156,6 @@ public class EmailServiceManager { store = (IMAPStore) session.getStore(); //连接 store.connect(email.getUsername(),email.getPassword()); - if (RandomUtil.randomInt(1, 5) == 3) - throw new MessagingException(); // 解决163普通邮箱无法建立连接问题 store.id(IAM); //获取收件箱 @@ -723,8 +721,8 @@ public class EmailServiceManager { try { subject = MimeUtility.decodeText(message.getSubject()); receivedDate = message.getReceivedDate(); - // message.setFlag(Flags.Flag.DELETED,true); -// log.info("EmailServiceManager: Remove Email:{},receiveTime:{}",message.getSubject(), DateUtils.formatDate(message.getReceivedDate(),"yyyy-MM-dd HH:mm:ss")); + message.setFlag(Flags.Flag.DELETED,true); + // log.info("EmailServiceManager: Remove Email:{},receiveTime:{}",message.getSubject(), DateUtils.formatDate(message.getReceivedDate(),"yyyy-MM-dd HH:mm:ss")); } catch (MessagingException | UnsupportedEncodingException e) { status = EmailLogManager.STATUS_ERROR; log.error("Email deletion failed, the subject of the email is :{}, the reason is :{}.",subject,e.getMessage()); @@ -750,6 +748,7 @@ public class EmailServiceManager { if(null != store){ store.close(); } + log.info("EmailServiceManage资源关闭完成."); // for(String messageId : messageIds){ // String key = RedisConstant.EMAIL_MSG_ID+StringConstant.COLON+messageId; // redisUtil.del(key); @@ -770,11 +769,11 @@ public class EmailServiceManager { try { String key = RedisConstant.EMAIL_MSG_ID+StringConstant.COLON+messageId; int numberKey = redisUtil.get(key) != null? (int) redisUtil.get(key):0; -// exist = redisUtil.hasKey(key); + // exist = redisUtil.hasKey(key); if(numberKey >= taskProperties.getForceDeletedNumber()){ exist = true; log.info("Check: Remove Email:{},receiveTime:{}",message.getSubject(), DateUtils.formatDate(message.getReceivedDate(),"yyyy-MM-dd HH:mm:ss")); - // message.setFlag(Flags.Flag.DELETED,true); + message.setFlag(Flags.Flag.DELETED,true); redisUtil.del(key); } return exist; diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java index 19bf67d0..99912a68 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java @@ -47,8 +47,6 @@ public class AutoProcessManager{ */ private Map emailExecThreadMap = new HashMap<>(); - private boolean flag = true; - /** * 启动自动处理 */ @@ -147,14 +145,9 @@ public class AutoProcessManager{ if(!email.isDelFlag()){ final EmailServiceManager emailServiceManager = EmailServiceManager.getInstance(); emailServiceManager.init(email); - /*boolean testFlag = emailServiceManager.testConnectEmailServer(); + boolean testFlag = emailServiceManager.testConnectEmailServer(); if(!testFlag){ emails.add(email); - }*/ - int i = RandomUtil.randomInt(1, 5); - flag = i == 3; - if(flag){ - emails.add(email); } } }); @@ -238,8 +231,8 @@ public class AutoProcessManager{ }else{ //如果不包含邮箱id 并且 邮箱处于启用状态 将邮箱对象存入到map中 并将新邮箱标识设置为true if(databaseEmail.getEnabled().equals(SysMailEnableType.ENABLE.getMailEnableType())){ - // final boolean testFlag = testConnectEmailServer(databaseEmail); - if(flag){ + final boolean testFlag = testConnectEmailServer(databaseEmail); + if(testFlag){ if (emailExecThreadMap.containsKey(databaseEmail.getId())) { EmailParsingActuator actuator = emailExecThreadMap.get(databaseEmail.getId()); actuator.setThreadSleep(false); diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java index c53a70d8..d9ed4cd8 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java @@ -91,13 +91,11 @@ public class EmailParsingActuator extends Thread{ //检验获取的邮件是否在之前删除失败列表中,若在直接调用邮件API删除,并且此次数组里元素也删除 for(int i=messages.length-1;i>=0;i--){ if (null == messages[i].getHeader("Message-ID")) { - System.out.println("Message ID是空值信息!!!!!!!"); messages = ArrayUtils.remove(messages, i); continue; } if (!messages[i].isExpunged()){ String messageId = ((MimeMessage) messages[i]).getMessageID(); - System.out.println("正常获取到的Message ID是:"+messageId); final boolean exist = emailServiceManager.check(messages[i],messageId); messageIds.add(messageId); if(exist){ @@ -117,15 +115,14 @@ public class EmailParsingActuator extends Thread{ poolExecutor.execute(spectrumParsingActuator); } taskLatch.await(); + log.info("EmailParsingActuator本次{}封邮件处理完成", messages.length); } } - } catch (MessagingException e) { - System.out.println("捕获MessagingException!!!!!!!!"); - // closeResource(); - throw new RuntimeException(e); } catch (Exception e) { -// closeResource(); - log.error(""+e); + log.error("EmailParsingActuator has exception: {}", e.getMessage()); + log.info("Mail-Parsing线程池资源关闭..."); + closeResource(); + throw new RuntimeException(e); } finally { //清除本批次邮件日志缓存 EmailLogManager.getInstance().clear(); From 897f469ea936c5bbc0b404a9fd3cd96d23a1d884 Mon Sep 17 00:00:00 2001 From: nieziyan Date: Thu, 6 Jun 2024 15:42:06 +0800 Subject: [PATCH 40/40] =?UTF-8?q?fix=EF=BC=9A=E5=A2=9E=E5=8A=A0=E8=B0=B1?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=84=E7=90=86=E7=8A=B6=E6=80=81=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jeecg/modules/service/impl/GardsSampleDataServiceImpl.java | 3 ++- .../org/jeecg/modules/spectrum/AbstractSpectrumHandler.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/GardsSampleDataServiceImpl.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/GardsSampleDataServiceImpl.java index 5a2d3d6a..b5b77ac7 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/GardsSampleDataServiceImpl.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/GardsSampleDataServiceImpl.java @@ -84,7 +84,8 @@ public class GardsSampleDataServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(GardsSampleData::getInputFileName,inputFileName); final GardsSampleData sampleData = this.getOne(queryWrapper); - if(Objects.nonNull(sampleData) && !SampleStatus.COMPLETE.getValue().equals(sampleData.getStatus())){ + if(Objects.nonNull(sampleData) && !SampleStatus.COMPLETE.getValue().equals(sampleData.getStatus()) + && !SampleStatus.INTERACTIVE.getValue().equals(sampleData.getStatus())){ this.baseMapper.updateStatus(status,inputFileName); } } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractSpectrumHandler.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractSpectrumHandler.java index 86b4ca66..b8e6df8e 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractSpectrumHandler.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractSpectrumHandler.java @@ -316,7 +316,7 @@ public abstract class AbstractSpectrumHandler extends AbstractChain { ex.printStackTrace(); } } else if(SpectrumSource.FROM_FILE_SOURCE.getSourceType().equals(spectrumSource) && (e instanceof FileRepeatException)){ - this.spectrumFile.delete(); + this.spectrumFile.delete(); // TODO 删除原始谱文件 } else if (SpectrumSource.FORM_FILE_UNDEL.getSourceType().equals(spectrumSource) && !(e instanceof FileRepeatException)) { try { if (isDateFormatErr) {