自动处理模块GPS谱流程代码修改
This commit is contained in:
parent
fc4623e584
commit
d92d55befc
|
@ -0,0 +1,12 @@
|
||||||
|
package org.jeecg.modules.exception;
|
||||||
|
|
||||||
|
/*
|
||||||
|
GPS文件读取失败时抛出异常
|
||||||
|
*/
|
||||||
|
public class GPSFileReadException extends RuntimeException{
|
||||||
|
|
||||||
|
public GPSFileReadException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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.GPSFileReadException;
|
||||||
import org.jeecg.modules.exception.PHD_ReadException;
|
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;
|
||||||
|
@ -59,13 +60,31 @@ public class GPSSpectrum extends AbstractSpectrumHandler{
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void preCheck() {
|
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
|
@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();
|
||||||
//解析邮件内容
|
//解析邮件内容
|
||||||
|
@ -97,18 +116,6 @@ 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();
|
||||||
//获取文件内容
|
|
||||||
File gpsFile = new File(super.spectrumFile.getAbsolutePath());
|
|
||||||
//判断文件是否存在,如果不存在抛出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;
|
||||||
//从第第五行开始遍历文件内容
|
//从第第五行开始遍历文件内容
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
package org.jeecg.modules.spectrum;
|
package org.jeecg.modules.spectrum;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
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.modules.ErrorLogManager;
|
||||||
import org.jeecg.modules.base.entity.original.SampleWaterResult;
|
import org.jeecg.modules.base.entity.original.SampleWaterResult;
|
||||||
import org.jeecg.modules.base.enums.DataType;
|
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.FormatErrorEvent;
|
||||||
|
import org.jeecg.modules.eneity.event.SpectrumErrorEvent;
|
||||||
|
import org.jeecg.modules.exception.GPSFileReadException;
|
||||||
import org.jeecg.modules.file.FileOperation;
|
import org.jeecg.modules.file.FileOperation;
|
||||||
import org.jeecg.modules.native_jni.struct.WaterResultStruct;
|
import org.jeecg.modules.native_jni.struct.WaterResultStruct;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
@ -14,8 +19,7 @@ import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.Date;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class WaterResultSpectrum extends AbstractSpectrumHandler{
|
public class WaterResultSpectrum extends AbstractSpectrumHandler{
|
||||||
|
|
||||||
|
@ -40,6 +44,23 @@ public class WaterResultSpectrum extends AbstractSpectrumHandler{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void preCheck() {
|
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
|
@Override
|
||||||
|
@ -75,6 +96,40 @@ public class WaterResultSpectrum extends AbstractSpectrumHandler{
|
||||||
@Override
|
@Override
|
||||||
protected void parseingEmail() throws Exception {
|
protected void parseingEmail() throws Exception {
|
||||||
this.sourceData = new WaterResultStruct();
|
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
|
@Override
|
||||||
|
|
|
@ -10,6 +10,8 @@ public class WaterResultStruct {
|
||||||
|
|
||||||
public String stationCode;
|
public String stationCode;
|
||||||
|
|
||||||
|
public String detectorCode;
|
||||||
|
|
||||||
public String sampleRefId;
|
public String sampleRefId;
|
||||||
|
|
||||||
public Double lon;
|
public Double lon;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user