自动处理模块GPS谱流程代码修改
This commit is contained in:
parent
8d3b380837
commit
fc4623e584
|
@ -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;
|
||||||
|
|
||||||
|
}
|
|
@ -52,7 +52,9 @@ public enum DataType {
|
||||||
SPHDP("SPHDP", ".PHD"),
|
SPHDP("SPHDP", ".PHD"),
|
||||||
SPHDF("SPHDF", ".PHD"),
|
SPHDF("SPHDF", ".PHD"),
|
||||||
|
|
||||||
GPS("RMSGPS", ".gps");
|
GPS("RMSGPS", ".gps"),
|
||||||
|
|
||||||
|
RESULT("HRULT", ".result");
|
||||||
|
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
}
|
|
@ -17,10 +17,7 @@ import org.jeecg.modules.eneity.event.SpectrumErrorEvent;
|
||||||
import org.jeecg.modules.eneity.event.SpectrumLog;
|
import org.jeecg.modules.eneity.event.SpectrumLog;
|
||||||
import org.jeecg.modules.enums.ErrorType;
|
import org.jeecg.modules.enums.ErrorType;
|
||||||
import org.jeecg.modules.enums.SpectrumSource;
|
import org.jeecg.modules.enums.SpectrumSource;
|
||||||
import org.jeecg.modules.exception.AnalySpectrumException;
|
import org.jeecg.modules.exception.*;
|
||||||
import org.jeecg.modules.exception.AnalyseException;
|
|
||||||
import org.jeecg.modules.exception.FileRepeatException;
|
|
||||||
import org.jeecg.modules.exception.HeaderBlockException;
|
|
||||||
import org.jeecg.modules.file.FileOperation;
|
import org.jeecg.modules.file.FileOperation;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
|
|
@ -12,6 +12,7 @@ import org.jeecg.modules.base.enums.SampleFileHeader;
|
||||||
import org.jeecg.modules.eneity.event.FormatErrorEvent;
|
import org.jeecg.modules.eneity.event.FormatErrorEvent;
|
||||||
import org.jeecg.modules.eneity.event.SpectrumErrorEvent;
|
import org.jeecg.modules.eneity.event.SpectrumErrorEvent;
|
||||||
import org.jeecg.modules.enums.ErrorType;
|
import org.jeecg.modules.enums.ErrorType;
|
||||||
|
import org.jeecg.modules.exception.PHD_ReadException;
|
||||||
import org.jeecg.modules.file.FileOperation;
|
import org.jeecg.modules.file.FileOperation;
|
||||||
import org.jeecg.modules.native_jni.struct.GPSSpectrumStruct;
|
import org.jeecg.modules.native_jni.struct.GPSSpectrumStruct;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
@ -45,6 +46,12 @@ public class GPSSpectrum extends AbstractSpectrumHandler{
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void setChina() {
|
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,14 +59,13 @@ public class GPSSpectrum extends AbstractSpectrumHandler{
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void preCheck() {
|
protected void preCheck() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handler() throws Exception {
|
public void handler() throws Exception {
|
||||||
if(DataType.GPS.getType().equals(super.currDataType.getType())){
|
if(DataType.GPS.getType().equals(super.currDataType.getType())){
|
||||||
try {
|
try {
|
||||||
//前置检查
|
|
||||||
this.preCheck();
|
|
||||||
//打印当前处理的能谱类型
|
//打印当前处理的能谱类型
|
||||||
super.printCurrDataType();
|
super.printCurrDataType();
|
||||||
//解析邮件内容
|
//解析邮件内容
|
||||||
|
@ -91,11 +97,24 @@ public class GPSSpectrum extends AbstractSpectrumHandler{
|
||||||
@Override
|
@Override
|
||||||
protected void parseingEmail() throws Exception {
|
protected void parseingEmail() throws Exception {
|
||||||
this.sourceData = new GPSSpectrumStruct();
|
this.sourceData = new GPSSpectrumStruct();
|
||||||
//从第第五行开始遍历文件内容
|
//获取文件内容
|
||||||
for (int i=0; i< lines.size(); i++) {
|
File gpsFile = new File(super.spectrumFile.getAbsolutePath());
|
||||||
String lineContent = lines.get(i);
|
//判断文件是否存在,如果不存在抛出phd文件读取异常
|
||||||
|
if (!gpsFile.exists()) {
|
||||||
|
throw new PHD_ReadException("THE PHDFile has some blocks can't be read:"+super.spectrumFile.getAbsolutePath());
|
||||||
|
}
|
||||||
|
//文件内容读取
|
||||||
|
try {
|
||||||
|
lines = FileUtils.readLines(gpsFile, "UTF-8");
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
//初始下标是0 0不进行读取
|
//初始下标是0 0不进行读取
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
//从第第五行开始遍历文件内容
|
||||||
|
for (int i=0; i< lines.size(); i++) {
|
||||||
|
//读取文件行内容
|
||||||
|
String lineContent = lines.get(i);
|
||||||
//判断当前行是否包含begin 如果包含 从当前行开始向后读取4行
|
//判断当前行是否包含begin 如果包含 从当前行开始向后读取4行
|
||||||
if (lineContent.contains(SampleFileHeader.BEGIN.getMessage())) {
|
if (lineContent.contains(SampleFileHeader.BEGIN.getMessage())) {
|
||||||
index = i + 4;
|
index = i + 4;
|
||||||
|
|
|
@ -48,6 +48,12 @@ public class HealthStatusSpectrum extends AbstractSpectrumHandler{
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void setChina() {
|
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);
|
super.handleParseingFailFile(e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
super.next.handler();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,6 +87,7 @@ public class SpectrumServiceQuotes {
|
||||||
private final MaximumPoolSizeProperties maximumPoolSizeProperties;
|
private final MaximumPoolSizeProperties maximumPoolSizeProperties;
|
||||||
|
|
||||||
private final IGardsGPSDataService gardsGPSDataService;
|
private final IGardsGPSDataService gardsGPSDataService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 原始库插入数据锁
|
* 原始库插入数据锁
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,164 @@
|
||||||
|
package org.jeecg.modules.spectrum;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||||
|
import org.jeecg.common.properties.SpectrumPathProperties;
|
||||||
|
import org.jeecg.common.util.DateUtils;
|
||||||
|
import org.jeecg.modules.base.entity.original.SampleWaterResult;
|
||||||
|
import org.jeecg.modules.base.enums.DataType;
|
||||||
|
import org.jeecg.modules.eneity.event.FormatErrorEvent;
|
||||||
|
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.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
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() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@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();
|
||||||
|
}
|
||||||
|
|
||||||
|
@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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
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 sampleRefId;
|
||||||
|
|
||||||
|
public Double lon;
|
||||||
|
|
||||||
|
public Double lat;
|
||||||
|
|
||||||
|
public List<ResultNuclide> resultNuclideList;
|
||||||
|
|
||||||
|
|
||||||
|
public WaterResultStruct() {
|
||||||
|
resultNuclideList = new LinkedList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user