fix:1.添加Alert谱file repeat问题2.修改按历史顺序查询邮件时不按日期查询过滤,提高性能

This commit is contained in:
panbaolin 2023-10-23 19:08:06 +08:00
parent 554e50a71d
commit 06daa65138
12 changed files with 90 additions and 35 deletions

View File

@ -126,8 +126,14 @@ public class EmailServiceManager {
//如果邮箱邮件数量 > 0
final int messageCount = folder.getMessageCount();
if(messageCount > 0){
Message[] messages = null;
if(Objects.isNull(this.systemStartupTime)){
int finalNum = messageCount > this.receiveNum?this.receiveNum:messageCount;
//邮箱邮件下标是从1开始的
return folder.getMessages(1,finalNum);
}
SearchTerm searchTerm = new ReceivedDateTerm(ComparisonTerm.GE,this.systemStartupTime);
Message[] messages = folder.search(searchTerm);
messages = folder.search(searchTerm);
Arrays.sort(messages, (o1, o2) -> {
try {
return o1.getReceivedDate().compareTo(o2.getReceivedDate());
@ -139,9 +145,8 @@ public class EmailServiceManager {
if(this.receiveNum >= messages.length){
return messages;
}else{
messages = Arrays.copyOfRange(messages,0,this.receiveNum-1);
return Arrays.copyOfRange(messages,0,this.receiveNum-1);
}
return messages;
}
return null;
}
@ -233,7 +238,6 @@ public class EmailServiceManager {
if(part.isMimeType(MailContentType.PLAIN.getContentType())){
content.append(part.getContent());
}else if(part.isMimeType("multipart/*")){
System.out.println(part.getContentType());
Multipart multipart = (Multipart) part.getContent();
for(int i=0;i<multipart.getCount();i++) {
final Part bodyPart = multipart.getBodyPart(i);

View File

@ -15,4 +15,11 @@ public interface IAlertSpectrumService extends IService<GardsAlertData> {
* @param fileName
*/
public GardsAlertData create(AlertSpectrumStruct struct,String fileName) throws Exception;
/**
* 查询GardsAlertData
* @param inputFileName
* @return
*/
public GardsAlertData findByInputFileName(String inputFileName);
}

View File

@ -3,7 +3,6 @@ package org.jeecg.modules.service;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.base.entity.original.GardsSohData;
import org.jeecg.modules.native_jni.struct.SOHSpectrumStruct;
import java.util.List;
/**

View File

@ -1,5 +1,6 @@
package org.jeecg.modules.service.impl;
import cn.hutool.core.util.StrUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -7,6 +8,7 @@ import lombok.RequiredArgsConstructor;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.base.entity.configuration.GardsStations;
import org.jeecg.modules.base.entity.original.GardsAlertData;
import org.jeecg.modules.file.FileOperation;
import org.jeecg.modules.mapper.GardsAlertDataMapper;
import org.jeecg.modules.mapper.GardsStationsMapper;
import org.jeecg.modules.native_jni.struct.AlertSpectrumStruct;
@ -48,8 +50,25 @@ public class AlertSpectrumServiceImpl extends ServiceImpl<GardsAlertDataMapper,
alertData.setTime(DateUtils.parseDate(struct.date+" "+struct.time));
alertData.setAlertType(struct.alert_type);
alertData.setAlertText(struct.desc);
alertData.setInputFileName(fileName);
alertData.setInputFileName(FileOperation.separatorConvert(fileName));
this.save(alertData);
return alertData;
}
/**
* 查询GardsAlertData
*
* @param inputFileName
* @return
*/
@Override
public GardsAlertData findByInputFileName(String inputFileName) {
if (StrUtil.isNotBlank(inputFileName)){
inputFileName = FileOperation.separatorConvert(inputFileName);
LambdaQueryWrapper<GardsAlertData> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(GardsAlertData::getInputFileName,inputFileName);
return this.getOne(queryWrapper);
}
return null;
}
}

View File

@ -8,6 +8,7 @@ import org.apache.commons.compress.utils.Lists;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.base.entity.configuration.GardsStations;
import org.jeecg.modules.base.entity.original.GardsMetData;
import org.jeecg.modules.file.FileOperation;
import org.jeecg.modules.mapper.GardsMetDataMapper;
import org.jeecg.modules.mapper.GardsStationsMapper;
import org.jeecg.modules.native_jni.struct.MetSpectrumStruct;
@ -61,7 +62,7 @@ public class MetSpectrumServiceImpl extends ServiceImpl<GardsMetDataMapper, Gard
metData.setAveWindDir(struct.average_wind_direction.get(i));
metData.setAveWindSpeed(struct.average_wind_speed.get(i));
metData.setRainfall(struct.rainfall.get(i));
metData.setInputFileName(fileName);
metData.setInputFileName(FileOperation.separatorConvert(fileName));
metData.setModdate(new Date());
list.add(metData);
}

View File

@ -9,6 +9,7 @@ import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.base.entity.configuration.GardsDetectors;
import org.jeecg.modules.base.entity.configuration.GardsStations;
import org.jeecg.modules.base.entity.original.GardsSohData;
import org.jeecg.modules.file.FileOperation;
import org.jeecg.modules.mapper.GardsDetectorsMapper;
import org.jeecg.modules.mapper.GardsSohDataMapper;
import org.jeecg.modules.mapper.GardsStationsMapper;
@ -67,7 +68,7 @@ public class SOHSpectrumServiceImpl extends ServiceImpl<GardsSohDataMapper, Gard
sohData.setTime(struct.af_interval_duration.get(i).doubleValue());
sohData.setAvgflowrate(struct.average_flow_rate.get(i));
sohData.setFlowratedev(struct.flow_rate_standard_deviation.get(i));
sohData.setInputFileName(fileName);
sohData.setInputFileName(FileOperation.separatorConvert(fileName));
sohData.setDetectorId(gardsDetectors.getDetectorId());
sohData.setModdate(new Date());
list.add(sohData);

View File

@ -6,6 +6,7 @@ import org.jeecg.common.properties.SpectrumPathProperties;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.base.entity.original.GardsAlertData;
import org.jeecg.modules.base.enums.DataType;
import org.jeecg.modules.exception.FileRepeatException;
import org.jeecg.modules.exception.PHD_ReadException;
import org.jeecg.modules.file.FileOperation;
import org.jeecg.modules.native_jni.EnergySpectrumHandler;
@ -34,6 +35,10 @@ public class AlertSpectrum extends AbstractSpectrumHandler{
* 结束存库时间
*/
private Date endIntoDatabaseTime = null;
/**
* 文件是否重复
*/
private boolean isFileRepeat;
/**
* 设置过滤链路
@ -56,18 +61,23 @@ public class AlertSpectrum extends AbstractSpectrumHandler{
DataType.ALERT_TEMP.getType().equals(super.currDataType.getType()) ||
DataType.ALERT_SYSTEM.getType().equals(super.currDataType.getType()) ||
DataType.ALERT_UPS.getType().equals(super.currDataType.getType())){
//打印当前处理的能谱类型
super.printCurrDataType();
//解析邮件内容
this.parseingEmail();
//保存PHD文件到savefile
super.saveFileToSavefile();
//结构体数据入库
this.handlerOriginalData();
//删除本地临时文件
super.deleteLocalTemporaryFile();
//把流程日志保存到日志目录
this.saveLogToLogDir();
try{
//打印当前处理的能谱类型
super.printCurrDataType();
//解析邮件内容
this.parseingEmail();
//保存PHD文件到savefile
super.saveFileToSavefile();
//结构体数据入库
this.handlerOriginalData();
//删除本地临时文件
super.deleteLocalTemporaryFile();
}catch (Exception e){
throw e;
}finally {
//把流程日志保存到日志目录
this.saveLogToLogDir();
}
}else{
super.next.handler();
}
@ -129,6 +139,13 @@ public class AlertSpectrum extends AbstractSpectrumHandler{
@Override
protected void handlerOriginalData() throws Exception {
this.startIntoDatabaseTime = new Date();
final GardsAlertData alertData = super.spectrumServiceQuotes.getAlertSpectrumService().findByInputFileName(super.spectrumFileRelativePath);
if(Objects.nonNull(alertData)){
this.alertData = alertData;
this.endIntoDatabaseTime = new Date();
this.isFileRepeat = true;
throw new FileRepeatException("file repeat");
}
this.alertData = super.spectrumServiceQuotes.getAlertSpectrumService().create(this.sourceData, super.spectrumFileRelativePath);
this.endIntoDatabaseTime = new Date();
}
@ -138,18 +155,28 @@ public class AlertSpectrum extends AbstractSpectrumHandler{
*/
@Override
protected void saveLogToLogDir() throws IOException {
final SpectrumPathProperties properties = super.spectrumServiceQuotes.getSpectrumPathProperties();
final String dirPath = properties.getRootPath()+File.separator+properties.getLogPath()+File.separator+this.getFileSaveRelativePath();
final String fileName = super.spectrumFile.getName().replace(this.currDataType.getSuffix(),LOG_FILE_SUFFIX);
final String finalPath = dirPath+File.separator+fileName;
//组装日志文件内容
StringBuilder logContent = new StringBuilder();
logContent.append("-------------------------- Write Data into Database at ").append(DateUtils.formatDate(this.startIntoDatabaseTime,"yyyy-MM-dd HH:mm:ss")).append(" ---------------------------");
logContent.append(System.lineSeparator()).append(System.lineSeparator());
logContent.append("ALERT ID: ").append(this.alertData.getAlertId()).append(" StandardFile:").append(super.spectrumServiceQuotes.getSpectrumPathProperties().getRootPath()).append(StringConstant.SLASH).append(super.spectrumFileRelativePath);
logContent.append(System.lineSeparator()).append(System.lineSeparator());
logContent.append("------------------- ").append("Write Data into Database Successfully at ").append(DateUtils.formatDate(this.endIntoDatabaseTime,"yyyy-MM-dd HH:mm:ss")).append(" --------------------");
final SpectrumPathProperties properties = super.spectrumServiceQuotes.getSpectrumPathProperties();
final String dirPath = properties.getLogPath()+File.separator+this.getFileSaveRelativePath();
final String fileName = super.spectrumFile.getName().replace(this.currDataType.getSuffix(),LOG_FILE_SUFFIX);
final String finalPath = dirPath+File.separator+fileName;
String handleFlag = "Successfully";
if(this.isFileRepeat){
handleFlag = "Error";
String fileStoreRelativePath = this.getFileSaveRelativePath()+File.separator+fileName;
logContent.append("File: ").append(fileStoreRelativePath).append(" repeat");
logContent.append(System.lineSeparator()).append(System.lineSeparator());
}
logContent.append("------------------- ").append("Write Data into Database ").append(handleFlag).append(" at ").append(DateUtils.formatDate(this.endIntoDatabaseTime,"yyyy-MM-dd HH:mm:ss")).append(" --------------------");
logContent.append(System.lineSeparator()).append(System.lineSeparator()).append(System.lineSeparator());
FileOperation.saveOrAppendFile(finalPath,logContent.toString(),true);
}
}

View File

@ -1,6 +1,5 @@
package org.jeecg.modules.spectrum;
import cn.hutool.core.io.FileUtil;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.constant.StringConstant;
import org.jeecg.common.properties.SpectrumPathProperties;
@ -39,7 +38,7 @@ public class HealthStatusSpectrum extends AbstractSpectrumHandler{
*/
private Date endIntoDatabaseTime = null;
private List<GardsSohData> sohDatas;
private List<GardsSohData> sohData;
/**
* 设置过滤链路
@ -134,7 +133,7 @@ public class HealthStatusSpectrum extends AbstractSpectrumHandler{
@Override
protected void handlerOriginalData() throws Exception {
this.startIntoDatabaseTime = new Date();
this.sohDatas = spectrumServiceQuotes.getSohSpectrumService().create(this.sourceData, super.spectrumFileRelativePath);
this.sohData = spectrumServiceQuotes.getSohSpectrumService().create(this.sourceData, super.spectrumFileRelativePath);
this.endIntoDatabaseTime = new Date();
}
@ -145,8 +144,8 @@ public class HealthStatusSpectrum extends AbstractSpectrumHandler{
protected void saveLogToLogDir() throws IOException {
//获取健康谱记录ID范围
String sohIdRange = "";
if(!CollectionUtils.isEmpty(this.sohDatas)){
sohIdRange = this.sohDatas.get(0).getSohId()+"-"+this.sohDatas.get(this.sohDatas.size()-1).getSohId();
if(!CollectionUtils.isEmpty(this.sohData)){
sohIdRange = this.sohData.get(0).getSohId()+"-"+this.sohData.get(this.sohData.size()-1).getSohId();
}
//组装日志文件内容
StringBuilder logContent = new StringBuilder();
@ -157,7 +156,7 @@ public class HealthStatusSpectrum extends AbstractSpectrumHandler{
logContent.append("------------------- ").append("Write Data into Database Successfully at ").append(DateUtils.formatDate(this.endIntoDatabaseTime,"yyyy-MM-dd HH:mm:ss")).append(" --------------------");
final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties();
final String dirPath = properties.getLogPath()+File.separator+this.getFileSaveRelativePath();
final String dirPath = properties.getRootPath()+File.separator+properties.getLogPath()+File.separator+this.getFileSaveRelativePath();
final String fileName = super.spectrumFile.getName().replace(this.currDataType.getSuffix(),LOG_FILE_SUFFIX);
final String finalPath = dirPath+ File.separator+fileName;
FileOperation.saveOrAppendFile(finalPath,logContent.toString(),true);

View File

@ -150,7 +150,7 @@ public class MetSpectrum extends AbstractSpectrumHandler{
logContent.append("------------------- ").append("Write Data into Database Successfully at ").append(DateUtils.formatDate(this.endIntoDatabaseTime,"yyyy-MM-dd HH:mm:ss")).append(" --------------------");
final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties();
final String dirPath = properties.getLogPath()+File.separator+this.getFileSaveRelativePath();
final String dirPath = properties.getRootPath()+File.separator+properties.getLogPath()+File.separator+this.getFileSaveRelativePath();
final String fileName = super.spectrumFile.getName().replace(this.currDataType.getSuffix(),LOG_FILE_SUFFIX);
final String finalPath = dirPath+File.separator+fileName;
FileOperation.saveOrAppendFile(finalPath,logContent.toString(),true);

View File

@ -50,7 +50,6 @@ public class SamplephdSpectrum extends AbstractS_D_Q_G_SpectrumHandler {
super.status = SampleStatus.COMPLETE.getValue();
super.updateStatus();
}catch (Exception e){
e.printStackTrace();
//修改状态为解析失败
super.status = SampleStatus.FAIL.getValue();
super.updateStatus();

View File

@ -104,7 +104,6 @@ public class SpectrumParsingActuator implements Runnable{
}
}
} catch (Exception e) {
// log.error(mailContent.toString());
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

@ -71,7 +71,7 @@ public class JeecgAutoProcessApplication extends SpringBootServletInitializer im
System.loadLibrary("ReadPHDFile");
System.loadLibrary("GammaAnaly");
//根据配置文件配置邮件获取策略定义时间条件默认EmailReceivePolicy.HISTORY_ORDER_RECEIVE.getPolicy()
Date systemStartupTime = DateUtils.parseDate("1970-01-01 00:00:00","yyyy-MM-dd HH:mm:ss");
Date systemStartupTime = null;
if(EmailReceivePolicy.CURR_DATE_ORDER_RECEIVE.getPolicy().equals(taskProperties.getReceivePolicy())){
systemStartupTime = new Date();
}