自动处理模块模块同步代码
This commit is contained in:
parent
7b5e167eb2
commit
c5ffa77954
|
@ -9,6 +9,8 @@ import com.sun.mail.imap.IMAPStore;
|
|||
import com.sun.mail.smtp.SMTPAddressFailedException;
|
||||
import io.swagger.models.auth.In;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.Charsets;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jeecg.common.api.dto.message.MessageDTO;
|
||||
import org.jeecg.common.constant.RedisConstant;
|
||||
|
@ -124,7 +126,7 @@ public class EmailServiceManager {
|
|||
/**
|
||||
* 接收邮件
|
||||
*/
|
||||
public Message[] receiveMail() {
|
||||
public Message[] receiveMail() throws MessagingException {
|
||||
String status = EmailLogManager.STATUS_SUCCESS;
|
||||
try{
|
||||
//配置邮件服务属性
|
||||
|
@ -183,12 +185,11 @@ public class EmailServiceManager {
|
|||
return Arrays.copyOfRange(messages,0,this.receiveNum-1);
|
||||
}
|
||||
}
|
||||
}catch (MessagingException e){
|
||||
} catch (MessagingException e){
|
||||
status = EmailLogManager.STATUS_ERROR;
|
||||
log.error("Email connection is abnormal, account is {}, service is {},the reason is {}.",email.getName(),email.getEmailServerAddress(),e.getMessage());
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}finally {
|
||||
throw e;
|
||||
} finally {
|
||||
EmailLogEvent connectEvent = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,email,status,EmailLogManager.CONNECT);
|
||||
EmailLogManager.getInstance().setConnectLogEvent(connectEvent);
|
||||
//GetAllId C++原业务是把远程邮箱邮件同步到C++,本次java编写没有这一步,所以和Connect绑定,若Connect成功则GetAllId成功
|
||||
|
|
|
@ -233,9 +233,15 @@ public class AutoProcessManager{
|
|||
if(databaseEmail.getEnabled().equals(SysMailEnableType.ENABLE.getMailEnableType())){
|
||||
final boolean testFlag = testConnectEmailServer(databaseEmail);
|
||||
if(testFlag){
|
||||
databaseEmail.setNewEmailFlag(true);
|
||||
if (emailExecThreadMap.containsKey(databaseEmail.getId())) {
|
||||
EmailParsingActuator actuator = emailExecThreadMap.get(databaseEmail.getId());
|
||||
actuator.setStop(false);
|
||||
log.info("{}邮箱重新加入监测队列",databaseEmail.getUsername());
|
||||
} else {
|
||||
databaseEmail.setNewEmailFlag(true);
|
||||
log.info("{}邮箱加入监测队列,设置新增标记",databaseEmail.getUsername());
|
||||
}
|
||||
emailMap.put(databaseEmail.getId(),databaseEmail);
|
||||
log.info("{}邮箱加入监测队列,设置新增标记",databaseEmail.getUsername());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -279,6 +285,7 @@ public class AutoProcessManager{
|
|||
if(next.getValue().getState() == State.TERMINATED){
|
||||
log.info("{}邮箱执行线程已停止,emailExecThreadMap删除此邮箱数据",next.getValue().getEmailProperties().getUsername());
|
||||
checkStopThreads.remove();
|
||||
emailMap.remove(next.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,10 +17,7 @@ import org.springframework.scheduling.concurrent.CustomizableThreadFactory;
|
|||
import javax.mail.Message;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
|
@ -79,11 +76,17 @@ public class EmailParsingActuator extends Thread{
|
|||
try {
|
||||
Message[] messages = emailServiceManager.receiveMail();
|
||||
if(ArrayUtils.isNotEmpty(messages)){
|
||||
log.info("EmailParsingActuator本次获取邮件数量为:{}",messages.length);
|
||||
log.info("EmailParsingActuator本次{}获取邮件数量为:{}", Thread.currentThread().getName(), messages.length);
|
||||
//检验获取的邮件是否在之前删除失败列表中,若在直接调用邮件API删除,并且此次数组里元素也删除
|
||||
for(int i=messages.length-1;i>=0;i--){
|
||||
if (null == messages[i].getHeader("Message-ID")) {
|
||||
System.out.println("Message ID是空值信息!!!!!!!");
|
||||
messages = ArrayUtils.remove(messages, i);
|
||||
continue;
|
||||
}
|
||||
if (!messages[i].isExpunged()){
|
||||
String messageId = ((MimeMessage) messages[i]).getMessageID();
|
||||
System.out.println("正常获取到的Message ID是:"+messageId);
|
||||
final boolean exist = emailServiceManager.check(messages[i],messageId);
|
||||
messageIds.add(messageId);
|
||||
if(exist){
|
||||
|
@ -105,10 +108,13 @@ public class EmailParsingActuator extends Thread{
|
|||
taskLatch.await();
|
||||
}
|
||||
}
|
||||
}catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (MessagingException e) {
|
||||
System.out.println("捕获MessagingException!!!!!!!!");
|
||||
closeResource();
|
||||
throw new RuntimeException(e);
|
||||
} catch (Exception e) {
|
||||
closeResource();
|
||||
log.error(""+e);
|
||||
} finally {
|
||||
//清除本批次邮件日志缓存
|
||||
EmailLogManager.getInstance().clear();
|
||||
|
|
|
@ -97,9 +97,6 @@ public class SpectrumParsingActuator implements Runnable{
|
|||
String emlName = subject+ StringConstant.UNDER_LINE+ receiveDate;
|
||||
String key = RedisConstant.EMAIL_MSG_ID+StringConstant.COLON+messageId;
|
||||
// spectrumServiceQuotes.getRedisUtil().set(key,emlName,expiryTime);
|
||||
//判断当前key的下载次数是否超过限制次数
|
||||
spectrumServiceQuotes.getRedisUtil().incr(key, 1L);
|
||||
spectrumServiceQuotes.getRedisUtil().expire(key, expiryTime);
|
||||
//线程开始初始化时,初始本线程负责的能谱日志事件
|
||||
SpectrumLogManager.mailSpectrumLogManager.offer(Thread.currentThread().getId(),null);
|
||||
|
||||
|
@ -144,7 +141,10 @@ 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,batchesCounter);
|
||||
}else {
|
||||
} else {
|
||||
//判断当前key的下载次数是否超过限制次数
|
||||
spectrumServiceQuotes.getRedisUtil().incr(key, 1L);
|
||||
spectrumServiceQuotes.getRedisUtil().expire(key, expiryTime);
|
||||
// 如果邮件内容校验失败(邮件内容不完整) 将错误邮件从eml移动到emlError
|
||||
if (Objects.nonNull(emlFile) && emlFile.exists()){
|
||||
moveEmail(emlFile, key);
|
||||
|
|
Loading…
Reference in New Issue
Block a user