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 fe112ee7..960eb5d9 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 @@ -1,6 +1,8 @@ package org.jeecg.common.email; +import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.ArrayUtil; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.google.common.collect.Lists; import com.sun.mail.imap.IMAPStore; @@ -12,6 +14,7 @@ import org.jeecg.common.constant.RedisConstant; import org.jeecg.common.constant.StringConstant; import org.jeecg.common.constant.SymbolConstant; import org.jeecg.common.email.emuns.MailContentType; +import org.jeecg.common.exception.DownloadEmailException; import org.jeecg.common.properties.SpectrumPathProperties; import org.jeecg.common.util.DateUtils; import org.jeecg.common.util.Md5Util; @@ -512,9 +515,10 @@ public class EmailServiceManager { /** * 把邮件下载到eml目录 * 格式为:发件人_主题_年月日_时分秒毫秒_计数(0-10000) + * 新格式为:发件人_主题_年月日_时分秒毫秒_receive_年月日_时分秒毫秒_计数(0-10000) * 当计数大于10000后从0开始,服务重启后也从0开始 */ - public File downloadEmailToEmlDir(@NotNull Message message,Integer emailCounter) throws MessagingException, IOException { + public File downloadEmailToEmlDir(@NotNull Message message,Integer emailCounter) throws MessagingException { String subject = ""; File emlFile = null; String status = EmailLogManager.STATUS_SUCCESS; @@ -540,6 +544,12 @@ public class EmailServiceManager { fileName.append(StringConstant.UNDER_LINE); fileName.append(DateUtils.formatDate(new Date(),"HHMMSSSSS")); fileName.append(StringConstant.UNDER_LINE); + fileName.append("receive"); + fileName.append(StringConstant.UNDER_LINE); + fileName.append(DateUtils.formatDate(message.getReceivedDate(),"YYMMdd")); + fileName.append(StringConstant.UNDER_LINE); + fileName.append(DateUtils.formatDate(message.getReceivedDate(),"HHMMSSSSS")); + fileName.append(StringConstant.UNDER_LINE); fileName.append(emailCounter); fileName.append(SAVE_EML_SUFFIX); final String rootPath = spectrumPathProperties.getRootPath(); @@ -547,10 +557,11 @@ public class EmailServiceManager { emlFile = new File(rootPath+emlPath+File.separator+fileName); message.writeTo(new FileOutputStream(emlFile)); } catch (MessagingException | IOException e) { - //下载邮件失败 + // 下载邮件失败 抛出自定义邮件下载异常 status = EmailLogManager.STATUS_ERROR; - log.error("The email download failed, the subject of the email is {}, the reason is {}.",subject,e.getMessage()); - throw e; + String errorMsg = StrUtil.format("The email download failed, the subject of the email is {}, the reason is {}.", subject, e.getMessage()); + log.error(errorMsg); + throw new DownloadEmailException(errorMsg); }finally { EmailLogEvent event = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,status,EmailLogManager.GETIDEML,subject,message.getReceivedDate(), (Objects.isNull(emlFile)?" ":emlFile.getAbsolutePath())); @@ -560,6 +571,24 @@ public class EmailServiceManager { return emlFile; } + /* + * 将eml中下载的未通过内容校验的邮件 移动到emlError目录 + * */ + public void emlToEmlError(File emlFile){ + if (ObjectUtil.isNull(emlFile)) return; + final String filename = emlFile.getName(); + try { + final String rootPath = spectrumPathProperties.getRootPath(); + final String emlErrorPath = spectrumPathProperties.getEmlErrorPath(); + File destDir = new File(rootPath + emlErrorPath); + // 如果目标目录不存在 则先创建 + if (!destDir.exists()) destDir.mkdir(); + FileUtil.move(emlFile, destDir, true); + }catch (Exception e){ + log.error("The error email {} move from eml to emlError failed: {}", filename, e.getMessage()); + } + } + /** * 删除邮件 * @param message diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/exception/DownloadEmailException.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/exception/DownloadEmailException.java new file mode 100644 index 00000000..626d77ff --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/exception/DownloadEmailException.java @@ -0,0 +1,15 @@ +package org.jeecg.common.exception; + +/* +* 自定义 邮件下载异常 +* */ +public class DownloadEmailException extends RuntimeException{ + + public DownloadEmailException() { + super(); + } + + public DownloadEmailException(String message) { + super(message); + } +} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/SpectrumPathProperties.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/SpectrumPathProperties.java index 43ac51f1..ce6d5e35 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/SpectrumPathProperties.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/SpectrumPathProperties.java @@ -39,6 +39,11 @@ public class SpectrumPathProperties implements Serializable { */ private String emlPath; + /** + * eml格式错误邮件存储路径 + */ + private String emlErrorPath; + /** * 日志文件存储路径 */ diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/bizVo/NuclideAvgVo.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/bizVo/NuclideAvgVo.java index e7effb0b..5f8adbfc 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/bizVo/NuclideAvgVo.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/bizVo/NuclideAvgVo.java @@ -9,4 +9,8 @@ public class NuclideAvgVo extends QueryRequest { private String startDate; private String endDate; + + private String stationId; + + private String sourceType; } diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/NuclideAvgDto.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/NuclideAvgDto.java index 9139aa95..5bb144a7 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/NuclideAvgDto.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/dto/NuclideAvgDto.java @@ -10,6 +10,10 @@ import java.time.LocalDate; @Data public class NuclideAvgDto implements Serializable { + private String stationId; + + private String stationCode; + /** 核素名称 */ private String nuclide; diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/AlarmAnalysisNuclideAvgController.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/AlarmAnalysisNuclideAvgController.java index 50dfa0ff..35750e6e 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/AlarmAnalysisNuclideAvgController.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/controller/AlarmAnalysisNuclideAvgController.java @@ -19,7 +19,7 @@ public class AlarmAnalysisNuclideAvgController extends JeecgController findPage(NuclideAvgVo nuclideAvgVo){ Page result = service.findPage(nuclideAvgVo); return Result.OK(result); } diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/AlarmAnalysisNuclideAvgMapper.xml b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/AlarmAnalysisNuclideAvgMapper.xml index cc9db717..0e604a4b 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/AlarmAnalysisNuclideAvgMapper.xml +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/mapper/xml/AlarmAnalysisNuclideAvgMapper.xml @@ -4,6 +4,7 @@ \ No newline at end of file diff --git a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmAnalysisNuclideAvgServiceImpl.java b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmAnalysisNuclideAvgServiceImpl.java index d95ef555..2659c56d 100644 --- a/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmAnalysisNuclideAvgServiceImpl.java +++ b/jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules/service/impl/AlarmAnalysisNuclideAvgServiceImpl.java @@ -6,8 +6,10 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.jeecg.modules.base.dto.NuclideAvgDto; import org.jeecg.modules.base.entity.postgre.AlarmAnalysisNuclideAvg; import org.jeecg.modules.base.bizVo.NuclideAvgVo; +import org.jeecg.modules.feignclient.SystemClient; import org.jeecg.modules.mapper.AlarmAnalysisNuclideAvgMapper; import org.jeecg.modules.service.IAlarmAnalysisNuclideAvgService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -16,10 +18,14 @@ import java.time.LocalDate; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; @Service public class AlarmAnalysisNuclideAvgServiceImpl extends ServiceImpl implements IAlarmAnalysisNuclideAvgService { + @Autowired + private SystemClient systemClient; + @Override public List list(Set nuclideNames,String dataSourceType) { LocalDate dayAgo = LocalDate.now().minusDays(1); @@ -37,6 +43,10 @@ public class AlarmAnalysisNuclideAvgServiceImpl extends ServiceImpl params = BeanUtil.beanToMap(nuclideAvgVo); Page page = new Page<>(pageNo, pageSize); page = baseMapper.findPage(page, params); - return page; + List nuclideAvgs = page.getRecords(); + List stationIds = nuclideAvgs.stream().map(NuclideAvgDto::getStationId).collect(Collectors.toList()); + Map codeMap = systemClient.stationCodesMap(stationIds); + nuclideAvgs.forEach(item -> item.setStationCode(codeMap.get(item.getStationId()))); + return page.setRecords(nuclideAvgs); } } 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 4af40e0a..e4dfd60f 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 @@ -8,12 +8,14 @@ import org.jeecg.common.constant.StringConstant; import org.jeecg.common.email.EmailLogEvent; import org.jeecg.common.email.EmailLogManager; import org.jeecg.common.email.EmailServiceManager; +import org.jeecg.common.exception.DownloadEmailException; import org.jeecg.common.util.DateUtils; import org.jeecg.modules.email.EmailProperties; import org.jeecg.modules.enums.SpectrumSource; import javax.mail.Message; import javax.mail.internet.MimeMessage; import java.io.File; +import java.nio.file.Files; import java.util.Objects; import java.util.concurrent.CountDownLatch; @@ -96,6 +98,7 @@ public class SpectrumParsingActuator implements Runnable{ } //判断是否是IMS2.0协议文件 + // 如果邮件内容校验成功 将文件保存到eml目录 并删除邮件对象 if(checkMailContent(mailContent,subject)){ AbstractSpectrumHandler spectrumHandler = new SamplephdSpectrum(); spectrumHandler.init(mailContent.toString(),emlFile.getName(),spectrumServiceQuotes,new StringBuilder(),SpectrumSource.FORM_EMAIL_SERVICE.getSourceType()); @@ -106,10 +109,16 @@ public class SpectrumParsingActuator implements Runnable{ }else{ log.warn("This email {} parsing failed and is not listed in the Met, Alert, SOH, Sample, Detbkphd, QC, Gasbkphd spectra.",subject); } + emailServiceManager.removeMail(message); + } + // 如果邮件内容校验失败(邮件内容不完整) 将错误邮件从eml移动到emlError + else { + emailServiceManager.emlToEmlError(emlFile); } - emailServiceManager.removeMail(message); } catch (Exception e) { - emailServiceManager.removeMail(message); + // 如果邮件正常下载 则删除下载的邮件对象 + if (!(e instanceof DownloadEmailException)) + emailServiceManager.removeMail(message); e.printStackTrace(); }finally { try { 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 ab22ec69..06b5bc9b 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 @@ -120,6 +120,7 @@ public class JeecgAutoProcessApplication extends SpringBootServletInitializer im FileUtil.mkdir(spectrumPathProperties.getRootPath()+File.separator+spectrumPathProperties.getUndealPath()); FileUtil.mkdir(spectrumPathProperties.getRootPath()+File.separator+spectrumPathProperties.getFilesourcePath()); FileUtil.mkdir(spectrumPathProperties.getRootPath()+File.separator+spectrumPathProperties.getEmlPath()); + FileUtil.mkdir(spectrumPathProperties.getRootPath()+File.separator+spectrumPathProperties.getEmlErrorPath()); FileUtil.mkdir(spectrumPathProperties.getRootPath()+File.separator+spectrumPathProperties.getErrorFilePath()); } } \ No newline at end of file diff --git a/jeecg-server-cloud/armd-spectrum-analysis-start/src/main/java/org/jeecg/JeecgSpectrumAnalysisApplication.java b/jeecg-server-cloud/armd-spectrum-analysis-start/src/main/java/org/jeecg/JeecgSpectrumAnalysisApplication.java index 695c9169..0709c795 100644 --- a/jeecg-server-cloud/armd-spectrum-analysis-start/src/main/java/org/jeecg/JeecgSpectrumAnalysisApplication.java +++ b/jeecg-server-cloud/armd-spectrum-analysis-start/src/main/java/org/jeecg/JeecgSpectrumAnalysisApplication.java @@ -63,11 +63,11 @@ public class JeecgSpectrumAnalysisApplication extends SpringBootServletInitializ @Override public void run(String... args) throws Exception { //Windows加载dll工具库 - /*System.loadLibrary("ReadPHDFile"); - System.loadLibrary("GammaAnaly");*/ + System.loadLibrary("ReadPHDFile"); + System.loadLibrary("GammaAnaly"); //Linux版本加载dll工具库 - System.load("/usr/local/jdk/lib/libReadPHDFile.so"); - System.load("/usr/local/jdk/lib/libGammaAnalyALG.so"); + /*System.load("/usr/local/jdk/lib/libReadPHDFile.so"); + System.load("/usr/local/jdk/lib/libGammaAnalyALG.so");*/ //创建缓存 betaCache.initCache(); localCache.initCache();