1.修改实体类主键,适配postgresql

2.修改自动处理工程,添加解析探测系统发来的压缩并编码后的文件
3.修改自动处理工程,根据要求修改dos谱处理逻辑,解析后复制一份到指定位置给西安用
This commit is contained in:
panbaolin 2025-05-20 16:40:58 +08:00
parent a2224c91e7
commit f4c3fa55a7
17 changed files with 183 additions and 52 deletions

View File

@ -74,6 +74,11 @@ public class SpectrumPathProperties implements Serializable {
*/
private String errorFilePath;
/**
* dos谱外放目录西安那边从外放目录拿取dos谱
*/
private String dosExternalDirectory;
/**
* 能谱文件存储路径以能谱系统类型/能谱类型为key以存储路径为value
*/

View File

@ -1,5 +1,6 @@
package org.jeecg.modules.base.entity.configuration;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
@ -22,7 +23,7 @@ public class GardsDetectors implements Serializable {
/**
* 探测器id
*/
@TableId(value = "DETECTOR_ID")
@TableId(type = IdType.INPUT)
private Integer detectorId;
/**

View File

@ -22,7 +22,7 @@ public class GardsAlertData implements Serializable {
@TableField(value = "STATION_CODE")
private String stationCode;
@TableId(value = "ALERT_ID",type = IdType.AUTO)
@TableId(type = IdType.AUTO)
private Integer alertId;
@TableField(value = "TIME")

View File

@ -1,6 +1,8 @@
package org.jeecg.modules.base.entity.original;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
@ -19,7 +21,7 @@ public class GardsGPSData implements Serializable {
@TableField(value = "STATION_CODE")
private String stationCode;
@TableField(value = "GPS_ID")
@TableId(type = IdType.AUTO)
private Integer gpsId;
@TableField(value = "LON")

View File

@ -31,7 +31,7 @@ public class GardsMetData implements Serializable {
/**
* 气象数据id
*/
@TableId(value = "MET_ID",type = IdType.AUTO)
@TableId(type = IdType.AUTO)
private Integer metId;
/**

View File

@ -27,7 +27,7 @@ public class GardsSampleData implements Serializable {
* 样品id
*/
@TableId(value = "SAMPLE_ID",type = IdType.AUTO)
@TableId(type = IdType.AUTO)
private Integer sampleId;
/**

View File

@ -31,7 +31,7 @@ public class GardsSohData implements Serializable {
/**
* 报警ID号
*/
@TableId(value = "SOH_ID",type = IdType.AUTO)
@TableId(type = IdType.AUTO)
@Excel(name = "SID",orderNum = "5")
private Integer sohId;

View File

@ -21,7 +21,7 @@ public class GardsAnalyses implements Serializable {
/**
* 分析ID号
*/
@TableId(value = "IDANALYSIS",type = IdType.AUTO)
@TableId(value = "idanalysis",type = IdType.AUTO)
private Integer idAnalysis;
/**
* 样品id

View File

@ -1,6 +1,8 @@
package org.jeecg.modules.base.entity.rnman;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
@ -20,7 +22,7 @@ public class GardsAnalyses implements Serializable {
/**
* 分析ID号
*/
@TableField(value = "IDANALYSIS")
@TableId(value = "idanalysis",type = IdType.AUTO)
private Integer idAnalysis;
/**
* 样品id

View File

@ -0,0 +1,107 @@
package org.jeecg.modules.common;
import cn.hutool.core.io.FileUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.LineIterator;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.util.Md5Util;
import org.jeecg.modules.enums.SpectrumSource;
import org.springframework.util.Base64Utils;
import java.io.*;
import java.util.Objects;
import java.util.zip.InflaterInputStream;
@Slf4j
public class SpectrumUtils {
/**
* IMS2.0格式邮件判断条件
*/
private final static String EMAIL_BEGIN = "BEGIN IMS2.0";
private final static String MSG_TYPE = "MSG_TYPE DATA";
private final static String EMAIL_STOP = "STOP";
/**
* 校验邮件内容完整性
* @param mailContent
* @param name 如果文件是.eml文件则名称是邮件主题如果文件是.phd文件则名称是phd文件名称
* @param file 如果spectrumSource值为0则file是.eml文件如果值为1则file是phd文件
* @param spectrumSource 0能谱来源于邮箱1能谱来源于filesource目录
* @return
*/
public static boolean checkMailContent(StringBuilder mailContent, String name, File file,Integer spectrumSource){
if (Objects.isNull(file) || !file.exists()){
return false;
}
boolean flag = false;
//获取邮件内容
mailContent.append(FileUtil.readUtf8String(file));
//如果内容是普通文本
if(StringUtils.isNotBlank(mailContent) && mailContent.indexOf(EMAIL_BEGIN) != -1 &&
mailContent.indexOf(MSG_TYPE) != -1 && mailContent.indexOf(EMAIL_STOP) != -1){
if(!StringUtils.startsWith(mailContent,EMAIL_BEGIN)){
mailContent.delete(0,mailContent.indexOf(EMAIL_BEGIN));
}
if(!StringUtils.endsWith(mailContent,EMAIL_STOP)){
mailContent.delete(mailContent.indexOf(EMAIL_STOP)+EMAIL_STOP.length(),mailContent.length());
}
flag = true;
}else {
//如果内容经过压缩
LineIterator it = IOUtils.lineIterator(new StringReader(mailContent.toString()));
while (it.hasNext()) {
String line = it.nextLine();
//如果某行包含3个|字符说明此行是邮件正文
//邮件内容压缩格式
//1.md5|压缩前字节|压缩后字节|内容(Base64)
//2.md5由压缩前字节|压缩后字节|内容(Base64) )生成
//3.内容(Base64) 邮件内容压缩后转Base64
if(StringUtils.countMatches(line, "|") == 3){
String[] contentArr = line.split("\\|");
String checkStr = contentArr[1]+"|"+contentArr[2]+"|"+contentArr[3];
String checkStrMd5 = Md5Util.md5Encode(checkStr, "utf-8");
if(checkStrMd5.equals(contentArr[0])){
byte[] bytes = Base64Utils.decodeFromString(contentArr[3]);
mailContent.setLength(0);
mailContent.append(decompressStream(bytes));
//如果文件来自于fileSource且内容是编码的则把未解码内容替换为解码后内容
if(SpectrumSource.FROM_FILE_SOURCE.getSourceType().equals(spectrumSource)){
FileUtil.writeUtf8String(mailContent.toString(),file);
}
flag = true;
}
break;
}
}
}
if (flag){
log.info("{}邮件校验成功符合IMS2.0格式",name);
}else {
log.warn("{}邮件校验成功此邮件不符合IMS2.0格式",name);
}
return flag;
}
/**
* 解压缩字节
* @param zipBytes
* @throws IOException
*/
private static String decompressStream(byte[] zipBytes){
try (InflaterInputStream iis = new InflaterInputStream(new ByteArrayInputStream(zipBytes));
ByteArrayOutputStream output = new ByteArrayOutputStream();) {
byte[] buffer = new byte[1024];
int len;
while ((len = iis.read(buffer)) > 0) {
output.write(buffer, 0, len);
}
return output.toString("UTF-8").trim();
}catch (Exception e){
log.error("解压缩邮件失败");
e.printStackTrace();
}
return null;
}
}

View File

@ -12,6 +12,7 @@ import org.jeecg.common.email.EmailLogManager;
import org.jeecg.common.properties.SpectrumPathProperties;
import org.jeecg.modules.ErrorLogManager;
import org.jeecg.modules.base.enums.DataType;
import org.jeecg.modules.common.SpectrumUtils;
import org.jeecg.modules.eneity.event.FormatErrorEvent;
import org.jeecg.modules.eneity.event.SpectrumErrorEvent;
import org.jeecg.modules.eneity.event.SpectrumLog;
@ -104,8 +105,12 @@ public abstract class AbstractSpectrumHandler extends AbstractChain {
this.spectrumServiceQuotes = spectrumServiceQuotes;
this.returnFileName = returnFileName;
this.spectrumSource = spectrumSource;
if(SpectrumSource.FROM_FILE_SOURCE.getSourceType().equals(spectrumSource)){
StringBuilder mailContent = new StringBuilder();
SpectrumUtils.checkMailContent(mailContent,phdFile.getName(),phdFile,SpectrumSource.FROM_FILE_SOURCE.getSourceType());
this.mailContent = mailContent.toString();
}
this.spectrumFile = phdFile;
this.mailContent = FileUtils.readFileToString(spectrumFile,"UTF-8");
this.sourceFilePath = spectrumFile.getAbsolutePath();
}

View File

@ -1,5 +1,6 @@
package org.jeecg.modules.spectrum;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ObjectUtil;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.constant.StringConstant;
@ -92,6 +93,8 @@ public class DOSSpectrum extends AbstractSpectrumHandler{
this.updateSpectrumFileName();
//保存PHD文件到savefile
super.saveFileToSavefile();
//把dos谱文件放到扩展目录给西安用
this.expandedStorage();
//结构体数据入库
this.handlerOriginalData();
//把流程日志保存到日志目录
@ -230,4 +233,29 @@ public class DOSSpectrum extends AbstractSpectrumHandler{
super.sendSpectrumLogToQueue(finalPath,logContent.toString());
}
/**
* 把dos谱放一份到扩展目录给西安用
* @throws IOException
*/
private void expandedStorage() throws IOException {
final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties();
//把dos谱外放一份到指定位置给西安用
File dosExtDir = new File(properties.getDosExternalDirectory());
if(dosExtDir.exists() && dosExtDir.isDirectory()){
LocalDate currentDate = LocalDate.now();
StringBuilder storagePath = new StringBuilder();
storagePath.append(dosExtDir.getAbsolutePath());
storagePath.append(File.separator);
storagePath.append(currentDate.getYear());
storagePath.append(File.separator);
storagePath.append(currentDate.getMonthValue());
if(!FileUtil.exist(storagePath.toString())){
FileUtil.mkdir(storagePath.toString());
}
storagePath.append(File.separator);
storagePath.append(this.spectrumFile.getName());
FileOperation.copyFile(this.spectrumFile,storagePath.toString(),true);
}
}
}

View File

@ -7,6 +7,8 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.LineIterator;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.constant.RedisConstant;
import org.jeecg.common.constant.StringConstant;
@ -15,18 +17,23 @@ 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.common.util.Md5Util;
import org.jeecg.modules.common.SpectrumUtils;
import org.jeecg.modules.email.EmailProperties;
import org.jeecg.modules.enums.SpectrumSource;
import org.jeecg.modules.exception.AnalySpectrumException;
import org.jeecg.modules.file.FileOperation;
import org.springframework.util.Base64Utils;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.internet.MimeMessage;
import java.io.File;
import java.io.IOException;
import java.io.*;
import java.nio.file.Files;
import java.util.Base64;
import java.util.Objects;
import java.util.Properties;
import java.util.concurrent.CountDownLatch;
/**
@ -34,12 +41,6 @@ import java.util.concurrent.CountDownLatch;
*/
@Slf4j
public class SpectrumParsingActuator implements Runnable{
/**
* IMS2.0格式邮件判断条件
*/
private final static String EMAIL_BEGIN = "BEGIN IMS2.0";
private final static String MSG_TYPE = "MSG_TYPE DATA";
private final static String EMAIL_STOP = "STOP";
/**
* 邮件对象
@ -114,15 +115,12 @@ public class SpectrumParsingActuator implements Runnable{
//保存邮件日志到PG数据库
this.spectrumServiceQuotes.getMailLogService().create(message,emailProperties);
//获取邮件内容
//封装邮件内容
StringBuilder mailContent = new StringBuilder();
if(Objects.nonNull(emlFile) && emlFile.length() > 0){
mailContent.append(FileUtil.readUtf8String(emlFile));
}
//判断是否是IMS2.0协议文件
//校验邮件是否是IMS2.0协议文件如果是设置邮件内容到mailContent变量
// 如果邮件内容校验成功 将文件保存到eml目录 并删除邮件对象
if(checkMailContent(mailContent,subject)){
if(checkMailContent(mailContent,subject,emlFile)){
AbstractSpectrumHandler spectrumHandler = new SamplephdSpectrum();
spectrumHandler.init(mailContent.toString(),emlFile.getName(),spectrumServiceQuotes,new StringBuilder(),SpectrumSource.FORM_EMAIL_SERVICE.getSourceType(),batchesCounter);
final boolean matchResult = spectrumHandler.saveEmailToLocal();
@ -179,33 +177,16 @@ public class SpectrumParsingActuator implements Runnable{
}
/**
* 校验邮件内容完整性
* 1.虽然包含BEGIN IMS2.0但是有些邮件的第一行不是BEGIN IMS2.0而是Mime-Version: 1.0 Content-Type: multipart/signed;等信息
* 2.所以若是IMS2.0协议邮件但是头部包含Mime-Version等信息了要删除
* 具体解释如下
* 1.邮件包含附件或特殊内容类型当邮件包含附件HTML 内容图像或其他非纯文本内容时通常会采用 MIME 格式来处理和传输这些内容
* 因此这样的邮件可能会在头部中指定 Mime-Version 和适当的 Content-Type
* 2.邮件需要进行签名或加密如果邮件需要进行数字签名加密或其他安全操作通常会使用 multipart/signed 或其他相关的 Content-Type
* 这些类型的邮件在头部中会指定相应的内容类型和协议信息
* 3.简单纯文本邮件另一方面简单的纯文本邮件没有特殊的附件或内容类型要求因此可能不需要使用 MIME 格式
* 这种情况下邮件文本中可能不包含 Mime-Version: 1.0 Content-Type: multipart/signed;
* 校验邮件内容是否符合IMS2.0格式
* @param mailContent
* @param subject
* @param emlFile
* @return
* @throws IOException
* @throws MessagingException
*/
private boolean checkMailContent(StringBuilder mailContent,String subject){
if(StringUtils.isNotBlank(mailContent) && mailContent.indexOf(EMAIL_BEGIN) != -1 &&
mailContent.indexOf(MSG_TYPE) != -1 && mailContent.indexOf(EMAIL_STOP) != -1){
if(!StringUtils.startsWith(mailContent,EMAIL_BEGIN)){
mailContent.delete(0,mailContent.indexOf(EMAIL_BEGIN));
}
if(!StringUtils.endsWith(mailContent,EMAIL_STOP)){
mailContent.delete(mailContent.indexOf(EMAIL_STOP)+EMAIL_STOP.length(),mailContent.length());
}
log.info("{}邮件校验成功符合IMS2.0格式",subject);
return true;
}
log.warn("{}邮件校验成功此邮件不符合IMS2.0格式",subject);
return false;
private boolean checkMailContent(StringBuilder mailContent,String subject,File emlFile) throws IOException, MessagingException {
return SpectrumUtils.checkMailContent(mailContent,subject,emlFile,SpectrumSource.FORM_EMAIL_SERVICE.getSourceType());
}
private void moveEmail(File emlFile, String key) throws IOException {

View File

@ -88,7 +88,7 @@ public class JeecgAutoProcessApplication extends SpringBootServletInitializer im
} else {
//Linux版本加载dll工具库
System.load("/usr/local/jdk/lib/libReadPHDFile.so");
System.load("/usr/local/jdk/lib/libGammaAnalyALG.so");
System.load("/usr/local/jdk/lib/libGammaAnaly.so");
}
nuclLibService.getNuclideMap();
//根据配置文件配置邮件获取策略定义时间条件默认EmailReceivePolicy.HISTORY_ORDER_RECEIVE.getPolicy()

View File

@ -32,7 +32,7 @@ spring:
#Sentinel配置
sentinel:
transport:
dashboard: jeecg-boot-sentinel:9000
dashboard: armd-nacos:9000
# 支持链路限流
web-context-unify: false
filter:

View File

@ -90,7 +90,7 @@ public class JeecgSpectrumAnalysisApplication extends SpringBootServletInitializ
} else {
//Linux版本加载dll工具库
System.load("/usr/local/jdk/lib/libReadPHDFile.so");
System.load("/usr/local/jdk/lib/libGammaAnalyALG.so");
System.load("/usr/local/jdk/lib/libGammaAnaly.so");
}
//创建缓存
betaCache.initCache();

View File

@ -476,7 +476,7 @@
<!--当前环境-->
<profile.name>dev</profile.name>
<!--Nacos服务地址-->
<config.server-addr>jeecg-boot-nacos:8848</config.server-addr>
<config.server-addr>armd-nacos:8848</config.server-addr>
<!--Nacos配置中心命名空间,用于支持多环境.这里必须使用ID不能使用名称,默认为空-->
<config.namespace></config.namespace>
<!--Nacos配置分组名称-->
@ -490,7 +490,7 @@
<!--当前环境-->
<profile.name>test</profile.name>
<!--Nacos服务地址-->
<config.server-addr>jeecg-boot-nacos:8848</config.server-addr>
<config.server-addr>armd-nacos:8848</config.server-addr>
<!--Nacos配置中心命名空间,用于支持多环境.这里必须使用ID不能使用名称,默认为空-->
<config.namespace></config.namespace>
<!--Nacos配置分组名称-->