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,30 +175,37 @@ 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());
// 生成日志文件 // 生成日志文件
writeLog(middleData.getAnalyses_LogPath(), middleData); writeLog(middleData.getAnalyses_LogPath(), middleData);
// 生成报告文件 // 生成报告文件
String reportContent = gammaFileUtil.GetReportContent(middleData); String reportContent = gammaFileUtil.GetReportContent(middleData);
String reportPath = StringUtils.substringBeforeLast(middleData.getAnalyses_ReportPath(), StringPool.SLASH); String reportPath = StringUtils.substringBeforeLast(middleData.getAnalyses_ReportPath(), StringPool.SLASH);
String reportName = StringUtils.substringAfterLast(middleData.getAnalyses_ReportPath(), StringPool.SLASH) + ".txt"; String reportName = StringUtils.substringAfterLast(middleData.getAnalyses_ReportPath(), StringPool.SLASH) + ".txt";
String savePath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + File.separator + reportPath + String savePath = spectrumPathProperties.getRootPath() + spectrumPathProperties.getSaveFilePath() + File.separator + reportPath +
File.separator + reportName; File.separator + reportName;
// 保存文件 // 保存文件
FileOperation.saveOrAppendFile(savePath, reportContent, false); FileOperation.saveOrAppendFile(savePath, reportContent, false);
//发送数据到redis //发送数据到redis
middleData.setSample_id(String.valueOf(sampleId)); middleData.setSample_id(String.valueOf(sampleId));
pushToRedis(middleData); pushToRedis(middleData);
}catch (Exception e){ } else {
ErrorLogManager.getInstance().write(new SpectrumErrorEvent(new Date(), phdFile.getAnalyMessage(), this.sampleFilename));
throw new AnalySpectrumException(phdFile.getAnalyMessage());
}
} 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);
}
} }