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 org.jeecg.modules.base.entity.postgre.SysEmail;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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.state = state;
|
||||
this.logProcess = logProcess;
|
||||
|
@ -92,7 +91,7 @@ public class EmailLogEvent {
|
|||
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.state = state;
|
||||
this.logProcess = logProcess;
|
||||
|
|
|
@ -238,7 +238,7 @@ public class EmailLogManager {
|
|||
logContent.append(" Get File subject:");
|
||||
logContent.append(event.getSubject());
|
||||
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(" EmlFile ");
|
||||
logContent.append(event.getEmlPath());
|
||||
|
@ -259,7 +259,7 @@ public class EmailLogManager {
|
|||
logContent.append(" Delete File subject:");
|
||||
logContent.append(event.getSubject());
|
||||
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(LOG_SUFFIX);
|
||||
logContent.append(System.lineSeparator());
|
||||
|
@ -278,7 +278,7 @@ public class EmailLogManager {
|
|||
logContent.append(" Expunge File subject:");
|
||||
logContent.append(event.getSubject());
|
||||
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(LOG_SUFFIX);
|
||||
logContent.append(System.lineSeparator());
|
||||
|
|
|
@ -522,6 +522,7 @@ public class EmailServiceManager {
|
|||
String subject = "";
|
||||
File emlFile = null;
|
||||
String status = EmailLogManager.STATUS_SUCCESS;
|
||||
Date receivedDate = null;
|
||||
try {
|
||||
//获取发件人
|
||||
final String address = ((InternetAddress) message.getFrom()[0]).getAddress();
|
||||
|
@ -534,7 +535,7 @@ public class EmailServiceManager {
|
|||
if(subject.indexOf(StringConstant.COLON) != -1){
|
||||
subject = StringUtils.replace(subject,StringConstant.COLON,"");
|
||||
}
|
||||
|
||||
receivedDate = message.getReceivedDate();
|
||||
StringBuilder fileName = new StringBuilder();
|
||||
fileName.append(from);
|
||||
fileName.append(StringConstant.UNDER_LINE);
|
||||
|
@ -546,9 +547,9 @@ public class EmailServiceManager {
|
|||
fileName.append(StringConstant.UNDER_LINE);
|
||||
fileName.append("receive");
|
||||
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(DateUtils.formatDate(message.getReceivedDate(),"HHMMSSSSS"));
|
||||
fileName.append(DateUtils.formatDate(receivedDate,"HHMMSSSSS"));
|
||||
fileName.append(StringConstant.UNDER_LINE);
|
||||
fileName.append(emailCounter);
|
||||
fileName.append(SAVE_EML_SUFFIX);
|
||||
|
@ -563,32 +564,13 @@ public class EmailServiceManager {
|
|||
log.error(errorMsg);
|
||||
throw new DownloadEmailException(errorMsg);
|
||||
}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()));
|
||||
EmailLogManager.getInstance().offer(Thread.currentThread().getId(),event);
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -607,10 +589,10 @@ public class EmailServiceManager {
|
|||
log.error("Email deletion failed, the subject of the email is :{}, the reason is :{}.",subject,e.getMessage());
|
||||
e.printStackTrace();
|
||||
}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);
|
||||
//这里删除和彻底删除一起写入日志,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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,6 +73,7 @@ public class EmailParsingActuator extends Thread{
|
|||
try {
|
||||
Message[] messages = emailServiceManager.receiveMail();
|
||||
if(ArrayUtils.isNotEmpty(messages)){
|
||||
log.info("EmailParsingActuator本次获取邮件数量为:{}",messages.length);
|
||||
//检验获取的邮件是否在之前删除失败列表中,若在直接调用邮件API删除,并且此次数组里元素也删除
|
||||
for(int i=messages.length-1;i>=0;i--){
|
||||
if (!messages[i].isExpunged()){
|
||||
|
@ -84,6 +85,7 @@ public class EmailParsingActuator extends Thread{
|
|||
}
|
||||
}
|
||||
}
|
||||
log.info("EmailParsingActuator本次真实执行邮件数量为:{}",messages.length);
|
||||
CountDownLatch taskLatch = new CountDownLatch(messages.length);
|
||||
for(Message message : messages){
|
||||
SpectrumParsingActuator spectrumParsingActuator = new SpectrumParsingActuator();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.jeecg.modules.spectrum;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
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.modules.email.EmailProperties;
|
||||
import org.jeecg.modules.enums.SpectrumSource;
|
||||
import org.jeecg.modules.file.FileOperation;
|
||||
|
||||
import javax.mail.Message;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
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);
|
||||
}
|
||||
emailServiceManager.removeMail(message);
|
||||
}
|
||||
// 如果邮件内容校验失败(邮件内容不完整) 将错误邮件从eml移动到emlError
|
||||
else {
|
||||
emailServiceManager.emlToEmlError(emlFile);
|
||||
}else {
|
||||
// 如果邮件内容校验失败(邮件内容不完整) 将错误邮件从eml移动到emlError
|
||||
if (Objects.nonNull(emlFile) && emlFile.exists()){
|
||||
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) {
|
||||
// 如果邮件正常下载 则删除下载的邮件对象
|
||||
if (!(e instanceof DownloadEmailException))
|
||||
// 如果不是下载导致的失败,则删除下载的邮件对象
|
||||
if(!(e instanceof DownloadEmailException)){
|
||||
emailServiceManager.removeMail(message);
|
||||
}
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue
Block a user