Merge remote-tracking branch 'origin/mdc' into mdc

This commit is contained in:
nieziyan 2024-03-07 18:01:38 +08:00
commit fdd3838e9b
5 changed files with 66 additions and 27 deletions

View File

@ -0,0 +1,9 @@
package org.jeecg.modules.exception;
public class AnalySpectrumException extends AnalyseException {
public AnalySpectrumException(String message) {
super(message);
}
}

View File

@ -17,6 +17,7 @@ import org.jeecg.modules.eneity.event.SpectrumErrorEvent;
import org.jeecg.modules.eneity.event.SpectrumLog; import org.jeecg.modules.eneity.event.SpectrumLog;
import org.jeecg.modules.enums.ErrorType; import org.jeecg.modules.enums.ErrorType;
import org.jeecg.modules.enums.SpectrumSource; import org.jeecg.modules.enums.SpectrumSource;
import org.jeecg.modules.exception.AnalySpectrumException;
import org.jeecg.modules.exception.AnalyseException; import org.jeecg.modules.exception.AnalyseException;
import org.jeecg.modules.exception.FileRepeatException; import org.jeecg.modules.exception.FileRepeatException;
import org.jeecg.modules.exception.HeaderBlockException; import org.jeecg.modules.exception.HeaderBlockException;
@ -268,7 +269,7 @@ public abstract class AbstractSpectrumHandler extends AbstractChain {
protected void handleParseingFailFile(Exception e) throws FileNotFoundException { protected void handleParseingFailFile(Exception e) throws FileNotFoundException {
if(!SpectrumSource.FORM_FILE_UNDEL.getSourceType().equals(spectrumSource) && !(e instanceof FileRepeatException)){ if(!SpectrumSource.FORM_FILE_UNDEL.getSourceType().equals(spectrumSource) && !(e instanceof FileRepeatException)){
try { try {
if (isDateFormatErr) { if (isDateFormatErr || (e instanceof AnalySpectrumException)) {
//修改能谱文件名称 //修改能谱文件名称
this.updateErrorSpectrumFileName(); this.updateErrorSpectrumFileName();
//解析失败会把文件移动到errorfile目录 //解析失败会把文件移动到errorfile目录

View File

@ -31,6 +31,7 @@ import org.jeecg.modules.config.datasource.DataSourceSwitcher;
import org.jeecg.modules.eneity.event.SpectrumErrorEvent; import org.jeecg.modules.eneity.event.SpectrumErrorEvent;
import org.jeecg.modules.entity.vo.*; import org.jeecg.modules.entity.vo.*;
import org.jeecg.modules.enums.ErrorType; import org.jeecg.modules.enums.ErrorType;
import org.jeecg.modules.exception.AnalySpectrumException;
import org.jeecg.modules.exception.GAnalyseException; import org.jeecg.modules.exception.GAnalyseException;
import org.jeecg.modules.file.FileOperation; import org.jeecg.modules.file.FileOperation;
import org.jeecg.modules.native_jni.struct.EnergySpectrumStruct; import org.jeecg.modules.native_jni.struct.EnergySpectrumStruct;
@ -130,7 +131,7 @@ public class Sample_G_Analysis {
sampleData.getInputFileName().lastIndexOf((StringConstant.SLASH))+1); sampleData.getInputFileName().lastIndexOf((StringConstant.SLASH))+1);
} }
public void analysis() throws GAnalyseException{ public void analysis() throws GAnalyseException, AnalySpectrumException{
log.info("Gamma自动处理分析--Start"); log.info("Gamma自动处理分析--Start");
PHDFile phdFile = new PHDFile(); PHDFile phdFile = new PHDFile();
try { try {
@ -174,8 +175,9 @@ public class Sample_G_Analysis {
//读取参数内容 //读取参数内容
readMDCParameter(phdFile); 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(), "");
if (analyFlag) {
// 数据插入数据库 // 数据插入数据库
this.storageDataToDatabase(phdFile, middleData, phdFile.getQcItems()); this.storageDataToDatabase(phdFile, middleData, phdFile.getQcItems());
@ -193,11 +195,17 @@ public class Sample_G_Analysis {
//发送数据到redis //发送数据到redis
middleData.setSample_id(String.valueOf(sampleId)); middleData.setSample_id(String.valueOf(sampleId));
pushToRedis(middleData); pushToRedis(middleData);
} else {
ErrorLogManager.getInstance().write(new SpectrumErrorEvent(new Date(), phdFile.getAnalyMessage(), this.sampleFilename));
throw new AnalySpectrumException(phdFile.getAnalyMessage());
}
} catch (Exception e){ } catch (Exception e){
e.printStackTrace(); e.printStackTrace();
log.error("Sample_G_Analysis", e); log.error("Sample_G_Analysis", e);
if (e instanceof DuplicateKeyException) { if (e instanceof DuplicateKeyException) {
throw new GAnalyseException("Sample Analyse Error at "+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"), true); 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 { } else {
throw new GAnalyseException("Sample Analyse Error at "+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss")); throw new GAnalyseException("Sample Analyse Error at "+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
} }

View File

@ -7,6 +7,7 @@ import org.jeecg.modules.base.enums.SystemType;
import org.jeecg.modules.eneity.event.SpectrumErrorEvent; import org.jeecg.modules.eneity.event.SpectrumErrorEvent;
import org.jeecg.modules.enums.ErrorType; import org.jeecg.modules.enums.ErrorType;
import org.jeecg.modules.enums.SpectrumSource; import org.jeecg.modules.enums.SpectrumSource;
import org.jeecg.modules.exception.AnalySpectrumException;
import org.jeecg.modules.exception.AnalyseException; import org.jeecg.modules.exception.AnalyseException;
import org.jeecg.modules.exception.GAnalyseException; import org.jeecg.modules.exception.GAnalyseException;
import org.springframework.dao.DuplicateKeyException; import org.springframework.dao.DuplicateKeyException;

View File

@ -15,6 +15,7 @@ import org.jeecg.common.exception.DownloadEmailException;
import org.jeecg.common.util.DateUtils; import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.email.EmailProperties; import org.jeecg.modules.email.EmailProperties;
import org.jeecg.modules.enums.SpectrumSource; import org.jeecg.modules.enums.SpectrumSource;
import org.jeecg.modules.exception.AnalySpectrumException;
import org.jeecg.modules.file.FileOperation; import org.jeecg.modules.file.FileOperation;
import javax.mail.Message; 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); spectrumHandler.init(mailContent.toString(),emlFile.getName(),spectrumServiceQuotes,new StringBuilder(),SpectrumSource.FORM_EMAIL_SERVICE.getSourceType(),batchesCounter);
final boolean matchResult = spectrumHandler.saveEmailToLocal(); final boolean matchResult = spectrumHandler.saveEmailToLocal();
if(matchResult){ if(matchResult){
try {
//开始解析 //开始解析
spectrumHandler.handler(); 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{ }else{
log.warn("This email {} parsing failed and is not listed in the Met, Alert, SOH, Sample, Detbkphd, QC, Gasbkphd spectra.",subject); 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 { }else {
// 如果邮件内容校验失败(邮件内容不完整) 将错误邮件从eml移动到emlError // 如果邮件内容校验失败(邮件内容不完整) 将错误邮件从eml移动到emlError
if (Objects.nonNull(emlFile) && emlFile.exists()){ if (Objects.nonNull(emlFile) && emlFile.exists()){
final String rootPath = spectrumServiceQuotes.getSpectrumPathProperties().getRootPath(); moveEmail(emlFile, key);
final String emlErrorPath = spectrumServiceQuotes.getSpectrumPathProperties().getEmlErrorPath();
final String finalPath = rootPath+emlErrorPath;
FileOperation.moveFile(emlFile,finalPath,true);
// 删除 key防止下次线程执行删除邮件
spectrumServiceQuotes.getRedisUtil().del(key);
throw new DownloadEmailException("邮件移走后手动抛出DownloadEmailException"); throw new DownloadEmailException("邮件移走后手动抛出DownloadEmailException");
} }
} }
@ -187,4 +198,13 @@ public class SpectrumParsingActuator implements Runnable{
return false; 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);
}
} }