fix:1.新加每次获取邮件数量日志2.修改日志接收时间不准确问题3.修改移动errorEml目录文件名称错误问题
This commit is contained in:
parent
8219e50afe
commit
0a26492926
|
@ -2,7 +2,6 @@ package org.jeecg.common.email;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.jeecg.modules.base.entity.postgre.SysEmail;
|
import org.jeecg.modules.base.entity.postgre.SysEmail;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,7 +33,7 @@ public class EmailLogEvent {
|
||||||
/**
|
/**
|
||||||
* 接收时间
|
* 接收时间
|
||||||
*/
|
*/
|
||||||
private Date recieveTime;
|
private String recieveTime;
|
||||||
/**
|
/**
|
||||||
* 能谱文件名称
|
* 能谱文件名称
|
||||||
*/
|
*/
|
||||||
|
@ -82,7 +81,7 @@ public class EmailLogEvent {
|
||||||
this.logTime = new Date();
|
this.logTime = new Date();
|
||||||
}
|
}
|
||||||
|
|
||||||
public EmailLogEvent(String gsType,String state, String logProcess,String subject,Date recieveTime,String emlPath) {
|
public EmailLogEvent(String gsType,String state, String logProcess,String subject,String recieveTime,String emlPath) {
|
||||||
this.gsType = gsType;
|
this.gsType = gsType;
|
||||||
this.state = state;
|
this.state = state;
|
||||||
this.logProcess = logProcess;
|
this.logProcess = logProcess;
|
||||||
|
@ -92,7 +91,7 @@ public class EmailLogEvent {
|
||||||
this.logTime = new Date();
|
this.logTime = new Date();
|
||||||
}
|
}
|
||||||
|
|
||||||
public EmailLogEvent(String gsType,String state, String logProcess,String subject,Date recieveTime) {
|
public EmailLogEvent(String gsType,String state, String logProcess,String subject,String recieveTime) {
|
||||||
this.gsType = gsType;
|
this.gsType = gsType;
|
||||||
this.state = state;
|
this.state = state;
|
||||||
this.logProcess = logProcess;
|
this.logProcess = logProcess;
|
||||||
|
|
|
@ -238,7 +238,7 @@ public class EmailLogManager {
|
||||||
logContent.append(" Get File subject:");
|
logContent.append(" Get File subject:");
|
||||||
logContent.append(event.getSubject());
|
logContent.append(event.getSubject());
|
||||||
logContent.append(" recieve datetime:");
|
logContent.append(" recieve datetime:");
|
||||||
logContent.append(DateUtils.formatDate(event.getRecieveTime(),"yyyy-MM-dd HH:mm:ss:SSS"));
|
logContent.append(event.getRecieveTime());
|
||||||
logContent.append(event.getState());
|
logContent.append(event.getState());
|
||||||
logContent.append(" EmlFile ");
|
logContent.append(" EmlFile ");
|
||||||
logContent.append(event.getEmlPath());
|
logContent.append(event.getEmlPath());
|
||||||
|
@ -259,7 +259,7 @@ public class EmailLogManager {
|
||||||
logContent.append(" Delete File subject:");
|
logContent.append(" Delete File subject:");
|
||||||
logContent.append(event.getSubject());
|
logContent.append(event.getSubject());
|
||||||
logContent.append(" recieve datetime:");
|
logContent.append(" recieve datetime:");
|
||||||
logContent.append(DateUtils.formatDate(event.getRecieveTime(),"yyyy-MM-dd HH:mm:ss:SSS"));
|
logContent.append(event.getRecieveTime());
|
||||||
logContent.append(event.getState());
|
logContent.append(event.getState());
|
||||||
logContent.append(LOG_SUFFIX);
|
logContent.append(LOG_SUFFIX);
|
||||||
logContent.append(System.lineSeparator());
|
logContent.append(System.lineSeparator());
|
||||||
|
@ -278,7 +278,7 @@ public class EmailLogManager {
|
||||||
logContent.append(" Expunge File subject:");
|
logContent.append(" Expunge File subject:");
|
||||||
logContent.append(event.getSubject());
|
logContent.append(event.getSubject());
|
||||||
logContent.append(" recieve datetime:");
|
logContent.append(" recieve datetime:");
|
||||||
logContent.append(DateUtils.formatDate(event.getRecieveTime(),"yyyy-MM-dd HH:mm:ss:SSS"));
|
logContent.append(event.getRecieveTime());
|
||||||
logContent.append(event.getState());
|
logContent.append(event.getState());
|
||||||
logContent.append(LOG_SUFFIX);
|
logContent.append(LOG_SUFFIX);
|
||||||
logContent.append(System.lineSeparator());
|
logContent.append(System.lineSeparator());
|
||||||
|
|
|
@ -522,6 +522,7 @@ public class EmailServiceManager {
|
||||||
String subject = "";
|
String subject = "";
|
||||||
File emlFile = null;
|
File emlFile = null;
|
||||||
String status = EmailLogManager.STATUS_SUCCESS;
|
String status = EmailLogManager.STATUS_SUCCESS;
|
||||||
|
Date receivedDate = null;
|
||||||
try {
|
try {
|
||||||
//获取发件人
|
//获取发件人
|
||||||
final String address = ((InternetAddress) message.getFrom()[0]).getAddress();
|
final String address = ((InternetAddress) message.getFrom()[0]).getAddress();
|
||||||
|
@ -534,7 +535,7 @@ public class EmailServiceManager {
|
||||||
if(subject.indexOf(StringConstant.COLON) != -1){
|
if(subject.indexOf(StringConstant.COLON) != -1){
|
||||||
subject = StringUtils.replace(subject,StringConstant.COLON,"");
|
subject = StringUtils.replace(subject,StringConstant.COLON,"");
|
||||||
}
|
}
|
||||||
|
receivedDate = message.getReceivedDate();
|
||||||
StringBuilder fileName = new StringBuilder();
|
StringBuilder fileName = new StringBuilder();
|
||||||
fileName.append(from);
|
fileName.append(from);
|
||||||
fileName.append(StringConstant.UNDER_LINE);
|
fileName.append(StringConstant.UNDER_LINE);
|
||||||
|
@ -546,9 +547,9 @@ public class EmailServiceManager {
|
||||||
fileName.append(StringConstant.UNDER_LINE);
|
fileName.append(StringConstant.UNDER_LINE);
|
||||||
fileName.append("receive");
|
fileName.append("receive");
|
||||||
fileName.append(StringConstant.UNDER_LINE);
|
fileName.append(StringConstant.UNDER_LINE);
|
||||||
fileName.append(DateUtils.formatDate(message.getReceivedDate(),"YYMMdd"));
|
fileName.append(DateUtils.formatDate(receivedDate,"YYMMdd"));
|
||||||
fileName.append(StringConstant.UNDER_LINE);
|
fileName.append(StringConstant.UNDER_LINE);
|
||||||
fileName.append(DateUtils.formatDate(message.getReceivedDate(),"HHMMSSSSS"));
|
fileName.append(DateUtils.formatDate(receivedDate,"HHMMSSSSS"));
|
||||||
fileName.append(StringConstant.UNDER_LINE);
|
fileName.append(StringConstant.UNDER_LINE);
|
||||||
fileName.append(emailCounter);
|
fileName.append(emailCounter);
|
||||||
fileName.append(SAVE_EML_SUFFIX);
|
fileName.append(SAVE_EML_SUFFIX);
|
||||||
|
@ -563,32 +564,13 @@ public class EmailServiceManager {
|
||||||
log.error(errorMsg);
|
log.error(errorMsg);
|
||||||
throw new DownloadEmailException(errorMsg);
|
throw new DownloadEmailException(errorMsg);
|
||||||
}finally {
|
}finally {
|
||||||
EmailLogEvent event = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,status,EmailLogManager.GETIDEML,subject,message.getReceivedDate(),
|
EmailLogEvent event = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,status,EmailLogManager.GETIDEML,subject,DateUtils.formatDate(receivedDate,"yyyy-MM-dd HH:mm:ss:SSS"),
|
||||||
(Objects.isNull(emlFile)?" ":emlFile.getAbsolutePath()));
|
(Objects.isNull(emlFile)?" ":emlFile.getAbsolutePath()));
|
||||||
EmailLogManager.getInstance().offer(Thread.currentThread().getId(),event);
|
EmailLogManager.getInstance().offer(Thread.currentThread().getId(),event);
|
||||||
}
|
}
|
||||||
|
|
||||||
return emlFile;
|
return emlFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* 将eml中下载的未通过内容校验的邮件 移动到emlError目录
|
|
||||||
* */
|
|
||||||
public void emlToEmlError(File emlFile){
|
|
||||||
if (ObjectUtil.isNull(emlFile)) return;
|
|
||||||
final String filename = emlFile.getName();
|
|
||||||
try {
|
|
||||||
final String rootPath = spectrumPathProperties.getRootPath();
|
|
||||||
final String emlErrorPath = spectrumPathProperties.getEmlErrorPath();
|
|
||||||
File destDir = new File(rootPath + emlErrorPath);
|
|
||||||
// 如果目标目录不存在 则先创建
|
|
||||||
if (!destDir.exists()) destDir.mkdir();
|
|
||||||
FileUtil.move(emlFile, destDir, true);
|
|
||||||
}catch (Exception e){
|
|
||||||
log.error("The error email {} move from eml to emlError failed: {}", filename, e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除邮件
|
* 删除邮件
|
||||||
* @param message
|
* @param message
|
||||||
|
@ -607,10 +589,10 @@ public class EmailServiceManager {
|
||||||
log.error("Email deletion failed, the subject of the email is :{}, the reason is :{}.",subject,e.getMessage());
|
log.error("Email deletion failed, the subject of the email is :{}, the reason is :{}.",subject,e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}finally {
|
}finally {
|
||||||
EmailLogEvent removeEvent = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,status,EmailLogManager.DELETEID,subject,receivedDate);
|
EmailLogEvent removeEvent = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,status,EmailLogManager.DELETEID,subject,DateUtils.formatDate(receivedDate,"yyyy-MM-dd HH:mm:ss:SSS"));
|
||||||
EmailLogManager.getInstance().offer(Thread.currentThread().getId(),removeEvent);
|
EmailLogManager.getInstance().offer(Thread.currentThread().getId(),removeEvent);
|
||||||
//这里删除和彻底删除一起写入日志,java和C++处理有差异,java是在连接关闭时彻底删除的
|
//这里删除和彻底删除一起写入日志,java和C++处理有差异,java是在连接关闭时彻底删除的
|
||||||
EmailLogEvent expungeEvent = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,status,EmailLogManager.EXPUNGE,subject,receivedDate);
|
EmailLogEvent expungeEvent = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,status,EmailLogManager.EXPUNGE,subject,DateUtils.formatDate(receivedDate,"yyyy-MM-dd HH:mm:ss:SSS"));
|
||||||
EmailLogManager.getInstance().offer(Thread.currentThread().getId(),expungeEvent);
|
EmailLogManager.getInstance().offer(Thread.currentThread().getId(),expungeEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,7 @@ public class EmailParsingActuator extends Thread{
|
||||||
try {
|
try {
|
||||||
Message[] messages = emailServiceManager.receiveMail();
|
Message[] messages = emailServiceManager.receiveMail();
|
||||||
if(ArrayUtils.isNotEmpty(messages)){
|
if(ArrayUtils.isNotEmpty(messages)){
|
||||||
|
log.info("EmailParsingActuator本次获取邮件数量为:{}",messages.length);
|
||||||
//检验获取的邮件是否在之前删除失败列表中,若在直接调用邮件API删除,并且此次数组里元素也删除
|
//检验获取的邮件是否在之前删除失败列表中,若在直接调用邮件API删除,并且此次数组里元素也删除
|
||||||
for(int i=messages.length-1;i>=0;i--){
|
for(int i=messages.length-1;i>=0;i--){
|
||||||
if (!messages[i].isExpunged()){
|
if (!messages[i].isExpunged()){
|
||||||
|
@ -84,6 +85,7 @@ public class EmailParsingActuator extends Thread{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log.info("EmailParsingActuator本次真实执行邮件数量为:{}",messages.length);
|
||||||
CountDownLatch taskLatch = new CountDownLatch(messages.length);
|
CountDownLatch taskLatch = new CountDownLatch(messages.length);
|
||||||
for(Message message : messages){
|
for(Message message : messages){
|
||||||
SpectrumParsingActuator spectrumParsingActuator = new SpectrumParsingActuator();
|
SpectrumParsingActuator spectrumParsingActuator = new SpectrumParsingActuator();
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.jeecg.modules.spectrum;
|
package org.jeecg.modules.spectrum;
|
||||||
|
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.jeecg.common.constant.RedisConstant;
|
import org.jeecg.common.constant.RedisConstant;
|
||||||
|
@ -12,6 +13,8 @@ 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.file.FileOperation;
|
||||||
|
|
||||||
import javax.mail.Message;
|
import javax.mail.Message;
|
||||||
import javax.mail.internet.MimeMessage;
|
import javax.mail.internet.MimeMessage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -110,15 +113,20 @@ public class SpectrumParsingActuator implements Runnable{
|
||||||
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);
|
||||||
}
|
}
|
||||||
emailServiceManager.removeMail(message);
|
emailServiceManager.removeMail(message);
|
||||||
}
|
}else {
|
||||||
// 如果邮件内容校验失败(邮件内容不完整) 将错误邮件从eml移动到emlError
|
// 如果邮件内容校验失败(邮件内容不完整) 将错误邮件从eml移动到emlError
|
||||||
else {
|
if (Objects.nonNull(emlFile) && emlFile.exists()){
|
||||||
emailServiceManager.emlToEmlError(emlFile);
|
final String rootPath = spectrumServiceQuotes.getSpectrumPathProperties().getRootPath();
|
||||||
|
final String emlErrorPath = spectrumServiceQuotes.getSpectrumPathProperties().getEmlErrorPath();
|
||||||
|
final String finalPath = rootPath+emlErrorPath;
|
||||||
|
FileOperation.moveFile(emlFile,finalPath,true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// 如果邮件正常下载 则删除下载的邮件对象
|
// 如果不是下载导致的失败,则删除下载的邮件对象
|
||||||
if (!(e instanceof DownloadEmailException))
|
if(!(e instanceof DownloadEmailException)){
|
||||||
emailServiceManager.removeMail(message);
|
emailServiceManager.removeMail(message);
|
||||||
|
}
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}finally {
|
}finally {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user