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

This commit is contained in:
nieziyan 2023-10-27 10:28:10 +08:00
commit 94ed1907d8
19 changed files with 286 additions and 134 deletions

View File

@ -0,0 +1,131 @@
package org.jeecg.common.util;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import org.jeecg.common.properties.SpectrumPathProperties;
import org.jeecg.common.properties.TaskProperties;
import org.jeecg.modules.base.entity.postgre.SysEmail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Objects;
@Component
public class LogFileUtil {
/**
* 相关Spring组件引用
*/
@Autowired
private SpectrumPathProperties spectrumPathProperties;
public void errorLog(String spectrumFileName, String warning) {
String logFilePath = spectrumPathProperties.getRootPath() + File.separator + spectrumPathProperties.getLogPath() + File.separator + "Error";
File logPath = new File(logFilePath);
if (!logPath.exists()) {
logPath.mkdir();
}
String logFileName = logFilePath + File.separator + spectrumFileName.replace("PHD", "log");
File logFile = new File(logFileName);
StringBuffer out = new StringBuffer();
String nowDate = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");
out.append(nowDate+ StringPool.SPACE + "Data Anlyse Error:");
out.append(warning);
out.append(System.lineSeparator());
out.append(System.lineSeparator());
out.append(System.lineSeparator());
FileWriter writer = null;
try {
writer = new FileWriter(logFile, true);
writer.write(out.toString());
} catch (IOException ex) {
throw new RuntimeException(ex);
} finally {
try {
if (Objects.nonNull(writer)) {
writer.close();
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}
/**
* GSType 区分日志生成是getEmail还是sendEmail的日志 warning是日志内容 state是状态 成功失败 logProccess是当前位于邮箱流程的位置
* @param GSType
* @param email
* @param state
* @param logProcess
*/
public void emailLog(String GSType, SysEmail email, String state, String logProcess) {
String warning = "";
switch (logProcess) {
case "CONNECT":
warning="Connect Server:"+email.getEmailServerAddress()+" Port:"+email.getPort()+" "+state+".....";
break;
case "GETALLID":
warning="Get All FileName "+state+".....";
break;
case "GETIDHEADER":
warning="Get FileNameHeader "+state+".....";
break;
case "GETIDBODY":
warning="Get File "+"FileName"+" FileNameBody "+state+".....";
break;
case "GETIDATTACH":
warning="Get File "+"subject"+" AttachFile "+"FileName"+" "+state+".....";
break;
case "GETIDEML":
warning="Get File "+"subject"+" EmlFile "+"FileName";
break;
case "DELETEID":
warning="Delete File "+"subject"+" "+state+".....";
break;
case "EXPUNGE":
warning="Expunge File "+"subject"+" "+state+".....";
break;
case "DONE":
warning="Done";
break;
default:
break;
}
LocalDateTime now = LocalDateTime.now();
String logFilePath = spectrumPathProperties.getRootPath() + File.separator + spectrumPathProperties.getLogPath() + File.separator + "Mail" + File.separator + GSType + File.separator + now.getYear() + File.separator + now.getMonthValue();
File logPath = new File(logFilePath);
if (!logPath.exists()) {
logPath.mkdirs();
}
String logFileName = logFilePath + File.separator + now.getYear() + StringPool.DASH + now.getMonthValue() + StringPool.DASH + now.getDayOfMonth() + StringPool.UNDERSCORE + "Mail.log";
File logFile = new File(logFileName);
StringBuffer out = new StringBuffer();
String nowDate = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");
out.append(nowDate+ StringPool.SPACE);
out.append(warning);
out.append(System.lineSeparator());
out.append(System.lineSeparator());
out.append(System.lineSeparator());
FileWriter writer = null;
try {
writer = new FileWriter(logFile, true);
writer.write(out.toString());
} catch (IOException ex) {
throw new RuntimeException(ex);
} finally {
try {
if (Objects.nonNull(writer)) {
writer.close();
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}
}

View File

@ -1,64 +0,0 @@
package org.jeecg.common.util;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import org.jeecg.common.properties.SpectrumPathProperties;
import org.jeecg.common.properties.TaskProperties;
import org.jeecg.modules.exception.StationNotFoundException;
import org.jeecg.modules.spectrum.SpectrumServiceQuotes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;
import java.util.Objects;
@Component
public class LogFileUtil {
/**
* 任务属性
*/
@Autowired
private TaskProperties taskProperties;
/**
* 相关Spring组件引用
*/
@Autowired
private SpectrumPathProperties spectrumPathProperties;
public void errorLog(String spectrumFileName, String warning, Exception e) {
String logFilePath = spectrumPathProperties.getRootPath() + File.separator + spectrumPathProperties.getLogPath() + File.separator + "Error";
File logPath = new File(logFilePath);
if (!logPath.exists()) {
logPath.mkdir();
}
String logFileName = logFilePath + File.separator + spectrumFileName.replace("PHD", "log");
File logFile = new File(logFileName);
StringBuffer out = new StringBuffer();
String nowDate = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");
out.append(nowDate+ StringPool.SPACE + "Data Anlyse Error:");
out.append(warning);
out.append(System.lineSeparator());
out.append(System.lineSeparator());
out.append(System.lineSeparator());
FileWriter writer = null;
try {
writer = new FileWriter(logFile, true);
writer.write(out.toString());
} catch (IOException ex) {
throw new RuntimeException(ex);
} finally {
try {
if (Objects.nonNull(writer)) {
writer.close();
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}
}

View File

@ -134,12 +134,13 @@ public class FileSourceHandleManager{
@Override
public void run() {
StringBuilder finalFileName = new StringBuilder();
try {
//获取文件内容
fileContent = FileUtils.readFileToString(spectrumFile,"UTF-8");
//解析文件
AbstractSpectrumHandler spectrumHandler = new SamplephdSpectrum();
spectrumHandler.init(fileContent,spectrumServiceQuotes);
spectrumHandler.init(fileContent,spectrumServiceQuotes,finalFileName);
final boolean matchResult = spectrumHandler.saveEmailToLocal();
if(matchResult){
//开始解析
@ -153,7 +154,7 @@ public class FileSourceHandleManager{
} else {
warning = e.getMessage();
}
spectrumServiceQuotes.getLogFileUtil().errorLog(spectrumFile.getName(), warning, e);
spectrumServiceQuotes.getLogFileUtil().errorLog(finalFileName.toString(), warning);
log.error("Parsing the {} file of the filesource directory failed.The reason is {}",spectrumFile.getName(),e.getMessage());
e.printStackTrace();

View File

@ -135,6 +135,7 @@ public class UndealHandleManager{
@Override
public void run() {
StringBuilder finalFileName = new StringBuilder();
long currentMillis = System.currentTimeMillis();
long createMillis = currentMillis;
//判断redis是否包含文件名称 key
@ -148,7 +149,7 @@ public class UndealHandleManager{
final String fileContent = FileUtils.readFileToString(spectrumFile,"UTF-8");
//解析文件
AbstractSpectrumHandler spectrumHandler = new SamplephdSpectrum();
spectrumHandler.init(fileContent,spectrumServiceQuotes,true);
spectrumHandler.init(fileContent,spectrumServiceQuotes,finalFileName,true);
final boolean matchResult = spectrumHandler.saveEmailToLocal();
if(matchResult){
//开始解析
@ -163,7 +164,7 @@ public class UndealHandleManager{
} else {
warning = e.getMessage();
}
spectrumServiceQuotes.getLogFileUtil().errorLog(spectrumFile.getName(), warning, e);
spectrumServiceQuotes.getLogFileUtil().errorLog(finalFileName.toString(), warning);
log.error("The {} file of the undeal directory fails to be parsed again.The reason is {}",spectrumFile.getName(),e.getMessage());
e.printStackTrace();
}finally {

View File

@ -90,7 +90,7 @@ public abstract class AbstractS_D_Q_G_SpectrumHandler extends AbstractSpectrumHa
@Override
protected void parseingEmail() throws Exception {
final EnergySpectrumStruct sourceData = EnergySpectrumHandler.getSourceData(super.spectrumFile.getAbsolutePath());
if(Objects.isNull(sourceData)){
if(Objects.isNull(sourceData) || StringUtils.isBlank(sourceData.data_type)){
throw new PHD_ReadException("THE PHDFile has some blocks can't be read:"+super.spectrumFile.getAbsolutePath());
}
this.sourceData = sourceData;

View File

@ -3,16 +3,14 @@ package org.jeecg.modules.spectrum;
import cn.hutool.core.io.FileUtil;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomUtils;
import org.jeecg.common.constant.StringConstant;
import org.jeecg.common.properties.SpectrumPathProperties;
import org.jeecg.modules.base.enums.DataType;
import org.jeecg.modules.exception.FileRepeatException;
import org.jeecg.modules.file.FileOperation;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
/**
@ -48,7 +46,10 @@ public abstract class AbstractSpectrumHandler extends AbstractChain {
* 是否来自于undel目录
*/
protected boolean fromUndel = false;
/**
* 返回调用方filesourceundelSpectrumParsingActuator的文件名称
*/
protected StringBuilder returnFileName;
/**
* 保存当前能谱文件有哪些#开头的标签
*/
@ -57,17 +58,19 @@ public abstract class AbstractSpectrumHandler extends AbstractChain {
/**
* 初始化参数
*/
public void init(String mailContent,SpectrumServiceQuotes spectrumServiceQuotes) throws Exception{
public void init(String mailContent,SpectrumServiceQuotes spectrumServiceQuotes,StringBuilder returnFileName) throws Exception{
this.mailContent = mailContent;
this.spectrumServiceQuotes = spectrumServiceQuotes;
this.returnFileName = returnFileName;
}
/**
* 初始化参数
*/
public void init(String mailContent,SpectrumServiceQuotes spectrumServiceQuotes,boolean fromUndel) throws Exception{
public void init(String mailContent,SpectrumServiceQuotes spectrumServiceQuotes,StringBuilder returnFileName,boolean fromUndel) throws Exception{
this.mailContent = mailContent;
this.spectrumServiceQuotes = spectrumServiceQuotes;
this.returnFileName = returnFileName;
this.fromUndel = fromUndel;
}
@ -75,12 +78,13 @@ public abstract class AbstractSpectrumHandler extends AbstractChain {
* 初始化参数
*/
protected void initNext(SpectrumServiceQuotes spectrumServiceQuotes,File spectrumFile,DataType currDataType,
String mailContent,boolean fromUndel){
String mailContent,boolean fromUndel,StringBuilder returnFileName){
this.spectrumServiceQuotes = spectrumServiceQuotes;
this.spectrumFile = spectrumFile;
this.currDataType = currDataType;
this.mailContent = mailContent;
this.fromUndel = fromUndel;
this.returnFileName = returnFileName;
this.setChina();
}
@ -183,8 +187,8 @@ public abstract class AbstractSpectrumHandler extends AbstractChain {
* 处理解析失败的文件上传到undeal目录
* @throws FileNotFoundException
*/
protected void handleParseingFailFile() throws FileNotFoundException {
if(!fromUndel){
protected void handleParseingFailFile(Exception e) throws FileNotFoundException {
if(!fromUndel && !(e instanceof FileRepeatException)){
try {
//解析失败会把文件移动到undeal目录
final String rootPath = spectrumServiceQuotes.getSpectrumPathProperties().getRootPath();
@ -214,13 +218,4 @@ public abstract class AbstractSpectrumHandler extends AbstractChain {
}
}
}
/**
* 删除本地临时文件
*/
protected void deleteLocalTemporaryFile(){
if(Objects.nonNull(spectrumFile) && spectrumFile.isFile() && spectrumFile.exists()){
spectrumFile.delete();
}
}
}

View File

@ -47,7 +47,7 @@ public class AlertSpectrum extends AbstractSpectrumHandler{
protected void setChina() {
AbstractSpectrumHandler spectrumHandler = new HealthStatusSpectrum();
spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile,
super.currDataType,super.mailContent,super.fromUndel);
super.currDataType,super.mailContent,super.fromUndel,super.returnFileName);
spectrumHandler.setPrevious(this);
super.setNext(spectrumHandler);
}
@ -73,6 +73,8 @@ public class AlertSpectrum extends AbstractSpectrumHandler{
//若本次文件来自于undel目录解析成功则删除
deleteIfFromUndelFile();
}catch (Exception e){
//异常返回文件名称用于报错日志
super.returnFileName.append(super.spectrumFile.getName());
throw e;
}finally {
//把流程日志保存到日志目录

View File

@ -2,6 +2,8 @@ package org.jeecg.modules.spectrum;
import org.jeecg.modules.base.enums.DataType;
import org.jeecg.modules.base.enums.SampleStatus;
import org.jeecg.modules.exception.FileRepeatException;
import java.util.Objects;
/**
@ -16,7 +18,7 @@ public class DetbkphdSpectrum extends AbstractS_D_Q_G_SpectrumHandler {
protected void setChina() {
AbstractSpectrumHandler spectrumHandler = new QcphdSpectrum();
spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile,
super.currDataType,super.mailContent,super.fromUndel);
super.currDataType,super.mailContent,super.fromUndel,super.returnFileName);
spectrumHandler.setPrevious(this);
super.setNext(spectrumHandler);
}
@ -48,12 +50,14 @@ public class DetbkphdSpectrum extends AbstractS_D_Q_G_SpectrumHandler {
//若本次文件来自于undel目录解析成功则删除
deleteIfFromUndelFile();
}catch (Exception e){
//异常返回文件名称用于报错日志
super.returnFileName.append(super.spectrumFile.getName());
//修改状态为解析失败
super.status = SampleStatus.FAIL.getValue();
super.updateStatus();
//处理解析失败的文件上传到undeal目录
super.handleParseingFailFile();
super.handleParseingFailFile(e);
throw e;
}finally {
if(Objects.nonNull(this.parsingProcessLog)){

View File

@ -3,6 +3,8 @@ package org.jeecg.modules.spectrum;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.base.enums.DataType;
import org.jeecg.modules.base.enums.SampleStatus;
import org.jeecg.modules.exception.FileRepeatException;
import java.util.Objects;
/**
@ -18,7 +20,7 @@ public class GasbkphdSpectrum extends AbstractS_D_Q_G_SpectrumHandler {
protected void setChina() {
AbstractSpectrumHandler spectrumHandler = new MetSpectrum();
spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile,
super.currDataType,super.mailContent,super.fromUndel);
super.currDataType,super.mailContent,super.fromUndel,super.returnFileName);
spectrumHandler.setPrevious(this);
super.setNext(spectrumHandler);
}
@ -50,12 +52,14 @@ public class GasbkphdSpectrum extends AbstractS_D_Q_G_SpectrumHandler {
//若本次文件来自于undel目录解析成功则删除
deleteIfFromUndelFile();
}catch (Exception e){
//异常返回文件名称用于报错日志
super.returnFileName.append(super.spectrumFile.getName());
//修改状态为解析失败
super.status = SampleStatus.FAIL.getValue();
super.updateStatus();
//处理解析失败的文件上传到undeal目录
super.handleParseingFailFile();
super.handleParseingFailFile(e);
throw e;
}finally {
if(Objects.nonNull(this.parsingProcessLog)){

View File

@ -59,18 +59,24 @@ public class HealthStatusSpectrum extends AbstractSpectrumHandler{
@Override
public void handler() throws Exception {
if(DataType.SOH.getType().equals(super.currDataType.getType())){
//打印当前处理的能谱类型
super.printCurrDataType();
//解析邮件内容
this.parseingEmail();
//保存PHD文件到savefile
super.saveFileToSavefile();
//结构体数据入库
this.handlerOriginalData();
//把流程日志保存到日志目录
this.saveLogToLogDir();
//若本次文件来自于undel目录解析成功则删除
deleteIfFromUndelFile();
try {
//打印当前处理的能谱类型
super.printCurrDataType();
//解析邮件内容
this.parseingEmail();
//保存PHD文件到savefile
super.saveFileToSavefile();
//结构体数据入库
this.handlerOriginalData();
//把流程日志保存到日志目录
this.saveLogToLogDir();
//若本次文件来自于undel目录解析成功则删除
deleteIfFromUndelFile();
}catch (Exception e){
//异常返回文件名称用于报错日志
super.returnFileName.append(super.spectrumFile.getName());
throw e;
}
}
}

View File

@ -43,7 +43,7 @@ public class MetSpectrum extends AbstractSpectrumHandler{
protected void setChina() {
AbstractSpectrumHandler spectrumHandler = new AlertSpectrum();
spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile,
super.currDataType,super.mailContent,super.fromUndel);
super.currDataType,super.mailContent,super.fromUndel,super.returnFileName);
spectrumHandler.setPrevious(this);
super.setNext(spectrumHandler);
}
@ -54,18 +54,24 @@ public class MetSpectrum extends AbstractSpectrumHandler{
@Override
public void handler() throws Exception {
if(DataType.MET.getType().equals(super.currDataType.getType())){
//打印当前处理的能谱类型
super.printCurrDataType();
//解析邮件内容
this.parseingEmail();
//保存PHD文件到savefile
super.saveFileToSavefile();
//结构体数据入库
this.handlerOriginalData();
//把流程日志保存到日志目录
this.saveLogToLogDir();
//若本次文件来自于undel目录解析成功则删除
deleteIfFromUndelFile();
try {
//打印当前处理的能谱类型
super.printCurrDataType();
//解析邮件内容
this.parseingEmail();
//保存PHD文件到savefile
super.saveFileToSavefile();
//结构体数据入库
this.handlerOriginalData();
//把流程日志保存到日志目录
this.saveLogToLogDir();
//若本次文件来自于undel目录解析成功则删除
deleteIfFromUndelFile();
}catch (Exception e){
//异常返回文件名称用于报错日志
super.returnFileName.append(super.spectrumFile.getName());
throw e;
}
}else{
super.next.handler();
}

View File

@ -741,6 +741,23 @@ public class ParsingProcessLog extends AbstractAutoLogOrReport{
}
}
/**
* 前置检查
*/
private boolean preCheck(){
boolean flag = true;
if(Objects.isNull(spectrumHandler)){
flag = false;
}
if(Objects.isNull(spectrumHandler.startIntoDatabaseTime) || Objects.isNull(spectrumHandler.endIntoDatabaseTime)){
flag = false;
}
if(Objects.isNull(spectrumHandler.sampleData)){
flag = false;
}
return flag;
}
/**
* 处理存储流程日志
* @return
@ -763,6 +780,10 @@ public class ParsingProcessLog extends AbstractAutoLogOrReport{
* 处理所有日志
*/
protected void handleLog() throws IOException {
//生成日志前置检查
if(this.preCheck() == false){
return;
}
this.handleStorageProcessLog();
if(DataType.SAMPLEPHD.getType().equals(this.spectrumHandler.currDataType.getType()) &&
this.spectrumHandler.sourceData.system_type.equals(SystemType.BETA.getType()) &&

View File

@ -2,6 +2,8 @@ package org.jeecg.modules.spectrum;
import org.jeecg.modules.base.enums.DataType;
import org.jeecg.modules.base.enums.SampleStatus;
import org.jeecg.modules.exception.FileRepeatException;
import java.util.Objects;
/**
@ -16,7 +18,7 @@ public class QcphdSpectrum extends AbstractS_D_Q_G_SpectrumHandler {
protected void setChina() {
AbstractSpectrumHandler spectrumHandler = new GasbkphdSpectrum();
spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile,
super.currDataType,super.mailContent,super.fromUndel);
super.currDataType,super.mailContent,super.fromUndel,super.returnFileName);
spectrumHandler.setPrevious(this);
super.setNext(spectrumHandler);
}
@ -49,12 +51,14 @@ public class QcphdSpectrum extends AbstractS_D_Q_G_SpectrumHandler {
//若本次文件来自于undel目录解析成功则删除
deleteIfFromUndelFile();
}catch (Exception e){
//异常返回文件名称用于报错日志
super.returnFileName.append(super.spectrumFile.getName());
//修改状态为解析失败
super.status = SampleStatus.FAIL.getValue();
super.updateStatus();
//处理解析失败的文件上传到undeal目录
super.handleParseingFailFile();
super.handleParseingFailFile(e);
throw e;
}finally {
if(Objects.nonNull(this.parsingProcessLog)){

View File

@ -200,8 +200,8 @@ public class Sample_B_Analysis implements BlockConstant {
final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties();
//构造报告文件路径
StringBuilder relativePath = new StringBuilder();
relativePath.append(properties.getSaveFilePath());
relativePath.append(File.separator);
// relativePath.append(properties.getSaveFilePath());
// relativePath.append(File.separator);
relativePath.append(properties.getArrPath());
relativePath.append(File.separator);
relativePath.append(this.spectrumFileRelativePath);
@ -792,6 +792,8 @@ public class Sample_B_Analysis implements BlockConstant {
StringBuilder finalReportPath = new StringBuilder();
finalReportPath.append(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath());
finalReportPath.append(File.separator);
finalReportPath.append(spectrumServiceQuotes.getSpectrumPathProperties().getSaveFilePath());
finalReportPath.append(File.separator);
finalReportPath.append(arrFilePath);
finalReportPath.append(File.separator);
finalReportPath.append(arrFileName);

View File

@ -3,6 +3,8 @@ package org.jeecg.modules.spectrum;
import org.jeecg.modules.base.enums.DataType;
import org.jeecg.modules.base.enums.SampleStatus;
import org.jeecg.modules.base.enums.SystemType;
import org.jeecg.modules.exception.FileRepeatException;
import java.util.Objects;
/**
@ -17,7 +19,7 @@ public class SamplephdSpectrum extends AbstractS_D_Q_G_SpectrumHandler {
protected void setChina() {
AbstractSpectrumHandler spectrumHandler = new DetbkphdSpectrum();
spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile,
super.currDataType,super.mailContent,super.fromUndel);
super.currDataType,super.mailContent,super.fromUndel,super.returnFileName);
spectrumHandler.setPrevious(this);
super.setNext(spectrumHandler);
}
@ -52,12 +54,14 @@ public class SamplephdSpectrum extends AbstractS_D_Q_G_SpectrumHandler {
//若本次文件来自于undel目录解析成功则删除
deleteIfFromUndelFile();
}catch (Exception e){
//异常返回文件名称用于报错日志
super.returnFileName.append(super.spectrumFile.getName());
//修改状态为解析失败
super.status = SampleStatus.FAIL.getValue();
super.updateStatus();
//处理解析失败的文件上传到undeal目录
super.handleParseingFailFile();
super.handleParseingFailFile(e);
throw e;
}finally {
if(Objects.nonNull(this.parsingProcessLog)){

View File

@ -1,5 +1,6 @@
package org.jeecg.modules.spectrum;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.constant.StringConstant;
@ -7,6 +8,7 @@ import org.jeecg.common.email.EmailServiceManager;
import org.jeecg.common.properties.SpectrumPathProperties;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.email.EmailProperties;
import org.jeecg.modules.exception.StationNotFoundException;
import javax.mail.Message;
import javax.mail.MessagingException;
@ -80,19 +82,21 @@ public class SpectrumParsingActuator implements Runnable{
StringBuilder mailContent = null;
String sendTime = null;
String receiveTime = null;
StringBuilder finalFileName = new StringBuilder();
try {
subject = MimeUtility.decodeText(message.getSubject());
sendTime = DateUtils.formatDate(message.getSentDate(),"yyyy-MM-dd HH:mm:ss");
receiveTime = DateUtils.formatDate(message.getReceivedDate(),"yyyy-MM-dd HH:mm:ss");
System.out.println(subject);
mailContent = new StringBuilder();
emailServiceManager.getMailContent(message,mailContent);
//读取文件内容成功后写入日志
spectrumServiceQuotes.getLogFileUtil().emailLog("Get", emailProperties, "Successful", "GETALLID");
//所有邮件都需以.eml格式存储到eml文件夹中
downloadEmailToEmlDir();
//判断是否是IMS2.0协议文件
if(checkMailContent(mailContent,subject)){
AbstractSpectrumHandler spectrumHandler = new SamplephdSpectrum();
spectrumHandler.init(mailContent.toString(),spectrumServiceQuotes);
spectrumHandler.init(mailContent.toString(),spectrumServiceQuotes,finalFileName);
final boolean matchResult = spectrumHandler.saveEmailToLocal();
if(matchResult){
//保存邮件解析日志到PG数据库
@ -104,6 +108,17 @@ public class SpectrumParsingActuator implements Runnable{
}
}
} catch (Exception e) {
if (e.getClass().equals(MessagingException.class)) {
spectrumServiceQuotes.getLogFileUtil().emailLog("Get", emailProperties, "Error", "GETALLID");
}
//生成日志
String warning = "";
if (e.getClass().equals(StationNotFoundException.class)) {
warning = e.getMessage()+ StringPool.SPACE+"timeout:0,waittime:"+spectrumServiceQuotes.getTaskProperties().getUndealFileTimeOut();
} else {
warning = e.getMessage();
}
spectrumServiceQuotes.getLogFileUtil().errorLog(finalFileName.toString(), warning);
log.error("This email failed to parse. The email subject is: {}, sent on: {}, received on: {}, and the reason for the failure is: {}",subject,sendTime,receiveTime,e.getMessage());
e.printStackTrace();
}finally {

View File

@ -1540,6 +1540,16 @@ public class GammaFileUtil extends AbstractLogOrReport {
ParameterInfo value = JSON.parseObject(JSON.toJSONString(entry.getValue()), ParameterInfo.class);
phd.setUsedTotEPara(value);
}
if (entry.getKey().equalsIgnoreCase("mapNucActMda")) {
HashMap<String, Object> jsonMap = JSON.parseObject(JSON.toJSONString(entry.getValue()), HashMap.class);
Map<String, NuclideActMda> value = new HashMap<>();
for (Map.Entry<String, Object> objectEntry:jsonMap.entrySet()) {
String key = objectEntry.getKey();
NuclideActMda entryValue = JSON.parseObject(JSON.toJSONString(objectEntry.getValue()), NuclideActMda.class);
value.put(key, entryValue);
}
phd.setMapNucActMda(value);
}
}
BeanUtils.copyProperties(phd.getSetting(), phd.getUsedSetting());
@ -2305,9 +2315,9 @@ public class GammaFileUtil extends AbstractLogOrReport {
map.put("AllData", datalist);
}
public String GetReportContent(PHDFile phd, boolean bLog) {
public String GetReportContent(PHDFile phd, String userName, boolean bLog) {
GStoreMiddleProcessData middleData = new GStoreMiddleProcessData();
GetInterMiddlData(phd, "", middleData);
GetInterMiddlData(phd, userName, middleData);
if(bLog) {
return GetLogContent(middleData);
} else {

View File

@ -83,14 +83,15 @@ public class GardsNuclLinesLibServiceImpl extends ServiceImpl<GardsNuclLinesLibM
int keyFlag = lib.getKeyFlag();
if (keyFlag > 0){
nuclideLines.setKey_flag(i);
nuclideLines.setMaxYeildIdx(i);
int index = nuclideNames.indexOf(lib.getName());
nuclideLines.setKey_flag(index);
nuclideLines.setMaxYeildIdx(index);
}
String name = lib.getName();
Double day = halfLife.get(name);
if (ObjectUtil.isNotNull(day))
lib.setHalflife(day * 86400);
nuclideLines.setHalflife(day * 86400);
result.put(lib.getName(), nuclideLines);
}

View File

@ -463,6 +463,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
map.put("dead_time", String.format("%.2f", deadTime*100));
map.put("checkBox_updateCal", phd.getSetting().isBUpdateCal());
map.put("bAnalyed", phd.isBAnalyed());
map.put("peak", phd.getVPeak());
// 更新页面折线图信息
gammaFileUtil.UpdateChart(phd, map, colorMap);
//将当前加载的phd信息加入到缓存中 文件名称作为缓存信息的key
@ -800,6 +801,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
map.put("dead_time", String.format("%.2f", deadTime*100));
map.put("checkBox_updateCal", phd.getSetting().isBUpdateCal());
map.put("bAnalyed", phd.isBAnalyed());
map.put("peak", phd.getVPeak());
gammaFileUtil.UpdateChart(phd, map, colorMap);
phdCache.put(fileName+"-"+userName, phd);
localCache.setPHDCache(phdCache);
@ -996,13 +998,14 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
Map<String, NuclideLines> nuclideLinesMap = GetNuclideLines(nuclides);
gammaFileUtil.AnalyseSpectrum(phd, nuclideLinesMap);
//重新分析各峰值对应的核素信息
gammaFileUtil.NuclidesIdent(phd, nuclideLinesMap);
// gammaFileUtil.NuclidesIdent(phd, nuclideLinesMap);
Map<String, Object> map = new HashMap<>();
gammaFileUtil.UpdateChart(phd, map, colorMap);
// 更新 QC Flags 状态
List<String> qcstate = gammaFileUtil.Qcstate(phd);
map.put("QCFlag", qcstate);
map.put("bAnalyed", phd.isBAnalyed());
map.put("peak", phd.getVPeak());
result.setSuccess(true);
result.setResult(map);
}
@ -3502,6 +3505,9 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
public void viewARR(Integer sampleId, HttpServletResponse response) {
//获取自动处理生成的报告地址
String reportPath = spectrumAnalysisMapper.viewARR(sampleId);
if (StringUtils.isBlank(reportPath)){
throw new RuntimeException("自动处理程序生成报告不存在!");
}
String pathName = StringPool.SLASH + spectrumPathProperties.getSaveFilePath() + StringPool.SLASH + reportPath.substring(0, reportPath.lastIndexOf(StringPool.SLASH));
String fileName = reportPath.substring(reportPath.lastIndexOf(StringPool.SLASH)+1)+".txt";
//连接ftp
@ -3612,7 +3618,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
result.error500("Please select the parse file first");
return result;
}
String reportContent = gammaFileUtil.GetReportContent(phd, false);
String reportContent = gammaFileUtil.GetReportContent(phd, userName, false);
result.setSuccess(true);
result.setResult(reportContent);
return result;
@ -3626,7 +3632,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
if (Objects.isNull(phd)) {
return;
}
String reportContent = gammaFileUtil.GetReportContent(phd, false);
String reportContent = gammaFileUtil.GetReportContent(phd, userName, false);
OutputStream fos = null;
try {
//设置响应类型
@ -4090,6 +4096,9 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
@Override
public void viewAutomaticAnalysisLog(Integer sampleId, HttpServletResponse response) {
String logPath = spectrumAnalysisMapper.findAutomaticLogPath(sampleId);
if (StringUtils.isBlank(logPath)){
throw new RuntimeException("自动处理程序生成日志不存在!");
}
String pathName = StringPool.SLASH + spectrumPathProperties.getLogPath() + StringPool.SLASH + logPath.substring(0, logPath.lastIndexOf(StringPool.SLASH));
String fileName = logPath.substring(logPath.lastIndexOf(StringPool.SLASH) + 1);
//连接ftp
@ -4146,7 +4155,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
result.error500("Please select the parse file first");
return result;
}
String reportContent = gammaFileUtil.GetReportContent(phd, true);
String reportContent = gammaFileUtil.GetReportContent(phd, userName, true);
result.setSuccess(true);
result.setResult(reportContent);
return result;