fix:1.错误eml情况处理2.核素浓度均值列表页增加过滤条件

This commit is contained in:
nieziyan 2024-02-19 18:57:43 +08:00
parent fe755c83ee
commit 09b2eb9739
11 changed files with 97 additions and 13 deletions

View File

@ -1,6 +1,8 @@
package org.jeecg.common.email; package org.jeecg.common.email;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.sun.mail.imap.IMAPStore; 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.StringConstant;
import org.jeecg.common.constant.SymbolConstant; import org.jeecg.common.constant.SymbolConstant;
import org.jeecg.common.email.emuns.MailContentType; import org.jeecg.common.email.emuns.MailContentType;
import org.jeecg.common.exception.DownloadEmailException;
import org.jeecg.common.properties.SpectrumPathProperties; import org.jeecg.common.properties.SpectrumPathProperties;
import org.jeecg.common.util.DateUtils; import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.Md5Util; import org.jeecg.common.util.Md5Util;
@ -512,9 +515,10 @@ public class EmailServiceManager {
/** /**
* 把邮件下载到eml目录 * 把邮件下载到eml目录
* 格式为发件人_主题_年月日_时分秒毫秒_计数0-10000 * 格式为发件人_主题_年月日_时分秒毫秒_计数0-10000
* 新格式为发件人_主题_年月日_时分秒毫秒_receive_年月日_时分秒毫秒_计数0-10000
* 当计数大于10000后从0开始服务重启后也从0开始 * 当计数大于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 = ""; String subject = "";
File emlFile = null; File emlFile = null;
String status = EmailLogManager.STATUS_SUCCESS; String status = EmailLogManager.STATUS_SUCCESS;
@ -540,6 +544,12 @@ public class EmailServiceManager {
fileName.append(StringConstant.UNDER_LINE); fileName.append(StringConstant.UNDER_LINE);
fileName.append(DateUtils.formatDate(new Date(),"HHMMSSSSS")); fileName.append(DateUtils.formatDate(new Date(),"HHMMSSSSS"));
fileName.append(StringConstant.UNDER_LINE); 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(emailCounter);
fileName.append(SAVE_EML_SUFFIX); fileName.append(SAVE_EML_SUFFIX);
final String rootPath = spectrumPathProperties.getRootPath(); final String rootPath = spectrumPathProperties.getRootPath();
@ -547,10 +557,11 @@ public class EmailServiceManager {
emlFile = new File(rootPath+emlPath+File.separator+fileName); emlFile = new File(rootPath+emlPath+File.separator+fileName);
message.writeTo(new FileOutputStream(emlFile)); message.writeTo(new FileOutputStream(emlFile));
} catch (MessagingException | IOException e) { } catch (MessagingException | IOException e) {
//下载邮件失败 // 下载邮件失败 抛出自定义邮件下载异常
status = EmailLogManager.STATUS_ERROR; status = EmailLogManager.STATUS_ERROR;
log.error("The email download failed, the subject of the email is {}, the reason is {}.",subject,e.getMessage()); String errorMsg = StrUtil.format("The email download failed, the subject of the email is {}, the reason is {}.", subject, e.getMessage());
throw e; log.error(errorMsg);
throw new DownloadEmailException(errorMsg);
}finally { }finally {
EmailLogEvent event = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,status,EmailLogManager.GETIDEML,subject,message.getReceivedDate(), EmailLogEvent event = new EmailLogEvent(EmailLogManager.GS_TYPE_GET,status,EmailLogManager.GETIDEML,subject,message.getReceivedDate(),
(Objects.isNull(emlFile)?" ":emlFile.getAbsolutePath())); (Objects.isNull(emlFile)?" ":emlFile.getAbsolutePath()));
@ -560,6 +571,24 @@ public class EmailServiceManager {
return emlFile; 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 * @param message

View File

@ -0,0 +1,15 @@
package org.jeecg.common.exception;
/*
* 自定义 邮件下载异常
* */
public class DownloadEmailException extends RuntimeException{
public DownloadEmailException() {
super();
}
public DownloadEmailException(String message) {
super(message);
}
}

View File

@ -39,6 +39,11 @@ public class SpectrumPathProperties implements Serializable {
*/ */
private String emlPath; private String emlPath;
/**
* eml格式错误邮件存储路径
*/
private String emlErrorPath;
/** /**
* 日志文件存储路径 * 日志文件存储路径
*/ */

View File

@ -9,4 +9,8 @@ public class NuclideAvgVo extends QueryRequest {
private String startDate; private String startDate;
private String endDate; private String endDate;
private String stationId;
private String sourceType;
} }

View File

@ -10,6 +10,10 @@ import java.time.LocalDate;
@Data @Data
public class NuclideAvgDto implements Serializable { public class NuclideAvgDto implements Serializable {
private String stationId;
private String stationCode;
/** 核素名称 */ /** 核素名称 */
private String nuclide; private String nuclide;

View File

@ -19,7 +19,7 @@ public class AlarmAnalysisNuclideAvgController extends JeecgController<AlarmAnal
@GetMapping("findPage") @GetMapping("findPage")
@ApiOperation(value = "核素浓度均值列表信息",notes = "核素浓度均值列表信息") @ApiOperation(value = "核素浓度均值列表信息",notes = "核素浓度均值列表信息")
public Result findPage(NuclideAvgVo nuclideAvgVo){ public Result<?> findPage(NuclideAvgVo nuclideAvgVo){
Page<NuclideAvgDto> result = service.findPage(nuclideAvgVo); Page<NuclideAvgDto> result = service.findPage(nuclideAvgVo);
return Result.OK(result); return Result.OK(result);
} }

View File

@ -4,6 +4,7 @@
<select id="findPage" resultType="org.jeecg.modules.base.dto.NuclideAvgDto"> <select id="findPage" resultType="org.jeecg.modules.base.dto.NuclideAvgDto">
SELECT SELECT
station_id,
nuclide, nuclide,
val, val,
cycle, cycle,
@ -23,7 +24,13 @@
<if test="params.endDate != null and params.endDate != ''"> <if test="params.endDate != null and params.endDate != ''">
AND cacl_date &lt;= #{params.endDate} AND cacl_date &lt;= #{params.endDate}
</if> </if>
<if test="params.stationId != null and params.stationId != ''">
AND station_id = #{params.stationId}
</if>
<if test="params.sourceType != null and params.sourceType != ''">
AND data_source_type = #{params.sourceType}
</if>
</where> </where>
ORDER BY cacl_date DESC ORDER BY cacl_date DESC, station_id, data_source_type, nuclide
</select> </select>
</mapper> </mapper>

View File

@ -6,8 +6,10 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.base.dto.NuclideAvgDto; import org.jeecg.modules.base.dto.NuclideAvgDto;
import org.jeecg.modules.base.entity.postgre.AlarmAnalysisNuclideAvg; import org.jeecg.modules.base.entity.postgre.AlarmAnalysisNuclideAvg;
import org.jeecg.modules.base.bizVo.NuclideAvgVo; import org.jeecg.modules.base.bizVo.NuclideAvgVo;
import org.jeecg.modules.feignclient.SystemClient;
import org.jeecg.modules.mapper.AlarmAnalysisNuclideAvgMapper; import org.jeecg.modules.mapper.AlarmAnalysisNuclideAvgMapper;
import org.jeecg.modules.service.IAlarmAnalysisNuclideAvgService; import org.jeecg.modules.service.IAlarmAnalysisNuclideAvgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -16,10 +18,14 @@ import java.time.LocalDate;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
@Service @Service
public class AlarmAnalysisNuclideAvgServiceImpl extends ServiceImpl<AlarmAnalysisNuclideAvgMapper, AlarmAnalysisNuclideAvg> implements IAlarmAnalysisNuclideAvgService { public class AlarmAnalysisNuclideAvgServiceImpl extends ServiceImpl<AlarmAnalysisNuclideAvgMapper, AlarmAnalysisNuclideAvg> implements IAlarmAnalysisNuclideAvgService {
@Autowired
private SystemClient systemClient;
@Override @Override
public List<AlarmAnalysisNuclideAvg> list(Set<String> nuclideNames,String dataSourceType) { public List<AlarmAnalysisNuclideAvg> list(Set<String> nuclideNames,String dataSourceType) {
LocalDate dayAgo = LocalDate.now().minusDays(1); LocalDate dayAgo = LocalDate.now().minusDays(1);
@ -37,6 +43,10 @@ public class AlarmAnalysisNuclideAvgServiceImpl extends ServiceImpl<AlarmAnalysi
Map<String, Object> params = BeanUtil.beanToMap(nuclideAvgVo); Map<String, Object> params = BeanUtil.beanToMap(nuclideAvgVo);
Page<NuclideAvgDto> page = new Page<>(pageNo, pageSize); Page<NuclideAvgDto> page = new Page<>(pageNo, pageSize);
page = baseMapper.findPage(page, params); page = baseMapper.findPage(page, params);
return page; List<NuclideAvgDto> nuclideAvgs = page.getRecords();
List<String> stationIds = nuclideAvgs.stream().map(NuclideAvgDto::getStationId).collect(Collectors.toList());
Map<String, String> codeMap = systemClient.stationCodesMap(stationIds);
nuclideAvgs.forEach(item -> item.setStationCode(codeMap.get(item.getStationId())));
return page.setRecords(nuclideAvgs);
} }
} }

View File

@ -8,12 +8,14 @@ import org.jeecg.common.constant.StringConstant;
import org.jeecg.common.email.EmailLogEvent; import org.jeecg.common.email.EmailLogEvent;
import org.jeecg.common.email.EmailLogManager; import org.jeecg.common.email.EmailLogManager;
import org.jeecg.common.email.EmailServiceManager; import org.jeecg.common.email.EmailServiceManager;
import org.jeecg.common.exception.DownloadEmailException;
import org.jeecg.common.util.DateUtils; import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.email.EmailProperties; import org.jeecg.modules.email.EmailProperties;
import org.jeecg.modules.enums.SpectrumSource; import org.jeecg.modules.enums.SpectrumSource;
import javax.mail.Message; import javax.mail.Message;
import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMessage;
import java.io.File; import java.io.File;
import java.nio.file.Files;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
@ -96,6 +98,7 @@ public class SpectrumParsingActuator implements Runnable{
} }
//判断是否是IMS2.0协议文件 //判断是否是IMS2.0协议文件
// 如果邮件内容校验成功 将文件保存到eml目录 并删除邮件对象
if(checkMailContent(mailContent,subject)){ if(checkMailContent(mailContent,subject)){
AbstractSpectrumHandler spectrumHandler = new SamplephdSpectrum(); AbstractSpectrumHandler spectrumHandler = new SamplephdSpectrum();
spectrumHandler.init(mailContent.toString(),emlFile.getName(),spectrumServiceQuotes,new StringBuilder(),SpectrumSource.FORM_EMAIL_SERVICE.getSourceType()); spectrumHandler.init(mailContent.toString(),emlFile.getName(),spectrumServiceQuotes,new StringBuilder(),SpectrumSource.FORM_EMAIL_SERVICE.getSourceType());
@ -106,9 +109,15 @@ public class SpectrumParsingActuator implements Runnable{
}else{ }else{
log.warn("This email {} parsing failed and is not listed in the Met, Alert, SOH, Sample, Detbkphd, QC, Gasbkphd spectra.",subject); log.warn("This email {} parsing failed and is not listed in the Met, Alert, SOH, Sample, Detbkphd, QC, Gasbkphd spectra.",subject);
} }
}
emailServiceManager.removeMail(message); emailServiceManager.removeMail(message);
}
// 如果邮件内容校验失败(邮件内容不完整) 将错误邮件从eml移动到emlError
else {
emailServiceManager.emlToEmlError(emlFile);
}
} catch (Exception e) { } catch (Exception e) {
// 如果邮件正常下载 则删除下载的邮件对象
if (!(e instanceof DownloadEmailException))
emailServiceManager.removeMail(message); emailServiceManager.removeMail(message);
e.printStackTrace(); e.printStackTrace();
}finally { }finally {

View File

@ -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.getUndealPath());
FileUtil.mkdir(spectrumPathProperties.getRootPath()+File.separator+spectrumPathProperties.getFilesourcePath()); FileUtil.mkdir(spectrumPathProperties.getRootPath()+File.separator+spectrumPathProperties.getFilesourcePath());
FileUtil.mkdir(spectrumPathProperties.getRootPath()+File.separator+spectrumPathProperties.getEmlPath()); FileUtil.mkdir(spectrumPathProperties.getRootPath()+File.separator+spectrumPathProperties.getEmlPath());
FileUtil.mkdir(spectrumPathProperties.getRootPath()+File.separator+spectrumPathProperties.getEmlErrorPath());
FileUtil.mkdir(spectrumPathProperties.getRootPath()+File.separator+spectrumPathProperties.getErrorFilePath()); FileUtil.mkdir(spectrumPathProperties.getRootPath()+File.separator+spectrumPathProperties.getErrorFilePath());
} }
} }

View File

@ -63,11 +63,11 @@ public class JeecgSpectrumAnalysisApplication extends SpringBootServletInitializ
@Override @Override
public void run(String... args) throws Exception { public void run(String... args) throws Exception {
//Windows加载dll工具库 //Windows加载dll工具库
/*System.loadLibrary("ReadPHDFile"); System.loadLibrary("ReadPHDFile");
System.loadLibrary("GammaAnaly");*/ System.loadLibrary("GammaAnaly");
//Linux版本加载dll工具库 //Linux版本加载dll工具库
System.load("/usr/local/jdk/lib/libReadPHDFile.so"); /*System.load("/usr/local/jdk/lib/libReadPHDFile.so");
System.load("/usr/local/jdk/lib/libGammaAnalyALG.so"); System.load("/usr/local/jdk/lib/libGammaAnalyALG.so");*/
//创建缓存 //创建缓存
betaCache.initCache(); betaCache.initCache();
localCache.initCache(); localCache.initCache();