From 0b6383770bced5f0db876faa0887f3a191d2cd44 Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Thu, 7 Mar 2024 18:00:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=A4=84=E7=90=86=E6=A8=A1?= =?UTF-8?q?=E5=9D=97gamma=E9=83=A8=E5=88=86=E7=AE=97=E6=B3=95=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E7=A8=8B=E5=BA=8F=E5=B4=A9=E6=BA=83=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=BC=82=E5=B8=B8=E6=8A=9B=E5=87=BA=E7=AE=97?= =?UTF-8?q?=E6=B3=95=E9=94=99=E8=AF=AF=E5=8E=9F=E5=9B=A0=E5=86=99=E5=85=A5?= =?UTF-8?q?error=E6=97=A5=E5=BF=97=20=E8=87=AA=E5=8A=A8=E5=A4=84=E7=90=86?= =?UTF-8?q?=E6=A8=A1=E5=9D=97gamma=E9=83=A8=E5=88=86=E7=AE=97=E6=B3=95?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E7=A8=8B=E5=BA=8F=E5=B4=A9=E6=BA=83=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 --- .../exception/AnalySpectrumException.java | 9 ++++ .../spectrum/AbstractSpectrumHandler.java | 3 +- .../modules/spectrum/Sample_G_Analysis.java | 44 +++++++++++-------- .../modules/spectrum/SamplephdSpectrum.java | 1 + .../spectrum/SpectrumParsingActuator.java | 36 +++++++++++---- 5 files changed, 66 insertions(+), 27 deletions(-) create mode 100644 jeecg-module-auto-process/src/main/java/org/jeecg/modules/exception/AnalySpectrumException.java diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/exception/AnalySpectrumException.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/exception/AnalySpectrumException.java new file mode 100644 index 00000000..f2d6597a --- /dev/null +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/exception/AnalySpectrumException.java @@ -0,0 +1,9 @@ +package org.jeecg.modules.exception; + +public class AnalySpectrumException extends AnalyseException { + + public AnalySpectrumException(String message) { + super(message); + } + +} 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 3b237f98..86b4ca66 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 @@ -17,6 +17,7 @@ import org.jeecg.modules.eneity.event.SpectrumErrorEvent; import org.jeecg.modules.eneity.event.SpectrumLog; import org.jeecg.modules.enums.ErrorType; import org.jeecg.modules.enums.SpectrumSource; +import org.jeecg.modules.exception.AnalySpectrumException; import org.jeecg.modules.exception.AnalyseException; import org.jeecg.modules.exception.FileRepeatException; import org.jeecg.modules.exception.HeaderBlockException; @@ -268,7 +269,7 @@ public abstract class AbstractSpectrumHandler extends AbstractChain { protected void handleParseingFailFile(Exception e) throws FileNotFoundException { if(!SpectrumSource.FORM_FILE_UNDEL.getSourceType().equals(spectrumSource) && !(e instanceof FileRepeatException)){ try { - if (isDateFormatErr) { + if (isDateFormatErr || (e instanceof AnalySpectrumException)) { //修改能谱文件名称 this.updateErrorSpectrumFileName(); //解析失败会把文件移动到errorfile目录 diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_G_Analysis.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_G_Analysis.java index 6baf4151..b3bbe087 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_G_Analysis.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_G_Analysis.java @@ -31,6 +31,7 @@ import org.jeecg.modules.config.datasource.DataSourceSwitcher; import org.jeecg.modules.eneity.event.SpectrumErrorEvent; import org.jeecg.modules.entity.vo.*; import org.jeecg.modules.enums.ErrorType; +import org.jeecg.modules.exception.AnalySpectrumException; import org.jeecg.modules.exception.GAnalyseException; import org.jeecg.modules.file.FileOperation; import org.jeecg.modules.native_jni.struct.EnergySpectrumStruct; @@ -130,7 +131,7 @@ public class Sample_G_Analysis { sampleData.getInputFileName().lastIndexOf((StringConstant.SLASH))+1); } - public void analysis() throws GAnalyseException{ + public void analysis() throws GAnalyseException, AnalySpectrumException{ log.info("Gamma自动处理分析--Start"); PHDFile phdFile = new PHDFile(); try { @@ -174,30 +175,37 @@ public class Sample_G_Analysis { //读取参数内容 readMDCParameter(phdFile); // 执行分析业务代码 - gammaFileUtil.GetMiddleData(phdFile, CommonConstant.REPORT_PREFIX_AUTO, nuclideLibs, middleData, MiddleDataType.Auto.getType(), ""); + boolean analyFlag = gammaFileUtil.GetMiddleData(phdFile, CommonConstant.REPORT_PREFIX_AUTO, nuclideLibs, middleData, MiddleDataType.Auto.getType(), ""); - // 数据插入数据库 - this.storageDataToDatabase(phdFile, middleData, phdFile.getQcItems()); + if (analyFlag) { + // 数据插入数据库 + this.storageDataToDatabase(phdFile, middleData, phdFile.getQcItems()); - // 生成日志文件 - writeLog(middleData.getAnalyses_LogPath(), middleData); + // 生成日志文件 + writeLog(middleData.getAnalyses_LogPath(), middleData); - // 生成报告文件 - String reportContent = gammaFileUtil.GetReportContent(middleData); - String reportPath = StringUtils.substringBeforeLast(middleData.getAnalyses_ReportPath(), StringPool.SLASH); - String reportName = StringUtils.substringAfterLast(middleData.getAnalyses_ReportPath(), StringPool.SLASH) + ".txt"; - String savePath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + File.separator + reportPath + - File.separator + reportName; - // 保存文件 - FileOperation.saveOrAppendFile(savePath, reportContent, false); - //发送数据到redis - middleData.setSample_id(String.valueOf(sampleId)); - pushToRedis(middleData); - }catch (Exception e){ + // 生成报告文件 + String reportContent = gammaFileUtil.GetReportContent(middleData); + String reportPath = StringUtils.substringBeforeLast(middleData.getAnalyses_ReportPath(), StringPool.SLASH); + String reportName = StringUtils.substringAfterLast(middleData.getAnalyses_ReportPath(), StringPool.SLASH) + ".txt"; + String savePath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + File.separator + reportPath + + File.separator + reportName; + // 保存文件 + FileOperation.saveOrAppendFile(savePath, reportContent, false); + //发送数据到redis + middleData.setSample_id(String.valueOf(sampleId)); + pushToRedis(middleData); + } else { + ErrorLogManager.getInstance().write(new SpectrumErrorEvent(new Date(), phdFile.getAnalyMessage(), this.sampleFilename)); + throw new AnalySpectrumException(phdFile.getAnalyMessage()); + } + } catch (Exception e){ e.printStackTrace(); log.error("Sample_G_Analysis", e); if (e instanceof DuplicateKeyException) { throw new GAnalyseException("Sample Analyse Error at "+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"), true); + } else if (e instanceof AnalySpectrumException) { + throw new AnalySpectrumException(e.getMessage()); } else { throw new GAnalyseException("Sample Analyse Error at "+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss")); } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SamplephdSpectrum.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SamplephdSpectrum.java index 9f962e63..1cdbd361 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SamplephdSpectrum.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SamplephdSpectrum.java @@ -7,6 +7,7 @@ import org.jeecg.modules.base.enums.SystemType; import org.jeecg.modules.eneity.event.SpectrumErrorEvent; import org.jeecg.modules.enums.ErrorType; import org.jeecg.modules.enums.SpectrumSource; +import org.jeecg.modules.exception.AnalySpectrumException; import org.jeecg.modules.exception.AnalyseException; import org.jeecg.modules.exception.GAnalyseException; import org.springframework.dao.DuplicateKeyException; 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 3567752c..53f17107 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 @@ -15,6 +15,7 @@ import org.jeecg.common.exception.DownloadEmailException; import org.jeecg.common.util.DateUtils; import org.jeecg.modules.email.EmailProperties; import org.jeecg.modules.enums.SpectrumSource; +import org.jeecg.modules.exception.AnalySpectrumException; import org.jeecg.modules.file.FileOperation; import javax.mail.Message; @@ -119,8 +120,23 @@ public class SpectrumParsingActuator implements Runnable{ spectrumHandler.init(mailContent.toString(),emlFile.getName(),spectrumServiceQuotes,new StringBuilder(),SpectrumSource.FORM_EMAIL_SERVICE.getSourceType(),batchesCounter); final boolean matchResult = spectrumHandler.saveEmailToLocal(); if(matchResult){ - //开始解析 - spectrumHandler.handler(); + try { + //开始解析 + spectrumHandler.handler(); + } 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); } @@ -128,12 +144,7 @@ public class SpectrumParsingActuator implements Runnable{ }else { // 如果邮件内容校验失败(邮件内容不完整) 将错误邮件从eml移动到emlError if (Objects.nonNull(emlFile) && emlFile.exists()){ - final String rootPath = spectrumServiceQuotes.getSpectrumPathProperties().getRootPath(); - final String emlErrorPath = spectrumServiceQuotes.getSpectrumPathProperties().getEmlErrorPath(); - final String finalPath = rootPath+emlErrorPath; - FileOperation.moveFile(emlFile,finalPath,true); - // 删除 key,防止下次线程执行删除邮件 - spectrumServiceQuotes.getRedisUtil().del(key); + moveEmail(emlFile, key); throw new DownloadEmailException("邮件移走后手动抛出DownloadEmailException"); } } @@ -187,4 +198,13 @@ public class SpectrumParsingActuator implements Runnable{ return false; } + private void moveEmail(File emlFile, String key) throws IOException { + final String rootPath = spectrumServiceQuotes.getSpectrumPathProperties().getRootPath(); + final String emlErrorPath = spectrumServiceQuotes.getSpectrumPathProperties().getEmlErrorPath(); + final String finalPath = rootPath+emlErrorPath; + FileOperation.moveFile(emlFile,finalPath,true); + // 删除 key,防止下次线程执行删除邮件 + spectrumServiceQuotes.getRedisUtil().del(key); + } + }