diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailLogManager.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailLogManager.java index 668bf016..f947be89 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailLogManager.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailLogManager.java @@ -1,12 +1,11 @@ package org.jeecg.common.email; import cn.hutool.core.io.FileUtil; -import com.baomidou.mybatisplus.core.toolkit.StringPool; import lombok.Setter; import org.jeecg.common.constant.StringConstant; import org.jeecg.common.properties.SpectrumPathProperties; import org.jeecg.common.util.DateUtils; - +import org.springframework.util.CollectionUtils; import java.io.File; import java.time.LocalDateTime; import java.util.*; @@ -44,11 +43,6 @@ public class EmailLogManager { @Setter private EmailLogEvent getAllIdLogEvent = null; - /** - * 完成解析邮件流程的线程id集合 - */ - private LinkedList completeThreadIds = new LinkedList<>(); - /** * 线程邮件日志队列 */ @@ -64,9 +58,6 @@ public class EmailLogManager { public EmailLogManager(SpectrumPathProperties spectrumPathProperties) { this.spectrumPathProperties = spectrumPathProperties; - EmailLogExecThread logExecThread = new EmailLogExecThread(); - logExecThread.setName("email-get-exec-thread"); - logExecThread.start(); } /** @@ -82,13 +73,9 @@ public class EmailLogManager { * @param event */ public void offer(Long threadId,EmailLogEvent event){ - synchronized (completeThreadIds){ + synchronized (queue){ if(queue.containsKey(threadId)){ queue.get(threadId).offer(event); - if(EmailLogManager.DONE.equals(event.getLogProcess())){ - completeThreadIds.offer(threadId); - completeThreadIds.notify(); - } }else{ LinkedList logEventList = new LinkedList<>(); logEventList.offer(event); @@ -97,61 +84,39 @@ public class EmailLogManager { } } + /** + * 清空队列日志 + */ + public void clear(){ + synchronized (queue){ + this.setConnectLogEvent(null); + this.setGetAllIdLogEvent(null); + this.queue.clear(); + } + } + /** * 获取日志事件 * @return * @throws InterruptedException */ - public LinkedList take(Long threadId) throws InterruptedException { - synchronized (completeThreadIds){ - final LinkedList logEventList = queue.remove(threadId); - return logEventList; - } - } - - /** - * 获取解析邮件完成的线程id - * @return - * @throws InterruptedException - */ - public Long getCompleteThreadId() throws InterruptedException { - synchronized (completeThreadIds){ - if(completeThreadIds.isEmpty()){ - completeThreadIds.wait(); - return null; - } - final Long threadId = completeThreadIds.removeFirst(); - return threadId; - } - } - - /** - * 邮件日志执行线程 - */ - private class EmailLogExecThread extends Thread{ - - @Override - public void run() { - for(;;){ - try { - final Long threadId = EmailLogManager.getInstance().getCompleteThreadId(); - if(Objects.nonNull(threadId)){ - final LinkedList logEventList = EmailLogManager.getInstance().take(threadId); - if(Objects.nonNull(getAllIdLogEvent)){ - logEventList.addFirst(getAllIdLogEvent); - } - if(Objects.nonNull(connectLogEvent)){ - logEventList.addFirst(connectLogEvent); - } - List logContentList = new ArrayList<>(); - logEventList.forEach(logEvent->{ - final String logContent = getLogContent(logEvent); - logContentList.add(logContent); - }); - writeLog(GS_TYPE_GET,logContentList); + public void writeLog(Long threadId){ + synchronized (queue){ + if(queue.containsKey(threadId)){ + final LinkedList logEventList = queue.remove(threadId); + if(!CollectionUtils.isEmpty(logEventList)){ + if(Objects.nonNull(getAllIdLogEvent)){ + logEventList.addFirst(getAllIdLogEvent); } - } catch (InterruptedException e) { - e.printStackTrace(); + if(Objects.nonNull(connectLogEvent)){ + logEventList.addFirst(connectLogEvent); + } + List logContentList = new ArrayList<>(); + logEventList.forEach(logEvent->{ + final String logContent = this.getLogContent(logEvent); + logContentList.add(logContent); + }); + this.write(GS_TYPE_GET,logContentList); } } } @@ -339,7 +304,7 @@ public class EmailLogManager { /** * 把日志写入文件 */ - private void writeLog(String gsType, List logContentList){ + private void write(String gsType, List logContentList){ LocalDateTime now = LocalDateTime.now(); StringBuilder logFilePath = new StringBuilder(); logFilePath.append(spectrumPathProperties.getRootPath()); diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java index 6c0a7a86..61b5cc1c 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java @@ -223,6 +223,7 @@ public class EmailServiceManager { // props.put("mail.imap.starttls.enable", "true"); Session session = Session.getInstance(props, new Authenticator() { + @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } @@ -286,6 +287,7 @@ public class EmailServiceManager { // props.put("mail.smtp.starttls.enable", "true"); Session session = Session.getInstance(props, new Authenticator() { + @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java index 741d3f01..484606d3 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/EmailParsingActuator.java @@ -63,9 +63,8 @@ public class EmailParsingActuator extends Thread{ }catch (InterruptedException e) { e.printStackTrace(); }finally { - //每批次连接关闭后清空邮箱全局日志 - EmailLogManager.getInstance().setConnectLogEvent(null); - EmailLogManager.getInstance().setGetAllIdLogEvent(null); + //清除本批次日志缓存 + EmailLogManager.getInstance().clear(); //关闭资源 emailServiceManager.close(); } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SamplephdSpectrum.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SamplephdSpectrum.java index eb2b5da4..c6f12a83 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SamplephdSpectrum.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/SamplephdSpectrum.java @@ -80,9 +80,9 @@ public class SamplephdSpectrum extends AbstractS_D_Q_G_SpectrumHandler { Sample_B_Analysis bAnalysis = new Sample_B_Analysis(this); bAnalysis.analysis(); } - if (this.sourceData.system_type.equals(SystemType.PARTICULATE.getType()) || this.sourceData.system_type.equals(SystemType.GAMMA.getType())) { - Sample_G_Analysis sample_g_analysis = new Sample_G_Analysis(super.sourceData, super.spectrumServiceQuotes, super.sampleData); - sample_g_analysis.analysis(); - } +// if (this.sourceData.system_type.equals(SystemType.PARTICULATE.getType()) || this.sourceData.system_type.equals(SystemType.GAMMA.getType())) { +// Sample_G_Analysis sample_g_analysis = new Sample_G_Analysis(super.sourceData, super.spectrumServiceQuotes, super.sampleData); +// sample_g_analysis.analysis(); +// } } } 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 3cb25246..d36894e3 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 @@ -87,13 +87,19 @@ 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); } catch (Exception e) { + emailServiceManager.removeMail(message); e.printStackTrace(); }finally { - emailServiceManager.removeMail(message); - EmailLogEvent expungeEvent = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,EmailLogManager.DONE); - EmailLogManager.getInstance().offer(Thread.currentThread().getId(),expungeEvent); - this.taskLatch.countDown(); + try { + EmailLogEvent expungeEvent = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,EmailLogManager.DONE); + EmailLogManager.getInstance().offer(Thread.currentThread().getId(),expungeEvent); + + EmailLogManager.getInstance().writeLog(Thread.currentThread().getId()); + }finally { + this.taskLatch.countDown(); + } } } diff --git a/jeecg-server-cloud/armd-auto-process-start/src/main/java/org/jeecg/JeecgAutoProcessApplication.java b/jeecg-server-cloud/armd-auto-process-start/src/main/java/org/jeecg/JeecgAutoProcessApplication.java index 54a0ea73..8aa0afa8 100644 --- a/jeecg-server-cloud/armd-auto-process-start/src/main/java/org/jeecg/JeecgAutoProcessApplication.java +++ b/jeecg-server-cloud/armd-auto-process-start/src/main/java/org/jeecg/JeecgAutoProcessApplication.java @@ -80,7 +80,7 @@ public class JeecgAutoProcessApplication extends SpringBootServletInitializer im EmailLogManager.init(spectrumPathProperties); //校验存储目录是否存在,不存在则创建,存在无操作 checkStorageDirectory(); -// autoProcessManager.start(systemStartupTime); + autoProcessManager.start(systemStartupTime); undealHandleManager.start(); fileSourceHandleManager.start(); // 删除过期的文件