自动处理程序修改逻辑

This commit is contained in:
qiaoqinzheng 2024-05-09 09:34:21 +08:00
parent 23bf9ee271
commit 72dbf2ba80
3 changed files with 20 additions and 15 deletions

View File

@ -126,7 +126,7 @@ public class EmailServiceManager {
/**
* 接收邮件
*/
public Message[] receiveMail() {
public Message[] receiveMail() throws MessagingException {
String status = EmailLogManager.STATUS_SUCCESS;
try{
//配置邮件服务属性
@ -185,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成功

View File

@ -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.*;
/**
@ -82,8 +79,14 @@ public class EmailParsingActuator extends Thread{
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();

View File

@ -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);