fix:1.修改B谱分析功能中存储报告路径去除文件后缀2.优化健康谱、报警谱日志功能3.添加获取邮件时可获取系统启动时间后的邮件功能逻辑
This commit is contained in:
parent
6b171b737d
commit
960b8be389
|
@ -17,6 +17,9 @@ import javax.mail.*;
|
||||||
import javax.mail.internet.InternetAddress;
|
import javax.mail.internet.InternetAddress;
|
||||||
import javax.mail.internet.MimeMessage;
|
import javax.mail.internet.MimeMessage;
|
||||||
import javax.mail.internet.MimeUtility;
|
import javax.mail.internet.MimeUtility;
|
||||||
|
import javax.mail.search.ComparisonTerm;
|
||||||
|
import javax.mail.search.ReceivedDateTerm;
|
||||||
|
import javax.mail.search.SearchTerm;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
@ -30,6 +33,10 @@ import java.util.stream.Collectors;
|
||||||
public class EmailServiceManager {
|
public class EmailServiceManager {
|
||||||
|
|
||||||
private SysEmail email;
|
private SysEmail email;
|
||||||
|
/**
|
||||||
|
* 系统启动时间
|
||||||
|
*/
|
||||||
|
private Date systemStartupTime;
|
||||||
/** 邮件接收数量 */
|
/** 邮件接收数量 */
|
||||||
private Integer receiveNum;
|
private Integer receiveNum;
|
||||||
/** smtp协议的存储对象 */
|
/** smtp协议的存储对象 */
|
||||||
|
@ -56,10 +63,11 @@ public class EmailServiceManager {
|
||||||
* 初始化邮件服务管理器
|
* 初始化邮件服务管理器
|
||||||
* @param email 邮件属性
|
* @param email 邮件属性
|
||||||
*/
|
*/
|
||||||
public void init(SysEmail email,Integer receiveNum,String temporaryStoragePath){
|
public void init(SysEmail email,Integer receiveNum,String temporaryStoragePath,Date systemStartupTime){
|
||||||
this.email = email;
|
this.email = email;
|
||||||
this.receiveNum = receiveNum;
|
this.receiveNum = receiveNum;
|
||||||
this.temporaryStoragePath = temporaryStoragePath;
|
this.temporaryStoragePath = temporaryStoragePath;
|
||||||
|
this.systemStartupTime = systemStartupTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -115,12 +123,24 @@ public class EmailServiceManager {
|
||||||
//获取收件箱
|
//获取收件箱
|
||||||
folder = store.getFolder("INBOX");
|
folder = store.getFolder("INBOX");
|
||||||
folder.open(Folder.READ_WRITE);
|
folder.open(Folder.READ_WRITE);
|
||||||
//获取邮件数量
|
//如果邮箱邮件数量 > 0
|
||||||
final int messageCount = folder.getMessageCount();
|
final int messageCount = folder.getMessageCount();
|
||||||
if(messageCount > 0){
|
if(messageCount > 0){
|
||||||
Integer start = 1;
|
SearchTerm searchTerm = new ReceivedDateTerm(ComparisonTerm.GT,this.systemStartupTime);
|
||||||
Integer end = this.receiveNum>messageCount?messageCount:this.receiveNum;
|
Message[] messages = folder.search(searchTerm);
|
||||||
final Message[] messages = folder.getMessages(start,end);
|
Arrays.sort(messages, (o1, o2) -> {
|
||||||
|
try {
|
||||||
|
return o1.getReceivedDate().compareTo(o2.getReceivedDate());
|
||||||
|
} catch (MessagingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
if(this.receiveNum >= messages.length){
|
||||||
|
return messages;
|
||||||
|
}else{
|
||||||
|
messages = Arrays.copyOfRange(messages,0,this.receiveNum-1);
|
||||||
|
}
|
||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -15,6 +15,11 @@ import java.io.Serializable;
|
||||||
@ConfigurationProperties(prefix = "task")
|
@ConfigurationProperties(prefix = "task")
|
||||||
public class TaskProperties implements Serializable {
|
public class TaskProperties implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮箱邮件获取策略:0-从历史按顺序获取,1-从当前系统启动时间按顺序获取,当前系统启动时间会在系统启动时赋值
|
||||||
|
*/
|
||||||
|
private Integer receivePolicy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 单次获取邮件数量
|
* 单次获取邮件数量
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -14,10 +14,8 @@ import org.jeecg.modules.spectrum.EmailCounter;
|
||||||
import org.jeecg.modules.spectrum.SpectrumServiceQuotes;
|
import org.jeecg.modules.spectrum.SpectrumServiceQuotes;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,9 +29,10 @@ public class AutoProcessManager{
|
||||||
private final ISysMailService mailService;
|
private final ISysMailService mailService;
|
||||||
private final TaskProperties taskProperties;
|
private final TaskProperties taskProperties;
|
||||||
private final RedisUtil redisUtil;
|
private final RedisUtil redisUtil;
|
||||||
private final SpectrumPathProperties spectrumPathProperties;
|
|
||||||
private final SpectrumServiceQuotes spectrumServiceQuotes;
|
private final SpectrumServiceQuotes spectrumServiceQuotes;
|
||||||
private final EmailCounter emailCounter;
|
private final EmailCounter emailCounter;
|
||||||
|
private Date systemStartupTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 邮件Map数据锁
|
* 邮件Map数据锁
|
||||||
*/
|
*/
|
||||||
|
@ -51,7 +50,8 @@ public class AutoProcessManager{
|
||||||
/**
|
/**
|
||||||
* 启动自动处理
|
* 启动自动处理
|
||||||
*/
|
*/
|
||||||
public void start() {
|
public void start(Date systemStartupTime) {
|
||||||
|
this.systemStartupTime = systemStartupTime;
|
||||||
//邮件数据监测线程
|
//邮件数据监测线程
|
||||||
final MailDataMonitor mailDataMonitor = new MailDataMonitor();
|
final MailDataMonitor mailDataMonitor = new MailDataMonitor();
|
||||||
mailDataMonitor.setName("mail-data-monitor");
|
mailDataMonitor.setName("mail-data-monitor");
|
||||||
|
@ -90,7 +90,7 @@ public class AutoProcessManager{
|
||||||
}
|
}
|
||||||
if(next.isNewEmailFlag()){
|
if(next.isNewEmailFlag()){
|
||||||
EmailParsingActuator emailParsingActuator = new EmailParsingActuator();
|
EmailParsingActuator emailParsingActuator = new EmailParsingActuator();
|
||||||
emailParsingActuator.init(next,spectrumServiceQuotes,emailCounter);
|
emailParsingActuator.init(next,spectrumServiceQuotes,emailCounter,systemStartupTime);
|
||||||
emailParsingActuator.setName(next.getUsername()+"-email-monitor");
|
emailParsingActuator.setName(next.getUsername()+"-email-monitor");
|
||||||
emailParsingActuator.start();
|
emailParsingActuator.start();
|
||||||
//把邮件监测执行线程加入管理队列
|
//把邮件监测执行线程加入管理队列
|
||||||
|
|
|
@ -10,6 +10,7 @@ import org.jeecg.modules.spectrum.SpectrumServiceQuotes;
|
||||||
import org.springframework.scheduling.concurrent.CustomizableThreadFactory;
|
import org.springframework.scheduling.concurrent.CustomizableThreadFactory;
|
||||||
import javax.mail.Message;
|
import javax.mail.Message;
|
||||||
import javax.mail.MessagingException;
|
import javax.mail.MessagingException;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,12 +23,14 @@ public class EmailParsingActuator extends Thread{
|
||||||
private ThreadPoolExecutor poolExecutor;
|
private ThreadPoolExecutor poolExecutor;
|
||||||
private SpectrumServiceQuotes spectrumServiceQuotes;
|
private SpectrumServiceQuotes spectrumServiceQuotes;
|
||||||
private EmailCounter emailCounter;
|
private EmailCounter emailCounter;
|
||||||
|
private Date systemStartupTime;
|
||||||
|
|
||||||
public void init(EmailProperties emailProperties,SpectrumServiceQuotes spectrumServiceQuotes,EmailCounter emailCounter){
|
public void init(EmailProperties emailProperties,SpectrumServiceQuotes spectrumServiceQuotes,EmailCounter emailCounter,Date systemStartupTime){
|
||||||
this.emailProperties = emailProperties;
|
this.emailProperties = emailProperties;
|
||||||
this.spectrumServiceQuotes = spectrumServiceQuotes;
|
this.spectrumServiceQuotes = spectrumServiceQuotes;
|
||||||
this.taskProperties = spectrumServiceQuotes.getTaskProperties();
|
this.taskProperties = spectrumServiceQuotes.getTaskProperties();
|
||||||
this.emailCounter = emailCounter;
|
this.emailCounter = emailCounter;
|
||||||
|
this.systemStartupTime = systemStartupTime;
|
||||||
|
|
||||||
//获取机器可用核心数
|
//获取机器可用核心数
|
||||||
int systemCores = Runtime.getRuntime().availableProcessors();
|
int systemCores = Runtime.getRuntime().availableProcessors();
|
||||||
|
@ -43,7 +46,7 @@ public class EmailParsingActuator extends Thread{
|
||||||
for(;;){
|
for(;;){
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
final EmailServiceManager emailServiceManager = EmailServiceManager.getInstance();
|
final EmailServiceManager emailServiceManager = EmailServiceManager.getInstance();
|
||||||
emailServiceManager.init(emailProperties,taskProperties.getReceiveNum(),taskProperties.getTemporaryStoragePath());
|
emailServiceManager.init(this.emailProperties,this.taskProperties.getReceiveNum(),this.taskProperties.getTemporaryStoragePath(),this.systemStartupTime);
|
||||||
try {
|
try {
|
||||||
final Message[] messages = emailServiceManager.receiveMail();
|
final Message[] messages = emailServiceManager.receiveMail();
|
||||||
if(ArrayUtils.isNotEmpty(messages)){
|
if(ArrayUtils.isNotEmpty(messages)){
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package org.jeecg.modules.email;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取邮件策略
|
||||||
|
*/
|
||||||
|
public enum EmailReceivePolicy {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 历史顺序获取
|
||||||
|
*/
|
||||||
|
HISTORY_ORDER_RECEIVE(0),
|
||||||
|
/**
|
||||||
|
* 当前时间顺序获取
|
||||||
|
*/
|
||||||
|
CURR_DATE_ORDER_RECEIVE(1);
|
||||||
|
|
||||||
|
private Integer policy;
|
||||||
|
|
||||||
|
EmailReceivePolicy(int policy) {
|
||||||
|
this.policy = policy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getPolicy(){
|
||||||
|
return this.policy;
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,7 +24,14 @@ public class CommentBlockServiceImpl extends ServiceImpl<GardsSampleDescriptionM
|
||||||
public void create(EnergySpectrumStruct struct,GardsSampleData sampleData){
|
public void create(EnergySpectrumStruct struct,GardsSampleData sampleData){
|
||||||
GardsSampleDescription description = new GardsSampleDescription();
|
GardsSampleDescription description = new GardsSampleDescription();
|
||||||
description.setSampleId(sampleData.getSampleId());
|
description.setSampleId(sampleData.getSampleId());
|
||||||
description.setDescription(struct.comment);
|
//C++固定写法备注大于1024则只保留1024长度字符
|
||||||
|
StringBuilder comment = new StringBuilder();
|
||||||
|
if(struct.comment.length()>1024){
|
||||||
|
comment.append(struct.comment.substring(0,1024));
|
||||||
|
}else {
|
||||||
|
comment.append(comment);
|
||||||
|
}
|
||||||
|
description.setDescription(comment.toString());
|
||||||
this.save(description);
|
this.save(description);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,8 +97,7 @@ public class AlertSpectrum extends SpectrumHandler{
|
||||||
//获取文件保存路径
|
//获取文件保存路径
|
||||||
String fileSavePath = this.getFileSavePath();
|
String fileSavePath = this.getFileSavePath();
|
||||||
final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties();
|
final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties();
|
||||||
fileSavePath = properties.getRootPath()+StringConstant.SLASH+fileSavePath;
|
super.ftpUtil.saveFile(properties.getRootPath()+StringConstant.SLASH+fileSavePath,this.mailFile.getName(),new FileInputStream(this.mailFile));
|
||||||
super.ftpUtil.saveFile(fileSavePath,this.mailFile.getName(),new FileInputStream(this.mailFile));
|
|
||||||
//设置FTP文件保存路径
|
//设置FTP文件保存路径
|
||||||
super.ftpSavePath = fileSavePath+StringConstant.SLASH+this.mailFile.getName();
|
super.ftpSavePath = fileSavePath+StringConstant.SLASH+this.mailFile.getName();
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,10 +99,9 @@ public class HealthStatusSpectrum extends SpectrumHandler{
|
||||||
//获取文件保存路径
|
//获取文件保存路径
|
||||||
String fileSavePath = this.getFileSavePath();
|
String fileSavePath = this.getFileSavePath();
|
||||||
final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties();
|
final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties();
|
||||||
fileSavePath = properties.getRootPath()+"/"+fileSavePath;
|
super.ftpUtil.saveFile(properties.getRootPath()+StringConstant.SLASH+fileSavePath,this.mailFile.getName(),new FileInputStream(this.mailFile));
|
||||||
super.ftpUtil.saveFile(fileSavePath,this.mailFile.getName(),new FileInputStream(this.mailFile));
|
|
||||||
//设置FTP文件保存路径
|
//设置FTP文件保存路径
|
||||||
super.ftpSavePath = fileSavePath+"/"+this.mailFile.getName();
|
super.ftpSavePath = fileSavePath+StringConstant.SLASH+this.mailFile.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -95,10 +95,9 @@ public class MetSpectrum extends SpectrumHandler{
|
||||||
//获取文件保存路径
|
//获取文件保存路径
|
||||||
String fileSavePath = this.getFileSavePath();
|
String fileSavePath = this.getFileSavePath();
|
||||||
final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties();
|
final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties();
|
||||||
fileSavePath = properties.getRootPath()+"/"+fileSavePath;
|
super.ftpUtil.saveFile(properties.getRootPath()+StringConstant.SLASH+fileSavePath,this.mailFile.getName(),new FileInputStream(this.mailFile));
|
||||||
super.ftpUtil.saveFile(fileSavePath,this.mailFile.getName(),new FileInputStream(this.mailFile));
|
|
||||||
//设置FTP文件保存路径
|
//设置FTP文件保存路径
|
||||||
super.ftpSavePath = fileSavePath+"/"+this.mailFile.getName();
|
super.ftpSavePath = fileSavePath+StringConstant.SLASH+this.mailFile.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -272,7 +272,8 @@ public class Sample_B_Analysis implements BlockConstant {
|
||||||
*/
|
*/
|
||||||
private void storageDataToDatabase(){
|
private void storageDataToDatabase(){
|
||||||
String logFileRelativePath = this.logFilePath+StringConstant.SLASH+this.logFileName;
|
String logFileRelativePath = this.logFilePath+StringConstant.SLASH+this.logFileName;
|
||||||
String arrFileRelativePath = this.arrFilePath+StringConstant.SLASH+this.arrFileName;
|
//报告路径存储到数据库时不包括后缀.txt,C++原来是这样做的,并且历史大量数据都是这样,暂时还保持这样
|
||||||
|
String arrFileRelativePath = this.arrFilePath+StringConstant.SLASH+this.arrFileName.substring(0,this.arrFileName.lastIndexOf(StringConstant.DOT));
|
||||||
//如果数据已经存储,不在重复存储
|
//如果数据已经存储,不在重复存储
|
||||||
final Integer idAnalysis = spectrumServiceQuotes.getAnalysesService().getIdAnalysis(this.sampleData.getSampleId());
|
final Integer idAnalysis = spectrumServiceQuotes.getAnalysesService().getIdAnalysis(this.sampleData.getSampleId());
|
||||||
if(Objects.nonNull(idAnalysis)){
|
if(Objects.nonNull(idAnalysis)){
|
||||||
|
|
|
@ -2,10 +2,13 @@ package org.jeecg;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.jeecg.common.properties.TaskProperties;
|
||||||
|
import org.jeecg.common.util.DateUtils;
|
||||||
import org.jeecg.common.util.oConvertUtils;
|
import org.jeecg.common.util.oConvertUtils;
|
||||||
import org.jeecg.modules.AutoProcessManager;
|
import org.jeecg.modules.AutoProcessManager;
|
||||||
import org.jeecg.modules.FileSourceHandleManager;
|
import org.jeecg.modules.FileSourceHandleManager;
|
||||||
import org.jeecg.modules.UndealHandleManager;
|
import org.jeecg.modules.UndealHandleManager;
|
||||||
|
import org.jeecg.modules.email.EmailReceivePolicy;
|
||||||
import org.springframework.boot.CommandLineRunner;
|
import org.springframework.boot.CommandLineRunner;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
@ -17,6 +20,7 @@ import org.springframework.core.env.Environment;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author 86187
|
* @author 86187
|
||||||
|
@ -28,6 +32,7 @@ import java.net.UnknownHostException;
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class JeecgAutoProcessApplication extends SpringBootServletInitializer implements CommandLineRunner {
|
public class JeecgAutoProcessApplication extends SpringBootServletInitializer implements CommandLineRunner {
|
||||||
|
|
||||||
|
private final TaskProperties taskProperties;
|
||||||
private final AutoProcessManager autoProcessManager;
|
private final AutoProcessManager autoProcessManager;
|
||||||
private final UndealHandleManager undealHandleManager;
|
private final UndealHandleManager undealHandleManager;
|
||||||
private final FileSourceHandleManager fileSourceHandleManager;
|
private final FileSourceHandleManager fileSourceHandleManager;
|
||||||
|
@ -55,7 +60,15 @@ public class JeecgAutoProcessApplication extends SpringBootServletInitializer im
|
||||||
public void run(String... args) throws Exception {
|
public void run(String... args) throws Exception {
|
||||||
//调用dll
|
//调用dll
|
||||||
System.loadLibrary("ReadPHDFile");
|
System.loadLibrary("ReadPHDFile");
|
||||||
// autoProcessManager.start();
|
//根据配置文件配置邮件获取策略定义时间条件
|
||||||
|
Date systemStartupTime = null;
|
||||||
|
if(EmailReceivePolicy.HISTORY_ORDER_RECEIVE.getPolicy().equals(taskProperties.getReceivePolicy())){
|
||||||
|
systemStartupTime = DateUtils.parseDate("1970-01-01 00:00:00","yyyy-MM-dd HH:mm:ss");
|
||||||
|
}
|
||||||
|
if(EmailReceivePolicy.CURR_DATE_ORDER_RECEIVE.getPolicy().equals(taskProperties.getReceivePolicy())){
|
||||||
|
systemStartupTime = new Date();
|
||||||
|
}
|
||||||
|
autoProcessManager.start(systemStartupTime);
|
||||||
undealHandleManager.start();
|
undealHandleManager.start();
|
||||||
fileSourceHandleManager.start();
|
fileSourceHandleManager.start();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user