From 72f564b155ed5ca7ea41cf3c9af3addd4c6cc5e5 Mon Sep 17 00:00:00 2001
From: panbaolin <123456>
Date: Wed, 21 Jun 2023 11:16:50 +0800
Subject: [PATCH 1/2] =?UTF-8?q?fix:1.=E6=8F=90=E4=BA=A4=E8=87=AA=E5=8A=A8?=
=?UTF-8?q?=E5=A4=84=E7=90=86=E7=A8=8B=E5=BA=8F=E5=B7=A5=E7=A8=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
jeecg-boot-base-core/pom.xml | 1 -
.../common/email/EmailServiceManager.java | 204 ++++++++++
.../common/email/emuns/MailContentType.java | 43 +++
.../jeecg/common/email/emuns/SysMailType.java | 26 ++
.../java/org/jeecg/common/util/FTPUtil.java | 1 +
.../base/struct/EnergySpectrumStruct.java | 363 ++++++++++++++++++
jeecg-module-auto-process/pom.xml | 30 ++
.../org/jeecg/modules/AutoProcessManager.java | 251 ++++++++++++
.../mybatis/CustomMetaObjectHandler.java | 26 ++
.../modules/email/EmailLogProperties.java | 18 +
.../modules/email/EmailParsingActuator.java | 107 ++++++
.../jeecg/modules/email/EmailProperties.java | 27 ++
.../modules/emuns/SysMailEnableType.java | 26 ++
.../jeecg/modules/mapper/SysMailMapper.java | 10 +
.../properties/SpectrumPathProperties.java | 28 ++
.../modules/properties/TaskProperties.java | 42 ++
.../modules/service/ISysMailService.java | 18 +
.../service/impl/SysMailServiceImpl.java | 47 +++
.../jeecg-auto-process-start/pom.xml | 42 ++
.../jeecg/JeecgAutoProcessApplication.java | 54 +++
.../src/main/resources/application.yml | 19 +
.../src/main/resources/logback-spring.xml | 77 ++++
jeecg-server-cloud/pom.xml | 1 +
pom.xml | 9 +-
24 files changed, 1462 insertions(+), 8 deletions(-)
create mode 100644 jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java
create mode 100644 jeecg-boot-base-core/src/main/java/org/jeecg/common/email/emuns/MailContentType.java
create mode 100644 jeecg-boot-base-core/src/main/java/org/jeecg/common/email/emuns/SysMailType.java
create mode 100644 jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/struct/EnergySpectrumStruct.java
create mode 100644 jeecg-module-auto-process/pom.xml
create mode 100644 jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java
create mode 100644 jeecg-module-auto-process/src/main/java/org/jeecg/modules/config/mybatis/CustomMetaObjectHandler.java
create mode 100644 jeecg-module-auto-process/src/main/java/org/jeecg/modules/email/EmailLogProperties.java
create mode 100644 jeecg-module-auto-process/src/main/java/org/jeecg/modules/email/EmailParsingActuator.java
create mode 100644 jeecg-module-auto-process/src/main/java/org/jeecg/modules/email/EmailProperties.java
create mode 100644 jeecg-module-auto-process/src/main/java/org/jeecg/modules/emuns/SysMailEnableType.java
create mode 100644 jeecg-module-auto-process/src/main/java/org/jeecg/modules/mapper/SysMailMapper.java
create mode 100644 jeecg-module-auto-process/src/main/java/org/jeecg/modules/properties/SpectrumPathProperties.java
create mode 100644 jeecg-module-auto-process/src/main/java/org/jeecg/modules/properties/TaskProperties.java
create mode 100644 jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/ISysMailService.java
create mode 100644 jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/SysMailServiceImpl.java
create mode 100644 jeecg-server-cloud/jeecg-auto-process-start/pom.xml
create mode 100644 jeecg-server-cloud/jeecg-auto-process-start/src/main/java/org/jeecg/JeecgAutoProcessApplication.java
create mode 100644 jeecg-server-cloud/jeecg-auto-process-start/src/main/resources/application.yml
create mode 100644 jeecg-server-cloud/jeecg-auto-process-start/src/main/resources/logback-spring.xml
diff --git a/jeecg-boot-base-core/pom.xml b/jeecg-boot-base-core/pom.xml
index 6775e78a..1e5181eb 100644
--- a/jeecg-boot-base-core/pom.xml
+++ b/jeecg-boot-base-core/pom.xml
@@ -259,5 +259,4 @@
3.3
-
\ No newline at end of file
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
new file mode 100644
index 00000000..70feb479
--- /dev/null
+++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java
@@ -0,0 +1,204 @@
+package org.jeecg.common.email;
+
+import com.google.common.collect.Lists;
+import com.sun.mail.imap.IMAPStore;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.email.emuns.MailContentType;
+import org.jeecg.modules.base.entity.SysEmail;
+import org.jetbrains.annotations.NotNull;
+import javax.mail.*;
+import javax.mail.internet.MimeUtility;
+import java.io.*;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * 邮件服务管理器
+ */
+@Slf4j
+public class EmailServiceManager {
+
+ private SysEmail email;
+ /** 邮件接收数量 */
+ private Integer receiveNum;
+ /** smtp协议的存储对象 */
+ private IMAPStore store = null;
+ /** 邮件附件临时存储路径 */
+ private String temporaryStoragePath;
+ /** 收件箱 */
+ private Folder folder = null;
+
+ @NotNull
+ public static EmailServiceManager getInstance(){
+ return new EmailServiceManager();
+ }
+
+ /**
+ * 初始化邮件服务管理器
+ * @param email 邮件属性
+ */
+ public void init(SysEmail email){
+ this.email = email;
+ }
+
+ /**
+ * 初始化邮件服务管理器
+ * @param email 邮件属性
+ */
+ public void init(SysEmail email,Integer receiveNum,String temporaryStoragePath){
+ this.email = email;
+ this.receiveNum = receiveNum;
+ this.temporaryStoragePath = temporaryStoragePath;
+ }
+
+ /**
+ * 测试邮件服务连通性
+ */
+ public boolean testConnectEmailServer(){
+ Socket socket = new Socket();
+ boolean flag = false;
+ try {
+ socket.connect(new InetSocketAddress(email.getEmailServerAddress(),email.getPort()),5000);
+ log.info("{}邮件服务连接测试成功",email.getEmailServerAddress());
+ flag = true;
+ } catch (IOException e) {
+ log.error("{}邮件服务连接测试失败,请检查邮件服务属性配置是否正确或邮件服务未开启,原因{}",email.getEmailServerAddress(),e.getMessage());
+ }finally {
+ try {
+ if(null != socket){
+ socket.close();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return flag;
+ }
+
+ /**
+ * 接收邮件
+ */
+ public Message[] receiveMail() throws MessagingException {
+ //配置邮件服务属性
+ Properties props = new Properties();
+ props.put("mail.store.protocol","imap");
+ props.put("mail.imap.host",email.getEmailServerAddress());
+ props.put("mail.imap.port",email.getPort());
+ //获取邮件回话
+ final Session session = Session.getInstance(props, new Authenticator() {
+ @Override
+ protected PasswordAuthentication getPasswordAuthentication() {
+ return new PasswordAuthentication(email.getUsername(), email.getPassword());
+ }
+ });
+ Map iam = new HashMap<>();
+ iam.put("name", "myname");
+ iam.put("version", "1.0.0");
+ iam.put("vendor", "myclient");
+ iam.put("support-email", "testmail@test.com");
+ //获取smtp协议的存储对象
+ store = (IMAPStore) session.getStore();
+ //连接
+ store.connect();
+ store.id(iam);
+ //获取收件箱
+ folder = store.getFolder("INBOX");
+ folder.open(Folder.READ_WRITE);
+ //获取邮件数量
+ final int messageCount = folder.getMessageCount();
+ if(messageCount > 0){
+ Integer start = 1;
+ Integer end = this.receiveNum>messageCount?messageCount:this.receiveNum;
+ final Message[] messages = folder.getMessages(start,end);
+ return messages;
+ }
+ return null;
+ }
+
+ /**
+ * 获取邮件内容
+ * @param part
+ * @return
+ * @throws MessagingException
+ * @throws IOException
+ */
+ public void getMailContent(@NotNull Part part, StringBuilder content) throws MessagingException, IOException {
+ Multipart multipart = (Multipart) part.getContent();
+ for(int i=0;i saveAttachment(@NotNull Part part) throws MessagingException, IOException {
+ List filePathList = Lists.newArrayList();
+ Multipart multipart = (Multipart) part.getContent();
+ for(int i=0;i g_energy;
+ /**
+ * centroid channel
+ */
+ private List g_centroid_channel;
+ /**
+ * uncertainty (channels)
+ */
+ private List g_uncertainty;
+
+ private Integer g_record_count;
+
+ /************************* b_Energy Block ******************/
+ /**
+ * electron energy (keV)
+ */
+ private List b_electron_energy;
+ /**
+ * decay mode descriptor: B for β-particle, C for conversion electron (CE)
+ */
+ private List b_decay_mode;
+ /**
+ * maximum channel of β-particle distribution or centroid channel of CE (channels)
+ */
+ private List b_channel;
+ /**
+ * uncertainty (channels)
+ */
+ private List b_uncertainty;
+
+ private Integer b_record_count;
+
+ /************************* g_Resolution Block ******************/
+ /**
+ * γ -energy (keV)
+ */
+ private List g_r_energy;
+ /**
+ * FWHM (keV)
+ */
+ private List g_r_FWHM;
+ /**
+ * uncertainty (keV)
+ */
+ private List g_r_uncertainty;
+
+ private Integer g_r_record_count;
+
+ /************************* b_Resolution Block ******************/
+ /**
+ * electron energy (keV)
+ */
+ private List b_r_electron_energy;
+ /**
+ * FWHM (keV)
+ */
+ private List b_r_FWHM;
+ /**
+ * uncertainty (keV)
+ */
+ private List b_r_uncertainty;
+
+ private Integer b_r_record_count;
+
+ /************************* g_Efficiency Block ******************/
+ /**
+ * γ -energy (keV)
+ */
+ private List g_e_energy;
+ /**
+ * efficiency (counts in peak/photon emitted)
+ */
+ private List g_e_efficiency;
+ /**
+ * uncertainty (counts in peak/photon emitted)
+ */
+ private List g_e_uncertainty;
+
+ private Integer g_e_record_count;
+
+ /************************* ROI_Limits Block ******************/
+ /**
+ * ROI number
+ */
+ private List ROI_number;
+ /**
+ * 2-D ROI β-range start, x 1 (keV)
+ */
+ private List POI_B_x1;
+ /**
+ * 2-D ROI β-range stop, x 2 (keV)
+ */
+ private List POI_B_x2;
+ /**
+ * 2-D ROI γ-range start, y 1 (keV)
+ */
+ private List POI_G_y1;
+ /**
+ * 2-D ROI γ-range stop, y 2 (keV)
+ */
+ private List POI_G_y2;
+
+ private Integer roi_record_count;
+
+ /************************* b-gEfficiency Block ******************/
+ /**
+ * nuclide name
+ */
+ private List bg_nuclide_name;
+ /**
+ * ROI number
+ */
+ private List bg_ROI_number;
+ /**
+ * β-γ coincidence efficiency (counts in ROI/β-γ pair emitted)
+ */
+ private List bg_efficiency;
+ /**
+ * uncertainty (counts in ROI/β-γ pair emitted)
+ */
+ private List bg_uncertainty;
+
+ private Integer bg_record_count;
+
+ /************************* Ratios Block ******************/
+ /**
+ * ratio identifier
+ */
+ private List ratio_id;
+ /**
+ * ROI number for the higher γ -energy ROI
+ */
+ private List ROI_num_highter_G_energy_ROI;
+ /**
+ * ROI number for the lower γ -energy ROI
+ */
+ private List ROI_num_lower_G_energy_ROI;
+ /**
+ * Q_DECLARE_METATYPE(RMSSOHData::HeaderBlock)count ratio(counts in higher γ -energy ROI/counts in lower γ -energy ROI)
+ */
+ private List count_ratio;
+ /**
+ * count ratio uncertainty (percent)
+ */
+ private List count_ratio_uncertainty;
+
+ private Integer ratio_record_count;
+
+ /************************* g_Spectrum Block ******************/
+ /**
+ * number of γ channels
+ */
+ private Long num_g_channel;
+ /**
+ * γ-energy span (keV)
+ */
+ private Long g_energy_span;
+ /**
+ * begin of channels
+ */
+ private Long g_begin_channel;
+ /**
+ * count at channel
+ */
+ private List g_counts;
+
+ /************************* b_Spectrum Block ******************/
+ /**
+ * number of β -channels
+ */
+ private Long num_b_channel;
+ /**
+ * β -energy span (keV)
+ */
+ private Long b_energy_span;
+ /**
+ * begin of channels
+ */
+ private Long b_begin_channel;
+ /**
+ * counts at channels
+ */
+ private List b_counts;
+
+ /************************* Histogram Block ******************/
+ /**
+ * β-channels
+ */
+ private Long b_channels;
+ /**
+ * γ-channels
+ */
+ private Long g_channels;
+ /**
+ * β-energy span
+ */
+ private Long b_h_energy_span;
+ /**
+ * γ-energy span
+ */
+ private Long g_h_energy_span;
+ /**
+ * counts at channels
+ */
+ private List h_counts;
+}
diff --git a/jeecg-module-auto-process/pom.xml b/jeecg-module-auto-process/pom.xml
new file mode 100644
index 00000000..7374c1ed
--- /dev/null
+++ b/jeecg-module-auto-process/pom.xml
@@ -0,0 +1,30 @@
+
+
+
+ jeecg-boot-parent
+ org.jeecgframework.boot
+ 3.5.1
+
+ 4.0.0
+
+ jeecg-module-auto-process
+
+
+
+ org.jeecgframework.boot
+ jeecg-boot-base-core
+
+
+
+ org.jeecgframework.boot
+ jeecg-boot-starter-cloud
+
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+ true
+
+
+
\ No newline at end of file
diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java
new file mode 100644
index 00000000..ff06c53d
--- /dev/null
+++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/AutoProcessManager.java
@@ -0,0 +1,251 @@
+package org.jeecg.modules;
+
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.constant.EmailConstant;
+import org.jeecg.common.email.EmailServiceManager;
+import org.jeecg.common.util.RedisUtil;
+import org.jeecg.modules.email.EmailParsingActuator;
+import org.jeecg.modules.emuns.SysMailEnableType;
+import org.jeecg.modules.email.EmailProperties;
+import org.jeecg.modules.properties.SpectrumPathProperties;
+import org.jeecg.modules.properties.TaskProperties;
+import org.jeecg.modules.service.ISysMailService;
+import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * 自动处理程序管理器
+ */
+@Slf4j
+@Component
+@RequiredArgsConstructor
+public class AutoProcessManager{
+
+ private final ISysMailService mailService;
+ private final TaskProperties taskProperties;
+ private final RedisUtil redisUtil;
+ private final SpectrumPathProperties spectrumPathProperties;
+
+ /**
+ * 邮件Map数据锁
+ */
+ private final Object lock = new Object();
+ /**
+ * 以邮件Id为key,邮件信息为value
+ */
+ private Map emailMap = new HashMap<>();
+
+ /**
+ * 以邮件id为key,以邮件执行线程为value
+ */
+ private Map emailExecThreadMap = new HashMap<>();
+
+ /**
+ * 启动自动处理
+ */
+ public void start() {
+ //邮件数据监测线程
+ final MailDataMonitor mailDataMonitor = new MailDataMonitor();
+ mailDataMonitor.setName("mail-data-monitor");
+ mailDataMonitor.start();
+ //邮件服务监测线程
+ final MailServerMonitor monitorThread = new MailServerMonitor();
+ monitorThread.setName("mail-server-monitor");
+ monitorThread.start();
+ //邮件执行线程管理
+ final MailExecManager autoProcessThread = new MailExecManager();
+ autoProcessThread.setName("mail-exec-thread-manage");
+ autoProcessThread.start();
+ }
+
+ /**
+ * 自动处理线程
+ */
+ private class MailExecManager extends Thread{
+
+ @Override
+ public void run() {
+ for(;;){
+ long start = System.currentTimeMillis();
+ if(!CollectionUtils.isEmpty(emailMap)){
+ Iterator iterator = emailMap.values().iterator();
+ while(iterator.hasNext()){
+ EmailProperties next = iterator.next();
+ if(next.isDelFlag()){
+ if(emailExecThreadMap.containsKey(next.getId())){
+ Thread thread = emailExecThreadMap.get(next.getId());
+ thread.interrupt();
+ emailExecThreadMap.remove(next.getId());
+ }
+ iterator.remove();
+ }
+ if(next.isNewEmailFlag()){
+ EmailParsingActuator emailParsingActuator = new EmailParsingActuator();
+ emailParsingActuator.init(taskProperties,next);
+ emailParsingActuator.setName(next.getUsername()+"-email-monitor");
+ emailParsingActuator.start();
+ //把邮件监测执行线程加入管理队列
+ emailExecThreadMap.put(next.getId(),emailParsingActuator);
+ //新邮件监测监测线程已启动则修改新邮件标记为false
+ next.setNewEmailFlag(false);
+ }
+ }
+ }
+ long end = System.currentTimeMillis();
+ long sleepTime = taskProperties.getMonitoringMailDataCycle() - (end-start);
+ //如果sleepTime > 0 需要睡眠到指定时间,否则继续下次获取邮件
+ if(sleepTime > 0){
+ try {
+ //如果本次
+ TimeUnit.MILLISECONDS.sleep(sleepTime);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * 邮箱通信监测线程,具体功能如下:
+ * 监测邮件服务通讯是否正常,把各邮箱通信状态写入redis
+ */
+ private class MailServerMonitor extends Thread{
+
+ @Override
+ public void run() {
+ for(;;){
+ long start = System.currentTimeMillis();
+ try{
+ if(!CollectionUtils.isEmpty(emailMap)){
+ emailMap.values().forEach(email->{
+ if(!email.isDelFlag()){
+ final EmailServiceManager emailServiceManager = EmailServiceManager.getInstance();
+ emailServiceManager.init(email);
+ boolean testFlag = emailServiceManager.testConnectEmailServer();
+ redisUtil.hset(EmailConstant.EMAIL_STATUS_PREFIX,email.getId(),testFlag);
+ if(testFlag && !emailExecThreadMap.containsKey(email.getId())){
+ email.setNewEmailFlag(true);
+ }
+ if(!testFlag){
+ //如果邮件服务通信测试失败则添加删除标记
+ email.setDelFlag(true);
+ }
+ }
+ });
+ }
+ //捕获异常不处理保障线程异常不退出
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ long end = System.currentTimeMillis();
+ long sleepTime = taskProperties.getMonitoringMailCommStatusCycle() - (end-start);
+ //如果sleepTime > 0 需要睡眠到指定时间,否则继续下次监测
+ if(sleepTime > 0){
+ try {
+ TimeUnit.MILLISECONDS.sleep(sleepTime);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * 邮箱数据监测线程,具体功能如下:
+ * 1.监测邮件数据表是否有变化
+ * 1.1有新邮件记录并且已启用则启动新线程执行
+ * 1.2有邮件记录被删除并且此邮箱信息已有线程执行则停止执行
+ */
+ private class MailDataMonitor extends Thread{
+
+ @Override
+ public void run() {
+ for (;;){
+ long start = System.currentTimeMillis();
+ try{
+ final List receiveMails = mailService.findReceiveMails();
+ if(!CollectionUtils.isEmpty(receiveMails)){
+ //如果库里已有数据原来已开启使用并且监测Map中已存在,现在关闭使用则添加删除标记
+ //如果本次查询数据监测Map中不存在,并且已开启使用的则加入监测Map
+ for(EmailProperties email : receiveMails){
+ final boolean flag = emailMap.containsKey(email.getId());
+ if(flag && email.getEnabled().equals(SysMailEnableType.NOT_ENABLE.getMailEnableType())){
+ EmailProperties sourceEmail = emailMap.get(email.getId());
+ sourceEmail.setDelFlag(true);
+ }
+ if(!flag && email.getEnabled().equals(SysMailEnableType.ENABLE.getMailEnableType())){
+ email.setNewEmailFlag(true);
+ putSysEmailMap(email);
+ log.info("{}邮箱加入监测队列",email.getEmailServerAddress());
+ }
+ }
+ //如果监测Map中存在的邮箱数据,在本次查询数据中不存在说明库里已删除,则添加删除标记
+ emailMap.forEach((emailId,sourceEmail)->{
+ final long result = receiveMails.stream().filter(email -> emailId.equals(email.getId())).count();
+ if (result <= 0){
+ sourceEmail.setDelFlag(true);
+ }
+ });
+ }
+ //捕获异常不处理保障线程异常不退出
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ long end = System.currentTimeMillis();
+ long sleepTime = taskProperties.getMonitoringMailDataCycle() - (end-start);
+ //如果sleepTime > 0 需要睡眠到指定时间,否则继续下次监测
+ if(sleepTime > 0){
+ try {
+ TimeUnit.MILLISECONDS.sleep(sleepTime);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * 新增邮箱数据
+ * @param email
+ */
+ private void putSysEmailMap(EmailProperties email){
+ synchronized (this.lock){
+ emailMap.put(email.getId(),email);
+ }
+ }
+
+ /**
+ * 删除邮箱数据
+ * @param emailId
+ */
+ private void removeSysEmailMap(String emailId){
+ synchronized (this.lock){
+ if (emailMap.containsKey(emailId)){
+ emailMap.remove(emailId);
+ }
+ }
+ }
+
+ /**
+ * 删除邮箱数据
+ * @param sysEmailIds
+ */
+ private void removeSysEmailMap(List sysEmailIds){
+ synchronized (this.lock){
+ for(String sysEmailId : sysEmailIds){
+ if (emailMap.containsKey(sysEmailId)){
+ emailMap.remove(sysEmailId);
+ }
+ }
+ }
+ }
+}
diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/config/mybatis/CustomMetaObjectHandler.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/config/mybatis/CustomMetaObjectHandler.java
new file mode 100644
index 00000000..8954a958
--- /dev/null
+++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/config/mybatis/CustomMetaObjectHandler.java
@@ -0,0 +1,26 @@
+package org.jeecg.modules.config.mybatis;
+
+import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
+import org.apache.ibatis.reflection.MetaObject;
+import org.springframework.stereotype.Component;
+
+import java.time.LocalDateTime;
+
+/**
+ * 自定义实体字段填充
+ * @author 86187
+ */
+@Component
+public class CustomMetaObjectHandler implements MetaObjectHandler {
+
+
+ @Override
+ public void insertFill(MetaObject metaObject) {
+ this.strictInsertFill(metaObject,"createTime", LocalDateTime.class,LocalDateTime.now());
+ }
+
+ @Override
+ public void updateFill(MetaObject metaObject) {
+
+ }
+}
diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/email/EmailLogProperties.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/email/EmailLogProperties.java
new file mode 100644
index 00000000..98da3486
--- /dev/null
+++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/email/EmailLogProperties.java
@@ -0,0 +1,18 @@
+package org.jeecg.modules.email;
+
+import lombok.Data;
+import org.jeecg.modules.base.entity.SysEmailLog;
+
+import java.util.List;
+
+/**
+ * 邮件日志属性
+ */
+@Data
+public class EmailLogProperties extends SysEmailLog {
+
+ /**
+ * 邮件附件本地存储路径
+ */
+ private List filePathList;
+}
diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/email/EmailParsingActuator.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/email/EmailParsingActuator.java
new file mode 100644
index 00000000..21880970
--- /dev/null
+++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/email/EmailParsingActuator.java
@@ -0,0 +1,107 @@
+package org.jeecg.modules.email;
+
+import org.jeecg.common.email.EmailServiceManager;
+import org.jeecg.common.email.emuns.MailContentType;
+import org.jeecg.modules.properties.TaskProperties;
+import org.jetbrains.annotations.NotNull;
+import org.springframework.scheduling.concurrent.CustomizableThreadFactory;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeUtility;
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * 邮件解析执行器
+ */
+public class EmailParsingActuator extends Thread{
+
+ private TaskProperties taskProperties;
+ private EmailProperties emailProperties;
+ private ThreadPoolExecutor poolExecutor;
+
+ public void init(TaskProperties taskProperties,
+ EmailProperties emailProperties){
+ this.taskProperties = taskProperties;
+ this.emailProperties = emailProperties;
+ //初始化线程池
+ ThreadFactory threadFactory = new CustomizableThreadFactory("mail-parsing-");
+ ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(taskProperties.getReceiveNum(),taskProperties.getReceiveNum()*2,5, TimeUnit.SECONDS, new LinkedBlockingQueue<>(),threadFactory);
+ }
+
+ @Override
+ public void run() {
+ for(;;){
+ long start = System.currentTimeMillis();
+ final EmailServiceManager emailServiceManager = EmailServiceManager.getInstance();
+ emailServiceManager.init(emailProperties,taskProperties.getReceiveNum(),taskProperties.getTemporaryStoragePath());
+ try {
+ final Message[] messages = emailServiceManager.receiveMail();
+ for(Message message : messages){
+ final EmailLogProperties emailLogProperties = this.parseingMail(emailServiceManager,message);
+ //如果邮件没有附件、获取附件都不是PHD文件、也不是IMS2.0协议的文件,需把邮件删除
+
+// emailServiceManager.removeMail(message);
+ }
+ }catch (MessagingException e) {
+ e.printStackTrace();
+ }catch (IOException e) {
+ e.printStackTrace();
+ }finally {
+ //关闭资源
+ emailServiceManager.close();
+ }
+ break;
+// long end = System.currentTimeMillis();
+// long sleepTime = taskProperties.getMailThreadExecCycle() - (end-start);
+// //如果sleepTime > 0 需要睡眠到指定时间,否则继续下次获取邮件
+// if(sleepTime > 0){
+// try {
+// //如果本次
+// TimeUnit.MILLISECONDS.sleep(sleepTime);
+// } catch (InterruptedException e) {
+// e.printStackTrace();
+// }
+// }
+ }
+ }
+
+ /**
+ * 解析邮件
+ * @param message
+ */
+ public EmailLogProperties parseingMail(@NotNull EmailServiceManager emailServiceManager,@NotNull Message message) throws MessagingException, IOException {
+ //如果是带有附件的邮件
+ if(message.getContentType().startsWith(MailContentType.MIXED.getContentType())){
+ //封装邮件日志信息
+ EmailLogProperties mailLog = new EmailLogProperties();
+ mailLog.setEmailId(emailProperties.getId());
+ mailLog.setSubject(MimeUtility.decodeText(message.getSubject()));
+ final StringBuilder content = new StringBuilder();
+ emailServiceManager.getMailContent(message,content);
+ mailLog.setContext(content.toString());
+ mailLog.setReceiveTime(message.getSentDate());
+ final List filePathList = emailServiceManager.saveAttachment(message);
+ mailLog.setFilePathList(filePathList);
+ return mailLog;
+ }else{
+ //如果此邮件不带有附件,则删除
+ emailServiceManager.removeMail(message);
+ }
+ return null;
+ }
+
+ //Sauna:β,Spalax:γ
+ private boolean checkMail(String filePath){
+ File file = new File(filePath);
+ if(file.isFile()){
+
+ }
+ return true;
+ }
+}
diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/email/EmailProperties.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/email/EmailProperties.java
new file mode 100644
index 00000000..14f20f05
--- /dev/null
+++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/email/EmailProperties.java
@@ -0,0 +1,27 @@
+package org.jeecg.modules.email;
+
+import lombok.Data;
+import org.jeecg.modules.base.entity.SysEmail;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+import java.io.Serializable;
+
+/**
+ * 邮件属性
+ * @author 86187
+ */
+@Data
+public class EmailProperties extends SysEmail {
+
+ /**
+ * 是否是新邮件
+ */
+ private boolean newEmailFlag;
+
+ /**
+ * 该邮件处理线程是否需要删除
+ */
+ private boolean delFlag;
+
+}
diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/emuns/SysMailEnableType.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/emuns/SysMailEnableType.java
new file mode 100644
index 00000000..a996288e
--- /dev/null
+++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/emuns/SysMailEnableType.java
@@ -0,0 +1,26 @@
+package org.jeecg.modules.emuns;
+
+/**
+ * 邮件类型
+ */
+public enum SysMailEnableType {
+
+ /**
+ * 未启用邮件
+ */
+ NOT_ENABLE(0),
+ /**
+ * 启用邮件
+ */
+ ENABLE(1);
+
+ private Integer mailEnableType;
+
+ SysMailEnableType(int mailEnableType) {
+ this.mailEnableType = mailEnableType;
+ }
+
+ public Integer getMailEnableType(){
+ return this.mailEnableType;
+ }
+}
diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/mapper/SysMailMapper.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/mapper/SysMailMapper.java
new file mode 100644
index 00000000..0ca57666
--- /dev/null
+++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/mapper/SysMailMapper.java
@@ -0,0 +1,10 @@
+package org.jeecg.modules.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.jeecg.modules.base.entity.SysEmail;
+
+/**
+ * 邮件数据表Mapper
+ */
+public interface SysMailMapper extends BaseMapper {
+}
diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/properties/SpectrumPathProperties.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/properties/SpectrumPathProperties.java
new file mode 100644
index 00000000..11794f5c
--- /dev/null
+++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/properties/SpectrumPathProperties.java
@@ -0,0 +1,28 @@
+package org.jeecg.modules.properties;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+import java.io.Serializable;
+import java.util.Map;
+
+/**
+ * 能谱文件存储路径属性
+ * @author 86187
+ */
+@Data
+@Component
+@ConfigurationProperties(prefix = "file-system")
+public class SpectrumPathProperties implements Serializable {
+
+ /**
+ * 能谱文件存储根路径
+ */
+ private String rootPath;
+
+ /**
+ * 能谱文件存储路径以能谱系统类型/能谱类型为key,以存储路径为value
+ */
+ private Map filePathMap;
+}
diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/properties/TaskProperties.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/properties/TaskProperties.java
new file mode 100644
index 00000000..f3d3b2db
--- /dev/null
+++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/properties/TaskProperties.java
@@ -0,0 +1,42 @@
+package org.jeecg.modules.properties;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+import java.io.Serializable;
+
+/**
+ * 邮件任务运行参数
+ * @author 86187
+ */
+@Data
+@Component
+@ConfigurationProperties(prefix = "task")
+public class TaskProperties implements Serializable {
+
+ /**
+ * 单次获取邮件数量
+ */
+ private Integer receiveNum;
+
+ /**
+ * 监测数据库邮箱数据变化周期
+ */
+ private Long monitoringMailDataCycle;
+
+ /**
+ * 监测邮箱通信状态周期
+ */
+ private Long monitoringMailCommStatusCycle;
+
+ /**
+ * 获取邮箱邮件线程执行周期
+ */
+ private Long mailThreadExecCycle;
+
+ /**
+ * 邮件附件临时存储路径
+ */
+ private String temporaryStoragePath;
+}
diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/ISysMailService.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/ISysMailService.java
new file mode 100644
index 00000000..8e9549e3
--- /dev/null
+++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/ISysMailService.java
@@ -0,0 +1,18 @@
+package org.jeecg.modules.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.modules.base.entity.SysEmail;
+import org.jeecg.modules.email.EmailProperties;
+import java.util.List;
+
+/**
+ * 邮箱数据服务
+ */
+public interface ISysMailService extends IService {
+
+ /**
+ * 查询接收邮箱数据
+ * @return
+ */
+ List findReceiveMails();
+}
diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/SysMailServiceImpl.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/SysMailServiceImpl.java
new file mode 100644
index 00000000..cc21366b
--- /dev/null
+++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/SysMailServiceImpl.java
@@ -0,0 +1,47 @@
+package org.jeecg.modules.service.impl;
+
+import com.baomidou.dynamic.datasource.annotation.DS;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.google.common.collect.Lists;
+import org.jeecg.common.email.emuns.SysMailType;
+import org.jeecg.modules.base.entity.SysEmail;
+import org.jeecg.modules.email.EmailProperties;
+import org.jeecg.modules.emuns.SysMailEnableType;
+import org.jeecg.modules.mapper.SysMailMapper;
+import org.jeecg.modules.service.ISysMailService;
+import org.springframework.beans.BeanUtils;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * 邮箱数据服务实现
+ */
+@Service
+@DS("master")
+public class SysMailServiceImpl extends ServiceImpl implements ISysMailService {
+
+ /**
+ * 查询接收邮箱数据
+ * @return
+ */
+ @Override
+ public List findReceiveMails() {
+ LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();
+ queryWrapper.eq(SysEmail::getEmilType, SysMailType.RECEIVE_EMAIL.getEmailType());
+ queryWrapper.eq(SysEmail::getEnabled, SysMailEnableType.ENABLE.getMailEnableType());
+ List sysEmail = this.list(queryWrapper);
+ if(!CollectionUtils.isEmpty(sysEmail)){
+ List emailPropertiesList = Lists.newArrayList();
+ for (SysEmail email : sysEmail){
+ EmailProperties mailProperties = new EmailProperties();
+ BeanUtils.copyProperties(email,mailProperties);
+ emailPropertiesList.add(mailProperties);
+ }
+ return emailPropertiesList;
+ }
+ return Collections.emptyList();
+ }
+}
diff --git a/jeecg-server-cloud/jeecg-auto-process-start/pom.xml b/jeecg-server-cloud/jeecg-auto-process-start/pom.xml
new file mode 100644
index 00000000..bf367068
--- /dev/null
+++ b/jeecg-server-cloud/jeecg-auto-process-start/pom.xml
@@ -0,0 +1,42 @@
+
+
+
+ jeecg-server-cloud
+ org.jeecgframework.boot
+ 3.5.1
+
+ 4.0.0
+
+ jeecg-auto-process-start
+
+
+
+
+ org.jeecgframework.boot
+ jeecg-boot-starter-cloud
+
+
+
+ org.jeecgframework.boot
+ jeecg-boot-base-core
+
+
+
+ org.jeecgframework.boot
+ jeecg-module-auto-process
+ 3.5.1
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+
+
\ No newline at end of file
diff --git a/jeecg-server-cloud/jeecg-auto-process-start/src/main/java/org/jeecg/JeecgAutoProcessApplication.java b/jeecg-server-cloud/jeecg-auto-process-start/src/main/java/org/jeecg/JeecgAutoProcessApplication.java
new file mode 100644
index 00000000..c6c9daa7
--- /dev/null
+++ b/jeecg-server-cloud/jeecg-auto-process-start/src/main/java/org/jeecg/JeecgAutoProcessApplication.java
@@ -0,0 +1,54 @@
+package org.jeecg;
+
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.util.oConvertUtils;
+import org.jeecg.modules.AutoProcessManager;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
+import org.springframework.cloud.openfeign.EnableFeignClients;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.core.env.Environment;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+/**
+ * @author 86187
+ */
+@Slf4j
+@SpringBootApplication
+@EnableFeignClients(basePackages = {"org.jeecg"})
+@EnableScheduling
+@RequiredArgsConstructor
+public class JeecgAutoProcessApplication extends SpringBootServletInitializer implements CommandLineRunner {
+
+ private final AutoProcessManager autoProcessManager;
+
+ @Override
+ protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
+ return application.sources(JeecgAutoProcessApplication.class);
+ }
+
+ public static void main(String[] args) throws UnknownHostException {
+ ConfigurableApplicationContext application = SpringApplication.run(JeecgAutoProcessApplication.class, args);
+ Environment env = application.getEnvironment();
+ String ip = InetAddress.getLocalHost().getHostAddress();
+ String port = env.getProperty("server.port");
+ String path = oConvertUtils.getString(env.getProperty("server.servlet.context-path"));
+ log.info("\n----------------------------------------------------------\n\t" +
+ "Application Jeecg-Boot is running! Access URLs:\n\t" +
+ "Local: \t\thttp://localhost:" + port + path + "/doc.html\n" +
+ "External: \thttp://" + ip + ":" + port + path + "/doc.html\n" +
+ "Swagger文档: \thttp://" + ip + ":" + port + path + "/doc.html\n" +
+ "----------------------------------------------------------");
+ }
+
+ @Override
+ public void run(String... args) throws Exception {
+ autoProcessManager.start();
+ }
+}
\ No newline at end of file
diff --git a/jeecg-server-cloud/jeecg-auto-process-start/src/main/resources/application.yml b/jeecg-server-cloud/jeecg-auto-process-start/src/main/resources/application.yml
new file mode 100644
index 00000000..9eb26427
--- /dev/null
+++ b/jeecg-server-cloud/jeecg-auto-process-start/src/main/resources/application.yml
@@ -0,0 +1,19 @@
+server:
+ port: 7004
+
+spring:
+ application:
+ name: jeecg-auto-process
+ cloud:
+ nacos:
+ config:
+ server-addr: @config.server-addr@
+ group: @config.group@
+ namespace: @config.namespace@
+ discovery:
+ server-addr: ${spring.cloud.nacos.config.server-addr}
+ config:
+ import:
+ - optional:nacos:jeecg.yaml
+ - optional:nacos:jeecg-auto-process-@profile.name@.yaml
+
diff --git a/jeecg-server-cloud/jeecg-auto-process-start/src/main/resources/logback-spring.xml b/jeecg-server-cloud/jeecg-auto-process-start/src/main/resources/logback-spring.xml
new file mode 100644
index 00000000..60d4c7df
--- /dev/null
+++ b/jeecg-server-cloud/jeecg-auto-process-start/src/main/resources/logback-spring.xml
@@ -0,0 +1,77 @@
+
+
+
+
+
+
+
+
+
+
+ %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %highlight(%-5level) %cyan(%logger{50}:%L) - %msg%n
+
+
+
+
+
+
+
+ ${LOG_HOME}/jeecg-system-%d{yyyy-MM-dd}.%i.log
+
+ 30
+ 10MB
+
+
+
+ %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}:%L - %msg%n
+
+
+
+
+
+
+
+ ERROR
+
+
+
+ %p%d%msg%M%F{32}%L
+
+
+ ${LOG_HOME}/error-log.html
+
+
+
+
+
+
+
+ ${LOG_HOME}/jeecg-system-%d{yyyy-MM-dd}.%i.html
+
+ 30
+ 10MB
+
+
+
+ %p%d%msg%M%F{32}%L
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/jeecg-server-cloud/pom.xml b/jeecg-server-cloud/pom.xml
index 47f9d6fe..137fef12 100644
--- a/jeecg-server-cloud/pom.xml
+++ b/jeecg-server-cloud/pom.xml
@@ -25,6 +25,7 @@
jeecg-web-statistics-start
jeecg-log-manage-start
jeecg-abnormal-alarm-start
+ jeecg-auto-process-start
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index a07ff46a..3c9672c0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -81,7 +81,8 @@
jeecg-module-log-manage
jeecg-module-station-operation
jeecg-module-web-statistics
- jeecg-module-abnormal-alarm
+ jeecg-module-abnormal-alarm
+ jeecg-module-auto-process
@@ -187,12 +188,6 @@
jeecg-module-web-statistics
${jeecgboot.version}
-
-
- org.jeecgframework.boot
- jeecg-module-abnormal-alarm
- ${jeecgboot.version}
-
org.jeecgframework.boot
From 1c99371fd25fada4c2a2120c49c29e401110cd72 Mon Sep 17 00:00:00 2001
From: panbaolin <123456>
Date: Wed, 21 Jun 2023 11:18:58 +0800
Subject: [PATCH 2/2] =?UTF-8?q?fix:1.=E6=8F=90=E4=BA=A4=E9=82=AE=E4=BB=B6?=
=?UTF-8?q?=E6=97=A5=E5=BF=97=E5=AE=9E=E4=BD=93?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../main/java/org/jeecg/modules/base/entity/SysEmailLog.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/SysEmailLog.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/SysEmailLog.java
index 5e448f9f..d297cda9 100644
--- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/SysEmailLog.java
+++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/SysEmailLog.java
@@ -46,7 +46,7 @@ public class SysEmailLog implements Serializable {
@TableField(value = "receive_time")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
- private LocalDateTime receiveTime;
+ private Date receiveTime;
/**
* 创建时间