diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java index 90704309..c6c19121 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SpectrumParsingActuator.java @@ -83,6 +83,7 @@ public class SpectrumParsingActuator implements Runnable{ @Override public void run() { String subject = null; + boolean downloadFlag = false; try { //获取邮件主题 subject = emailServiceManager.getMailSubject(message,this.batchesCounter); @@ -97,6 +98,8 @@ public class SpectrumParsingActuator implements Runnable{ //所有邮件都需以.eml格式存储到eml文件夹中 final File emlFile = emailServiceManager.downloadEmailToEmlDir(message, emailCounter.getCurrValue(),this.batchesCounter); + downloadFlag = true; + //保存邮件日志到PG数据库 this.spectrumServiceQuotes.getMailLogService().create(message,emailProperties); @@ -126,13 +129,14 @@ public class SpectrumParsingActuator implements Runnable{ final String emlErrorPath = spectrumServiceQuotes.getSpectrumPathProperties().getEmlErrorPath(); final String finalPath = rootPath+emlErrorPath; FileOperation.moveFile(emlFile,finalPath,true); + // 删除 key,防止下次线程执行删除邮件 spectrumServiceQuotes.getRedisUtil().del(key); throw new DownloadEmailException("邮件移走后手动抛出DownloadEmailException"); } } } catch (Exception e) { - // 如果不是下载导致的失败,则删除下载的邮件对象 - if(!(e instanceof DownloadEmailException)){ + // 如果不是下载导致的失败 并且 下载成功,则删除下载的邮件对象 + if(!(e instanceof DownloadEmailException) && downloadFlag){ try { log.error("Remove Email:"+ message.getSubject() + StringPool.UNDERSCORE + DateUtils.formatDate(message.getReceivedDate(), "yyyy-MM-dd HH:mm:ss") + StringPool.UNDERSCORE); } catch (MessagingException ex) { @@ -141,7 +145,11 @@ public class SpectrumParsingActuator implements Runnable{ emailServiceManager.removeMail(message,batchesCounter); } //输出异常信息 - log.error("邮件处理异常:",e); + try { + log.error("邮件处理异常{},邮件主题:{}:", e, message.getSubject()); + } catch (MessagingException ex) { + ex.printStackTrace(); + } }finally { try { EmailLogEvent expungeEvent = new EmailLogEvent(this.batchesCounter,Thread.currentThread().getId(),EmailLogManager.GS_TYPE_GET,EmailLogManager.DONE);