diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/exception/GPSFileReadException.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/exception/GPSFileReadException.java new file mode 100644 index 00000000..ca1820ed --- /dev/null +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/exception/GPSFileReadException.java @@ -0,0 +1,12 @@ +package org.jeecg.modules.exception; + +/* + GPS文件读取失败时抛出异常 + */ +public class GPSFileReadException extends RuntimeException{ + + public GPSFileReadException(String message) { + super(message); + } + +} diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/GPSSpectrum.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/GPSSpectrum.java index 89360bd4..e634758b 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/GPSSpectrum.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/GPSSpectrum.java @@ -12,6 +12,7 @@ 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; @@ -59,13 +60,31 @@ 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 public void handler() throws Exception { if(DataType.GPS.getType().equals(super.currDataType.getType())){ try { + //前置检查 + this.preCheck(); //打印当前处理的能谱类型 super.printCurrDataType(); //解析邮件内容 @@ -97,18 +116,6 @@ public class GPSSpectrum extends AbstractSpectrumHandler{ @Override protected void parseingEmail() throws Exception { 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不进行读取 int index = 0; //从第第五行开始遍历文件内容 diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/WaterResultSpectrum.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/WaterResultSpectrum.java index efb3f244..708e113f 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/WaterResultSpectrum.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/WaterResultSpectrum.java @@ -1,11 +1,16 @@ 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; @@ -14,8 +19,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.time.LocalDate; -import java.util.Date; -import java.util.List; +import java.util.*; public class WaterResultSpectrum extends AbstractSpectrumHandler{ @@ -40,6 +44,23 @@ public class WaterResultSpectrum extends AbstractSpectrumHandler{ @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 @@ -75,6 +96,40 @@ public class WaterResultSpectrum extends AbstractSpectrumHandler{ @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 map = new HashMap<>(); + this.readContent(i+1, map); + } + + + + } + } + + private int readContent(int index, Map map) { + int lastIndex = 0; + for (int i= index; i contents = Arrays.asList(lineContent.split("\\s+")); + //遍历当前行内容 + for (int j=0; j