From b5f78b4f41e1a38225588e77ca3e7f4d6482b2a2 Mon Sep 17 00:00:00 2001 From: panbaolin <123456> Date: Tue, 2 Jan 2024 14:53:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:1.=E4=BF=AE=E6=94=B9=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E8=83=BD=E8=B0=B1=E9=94=99=E8=AF=AF=E6=97=A5=E5=BF=97=E5=AD=98?= =?UTF-8?q?=E5=85=A5log/error=E7=9B=AE=E5=BD=95=E5=8A=9F=E8=83=BD=E7=BB=93?= =?UTF-8?q?=E6=9E=84=EF=BC=8C=E8=8B=A5=E6=98=AFheader=E3=80=81acq=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E5=88=99=E6=96=87=E4=BB=B6=E5=90=8D=E7=A7=B0=E4=BB=A5?= =?UTF-8?q?MSG=5FID=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jeecg/modules/ErrorLogManager.java | 43 ++++++++++++------- .../eneity/event/SpectrumErrorEvent.java | 27 +++++++++--- .../org/jeecg/modules/enums/ErrorType.java | 2 +- .../impl/GardsStationsServiceImpl.java | 3 +- .../AbstractS_D_Q_G_SpectrumHandler.java | 4 +- .../spectrum/AbstractSpectrumHandler.java | 19 +++++++- .../jeecg/modules/spectrum/AlertSpectrum.java | 2 +- .../spectrum/HealthStatusSpectrum.java | 2 +- .../modules/spectrum/Sample_B_Analysis.java | 4 +- .../jeecg/JeecgAutoProcessApplication.java | 2 +- 10 files changed, 75 insertions(+), 33 deletions(-) diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/ErrorLogManager.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/ErrorLogManager.java index e6f7317d..12fbc580 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/ErrorLogManager.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/ErrorLogManager.java @@ -2,17 +2,11 @@ package org.jeecg.modules; import cn.hutool.core.date.DateUtil; import cn.hutool.core.io.FileUtil; -import lombok.Setter; -import org.apache.commons.lang3.time.DateUtils; import org.jeecg.common.constant.StringConstant; -import org.jeecg.common.email.EmailLogEvent; import org.jeecg.common.properties.SpectrumPathProperties; import org.jeecg.modules.eneity.event.SpectrumErrorEvent; -import org.springframework.util.CollectionUtils; - +import org.jeecg.modules.enums.ErrorType; import java.io.File; -import java.time.LocalDateTime; -import java.util.*; /** * 邮件过程日志 @@ -48,6 +42,25 @@ public class ErrorLogManager { * 把日志写入文件 */ public void write(SpectrumErrorEvent event){ + //错误内容 + String errorContent = ""; + //文件名称 + String fileName = ""; + //台站找不到,格式化报错信息 + if(event.getErrorType().equals(ErrorType.STATION_ERROR)){ + errorContent = String.format(ErrorType.STATION_ERROR.getContent(),event.getFormatArgs()); + }else{ + errorContent = event.getErrorType().getContent(); + } + //header、acquisition、ariSamplerFlow错误使用mesg_id生成文件名称 + if(event.getErrorType().equals(ErrorType.HEADER_ERROR) || event.getErrorType().equals(ErrorType.ACQUISITION_ERROR) || + event.getErrorType().equals(ErrorType.AIR_SAMPLER_FLOW_ERROR)){ + //第一个参数就是msg_id + fileName = event.getFormatArgs()[0]+SUFFIX; + }else{ + fileName = event.getFileName().substring(0,event.getFileName().lastIndexOf(StringConstant.DOT))+SUFFIX; + } + StringBuilder logFilePath = new StringBuilder(); logFilePath.append(spectrumPathProperties.getRootPath()); logFilePath.append(File.separator); @@ -55,15 +68,15 @@ public class ErrorLogManager { logFilePath.append(File.separator); logFilePath.append("error"); logFilePath.append(File.separator); - logFilePath.append(event.getFileName().substring(0,event.getFileName().lastIndexOf(StringConstant.DOT))+SUFFIX); + logFilePath.append(fileName); - StringBuilder errorContent = new StringBuilder(); - errorContent.append(DateUtil.format(event.getTime(),"yyyy-MM-dd HH:mm:ss")); - errorContent.append(StringConstant.SPACE); - errorContent.append(ERROR_PREFIX); - errorContent.append(event.getErrorContent()); - errorContent.append(System.lineSeparator()); - FileUtil.appendString(errorContent.toString(),logFilePath.toString(),"UTF-8"); + StringBuilder finalErrorContent = new StringBuilder(); + finalErrorContent.append(DateUtil.format(event.getTime(),"yyyy-MM-dd HH:mm:ss")); + finalErrorContent.append(StringConstant.SPACE); + finalErrorContent.append(ERROR_PREFIX); + finalErrorContent.append(errorContent); + finalErrorContent.append(System.lineSeparator()); + FileUtil.appendString(finalErrorContent.toString(),logFilePath.toString(),"UTF-8"); } } \ No newline at end of file diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/eneity/event/SpectrumErrorEvent.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/eneity/event/SpectrumErrorEvent.java index 73e81069..90e64bf5 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/eneity/event/SpectrumErrorEvent.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/eneity/event/SpectrumErrorEvent.java @@ -2,27 +2,40 @@ package org.jeecg.modules.eneity.event; import lombok.Data; +import lombok.Getter; +import lombok.Setter; import org.jeecg.modules.enums.ErrorType; import java.util.Date; -/** - * 能谱解析错误日志事件 - */ -@Data + public class SpectrumErrorEvent { + @Setter @Getter private Date time; - private String errorContent; + @Setter @Getter + private ErrorType errorType; + @Setter @Getter private String fileName; + @Setter @Getter + private String[] formatArgs; + public SpectrumErrorEvent() {} - public SpectrumErrorEvent(Date time,String errorContent,String fileName) { + public SpectrumErrorEvent(Date time,ErrorType errorType,String fileName) { this.time = time; - this.errorContent = errorContent; + this.errorType = errorType; this.fileName = fileName; } + + public SpectrumErrorEvent(Date time,ErrorType errorType,String fileName,String... formatArgs) { + this.time = time; + this.errorType = errorType; + this.fileName = fileName; + this.formatArgs = formatArgs; + } + } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/enums/ErrorType.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/enums/ErrorType.java index b1073e12..9c002fe4 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/enums/ErrorType.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/enums/ErrorType.java @@ -4,7 +4,7 @@ public enum ErrorType { HEADER_ERROR("this is no header data"), ACQUISITION_ERROR("this is no acquisition data"), - STATION_ERROR("station_code:"), + STATION_ERROR("station_code:%s=0"), FILE_REPEAT("file repeat"), GAS_OR_DET_ERROR("gas or det file is no exist or is error"), AIR_SAMPLER_FLOW_ERROR("this is no ariSamplerFlow data"); diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/GardsStationsServiceImpl.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/GardsStationsServiceImpl.java index 7dd00ff3..12a9060a 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/GardsStationsServiceImpl.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/service/impl/GardsStationsServiceImpl.java @@ -42,8 +42,7 @@ public class GardsStationsServiceImpl extends ServiceImpl list = FileUtil.readLines(this.spectrumFile, "UTF-8"); + final String[] msgIdBlock = list.get(2).split(" "); + if(ArrayUtils.isNotEmpty(msgIdBlock) && msgIdBlock.length > 2){ + return msgIdBlock[1]; + } + } + return "default"; + } } 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 2cff55c8..68505342 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 @@ -183,7 +183,7 @@ public class AlertSpectrum extends AbstractSpectrumHandler{ this.isFileRepeat = true; //发送文件重复错误事件,后续统计报告使用 spectrumServiceQuotes.getApplicationContext().publishEvent(new FormatErrorEvent()); - ErrorLogManager.getInstance().write(new SpectrumErrorEvent(new Date(), ErrorType.FILE_REPEAT.getContent(),super.spectrumFile.getName())); + ErrorLogManager.getInstance().write(new SpectrumErrorEvent(new Date(), ErrorType.FILE_REPEAT,super.spectrumFile.getName())); throw new FileRepeatException("file repeat"); } this.alertData = super.spectrumServiceQuotes.getAlertSpectrumService().create(this.sourceData, super.spectrumFileRelativePath); 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 d4f2f927..0438587d 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 @@ -60,7 +60,7 @@ public class HealthStatusSpectrum extends AbstractSpectrumHandler{ protected void checkAirSamplerFlowBlock(){ if(super.mailContent.indexOf("#AirSamplerFlow") == -1){ - ErrorLogManager.getInstance().write(new SpectrumErrorEvent(new Date(), ErrorType.AIR_SAMPLER_FLOW_ERROR.getContent(),super.spectrumFile.getName())); + ErrorLogManager.getInstance().write(new SpectrumErrorEvent(new Date(), ErrorType.AIR_SAMPLER_FLOW_ERROR,super.spectrumFile.getName(),super.getMsgId())); throw new AirSamplerFlowException("this is no ariSamplerFlow data"); } } diff --git a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_B_Analysis.java b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_B_Analysis.java index dac87c66..b07b117e 100644 --- a/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_B_Analysis.java +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/spectrum/Sample_B_Analysis.java @@ -194,7 +194,7 @@ public class Sample_B_Analysis implements BlockConstant { parsingProcessLog.setFileNotExist(true); this.spectrumServiceQuotes.getSampleDataService().updateStatus(SampleStatus.FAIL.getValue(),this.sampleData.getInputFileName()); - ErrorLogManager.getInstance().write(new SpectrumErrorEvent(new Date(), ErrorType.GAS_OR_DET_ERROR.getContent(),this.phdFileName)); + ErrorLogManager.getInstance().write(new SpectrumErrorEvent(new Date(), ErrorType.GAS_OR_DET_ERROR,this.phdFileName)); throw new FileNotExistException("gas or det file is no exist or is error.."); } } @@ -265,7 +265,7 @@ public class Sample_B_Analysis implements BlockConstant { if(flag){ parsingProcessLog.setFileNotExist(true); - ErrorLogManager.getInstance().write(new SpectrumErrorEvent(new Date(), ErrorType.GAS_OR_DET_ERROR.getContent(),this.phdFileName)); + ErrorLogManager.getInstance().write(new SpectrumErrorEvent(new Date(), ErrorType.GAS_OR_DET_ERROR,this.phdFileName)); throw new FileNotExistException("gas or det file is no exist or is error.."); } this.detStruct = EnergySpectrumHandler.getSourceData(this.detFileFinalPath); diff --git a/jeecg-server-cloud/armd-auto-process-start/src/main/java/org/jeecg/JeecgAutoProcessApplication.java b/jeecg-server-cloud/armd-auto-process-start/src/main/java/org/jeecg/JeecgAutoProcessApplication.java index 62691bc5..59bc640e 100644 --- a/jeecg-server-cloud/armd-auto-process-start/src/main/java/org/jeecg/JeecgAutoProcessApplication.java +++ b/jeecg-server-cloud/armd-auto-process-start/src/main/java/org/jeecg/JeecgAutoProcessApplication.java @@ -82,7 +82,7 @@ public class JeecgAutoProcessApplication extends SpringBootServletInitializer im ErrorLogManager.init(spectrumPathProperties); //校验存储目录是否存在,不存在则创建,存在无操作 checkStorageDirectory(); - autoProcessManager.start(systemStartupTime); +// autoProcessManager.start(systemStartupTime); undealHandleManager.start(); fileSourceHandleManager.start(); // 删除过期的文件