diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/SpectrumPathProperties.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/SpectrumPathProperties.java index 4e44e1e2..43ac51f1 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/SpectrumPathProperties.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/properties/SpectrumPathProperties.java @@ -64,6 +64,11 @@ public class SpectrumPathProperties implements Serializable { */ private String filesourcePath; + /** + * 错误文件存储路径 + */ + private String errorFilePath; + /** * 能谱文件存储路径以能谱系统类型/能谱类型为key,以存储路径为value */ diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/exception/DateFormatErrorException.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/exception/DateFormatErrorException.java new file mode 100644 index 00000000..4e60cd5f --- /dev/null +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/exception/DateFormatErrorException.java @@ -0,0 +1,12 @@ +package org.jeecg.modules.exception; + +/** + * 判断日期是否是正确格式 + */ +public class DateFormatErrorException extends RuntimeException { + + public DateFormatErrorException(String message) { + super(message); + } + +} diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractS_D_Q_G_SpectrumHandler.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractS_D_Q_G_SpectrumHandler.java index 0cea7364..eb21a45a 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractS_D_Q_G_SpectrumHandler.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractS_D_Q_G_SpectrumHandler.java @@ -1,21 +1,20 @@ package org.jeecg.modules.spectrum; import cn.hutool.core.io.FileUtil; +import com.baomidou.mybatisplus.core.toolkit.StringPool; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.util.Strings; import org.jeecg.common.constant.StringConstant; import org.jeecg.common.properties.SpectrumPathProperties; +import org.jeecg.common.util.DateUtils; import org.jeecg.modules.base.entity.original.GardsSampleData; import org.jeecg.modules.base.enums.SampleStatus; import org.jeecg.modules.config.datasource.DataSourceSwitcher; import org.jeecg.modules.eneity.event.FormatErrorEvent; import org.jeecg.modules.eneity.event.RepeatErrorEvent; -import org.jeecg.modules.exception.AcquisitionBlockException; -import org.jeecg.modules.exception.FileRepeatException; -import org.jeecg.modules.exception.HeaderBlockException; -import org.jeecg.modules.exception.PHD_ReadException; +import org.jeecg.modules.exception.*; import org.jeecg.modules.native_jni.EnergySpectrumHandler; import org.jeecg.modules.native_jni.struct.EnergySpectrumStruct; import org.jeecg.modules.service.ISpectrumBlockService; @@ -25,9 +24,11 @@ import java.io.*; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.text.ParseException; import java.util.Date; import java.util.List; import java.util.Objects; +import java.util.Random; /** * 样品谱(Samplephd)、探测器本地谱(Detbkphd)、QC谱(Qcphd)、气体谱(Gasbkphd) @@ -99,7 +100,39 @@ public abstract class AbstractS_D_Q_G_SpectrumHandler extends AbstractSpectrumHa spectrumServiceQuotes.getApplicationContext().publishEvent(new FormatErrorEvent()); throw new PHD_ReadException("THE PHDFile has some blocks can't be read:"+super.spectrumFile.getAbsolutePath()); } - this.sourceData = sourceData; + try { + //如果是其中单一一个为空 抛出异常 + //如果两个都为空 就不抛出异常 + //如果两个都不为空 进行日期格式化 格式化失败 + if ((StringUtils.isBlank(sourceData.collection_start_date) && StringUtils.isNotBlank(sourceData.collection_start_time)) || + (StringUtils.isBlank(sourceData.collection_start_time) && StringUtils.isNotBlank(sourceData.collection_start_date))) { + throw new RuntimeException(); + } else if (StringUtils.isNotBlank(sourceData.collection_start_time) && StringUtils.isNotBlank(sourceData.collection_start_date)) { + DateUtils.parseDate(sourceData.collection_start_date + StringPool.SPACE + sourceData.collection_start_time); + } + + if ((StringUtils.isBlank(sourceData.collection_stop_date) && StringUtils.isNotBlank(sourceData.collection_stop_time)) || + (StringUtils.isBlank(sourceData.collection_stop_time) && StringUtils.isNotBlank(sourceData.collection_stop_date))) { + throw new RuntimeException(); + } else if (StringUtils.isNotBlank(sourceData.collection_stop_time) && StringUtils.isNotBlank(sourceData.collection_stop_date)) { + DateUtils.parseDate(sourceData.collection_stop_date + StringPool.SPACE + sourceData.collection_stop_time); + } + + if ((StringUtils.isBlank(sourceData.acquisition_start_date) && StringUtils.isNotBlank(sourceData.acquisition_start_time)) || + (StringUtils.isBlank(sourceData.acquisition_start_time) && StringUtils.isNotBlank(sourceData.acquisition_start_date))) { + throw new RuntimeException(); + } else if (StringUtils.isNotBlank(sourceData.acquisition_start_time) && StringUtils.isNotBlank(sourceData.acquisition_start_date)) { + DateUtils.parseDate(sourceData.acquisition_start_date + StringPool.SPACE + sourceData.acquisition_start_time); + } + } catch (Exception e) { + //将文件移动到错误文件目录 + super.isDateFormatErr = true; + //发送格式化错误事件,后续统计报告使用 + spectrumServiceQuotes.getApplicationContext().publishEvent(new FormatErrorEvent()); + throw new DateFormatErrorException("This PHDFile contains the wrong date format content:"+super.spectrumFile.getAbsolutePath()); + } finally { + this.sourceData = sourceData; + } } /** @@ -144,6 +177,36 @@ public abstract class AbstractS_D_Q_G_SpectrumHandler extends AbstractSpectrumHa super.spectrumFile = FileUtil.rename(super.spectrumFile, newFileName.toString(), true); } + /** + * 对错误的本地能谱临时文件进行改名 + */ + @Override + protected void updateErrorSpectrumFileName() throws FileNotFoundException { + StringBuilder newFileName = new StringBuilder(); + newFileName.append(this.sourceData.detector_code); + newFileName.append(StringConstant.DASH); + if (StringUtils.isNotBlank(this.sourceData.acquisition_start_date) && StringUtils.isNotBlank(this.sourceData.acquisition_start_time)) { + newFileName.append(StringUtils.replace(this.sourceData.acquisition_start_date,StringConstant.SLASH,"")); + newFileName.append(StringConstant.UNDER_LINE); + newFileName.append(StringUtils.replace(this.sourceData.acquisition_start_time.substring(0,this.sourceData.acquisition_start_time.lastIndexOf(":")),":","")); + } else { + newFileName.append(""); + } + if (StringUtils.isNotBlank(this.sourceData.spectrum_quantity) && Double.isFinite(this.sourceData.acquisition_live_time)) { + newFileName.append(super.spectrumServiceQuotes.getNameStandUtil().GetSuffix(super.currDataType.getType(),this.sourceData.spectrum_quantity,String.valueOf(this.sourceData.acquisition_live_time))); + } else { + Random ran = new Random(); + double live_time = ran.nextDouble() * 10000; + newFileName.append(super.spectrumServiceQuotes.getNameStandUtil().GetSuffix(super.currDataType.getType(),this.sourceData.spectrum_quantity,String.valueOf(live_time))); + } + if(!super.spectrumFile.exists()){ + //发送格式化错误事件,后续统计报告使用 + spectrumServiceQuotes.getApplicationContext().publishEvent(new FormatErrorEvent()); + throw new FileNotFoundException(super.spectrumFile.getAbsolutePath()+" does not exist"); + } + super.spectrumFile = FileUtil.rename(super.spectrumFile, newFileName.toString(), true); + } + /** * 读取邮件内容#开头的标签 * @throws Exception diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractSpectrumHandler.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractSpectrumHandler.java index 1502f4ea..2f9b75b4 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractSpectrumHandler.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AbstractSpectrumHandler.java @@ -60,6 +60,8 @@ public abstract class AbstractSpectrumHandler extends AbstractChain { * 返回调用方(filesource,undel,SpectrumParsingActuator)的文件名称 */ protected StringBuilder returnFileName; + + protected boolean isDateFormatErr = false; /** * 保存当前能谱文件有哪些#开头的标签 */ @@ -148,6 +150,11 @@ public abstract class AbstractSpectrumHandler extends AbstractChain { */ protected abstract void updateSpectrumFileName() throws FileNotFoundException; + /** + * 对错误的本地能谱临时文件进行改名 + */ + protected abstract void updateErrorSpectrumFileName() throws FileNotFoundException; + /** * 处理原始数据 */ @@ -222,11 +229,21 @@ public abstract class AbstractSpectrumHandler extends AbstractChain { protected void handleParseingFailFile(Exception e) throws FileNotFoundException { if(!SpectrumSource.FORM_FILE_UNDEL.getSourceType().equals(spectrumSource) && !(e instanceof FileRepeatException)){ try { - //解析失败会把文件移动到undeal目录 - final String rootPath = spectrumServiceQuotes.getSpectrumPathProperties().getRootPath(); - final String undealPath = spectrumServiceQuotes.getSpectrumPathProperties().getUndealPath(); - final String finalPath = rootPath+File.separator+undealPath; - FileOperation.copyFile(spectrumFile,finalPath,true); + if (isDateFormatErr) { + //修改能谱文件名称 + this.updateErrorSpectrumFileName(); + //解析失败会把文件移动到undeal目录 + final String rootPath = spectrumServiceQuotes.getSpectrumPathProperties().getRootPath(); + final String errorFilePath = spectrumServiceQuotes.getSpectrumPathProperties().getErrorFilePath(); + final String finalPath = rootPath+File.separator+errorFilePath; + FileOperation.moveFile(spectrumFile,finalPath,true); + } else { + //解析失败会把文件移动到undeal目录 + final String rootPath = spectrumServiceQuotes.getSpectrumPathProperties().getRootPath(); + final String undealPath = spectrumServiceQuotes.getSpectrumPathProperties().getUndealPath(); + final String finalPath = rootPath+File.separator+undealPath; + FileOperation.copyFile(spectrumFile,finalPath,true); + } } catch (IOException ex) { ex.printStackTrace(); } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AlertSpectrum.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AlertSpectrum.java index 59a768ef..3c04e2ea 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AlertSpectrum.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/AlertSpectrum.java @@ -141,6 +141,25 @@ public class AlertSpectrum extends AbstractSpectrumHandler{ super.spectrumFile = FileOperation.rename(super.spectrumFile,newFileName.toString(),true); } + @Override + protected void updateErrorSpectrumFileName() throws FileNotFoundException { + StringBuilder newFileName = new StringBuilder(); + newFileName.append(this.sourceData.station_code); + newFileName.append(StringConstant.UNDER_LINE); + newFileName.append(super.currDataType.getType()); + newFileName.append(StringConstant.DASH); + newFileName.append(StringUtils.replace(this.sourceData.date,StringConstant.SLASH,"")); + newFileName.append(StringConstant.UNDER_LINE); + newFileName.append(StringUtils.replace(this.sourceData.time,":","")); + 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); + } + /** * 处理原始数据 */ diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/HealthStatusSpectrum.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/HealthStatusSpectrum.java index fee454f4..64023e11 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/HealthStatusSpectrum.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/HealthStatusSpectrum.java @@ -136,6 +136,25 @@ public class HealthStatusSpectrum extends AbstractSpectrumHandler{ super.spectrumFile = FileOperation.rename(super.spectrumFile,newFileName.toString(),true); } + @Override + protected void updateErrorSpectrumFileName() throws FileNotFoundException { + StringBuilder newFileName = new StringBuilder(); + newFileName.append(this.sourceData.station_code); + newFileName.append(StringConstant.UNDER_LINE); + newFileName.append(super.currDataType.getType()); + newFileName.append(StringConstant.DASH); + newFileName.append(StringUtils.replace(this.sourceData.start_date,StringConstant.SLASH,"")); + newFileName.append(StringConstant.UNDER_LINE); + newFileName.append(StringUtils.replace(this.sourceData.start_time,":","")); + 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); + } + /** * 处理原始数据 */ diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/MetSpectrum.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/MetSpectrum.java index 927be44e..64d7e15d 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/MetSpectrum.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/MetSpectrum.java @@ -132,6 +132,25 @@ public class MetSpectrum extends AbstractSpectrumHandler{ super.spectrumFile = FileOperation.rename(super.spectrumFile,newFileName.toString(),true); } + @Override + protected void updateErrorSpectrumFileName() throws FileNotFoundException { + StringBuilder newFileName = new StringBuilder(); + newFileName.append(this.sourceData.station_code); + newFileName.append(StringConstant.UNDER_LINE); + newFileName.append(super.currDataType.getType()); + newFileName.append(StringConstant.DASH); + newFileName.append(StringUtils.replace(this.sourceData.met_start_date.get(0),StringConstant.SLASH,"")); + newFileName.append(StringConstant.UNDER_LINE); + newFileName.append(StringUtils.replace(this.sourceData.met_start_time.get(0),":","")); + 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); + } + /** * 处理原始数据 */