Compare commits

...

10 Commits

Author SHA1 Message Date
nieziyan
d5dce1c3fc feat:探测器报警信息 2024-06-04 09:52:58 +08:00
nieziyan
e83c1d6199 feat:探测器报警信息 2024-06-04 09:47:58 +08:00
qiaoqinzheng
600c5235ec 自建台站分支同步代码 2024-04-30 11:51:54 +08:00
qiaoqinzheng
3a1567f853 自建台站分支初始化数据返回值关键字改为void 2024-04-26 11:25:27 +08:00
nieziyan
d5b18e57b5 fix:增加排序 2024-04-11 14:51:57 +08:00
nieziyan
14e64306b2 Merge remote-tracking branch 'origin/SelfStation' into SelfStation 2024-04-10 19:10:14 +08:00
nieziyan
0c8019ad15 feat:修改是否对文件内容解码逻辑 2024-04-10 19:09:32 +08:00
qiaoqinzheng
d92d55befc 自动处理模块GPS谱流程代码修改 2024-04-10 12:40:14 +08:00
qiaoqinzheng
fc4623e584 自动处理模块GPS谱流程代码修改 2024-04-10 11:31:27 +08:00
qiaoqinzheng
8d3b380837 自动处理模块service配置类增加GPS基础数据相关service实体 2024-04-10 09:13:56 +08:00
26 changed files with 606 additions and 191 deletions

View File

@ -20,6 +20,7 @@ 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.properties.TaskProperties;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.Md5Util;
import org.jeecg.common.util.RedisUtil;
@ -54,6 +55,8 @@ public class EmailServiceManager {
private SysEmail email;
private SpectrumPathProperties spectrumPathProperties;
private TaskProperties taskProperties;
/**
* 系统启动时间
*/
@ -69,6 +72,8 @@ public class EmailServiceManager {
private RedisUtil redisUtil;
private Object downloadEmlLocal = new Object();
@NotNull
public static EmailServiceManager getInstance(){
return new EmailServiceManager();
@ -87,13 +92,14 @@ public class EmailServiceManager {
* @param email 邮件属性
*/
public void init(SysEmail email, Integer receiveNum, String temporaryStoragePath,
Date systemStartupTime, SpectrumPathProperties pathProperties,
Date systemStartupTime, SpectrumPathProperties pathProperties,TaskProperties taskProperties,
RedisUtil redisUtil){
this.email = email;
this.receiveNum = receiveNum;
this.temporaryStoragePath = temporaryStoragePath;
this.systemStartupTime = systemStartupTime;
this.spectrumPathProperties = pathProperties;
this.taskProperties = taskProperties;
this.redisUtil = redisUtil;
}
@ -528,102 +534,85 @@ public class EmailServiceManager {
* 当计数大于10000后从0开始服务重启后也从0开始
*/
public File downloadEmailToEmlDir(@NotNull Message message,Integer emailCounter,Integer batchesCounter) throws MessagingException {
String subject = "";
File emlFile = null;
String status = EmailLogManager.STATUS_SUCCESS;
Date receivedDate = null;
try {
//获取发件人
final String address = ((InternetAddress) message.getFrom()[0]).getAddress();
final String from = address.substring(0,address.indexOf(StringConstant.AT));
//获取主题
subject = MimeUtility.decodeText(message.getSubject());
if(subject.contains(StringConstant.SLASH)){
subject = StringUtils.replace(subject,StringConstant.SLASH,"");
}
if(subject.contains(StringConstant.COLON)){
subject = StringUtils.replace(subject,StringConstant.COLON,"");
}
receivedDate = message.getReceivedDate();
StringBuilder fileName = new StringBuilder();
fileName.append(from);
fileName.append(StringConstant.UNDER_LINE);
fileName.append(subject);
fileName.append(StringConstant.UNDER_LINE);
fileName.append(DateUtils.formatDate(new Date(),"YYMMdd"));
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(receivedDate,"YYMMdd"));
fileName.append(StringConstant.UNDER_LINE);
fileName.append(DateUtils.formatDate(receivedDate,"HHmmssSSS"));
fileName.append(StringConstant.UNDER_LINE);
fileName.append(emailCounter);
fileName.append(SAVE_EML_SUFFIX);
final String rootPath = spectrumPathProperties.getRootPath();
final String emlPath = spectrumPathProperties.getEmlPath();
emlFile = new File(rootPath + emlPath + File.separator + fileName);
/* 如果邮件内容经过Base64编码 需要解码后再生成.eml文件 否则直接生成.eml文件 */
List<String> specified = ListUtil.toList("");
if (CollUtil.contains(specified, from)){ // 来自指定邮箱 此邮箱对邮件内容进行了Base64编码
// 先将未解码的内容保存为.eml文件
FileUtil.writeFromStream(message.getInputStream(), emlFile);
// 对正文内容进行解码
String content = (String) message.getContent();
// String content = FileUtil.readUtf8String(emlFile);
List<String> contents = ListUtil.toList(StrUtil.split(content, '|', 2));
String md5 = contents.get(0);
content = contents.get(1);
if (StrUtil.isBlank(content)) return emlFile;
content = StrUtil.cleanBlank(content);
String md5Verified = MD5.create().digestHex(content);
// 如果md5验证失败 则不进行解码
if (!StrUtil.equals(md5, md5Verified)) return emlFile;
contents = ListUtil.toList(StrUtil.split(content, "|"));
String base64 = contents.get(contents.size() - 1);
// 解码Base64字符串 并用解码后的内容覆盖未解码内容
byte[] data = Base64.decode(base64);
try (OutputStream out = Files.newOutputStream(emlFile.toPath());
InflaterOutputStream inflaterOutputStream = new InflaterOutputStream(out)) {
inflaterOutputStream.write(data);
} catch (Exception e) {
log.error("Create the base64 decoded file[{}] error: {}", emlFile.getAbsolutePath(), e.getMessage());
synchronized (downloadEmlLocal) {
String subject = "";
File emlFile = null;
String status = EmailLogManager.STATUS_SUCCESS;
Date receivedDate = null;
InputStream inputStream = null;
BufferedOutputStream outputStream = null;
try {
//获取发件人
final String address = ((InternetAddress) message.getFrom()[0]).getAddress();
final String from = address.substring(0,address.indexOf(StringConstant.AT));
//获取主题
subject = MimeUtility.decodeText(message.getSubject());
if(subject.indexOf(StringConstant.SLASH) != -1){
subject = StringUtils.replace(subject,StringConstant.SLASH,"");
}
if(subject.indexOf(StringConstant.COLON) != -1){
subject = StringUtils.replace(subject,StringConstant.COLON,"");
}
receivedDate = message.getReceivedDate();
StringBuilder fileName = new StringBuilder();
fileName.append(from);
fileName.append(StringConstant.UNDER_LINE);
fileName.append(subject);
fileName.append(StringConstant.UNDER_LINE);
fileName.append(DateUtils.formatDate(new Date(),"YYMMdd"));
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(receivedDate,"YYMMdd"));
fileName.append(StringConstant.UNDER_LINE);
fileName.append(DateUtils.formatDate(receivedDate,"HHmmssSSS"));
fileName.append(StringConstant.UNDER_LINE);
fileName.append(emailCounter);
fileName.append(SAVE_EML_SUFFIX);
final String rootPath = spectrumPathProperties.getRootPath();
final String emlPath = spectrumPathProperties.getEmlPath();
emlFile = new File(rootPath+emlPath+File.separator+fileName);
// outputStream = new FileOutputStream(emlFile);
// message.writeTo(outputStream);
int bufferSize = 1024 * 1024; // 1M
inputStream = message.getInputStream();
outputStream = new BufferedOutputStream(new FileOutputStream(emlFile), bufferSize);
// 从邮件的输入流读取内容并写入到本地文件
byte[] buffer = new byte[bufferSize];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
} catch (MessagingException | IOException e) {
// 下载邮件失败 抛出自定义邮件下载异常
status = EmailLogManager.STATUS_ERROR;
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);
}catch (Exception e) {
log.error("",e);
}finally {
EmailLogEvent event = new EmailLogEvent(batchesCounter,Thread.currentThread().getId(),EmailLogManager.GS_TYPE_GET,status,EmailLogManager.GETIDEML,subject,DateUtils.formatDate(receivedDate,"yyyy-MM-dd HH:mm:ss:SSS"),
(Objects.isNull(emlFile)?" ":emlFile.getAbsolutePath()));
EmailLogManager.getInstance().offer(Thread.currentThread().getId(),event);
try {
if (Objects.nonNull(inputStream)) {
inputStream.close();
}
if (Objects.nonNull(outputStream)) {
outputStream.flush();
outputStream.close();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
} else { // 直接生成.eml文件
message.writeTo(Files.newOutputStream(emlFile.toPath()));
}
// int bufferSize = 1024 * 1024; // 1M
// InputStream inputStream = message.getInputStream();
// BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream, bufferSize);
// // 或者使用 BufferedOutputStream
// OutputStream outputStream = new FileOutputStream(emlFile);
// BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream, bufferSize);
// // 从邮件的输入流读取内容并写入到本地文件
// byte[] buffer = new byte[bufferSize];
// int bytesRead;
// while ((bytesRead = bufferedInputStream.read(buffer)) != -1) {
// bufferedOutputStream.write(buffer, 0, bytesRead);
// }
//
// // 关闭流
// bufferedInputStream.close();
// bufferedOutputStream.close();
} catch (MessagingException | IOException e) {
// 下载邮件失败 抛出自定义邮件下载异常
status = EmailLogManager.STATUS_ERROR;
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);
}catch (Exception e) {
log.error("The email download failed: {}", e.getMessage());
}finally {
EmailLogEvent event = new EmailLogEvent(batchesCounter,Thread.currentThread().getId(),EmailLogManager.GS_TYPE_GET,status,EmailLogManager.GETIDEML,subject,DateUtils.formatDate(receivedDate,"yyyy-MM-dd HH:mm:ss:SSS"),
(Objects.isNull(emlFile)?" ":emlFile.getAbsolutePath()));
EmailLogManager.getInstance().offer(Thread.currentThread().getId(),event);
return emlFile;
}
return emlFile;
}
/**
@ -665,10 +654,10 @@ public class EmailServiceManager {
if(null != store){
store.close();
}
for(String messageId : messageIds){
String key = RedisConstant.EMAIL_MSG_ID+StringConstant.COLON+messageId;
redisUtil.del(key);
}
// for(String messageId : messageIds){
// String key = RedisConstant.EMAIL_MSG_ID+StringConstant.COLON+messageId;
// redisUtil.del(key);
// }
} catch (MessagingException e) {
log.error("Email closure failed, email address is: {}, reason is: {}",email.getUsername(),e.getMessage());
e.printStackTrace();
@ -684,10 +673,13 @@ public class EmailServiceManager {
boolean exist = false;
try {
String key = RedisConstant.EMAIL_MSG_ID+StringConstant.COLON+messageId;
exist = redisUtil.hasKey(key);
if(exist){
int numberKey = redisUtil.get(key) != null? (int) redisUtil.get(key):0;
// exist = redisUtil.hasKey(key);
if(numberKey >= taskProperties.getForceDeletedNumber()){
exist = true;
log.info("Check: Remove Email:{},receiveTime:{}",message.getSubject(), DateUtils.formatDate(message.getReceivedDate(),"yyyy-MM-dd HH:mm:ss"));
message.setFlag(Flags.Flag.DELETED,true);
redisUtil.del(key);
}
return exist;
} catch (MessagingException e) {

View File

@ -41,6 +41,11 @@ public class TaskProperties implements Serializable {
*/
private Integer mailThreadExecCycle;
/**
* 线程获取失败邮件次数
*/
private Integer forceDeletedNumber;
/**
* 监测需删除的邮件线程执行周期毫秒
*/

View File

@ -0,0 +1,51 @@
package org.jeecg.modules.base.entity.original;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
@Data
@TableName("ORIGINAL.SAMPLE_WATER_RESULT")
public class SampleWaterResult implements Serializable {
@TableField(value = "SAMPLE_RESULT_ID")
private Integer sampleResultId;
@TableField(value = "SAMPLE_ID")
private Integer sampleId;
@TableField(value = "NUCLIDE_NAME")
private String nuclideName;
@TableField(value = "ENERGY")
private Double energy;
@TableField(value = "CSC_RATIO")
private Double cscRatio;
@TableField(value = "HALF_LIFE")
private Double halfLife;
@TableField(value = "MDA")
private Double mda;
@TableField(value = "ACTIVITY")
private Double activity;
@TableField(value = "SPEC_ACTIVITY")
private Double specActivity;
@TableField(value = "NID_FLAG")
private Integer nidFlag;
@TableField(value = "MODDATE")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date moddate;
}

View File

@ -9,7 +9,7 @@ import lombok.Getter;
public enum Condition {
FIRST_FOUND("1"), ABOVE_AVERAGE("2"), MEANWHILE("3");
private String value;
private final String value;
public static Condition valueOf1(String value){
for (Condition condition : Condition.values()) {

View File

@ -52,7 +52,9 @@ public enum DataType {
SPHDP("SPHDP", ".PHD"),
SPHDF("SPHDF", ".PHD"),
GPS("RMSGPS", ".gps");
GPS("RMSGPS", ".gps"),
RESULT("HRULT", ".result");
private String type;

View File

@ -0,0 +1,26 @@
package org.jeecg.modules.entity.vo;
import lombok.Data;
import java.io.Serializable;
@Data
public class ResultNuclide implements Serializable {
private String nuclideName;
private Double energy;
private Double cscRatio;
private String halfLife;
private Double mda;
private Double activity;
private Double specActivity;
private String nidFlag;
}

View File

@ -233,9 +233,15 @@ public class AutoProcessManager{
if(databaseEmail.getEnabled().equals(SysMailEnableType.ENABLE.getMailEnableType())){
final boolean testFlag = testConnectEmailServer(databaseEmail);
if(testFlag){
databaseEmail.setNewEmailFlag(true);
if (emailExecThreadMap.containsKey(databaseEmail.getId())) {
EmailParsingActuator actuator = emailExecThreadMap.get(databaseEmail.getId());
actuator.setStop(false);
log.info("{}邮箱重新加入监测队列",databaseEmail.getUsername());
} else {
databaseEmail.setNewEmailFlag(true);
log.info("{}邮箱加入监测队列,设置新增标记",databaseEmail.getUsername());
}
emailMap.put(databaseEmail.getId(),databaseEmail);
log.info("{}邮箱加入监测队列,设置新增标记",databaseEmail.getUsername());
}
}
}
@ -279,6 +285,7 @@ public class AutoProcessManager{
if(next.getValue().getState() == State.TERMINATED){
log.info("{}邮箱执行线程已停止emailExecThreadMap删除此邮箱数据",next.getValue().getEmailProperties().getUsername());
checkStopThreads.remove();
emailMap.remove(next.getKey());
}
}

View File

@ -74,23 +74,23 @@ public class EmailParsingActuator extends Thread{
long start = System.currentTimeMillis();
final EmailServiceManager emailServiceManager = EmailServiceManager.getInstance();
emailServiceManager.init(this.emailProperties,this.taskProperties.getReceiveNum(),this.taskProperties.getTemporaryStoragePath(),
this.systemStartupTime, spectrumServiceQuotes.getSpectrumPathProperties(),spectrumServiceQuotes.getRedisUtil());
this.systemStartupTime, spectrumServiceQuotes.getSpectrumPathProperties(), spectrumServiceQuotes.getTaskProperties(), spectrumServiceQuotes.getRedisUtil());
List<String> messageIds = new ArrayList<>();
try {
Message[] messages = emailServiceManager.receiveMail();
if(ArrayUtils.isNotEmpty(messages)){
log.info("EmailParsingActuator本次获取邮件数量为:{}",messages.length);
log.info("EmailParsingActuator本次{}获取邮件数量为:{}", Thread.currentThread().getName(), messages.length);
//检验获取的邮件是否在之前删除失败列表中若在直接调用邮件API删除并且此次数组里元素也删除
// for(int i=messages.length-1;i>=0;i--){
// if (!messages[i].isExpunged()){
// String messageId = ((MimeMessage) messages[i]).getMessageID();
// final boolean exist = emailServiceManager.check(messages[i],messageId);
// messageIds.add(messageId);
// if(exist){
// messages = ArrayUtils.remove(messages,i);
// }
// }
// }
for(int i=messages.length-1;i>=0;i--){
if (!messages[i].isExpunged()){
String messageId = ((MimeMessage) messages[i]).getMessageID();
final boolean exist = emailServiceManager.check(messages[i],messageId);
messageIds.add(messageId);
if(exist){
messages = ArrayUtils.remove(messages,i);
}
}
}
log.info("EmailParsingActuator本次真实执行邮件数量为{}",messages.length);
if(messages.length > 0){
//本批次邮件号
@ -105,8 +105,10 @@ public class EmailParsingActuator extends Thread{
taskLatch.await();
}
}
}catch (InterruptedException e) {
} catch (InterruptedException e) {
e.printStackTrace();
} catch (MessagingException e) {
throw new RuntimeException(e);
} finally {
//清除本批次邮件日志缓存
EmailLogManager.getInstance().clear();

View File

@ -0,0 +1,12 @@
package org.jeecg.modules.exception;
/*
GPS文件读取失败时抛出异常
*/
public class GPSFileReadException extends RuntimeException{
public GPSFileReadException(String message) {
super(message);
}
}

View File

@ -17,10 +17,7 @@ import org.jeecg.modules.eneity.event.SpectrumErrorEvent;
import org.jeecg.modules.eneity.event.SpectrumLog;
import org.jeecg.modules.enums.ErrorType;
import org.jeecg.modules.enums.SpectrumSource;
import org.jeecg.modules.exception.AnalySpectrumException;
import org.jeecg.modules.exception.AnalyseException;
import org.jeecg.modules.exception.FileRepeatException;
import org.jeecg.modules.exception.HeaderBlockException;
import org.jeecg.modules.exception.*;
import org.jeecg.modules.file.FileOperation;
import java.io.File;
import java.io.FileNotFoundException;

View File

@ -12,6 +12,8 @@ import org.jeecg.modules.base.enums.SampleFileHeader;
import org.jeecg.modules.eneity.event.FormatErrorEvent;
import org.jeecg.modules.eneity.event.SpectrumErrorEvent;
import org.jeecg.modules.enums.ErrorType;
import org.jeecg.modules.exception.GPSFileReadException;
import org.jeecg.modules.exception.PHD_ReadException;
import org.jeecg.modules.file.FileOperation;
import org.jeecg.modules.native_jni.struct.GPSSpectrumStruct;
import org.springframework.util.CollectionUtils;
@ -45,6 +47,12 @@ public class GPSSpectrum extends AbstractSpectrumHandler{
*/
@Override
protected void setChina() {
AbstractSpectrumHandler spectrumHandler = new WaterResultSpectrum();
spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile,super.sourceFilePath,
super.currDataType,super.mailContent,super.emlFileName,
super.spectrumSource,super.returnFileName, super.batchesCounter);
spectrumHandler.setPrevious(this);
super.setNext(spectrumHandler);
}
/**
@ -52,6 +60,23 @@ public class GPSSpectrum extends AbstractSpectrumHandler{
*/
@Override
protected void preCheck() {
this.readFile();
}
protected void readFile() {
//获取文件内容
File gpsFile = new File(super.spectrumFile.getAbsolutePath());
//判断文件是否存在如果不存在抛出phd文件读取异常
if (!gpsFile.exists()) {
throw new GPSFileReadException("This GPS file cannot be found in:"+super.spectrumFile.getAbsolutePath());
}
//文件内容读取
try {
lines = FileUtils.readLines(gpsFile, "UTF-8");
} catch (IOException e) {
ErrorLogManager.getInstance().write(new SpectrumErrorEvent(new Date(), "This GPS file read content error", super.spectrumFile.getName()));
throw new GPSFileReadException("This GPS file read content error");
}
}
@Override
@ -91,11 +116,12 @@ public class GPSSpectrum extends AbstractSpectrumHandler{
@Override
protected void parseingEmail() throws Exception {
this.sourceData = new GPSSpectrumStruct();
//初始下标是0 0不进行读取
int index = 0;
//从第第五行开始遍历文件内容
for (int i=0; i< lines.size(); i++) {
//读取文件行内容
String lineContent = lines.get(i);
//初始下标是0 0不进行读取
int index = 0;
//判断当前行是否包含begin 如果包含 从当前行开始向后读取4行
if (lineContent.contains(SampleFileHeader.BEGIN.getMessage())) {
index = i + 4;

View File

@ -48,6 +48,12 @@ public class HealthStatusSpectrum extends AbstractSpectrumHandler{
*/
@Override
protected void setChina() {
AbstractSpectrumHandler spectrumHandler = new GPSSpectrum();
spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile,super.sourceFilePath,
super.currDataType,super.mailContent,super.emlFileName,
super.spectrumSource,super.returnFileName, super.batchesCounter);
spectrumHandler.setPrevious(this);
super.setNext(spectrumHandler);
}
/**
@ -102,6 +108,8 @@ public class HealthStatusSpectrum extends AbstractSpectrumHandler{
super.handleParseingFailFile(e);
throw e;
}
} else {
super.next.handler();
}
}

View File

@ -96,7 +96,10 @@ public class SpectrumParsingActuator implements Runnable{
receiveDate = DateUtils.formatDate(message.getReceivedDate(),"yyyy-MM-dd HH:mm:ss");
String emlName = subject+ StringConstant.UNDER_LINE+ receiveDate;
String key = RedisConstant.EMAIL_MSG_ID+StringConstant.COLON+messageId;
spectrumServiceQuotes.getRedisUtil().set(key,emlName,expiryTime);
// spectrumServiceQuotes.getRedisUtil().set(key,emlName,expiryTime);
//判断当前key的下载次数是否超过限制次数
spectrumServiceQuotes.getRedisUtil().incr(key, 1L);
spectrumServiceQuotes.getRedisUtil().expire(key, expiryTime);
//线程开始初始化时初始本线程负责的能谱日志事件
SpectrumLogManager.mailSpectrumLogManager.offer(Thread.currentThread().getId(),null);
@ -123,6 +126,7 @@ public class SpectrumParsingActuator implements Runnable{
try {
//开始解析
spectrumHandler.handler();
spectrumServiceQuotes.getRedisUtil().del(key);
} catch (Exception e) {
//如果是gamma谱的分析异常
if (e instanceof AnalySpectrumException) {
@ -136,7 +140,6 @@ public class SpectrumParsingActuator implements Runnable{
throw e;
}
}
}else{
log.warn("This email {} parsing failed and is not listed in the Met, Alert, SOH, Sample, Detbkphd, QC, Gasbkphd spectra.",subject);
}
@ -204,7 +207,7 @@ public class SpectrumParsingActuator implements Runnable{
final String finalPath = rootPath+emlErrorPath;
FileOperation.moveFile(emlFile,finalPath,true);
// 删除 key防止下次线程执行删除邮件
spectrumServiceQuotes.getRedisUtil().del(key);
// spectrumServiceQuotes.getRedisUtil().del(key);
}
}

View File

@ -85,6 +85,9 @@ public class SpectrumServiceQuotes {
private final RedisUtil redisUtil;
private final MaximumPoolSizeProperties maximumPoolSizeProperties;
private final IGardsGPSDataService gardsGPSDataService;
/**
* 原始库插入数据锁
*/

View File

@ -0,0 +1,219 @@
package org.jeecg.modules.spectrum;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import org.apache.commons.io.FileUtils;
import org.jeecg.common.properties.SpectrumPathProperties;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.ErrorLogManager;
import org.jeecg.modules.base.entity.original.SampleWaterResult;
import org.jeecg.modules.base.enums.DataType;
import org.jeecg.modules.base.enums.SampleFileHeader;
import org.jeecg.modules.eneity.event.FormatErrorEvent;
import org.jeecg.modules.eneity.event.SpectrumErrorEvent;
import org.jeecg.modules.exception.GPSFileReadException;
import org.jeecg.modules.file.FileOperation;
import org.jeecg.modules.native_jni.struct.WaterResultStruct;
import org.springframework.util.CollectionUtils;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.time.LocalDate;
import java.util.*;
public class WaterResultSpectrum extends AbstractSpectrumHandler{
private List<String> lines = null;
private WaterResultStruct sourceData = null;
/**
* 开始存库时间
*/
private Date startIntoDatabaseTime = null;
/**
* 结束存库时间
*/
private Date endIntoDatabaseTime = null;
private List<SampleWaterResult> waterResultList = null;
@Override
protected void setChina() {
}
@Override
protected void preCheck() {
this.readFile();
}
protected void readFile() {
//获取文件内容
File resultFile = new File(super.spectrumFile.getAbsolutePath());
//判断文件是否存在如果不存在抛出phd文件读取异常
if (!resultFile.exists()) {
throw new GPSFileReadException("This Result file cannot be found in:"+super.spectrumFile.getAbsolutePath());
}
//文件内容读取
try {
lines = FileUtils.readLines(resultFile, "UTF-8");
} catch (IOException e) {
ErrorLogManager.getInstance().write(new SpectrumErrorEvent(new Date(), "This Result file read content error", super.spectrumFile.getName()));
throw new GPSFileReadException("This Result file read content error");
}
}
@Override
public void handler() throws Exception {
if(DataType.RESULT.getType().equals(super.currDataType.getType())){
try {
//前置检查
this.preCheck();
//打印当前处理的能谱类型
super.printCurrDataType();
//解析邮件内容
this.parseingEmail();
//修改能谱文件名称
this.updateSpectrumFileName();
//保存PHD文件到savefile
super.saveFileToSavefile();
//结构体数据入库
this.handlerOriginalData();
//把流程日志保存到日志目录
this.saveLogToLogDir();
//若本次文件来自于undel目录解析成功则删除
deleteIfFromUndelFile();
}catch (Exception e){
//异常返回文件名称用于报错日志
super.returnFileName.append(super.spectrumFile.getName());
//处理解析失败的文件
super.handleParseingFailFile(e);
throw e;
}
}
}
@Override
protected void parseingEmail() throws Exception {
this.sourceData = new WaterResultStruct();
//遍历文件内容
for (int i=0; i< lines.size(); i++) {
//获取行内容
String lineContent = lines.get(i);
//判断行内容是否包含header的内容
if (lineContent.contains(SampleFileHeader.HEADER.getMessage())) {
Map<String, String> map = new HashMap<>();
this.readContent(i+1, map);
}
}
}
private int readContent(int index, Map<String, String> map) {
int lastIndex = 0;
for (int i= index; i<lines.size(); i++) {
//从当前下标开始读取内容 直到下一个结束的标识为止 并返回结束标识的下标
String lineContent = lines.get(i);
//判断当前行是否包含# 或者 STOP 如果都不包含则进行内容读取 如果包含则跳过
if (!lineContent.contains("#") && !lineContent.contains(SampleFileHeader.STOP.getMessage())) {
//切割任意类型空格 获取行内容
List<String> contents = Arrays.asList(lineContent.split("\\s+"));
//遍历当前行内容
for (int j=0; j<contents.size(); j++) {
String content = contents.get(j);
}
} else {
lastIndex = i;
}
}
return lastIndex;
}
@Override
protected String getFileSaveRelativePath() {
final int year = LocalDate.now().getYear();
final int month = LocalDate.now().getMonth().getValue();
final SpectrumPathProperties properties = super.spectrumServiceQuotes.getSpectrumPathProperties();
StringBuilder relativePath = new StringBuilder();
relativePath.append(properties.getFilePathMap().get(super.currDataType.getType()));
relativePath.append(File.separator);
relativePath.append(year);
relativePath.append(File.separator);
relativePath.append(month>=10?month:"0"+month);
return relativePath.toString();
}
@Override
protected void updateSpectrumFileName() throws FileNotFoundException {
StringBuilder newFileName = new StringBuilder();
newFileName.append(this.sourceData.stationCode);
newFileName.append(StringPool.UNDERSCORE);
newFileName.append(super.currDataType.getType());
newFileName.append(StringPool.DASH);
newFileName.append(this.sourceData.sampleRefId.substring(5, 17));
newFileName.append(super.currDataType.getSuffix());
if(!super.spectrumFile.exists()){
//发送格式化错误事件后续统计报告使用
spectrumServiceQuotes.getApplicationContext().publishEvent(new FormatErrorEvent());
throw new FileNotFoundException(super.spectrumFile.getAbsolutePath()+" does not exist");
}
super.spectrumFile = FileOperation.rename(super.spectrumFile,newFileName.toString(),true);
//设置能谱文件保存相对路径包含文件名称
String fileSavePath = this.getFileSaveRelativePath();
this.spectrumFileRelativePath = fileSavePath+File.separator+this.spectrumFile.getName();
}
@Override
protected void updateErrorSpectrumFileName() throws FileNotFoundException {
StringBuilder newFileName = new StringBuilder();
newFileName.append(this.sourceData.stationCode);
newFileName.append(StringPool.UNDERSCORE);
newFileName.append(super.currDataType.getType());
newFileName.append(StringPool.DASH);
newFileName.append(this.sourceData.sampleRefId.substring(5, 17));
newFileName.append(super.currDataType.getSuffix());
if(!super.spectrumFile.exists()){
//发送格式化错误事件后续统计报告使用
spectrumServiceQuotes.getApplicationContext().publishEvent(new FormatErrorEvent());
throw new FileNotFoundException(super.spectrumFile.getAbsolutePath()+" does not exist");
}
super.spectrumFile = FileOperation.rename(super.spectrumFile,newFileName.toString(),true);
}
@Override
protected void handlerOriginalData() throws Exception {
this.startIntoDatabaseTime = new Date();
// this.gpsData = spectrumServiceQuotes.getGardsGPSDataService().create(this.sourceData, super.spectrumFileRelativePath);
this.endIntoDatabaseTime = new Date();
}
/**
* 把流程日志保存到日志目录
*/
@Override
protected void saveLogToLogDir() throws IOException {
//获取海水结果谱记录核素ID范围
String nuclideIdRange = "";
if(!CollectionUtils.isEmpty(this.waterResultList)){
nuclideIdRange = this.waterResultList.get(0).getSampleResultId()+"-"+this.waterResultList.get(this.waterResultList.size()-1).getSampleResultId();
}
//组装日志文件内容
StringBuilder logContent = new StringBuilder();
logContent.append("-------------------------- Write Data into Database at ").append(DateUtils.formatDate(this.startIntoDatabaseTime,"yyyy-MM-dd HH:mm:ss")).append(" ---------------------------");
logContent.append(System.lineSeparator()).append(System.lineSeparator());
logContent.append("WATER RESULT NUCLIDE ID: ").append(nuclideIdRange).append(" StandardFile:").append(super.spectrumFile.getAbsolutePath());
logContent.append(System.lineSeparator()).append(System.lineSeparator());
logContent.append("------------------- ").append("Write Data into Database Successfully at ").append(DateUtils.formatDate(this.endIntoDatabaseTime,"yyyy-MM-dd HH:mm:ss")).append(" --------------------");
final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties();
final String dirPath = properties.getRootPath()+properties.getLogPath()+File.separator+this.getFileSaveRelativePath();
final String fileName = super.spectrumFile.getName().replace(this.currDataType.getSuffix(),LOG_FILE_SUFFIX);
final String finalPath = dirPath+ File.separator+fileName;
super.sendSpectrumLogToQueue(finalPath,logContent.toString());
}
}

View File

@ -0,0 +1,28 @@
package org.jeecg.modules.native_jni.struct;
import org.jeecg.modules.entity.vo.ResultNuclide;
import java.util.LinkedList;
import java.util.List;
public class WaterResultStruct {
public String stationCode;
public String detectorCode;
public String sampleRefId;
public Double lon;
public Double lat;
public List<ResultNuclide> resultNuclideList;
public WaterResultStruct() {
resultNuclideList = new LinkedList<>();
}
}

View File

@ -22,8 +22,8 @@ public class SelfStationController {
@GetMapping("initValue")
@ApiOperation(value = "预加载谱文件数据", notes = "预加载谱文件数据")
public Result initValue(String dbName, Integer sampleId, String analyst, String sampleFileName, String detFileName, HttpServletRequest request) {
return selfStationService.initValue(dbName, sampleId, analyst, sampleFileName, detFileName, request);
public void initValue(String dbName, Integer sampleId, String analyst, String sampleFileName, String detFileName, HttpServletRequest request) {
selfStationService.initValue(dbName, sampleId, analyst, sampleFileName, detFileName, request);
}
@GetMapping("loadFromDB")

View File

@ -10,7 +10,7 @@ import java.util.List;
public interface ISelfStationService {
Result initValue(String dbName, Integer sampleId, String analyst, String sampleFileName, String detFileName, HttpServletRequest request);
void initValue(String dbName, Integer sampleId, String analyst, String sampleFileName, String detFileName, HttpServletRequest request);
Result loadFromDB(String dbName, Integer sampleId, String analyst, HttpServletRequest request);

View File

@ -46,11 +46,11 @@ public class SelfStationServiceImpl implements ISelfStationService {
private SpectrumAnalysisMapper spectrumAnalysisMapper;
@Override
public Result initValue(String dbName, Integer sampleId, String analyst, String sampleFileName, String detFileName, HttpServletRequest request) {
public void initValue(String dbName, Integer sampleId, String analyst, String sampleFileName, String detFileName, HttpServletRequest request) {
if (StringUtils.isNotBlank(dbName) && Objects.nonNull(sampleId)) {
return loadFromDB(dbName, sampleId, analyst, request);
loadFromDB(dbName, sampleId, analyst, request);
} else {
return loadSelfStationByFile(sampleFileName, detFileName, request);
loadSelfStationByFile(sampleFileName, detFileName, request);
}
}

View File

@ -44,12 +44,14 @@ public class GardsAlertSystemServiceImpl extends ServiceImpl<GardsAlertSystemMap
String code = alertSystemVo.getCode();
String content = alertSystemVo.getContent();
LambdaQueryWrapper<GardsAlertSystem> wrapper = new LambdaQueryWrapper<>();
wrapper.orderByAsc(GardsAlertSystem::getCode);
wrapper.like(StrUtil.isNotBlank(code), GardsAlertSystem::getCode, code);
wrapper.like(StrUtil.isNotBlank(content), GardsAlertSystem::getContent, content);
page = this.page(page, wrapper);
// 手动切换为主数据源
DynamicDataSourceContextHolder.push("master");
List<DictModel> items = dictService.getItems(DictConstant.ALERT_SYSTEM_CODE);
DynamicDataSourceContextHolder.clear();
Map<String, String> typeMap = items.stream().collect(Collectors
.toMap(DictModel::getValue, DictModel::getText, (oldValue, newValue) -> newValue));
page.getRecords().forEach(item -> {
@ -62,15 +64,26 @@ public class GardsAlertSystemServiceImpl extends ServiceImpl<GardsAlertSystemMap
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public Result<?> saveOrUpdate1(GardsAlertSystem alertSystem) {
String id = alertSystem.getId();
String code = alertSystem.getCode();
LambdaQueryWrapper<GardsAlertSystem> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(GardsAlertSystem::getCode, code);
if (CollUtil.isNotEmpty(this.list(wrapper)))
return Result.error("Code " + code + "is exist!");
boolean success = this.saveOrUpdate(alertSystem);
if (success)
return Result.OK(Prompt.UPDATE_SUCC);
return Result.error(Prompt.UPDATE_ERR);
if (StrUtil.isBlank(id)){ // 如果是新增,判断code是否已经存在
if (CollUtil.isNotEmpty(this.list(wrapper)))
return Result.error("Code " + code + " is exist!");
if (this.saveOrUpdate(alertSystem))
return Result.OK(Prompt.ADD_SUCC);
return Result.error(Prompt.ADD_ERR);
} else { // 如果是修改,判断code是否修改,如果code修改,判断修改的code是否已经存在
GardsAlertSystem alertSystemOld = this.getById(id);
String oldCode = alertSystemOld.getCode();
if (!StrUtil.equals(code, oldCode))
if (CollUtil.isNotEmpty(this.list(wrapper)))
return Result.error("Code " + code + " is exist!");
if (this.saveOrUpdate(alertSystem))
return Result.OK(Prompt.UPDATE_SUCC);
return Result.error(Prompt.UPDATE_ERR);
}
}
@Override

View File

@ -88,7 +88,7 @@ public class WebStatisticsController {
@GetMapping("findAlertSohPage")
@ApiOperation(value = "台站报警数据分页查询", notes = "台站报警数据分页查询")
public Result findAlertSohPage(QueryRequest queryRequest, Integer[] stationIds,@DateTimeFormat(pattern = "yyyy-MM-dd") Date startTime,@DateTimeFormat(pattern = "yyyy-MM-dd") Date endTime){
public Result findAlertSohPage(QueryRequest queryRequest, Integer[] stationIds, String startTime, String endTime){
return gardsSohDataService.findAlertSohPage(queryRequest, stationIds, startTime, endTime);
}

View File

@ -14,4 +14,6 @@ public class GardsAlertDataWeb extends GardsAlertData {
@TableField(exist = false)
private Integer no;
@TableField(exist = false)
private Integer category;
}

View File

@ -1,8 +1,12 @@
package org.jeecg.modules.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.entity.GardsAlertDataWeb;
public interface GardsAlertDataMapper extends BaseMapper<GardsAlertDataWeb> {
import java.util.List;
import java.util.Map;
public interface GardsAlertDataMapper extends BaseMapper<GardsAlertDataWeb> {
Page<GardsAlertDataWeb> page(Page<GardsAlertDataWeb> page, Map<String, Object> params);
}

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.jeecg.modules.mapper.GardsAlertDataMapper">
<select id="page" resultType="org.jeecg.modules.entity.GardsAlertDataWeb">
SELECT
d.*, s.CATEGORY
FROM
ORIGINAL.GARDS_ALERT_DATA d
LEFT JOIN CONFIGURATION.GARDS_STATIONS s ON d.STATION_ID = s.STATION_ID
<where>
<if test="params.stationIds != null and params.stationIds.size() > 0">
d.STATION_ID IN
<foreach collection="params.stationIds" index="index" item="stationId" open="(" separator="," close=")">
#{stationId}
</foreach>
</if>
AND d.TIME BETWEEN TO_DATE(#{params.startTime}, 'YYYY-MM-DD HH24:MI:SS') AND TO_DATE(#{params.endTime}, 'YYYY-MM-DD HH24:MI:SS')
</where>
ORDER BY d.TIME DESC
</select>
</mapper>

View File

@ -29,7 +29,7 @@ public interface IGardsSohDataService extends IService<GardsSohDataWeb> {
* @param endTime
* @return
*/
Result findAlertSohPage(QueryRequest queryRequest, Integer[] stationIds, Date startTime, Date endTime);
Result findAlertSohPage(QueryRequest queryRequest, Integer[] stationIds, String startTime, String endTime);
/**
* 获取单个SOH对象

View File

@ -1,6 +1,7 @@
package org.jeecg.modules.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
@ -13,6 +14,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.poi.ss.usermodel.Workbook;
import org.jeecg.common.api.QueryRequest;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.DateConstant;
import org.jeecg.common.constant.Prompt;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.ExportUtil;
import org.jeecg.common.util.RedisUtil;
@ -95,58 +98,47 @@ public class GardsSohDataServiceImpl extends ServiceImpl<GardsSohDataMapper, Gar
}
@Override
public Result findAlertSohPage(QueryRequest queryRequest, Integer[] stationIds, Date startTime, Date endTime) {
try {
Result result = new Result();
if (Objects.isNull(stationIds)){
result.setResult(Collections.emptyList());
return result;
}
if (Objects.isNull(startTime)){
result.error500("The start time cannot be empty");
return result;
}
if (Objects.isNull(endTime)){
result.error500("The end time cannot be empty");
return result;
}
Date startDate = DateUtils.parseDate(DateUtils.formatDate(startTime, "yyyy-MM-dd") + " 00:00:00", "yyyy-MM-dd HH:mm:ss");
Date endDate = DateUtils.parseDate(DateUtils.formatDate(endTime, "yyyy-MM-dd") + " 23:59:59", "yyyy-MM-dd HH:mm:ss");
//获取redis中缓存的探测器信息
Map<Integer, String> detectorsMap = (Map<Integer, String>)redisUtil.get("detectorsMap");
Page<GardsAlertDataWeb> page = new Page<>(queryRequest.getPageNo(), queryRequest.getPageSize());
LambdaQueryWrapper<GardsAlertDataWeb> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(GardsAlertDataWeb::getStationId, stationIds);
queryWrapper.ge(GardsAlertDataWeb::getTime, startDate);
queryWrapper.le(GardsAlertDataWeb::getTime, endDate);
queryWrapper.orderByDesc(GardsAlertDataWeb::getTime);
Page<GardsAlertDataWeb> alertDataPage = gardsAlertDataMapper.selectPage(page, queryWrapper);
List<GardsAlertDataWeb> records = alertDataPage.getRecords();
if (CollUtil.isEmpty(records))
return Result.OK(alertDataPage);
// 获取Map(key: code, value: code对应内容)
Map<String, String> codeMap = systemClient.codeMap();
String flag = "Error code: ";
String regex = flag + "(\\S+)";
for (GardsAlertDataWeb record : records) {
String alertType = record.getAlertType();
if (!StrUtil.equals(alertType, "ALERT_SYSTEM"))
continue;
String alertText = record.getAlertText();
if (!StrUtil.contains(alertText, flag))
continue;
// 获取code并通过code获取对应code内容
String code = ReUtil.getGroup1(regex, alertText);
String replace = flag + codeMap.get(code);
String replaced = ReUtil.getGroup0(regex, alertText);
// 将code替换为对应内容
alertText = StrUtil.replace(alertText, replaced, replace);
record.setAlertText(alertText);
}
public Result<?> findAlertSohPage(QueryRequest queryRequest, Integer[] stationIds, String startTime, String endTime) {
if (StrUtil.isBlank(startTime))
return Result.error("StartTime" + Prompt.PARAM_REQUIRED);
if (StrUtil.isBlank(endTime))
return Result.error("EndTime" + Prompt.PARAM_REQUIRED);
startTime += DateConstant.TIME_START;
endTime += DateConstant.TIME_END;
Map<String, Object> params = new HashMap<>();
params.put("stationIds", ListUtil.toList(stationIds));
params.put("startTime", startTime);
params.put("endTime", endTime);
Integer pageNo = queryRequest.getPageNo();
Integer pageSize = queryRequest.getPageSize();
Page<GardsAlertDataWeb> page = new Page<>(pageNo, pageSize);
Page<GardsAlertDataWeb> alertDataPage = gardsAlertDataMapper.page(page, params);
List<GardsAlertDataWeb> records = alertDataPage.getRecords();
if (CollUtil.isEmpty(records))
return Result.OK(alertDataPage);
} catch (ParseException e) {
throw new RuntimeException(e);
Map<String, String> codeMap = systemClient.codeMap();
String flag1 = "Error code: ";
String flag2 = "Error code : ";
String regex1 = flag1 + "(\\S+)";
String regex2 = flag2 + "(\\S+)";
for (GardsAlertDataWeb record : records) {
String alertType = record.getAlertType();
if (!StrUtil.equals(alertType, "ALERT_SYSTEM"))
continue;
String alertText = record.getAlertText();
boolean c1 = StrUtil.contains(alertText, flag1);
boolean c2 = StrUtil.contains(alertText, flag2);
if (!c1 && !c2) continue;
String flag = c1 ? flag1 : flag2;
String regex = c1 ? regex1 : regex2;
String code = ReUtil.getGroup1(regex, alertText);
String replace = flag + codeMap.get(code);
String replaced = ReUtil.getGroup0(regex, alertText);
alertText = StrUtil.replace(alertText, replaced, replace);
record.setAlertText(alertText);
}
return Result.OK(alertDataPage);
}
@Override