Merge remote-tracking branch 'origin/station' into station
This commit is contained in:
commit
5f7cc6be38
|
@ -39,7 +39,12 @@ public class SpectrumPathProperties implements Serializable {
|
|||
/**
|
||||
* 用户上传文件路径
|
||||
*/
|
||||
private String uploadPath;
|
||||
private String uploadPath;;
|
||||
|
||||
/**
|
||||
* 能谱解析失败文件存储路径
|
||||
*/
|
||||
private String failPath;
|
||||
|
||||
/**
|
||||
* 能谱文件存储路径以能谱系统类型/能谱类型为key,以存储路径为value
|
||||
|
|
|
@ -124,13 +124,46 @@ public class FTPUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* 写入文件,若文件或文件目录不存在则自行创建
|
||||
* 写入文件,若文件或文件目录不存在则自行创建,存在先删除再创建
|
||||
* @param filePath 文件路径
|
||||
* @param fileName 文件名称
|
||||
* @param inputStream 文件输入流
|
||||
* @return 返回值true/false
|
||||
*/
|
||||
public boolean saveFile(String filePath,String fileName,InputStream inputStream){
|
||||
try{
|
||||
final boolean flag = this.checkDirectory(filePath);
|
||||
if(flag){
|
||||
final FTPFile[] ftpFiles = this.client.listFiles(fileName);
|
||||
if(ArrayUtils.isNotEmpty(ftpFiles)){
|
||||
client.deleteFile(fileName);
|
||||
}
|
||||
return client.storeFile(fileName, inputStream);
|
||||
}
|
||||
}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();
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入文件,若文件或文件目录不存在则自行创建,存在则追加内容
|
||||
* @param filePath 文件路径
|
||||
* @param fileName 文件名称
|
||||
* @param inputStream 文件输入流
|
||||
* @return 返回值true/false
|
||||
*/
|
||||
public boolean saveOrAppendFile(String filePath,String fileName,InputStream inputStream){
|
||||
try{
|
||||
final boolean flag = this.checkDirectory(filePath);
|
||||
if(flag){
|
||||
|
|
|
@ -45,7 +45,7 @@ public class AlertSpectrum extends SpectrumHandler{
|
|||
protected void setChina() {
|
||||
SpectrumHandler spectrumHandler = new HealthStatusSpectrum();
|
||||
spectrumHandler.initNext(super.spectrumServiceQuotes,super.mailFile,
|
||||
super.currDataType,super.message,super.emailProperties,super.ftpUtil,super.mailContent);
|
||||
super.currDataType,super.ftpUtil,super.mailContent);
|
||||
spectrumHandler.setPrevious(this);
|
||||
super.setNext(spectrumHandler);
|
||||
}
|
||||
|
@ -67,8 +67,6 @@ public class AlertSpectrum extends SpectrumHandler{
|
|||
this.saveFileToFtp();
|
||||
//结构体数据入库
|
||||
this.handlerOriginalData();
|
||||
//保存email日志
|
||||
super.saveEmailLog();
|
||||
//删除本地临时文件
|
||||
super.deleteLocalTemporaryFile();
|
||||
//把流程日志写入ftp日志文件
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.jeecg.modules.spectrum;
|
|||
|
||||
|
||||
import org.jeecg.modules.base.enums.DataType;
|
||||
import org.jeecg.modules.base.enums.SampleStatus;
|
||||
|
||||
/**
|
||||
* 探测器本地谱处理
|
||||
|
@ -15,7 +16,7 @@ public class DetbkphdSpectrum extends S_D_Q_G_SpectrumHandler{
|
|||
protected void setChina() {
|
||||
SpectrumHandler spectrumHandler = new QcphdSpectrum();
|
||||
spectrumHandler.initNext(super.spectrumServiceQuotes,super.mailFile,
|
||||
super.currDataType,super.message,super.emailProperties,super.ftpUtil,super.mailContent);
|
||||
super.currDataType,super.ftpUtil,super.mailContent);
|
||||
spectrumHandler.setPrevious(this);
|
||||
super.setNext(spectrumHandler);
|
||||
}
|
||||
|
@ -26,24 +27,31 @@ public class DetbkphdSpectrum extends S_D_Q_G_SpectrumHandler{
|
|||
@Override
|
||||
protected void handler() throws Exception {
|
||||
if(DataType.DETBKPHD.getType().equals(super.currDataType.getType())){
|
||||
//前置检查
|
||||
this.preCheck();
|
||||
//打印当前处理的能谱类型
|
||||
super.printCurrDataType();
|
||||
//解析邮件内容
|
||||
super.parseingEmail();
|
||||
//读取邮件内容标签
|
||||
super.readFileLabel();
|
||||
//保存PHD文件到ftp
|
||||
super.saveFileToFtp();
|
||||
//结构体数据入库
|
||||
super.handlerOriginalData();
|
||||
//保存email日志
|
||||
super.saveEmailLog();
|
||||
//删除本地临时文件
|
||||
super.deleteLocalTemporaryFile();
|
||||
//把流程日志写入ftp日志文件
|
||||
super.saveLogToFtp();
|
||||
try{
|
||||
//前置检查
|
||||
this.preCheck();
|
||||
//打印当前处理的能谱类型
|
||||
super.printCurrDataType();
|
||||
//解析邮件内容
|
||||
super.parseingEmail();
|
||||
//读取邮件内容标签
|
||||
super.readFileLabel();
|
||||
//保存PHD文件到ftp
|
||||
super.saveFileToFtp();
|
||||
//结构体数据入库
|
||||
super.handlerOriginalData();
|
||||
//把流程日志写入ftp日志文件
|
||||
super.saveLogToFtp();
|
||||
}catch (Exception e){
|
||||
//修改状态为解析失败
|
||||
this.spectrumServiceQuotes.getSampleDataService().updateStatus(SampleStatus.FAIL.getValue(),super.sampleData.getInputFileName());
|
||||
//处理解析失败的文件,上传到ftp->undeal目录
|
||||
super.handleParseingFailFile();
|
||||
throw e;
|
||||
}finally {
|
||||
//删除本地临时文件
|
||||
super.deleteLocalTemporaryFile();
|
||||
}
|
||||
}else{
|
||||
super.next.handler();
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.jeecg.modules.spectrum;
|
|||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.modules.base.enums.DataType;
|
||||
import org.jeecg.modules.base.enums.SampleStatus;
|
||||
|
||||
/**
|
||||
* 气体谱处理
|
||||
|
@ -16,7 +17,7 @@ public class GasbkphdSpectrum extends S_D_Q_G_SpectrumHandler{
|
|||
protected void setChina() {
|
||||
SpectrumHandler spectrumHandler = new MetSpectrum();
|
||||
spectrumHandler.initNext(super.spectrumServiceQuotes,super.mailFile,
|
||||
super.currDataType,super.message,super.emailProperties,super.ftpUtil,super.mailContent);
|
||||
super.currDataType,super.ftpUtil,super.mailContent);
|
||||
spectrumHandler.setPrevious(this);
|
||||
super.setNext(spectrumHandler);
|
||||
}
|
||||
|
@ -27,24 +28,31 @@ public class GasbkphdSpectrum extends S_D_Q_G_SpectrumHandler{
|
|||
@Override
|
||||
protected void handler() throws Exception {
|
||||
if(DataType.GASBKPHD.getType().equals(super.currDataType.getType())){
|
||||
//前置检查
|
||||
this.preCheck();
|
||||
//打印当前处理的能谱类型
|
||||
super.printCurrDataType();
|
||||
//解析邮件内容
|
||||
super.parseingEmail();
|
||||
//读取邮件内容标签
|
||||
super.readFileLabel();
|
||||
//保存PHD文件到ftp
|
||||
super.saveFileToFtp();
|
||||
//结构体数据入库
|
||||
super.handlerOriginalData();
|
||||
//保存email日志
|
||||
super.saveEmailLog();
|
||||
//删除本地临时文件
|
||||
super.deleteLocalTemporaryFile();
|
||||
//把流程日志写入ftp日志文件
|
||||
super.saveLogToFtp();
|
||||
try{
|
||||
//前置检查
|
||||
this.preCheck();
|
||||
//打印当前处理的能谱类型
|
||||
super.printCurrDataType();
|
||||
//解析邮件内容
|
||||
super.parseingEmail();
|
||||
//读取邮件内容标签
|
||||
super.readFileLabel();
|
||||
//保存PHD文件到ftp
|
||||
super.saveFileToFtp();
|
||||
//结构体数据入库
|
||||
super.handlerOriginalData();
|
||||
//把流程日志写入ftp日志文件
|
||||
super.saveLogToFtp();
|
||||
}catch (Exception e){
|
||||
//修改状态为解析失败
|
||||
this.spectrumServiceQuotes.getSampleDataService().updateStatus(SampleStatus.FAIL.getValue(),super.sampleData.getInputFileName());
|
||||
//处理解析失败的文件,上传到ftp->undeal目录
|
||||
super.handleParseingFailFile();
|
||||
throw e;
|
||||
}finally {
|
||||
//删除本地临时文件
|
||||
super.deleteLocalTemporaryFile();
|
||||
}
|
||||
}else{
|
||||
super.next.handler();
|
||||
}
|
||||
|
|
|
@ -68,8 +68,6 @@ public class HealthStatusSpectrum extends SpectrumHandler{
|
|||
this.saveFileToFtp();
|
||||
//结构体数据入库
|
||||
this.handlerOriginalData();
|
||||
//保存email日志
|
||||
super.saveEmailLog();
|
||||
//删除本地临时文件
|
||||
super.deleteLocalTemporaryFile();
|
||||
//把流程日志写入ftp日志文件
|
||||
|
|
|
@ -46,7 +46,7 @@ public class MetSpectrum extends SpectrumHandler{
|
|||
protected void setChina() {
|
||||
SpectrumHandler spectrumHandler = new AlertSpectrum();
|
||||
spectrumHandler.initNext(super.spectrumServiceQuotes,super.mailFile,
|
||||
super.currDataType,super.message,super.emailProperties,super.ftpUtil,super.mailContent);
|
||||
super.currDataType,super.ftpUtil,super.mailContent);
|
||||
spectrumHandler.setPrevious(this);
|
||||
super.setNext(spectrumHandler);
|
||||
}
|
||||
|
@ -65,8 +65,6 @@ public class MetSpectrum extends SpectrumHandler{
|
|||
this.saveFileToFtp();
|
||||
//结构体数据入库
|
||||
this.handlerOriginalData();
|
||||
//保存email日志
|
||||
super.saveEmailLog();
|
||||
//删除本地临时文件
|
||||
super.deleteLocalTemporaryFile();
|
||||
//把流程日志写入ftp日志文件
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.jeecg.modules.spectrum;
|
||||
|
||||
import org.jeecg.modules.base.enums.DataType;
|
||||
import org.jeecg.modules.base.enums.SampleStatus;
|
||||
|
||||
/**
|
||||
* QC谱处理
|
||||
|
@ -14,7 +15,7 @@ public class QcphdSpectrum extends S_D_Q_G_SpectrumHandler{
|
|||
protected void setChina() {
|
||||
SpectrumHandler spectrumHandler = new GasbkphdSpectrum();
|
||||
spectrumHandler.initNext(super.spectrumServiceQuotes,super.mailFile,
|
||||
super.currDataType,super.message,super.emailProperties,super.ftpUtil,super.mailContent);
|
||||
super.currDataType,super.ftpUtil,super.mailContent);
|
||||
spectrumHandler.setPrevious(this);
|
||||
super.setNext(spectrumHandler);
|
||||
}
|
||||
|
@ -26,24 +27,31 @@ public class QcphdSpectrum extends S_D_Q_G_SpectrumHandler{
|
|||
protected void handler() throws Exception {
|
||||
//判断当前邮件内容是否是QC谱
|
||||
if(DataType.QCPHD.getType().equals(super.currDataType.getType())){
|
||||
//前置检查
|
||||
this.preCheck();
|
||||
//打印当前处理的能谱类型
|
||||
super.printCurrDataType();
|
||||
//解析邮件内容
|
||||
super.parseingEmail();
|
||||
//读取邮件内容标签
|
||||
super.readFileLabel();
|
||||
//保存PHD文件到ftp
|
||||
super.saveFileToFtp();
|
||||
//结构体数据入库
|
||||
super.handlerOriginalData();
|
||||
//保存email日志
|
||||
super.saveEmailLog();
|
||||
//删除本地临时文件
|
||||
super.deleteLocalTemporaryFile();
|
||||
//把流程日志写入ftp日志文件
|
||||
super.saveLogToFtp();
|
||||
try{
|
||||
//前置检查
|
||||
this.preCheck();
|
||||
//打印当前处理的能谱类型
|
||||
super.printCurrDataType();
|
||||
//解析邮件内容
|
||||
super.parseingEmail();
|
||||
//读取邮件内容标签
|
||||
super.readFileLabel();
|
||||
//保存PHD文件到ftp
|
||||
super.saveFileToFtp();
|
||||
//结构体数据入库
|
||||
super.handlerOriginalData();
|
||||
//把流程日志写入ftp日志文件
|
||||
super.saveLogToFtp();
|
||||
}catch (Exception e){
|
||||
//修改状态为解析失败
|
||||
this.spectrumServiceQuotes.getSampleDataService().updateStatus(SampleStatus.FAIL.getValue(),super.sampleData.getInputFileName());
|
||||
//处理解析失败的文件,上传到ftp->undeal目录
|
||||
super.handleParseingFailFile();
|
||||
throw e;
|
||||
}finally {
|
||||
//删除本地临时文件
|
||||
super.deleteLocalTemporaryFile();
|
||||
}
|
||||
}else{
|
||||
super.next.handler();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.jeecg.modules.spectrum;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.util.Strings;
|
||||
|
@ -35,6 +36,7 @@ import java.util.Objects;
|
|||
/**
|
||||
* 样品谱(Samplephd)、探测器本地谱(Detbkphd)、QC谱(Qcphd)、气体谱(Gasbkphd)
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class S_D_Q_G_SpectrumHandler extends SpectrumHandler{
|
||||
|
||||
/**
|
||||
|
@ -202,11 +204,14 @@ public abstract class S_D_Q_G_SpectrumHandler extends SpectrumHandler{
|
|||
*/
|
||||
@Override
|
||||
protected void handlerOriginalData() throws Exception {
|
||||
this.startIntoDatabaseTime = new Date();
|
||||
//如果数据已经存储,不在重复存储
|
||||
final boolean exist = spectrumServiceQuotes.getSampleDataService().fileExist(super.ftpSavePath);
|
||||
if(exist){
|
||||
throw new FileRepeatException("file repeat");
|
||||
this.endIntoDatabaseTime = new Date();
|
||||
log.warn("{} file data has been stored",super.mailFile.getName());
|
||||
return;
|
||||
}
|
||||
this.startIntoDatabaseTime = new Date();
|
||||
DataSourceSwitcher.switchToOracle();
|
||||
final TransactionStatus transactionStatus = spectrumServiceQuotes.getTransactionManager().getTransaction(spectrumServiceQuotes.getTransactionDefinition());
|
||||
try{
|
||||
|
@ -266,7 +271,7 @@ public abstract class S_D_Q_G_SpectrumHandler extends SpectrumHandler{
|
|||
this.logFilePath = properties.getLogPath()+StringConstant.SLASH+this.getFileSavePath();
|
||||
this.logFileName = super.mailFile.getName().replace(this.currDataType.getSuffix(),LOG_FILE_SUFFIX);
|
||||
|
||||
super.ftpUtil.saveFile(logFilePath,logFileName,new ByteArrayInputStream(logContent.toString().getBytes(StandardCharsets.UTF_8)));
|
||||
super.ftpUtil.saveOrAppendFile(logFilePath,logFileName,new ByteArrayInputStream(logContent.toString().getBytes(StandardCharsets.UTF_8)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.jeecg.modules.spectrum;
|
|||
import cn.hutool.core.io.FileUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import io.swagger.models.auth.In;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.RandomUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -36,6 +37,7 @@ import java.util.stream.Collectors;
|
|||
/**
|
||||
* B谱分析过程
|
||||
*/
|
||||
@Slf4j
|
||||
public class Sample_B_Analysis implements BlockConstant {
|
||||
|
||||
/**
|
||||
|
@ -141,8 +143,8 @@ public class Sample_B_Analysis implements BlockConstant {
|
|||
/**
|
||||
* 执行解析过程
|
||||
*/
|
||||
public void start(){
|
||||
try {
|
||||
public void start() throws BAnalyseException {
|
||||
try{
|
||||
//修改状态为解析中
|
||||
this.updateStatus(SampleStatus.IN_PROCESS.getValue());
|
||||
//查询det、gas数据(sampleId,inputFileName),sample数据在构造函数已经传过来
|
||||
|
@ -158,15 +160,19 @@ public class Sample_B_Analysis implements BlockConstant {
|
|||
//生成报告
|
||||
Sample_B_Analysis.B_AnalysisReport report = new Sample_B_Analysis.B_AnalysisReport();
|
||||
report.start();
|
||||
//删除下载的det和gas临时文件
|
||||
this.deleteLocalTemporaryFile();
|
||||
//修改状态为解析成功
|
||||
this.updateStatus(SampleStatus.COMPLETE.getValue());
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
throw new BAnalyseException("Sample Analyse Error at "+DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
|
||||
}finally {
|
||||
//删除下载的det和gas临时文件
|
||||
this.deleteLocalTemporaryFile();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改状态为解析中
|
||||
* 修改状态
|
||||
* @param analysesStatus
|
||||
*/
|
||||
private void updateStatus(String analysesStatus){
|
||||
|
@ -270,6 +276,12 @@ public class Sample_B_Analysis implements BlockConstant {
|
|||
private void storageDataToDatabase(){
|
||||
String logFileRelativePath = this.logFilePath+StringConstant.SLASH+this.logFileName;
|
||||
String arrFileRelativePath = this.arrFilePath+StringConstant.SLASH+this.arrFileName;
|
||||
//如果数据已经存储,不在重复存储
|
||||
final Integer idAnalysis = spectrumServiceQuotes.getAnalysesService().getIdAnalysis(this.sampleData.getSampleId());
|
||||
if(Objects.nonNull(idAnalysis)){
|
||||
log.warn("{} file analysis data has been stored",new File(this.sampleTempFilePath).getName());
|
||||
return;
|
||||
}
|
||||
DataSourceSwitcher.switchToOracle();
|
||||
final TransactionStatus transactionStatus = spectrumServiceQuotes.getTransactionManager().getTransaction(spectrumServiceQuotes.getTransactionDefinition());
|
||||
try{
|
||||
|
@ -312,14 +324,17 @@ public class Sample_B_Analysis implements BlockConstant {
|
|||
* 删除下载的det和gas临时文件
|
||||
*/
|
||||
private void deleteLocalTemporaryFile(){
|
||||
File detFile = new File(this.detTempFilePath);
|
||||
if(detFile.exists() && detFile.isFile()){
|
||||
detFile.delete();
|
||||
if(StringUtils.isNotBlank(this.detTempFilePath)){
|
||||
File detFile = new File(this.detTempFilePath);
|
||||
if(detFile.exists() && detFile.isFile()){
|
||||
detFile.delete();
|
||||
}
|
||||
}
|
||||
|
||||
File gasFile = new File(this.gasTempFilePath);
|
||||
if(gasFile.exists() && gasFile.isFile()){
|
||||
gasFile.delete();
|
||||
if(StringUtils.isNotBlank(this.gasTempFilePath)){
|
||||
File gasFile = new File(this.gasTempFilePath);
|
||||
if(gasFile.exists() && gasFile.isFile()){
|
||||
gasFile.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
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;
|
||||
|
||||
/**
|
||||
|
@ -15,7 +16,7 @@ public class SamplephdSpectrum extends S_D_Q_G_SpectrumHandler{
|
|||
protected void setChina() {
|
||||
SpectrumHandler spectrumHandler = new DetbkphdSpectrum();
|
||||
spectrumHandler.initNext(super.spectrumServiceQuotes,super.mailFile,
|
||||
super.currDataType,super.message,super.emailProperties,super.ftpUtil,super.mailContent);
|
||||
super.currDataType,super.ftpUtil,super.mailContent);
|
||||
spectrumHandler.setPrevious(this);
|
||||
super.setNext(spectrumHandler);
|
||||
}
|
||||
|
@ -26,26 +27,33 @@ public class SamplephdSpectrum extends S_D_Q_G_SpectrumHandler{
|
|||
@Override
|
||||
protected void handler() throws Exception {
|
||||
if(DataType.SAMPLEPHD.getType().equals(super.currDataType.getType())){
|
||||
//前置检查
|
||||
this.preCheck();
|
||||
//打印当前处理的能谱类型
|
||||
super.printCurrDataType();
|
||||
//解析邮件内容
|
||||
super.parseingEmail();
|
||||
//读取邮件内容标签
|
||||
super.readFileLabel();
|
||||
//保存PHD文件到ftp
|
||||
super.saveFileToFtp();
|
||||
//结构体数据入库
|
||||
super.handlerOriginalData();
|
||||
//保存email日志
|
||||
super.saveEmailLog();
|
||||
//把原始库流程日志写入ftp日志文件
|
||||
super.saveLogToFtp();
|
||||
//进行B、G(P)谱分析
|
||||
this.autoAnalysis();
|
||||
//删除本地临时文件
|
||||
super.deleteLocalTemporaryFile();
|
||||
try{
|
||||
//前置检查
|
||||
this.preCheck();
|
||||
//打印当前处理的能谱类型
|
||||
super.printCurrDataType();
|
||||
//解析邮件内容
|
||||
super.parseingEmail();
|
||||
//读取邮件内容标签
|
||||
super.readFileLabel();
|
||||
//保存PHD文件到ftp
|
||||
super.saveFileToFtp();
|
||||
//结构体数据入库
|
||||
super.handlerOriginalData();
|
||||
//把原始库流程日志写入ftp日志文件
|
||||
super.saveLogToFtp();
|
||||
//进行B、G(P)谱分析
|
||||
this.autoAnalysis();
|
||||
}catch (Exception e){
|
||||
//修改状态为解析失败
|
||||
this.spectrumServiceQuotes.getSampleDataService().updateStatus(SampleStatus.FAIL.getValue(),super.sampleData.getInputFileName());
|
||||
//处理解析失败的文件,上传到ftp->undeal目录
|
||||
super.handleParseingFailFile();
|
||||
throw e;
|
||||
}finally {
|
||||
//删除本地临时文件
|
||||
super.deleteLocalTemporaryFile();
|
||||
}
|
||||
}else{
|
||||
super.next.handler();
|
||||
}
|
||||
|
|
|
@ -4,11 +4,9 @@ import cn.hutool.core.io.FileUtil;
|
|||
import com.google.common.collect.Lists;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.modules.base.enums.DataType;
|
||||
import org.jeecg.modules.email.EmailProperties;
|
||||
import org.jeecg.modules.exception.PHD_ReadException;
|
||||
import org.jeecg.modules.ftp.FTPUtils;
|
||||
import javax.mail.Message;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
@ -22,14 +20,6 @@ public abstract class SpectrumHandler extends Chain{
|
|||
private final static String DATA_TYPE_PREFIX = "DATA_TYPE ";
|
||||
|
||||
protected final static String LOG_FILE_SUFFIX = ".log";
|
||||
/**
|
||||
* 当前邮件信息
|
||||
*/
|
||||
protected Message message;
|
||||
/**
|
||||
* 邮件属性
|
||||
*/
|
||||
protected EmailProperties emailProperties;
|
||||
/**
|
||||
* 处理能谱数据相关Service引用
|
||||
*/
|
||||
|
@ -63,12 +53,9 @@ public abstract class SpectrumHandler extends Chain{
|
|||
/**
|
||||
* 初始化参数
|
||||
*/
|
||||
protected void init(String mailContent,SpectrumServiceQuotes spectrumServiceQuotes,Message message,
|
||||
EmailProperties emailProperties,FTPUtils ftpUtil) throws Exception{
|
||||
protected void init(String mailContent,SpectrumServiceQuotes spectrumServiceQuotes,FTPUtils ftpUtil) throws Exception{
|
||||
this.mailContent = mailContent;
|
||||
this.spectrumServiceQuotes = spectrumServiceQuotes;
|
||||
this.message = message;
|
||||
this.emailProperties = emailProperties;
|
||||
this.ftpUtil = ftpUtil;
|
||||
}
|
||||
|
||||
|
@ -76,12 +63,10 @@ public abstract class SpectrumHandler extends Chain{
|
|||
* 初始化参数
|
||||
*/
|
||||
protected void initNext(SpectrumServiceQuotes spectrumServiceQuotes,File mailFile,DataType currDataType,
|
||||
Message message,EmailProperties emailProperties,FTPUtils ftpUtil,String mailContent){
|
||||
FTPUtils ftpUtil,String mailContent){
|
||||
this.spectrumServiceQuotes = spectrumServiceQuotes;
|
||||
this.mailFile = mailFile;
|
||||
this.currDataType = currDataType;
|
||||
this.message = message;
|
||||
this.emailProperties = emailProperties;
|
||||
this.ftpUtil = ftpUtil;
|
||||
this.mailContent = mailContent;
|
||||
this.setChina();
|
||||
|
@ -153,11 +138,11 @@ public abstract class SpectrumHandler extends Chain{
|
|||
}
|
||||
|
||||
/**
|
||||
* 保存邮件日志到PG数据库
|
||||
* @throws Exception
|
||||
* 处理解析失败的文件,上传到ftp->undeal目录
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
protected void saveEmailLog() throws Exception {
|
||||
this.spectrumServiceQuotes.getMailLogService().create(this.message,this.emailProperties);
|
||||
protected void handleParseingFailFile() throws FileNotFoundException {
|
||||
this.ftpUtil.saveFile(spectrumServiceQuotes.getSpectrumPathProperties().getFailPath(),this.mailFile.getName(),new FileInputStream(this.mailFile));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.jeecg.modules.spectrum;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jeecg.common.constant.StringConstant;
|
||||
|
@ -10,8 +9,8 @@ import org.jeecg.common.util.DateUtils;
|
|||
import org.jeecg.modules.email.EmailProperties;
|
||||
import org.jeecg.modules.ftp.FTPProperties;
|
||||
import org.jeecg.modules.ftp.FTPUtils;
|
||||
|
||||
import javax.mail.Message;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.mail.internet.MimeUtility;
|
||||
import java.util.Date;
|
||||
|
@ -99,22 +98,28 @@ public class SpectrumParsingActuator implements Runnable{
|
|||
//判断是否是IMS2.0协议文件
|
||||
if(checkMailContent(mailContent,subject)){
|
||||
SpectrumHandler spectrumHandler = new SamplephdSpectrum();
|
||||
spectrumHandler.init(mailContent.toString(),spectrumServiceQuotes,message,emailProperties,ftpUtil);
|
||||
spectrumHandler.init(mailContent.toString(),spectrumServiceQuotes,ftpUtil);
|
||||
final boolean matchResult = spectrumHandler.saveEmailToLocal();
|
||||
if(matchResult){
|
||||
//保存邮件解析日志到PG数据库
|
||||
this.spectrumServiceQuotes.getMailLogService().create(message,emailProperties);
|
||||
//开始解析
|
||||
spectrumHandler.handler();
|
||||
}else{
|
||||
log.warn("此邮件{}匹配失败,不在气象谱、警告谱、健康状态谱、样品谱、探测器本地谱、QC谱、气体谱之列",subject);
|
||||
}
|
||||
}
|
||||
//删除邮箱中已处理过的邮件
|
||||
emailServiceManager.removeMail(message);
|
||||
} catch (Exception e) {
|
||||
log.error(mailContent.toString());
|
||||
log.error("邮件解析失败,邮件主题为:{},发送时间为:{},接收时间为:{},失败原因为:{}",subject,sendTime,receiveTime,e.getMessage());
|
||||
this.handleErrorLog(e);
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
//删除邮箱中已处理过的邮件
|
||||
try {
|
||||
emailServiceManager.removeMail(message);
|
||||
} catch (MessagingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.taskLatch.countDown();
|
||||
ftpUtil.close();
|
||||
}
|
||||
|
@ -181,13 +186,4 @@ public class SpectrumParsingActuator implements Runnable{
|
|||
fileName.append(SAVE_EML_SUFFIX);
|
||||
ftpUtil.saveFile(spectrumPathProperties.getEmlPath(),fileName.toString(),message.getInputStream());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理解析报错日志
|
||||
* @param e
|
||||
*/
|
||||
private void handleErrorLog(Exception e){
|
||||
StringBuilder logContent = new StringBuilder();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user