From 0a2a2c2260f34e4f4bf6848d0cff07b7d74496f9 Mon Sep 17 00:00:00 2001 From: panbaolin <123456> Date: Sun, 31 Dec 2023 20:45:06 +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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jeecg/modules/ErrorLogManager.java | 69 +++++++++++++++++++ .../eneity/event/SpectrumErrorEvent.java | 28 ++++++++ .../org/jeecg/modules/enums/ErrorType.java | 22 ++++++ .../impl/GardsStationsServiceImpl.java | 13 ++-- .../AbstractS_D_Q_G_SpectrumHandler.java | 19 ++--- .../spectrum/AbstractSpectrumHandler.java | 23 +++++++ .../jeecg/modules/spectrum/AlertSpectrum.java | 11 +++ .../spectrum/HealthStatusSpectrum.java | 15 ++++ .../jeecg/modules/spectrum/MetSpectrum.java | 8 +++ .../modules/spectrum/Sample_B_Analysis.java | 5 ++ .../jeecg/JeecgAutoProcessApplication.java | 2 + 11 files changed, 197 insertions(+), 18 deletions(-) create mode 100644 jeecg-module-auto-process/src/main/java/org/jeecg/modules/ErrorLogManager.java create mode 100644 jeecg-module-auto-process/src/main/java/org/jeecg/modules/eneity/event/SpectrumErrorEvent.java create mode 100644 jeecg-module-auto-process/src/main/java/org/jeecg/modules/enums/ErrorType.java 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 new file mode 100644 index 00000000..e6f7317d --- /dev/null +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/ErrorLogManager.java @@ -0,0 +1,69 @@ +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 java.io.File; +import java.time.LocalDateTime; +import java.util.*; + +/** + * 邮件过程日志 + */ +public class ErrorLogManager { + + private final static String ERROR_PREFIX = "Data Anlyse Error:"; + + private final static String SUFFIX = ".log"; + + private SpectrumPathProperties spectrumPathProperties; + + private static ErrorLogManager errorLogManager = null; + + public static ErrorLogManager getInstance(){ + return errorLogManager; + } + + public ErrorLogManager(SpectrumPathProperties spectrumPathProperties) { + this.spectrumPathProperties = spectrumPathProperties; + } + + /** + * 初始化 + * @param spectrumPathProperties + */ + public static void init(SpectrumPathProperties spectrumPathProperties){ + errorLogManager = new ErrorLogManager(spectrumPathProperties); + } + + + /** + * 把日志写入文件 + */ + public void write(SpectrumErrorEvent event){ + StringBuilder logFilePath = new StringBuilder(); + logFilePath.append(spectrumPathProperties.getRootPath()); + logFilePath.append(File.separator); + logFilePath.append(spectrumPathProperties.getLogPath()); + logFilePath.append(File.separator); + logFilePath.append("error"); + logFilePath.append(File.separator); + logFilePath.append(event.getFileName().substring(0,event.getFileName().lastIndexOf(StringConstant.DOT))+SUFFIX); + + 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"); + } + +} \ 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 new file mode 100644 index 00000000..73e81069 --- /dev/null +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/eneity/event/SpectrumErrorEvent.java @@ -0,0 +1,28 @@ +package org.jeecg.modules.eneity.event; + + +import lombok.Data; +import org.jeecg.modules.enums.ErrorType; + +import java.util.Date; + +/** + * 能谱解析错误日志事件 + */ +@Data +public class SpectrumErrorEvent { + + private Date time; + + private String errorContent; + + private String fileName; + + public SpectrumErrorEvent() {} + + public SpectrumErrorEvent(Date time,String errorContent,String fileName) { + this.time = time; + this.errorContent = errorContent; + this.fileName = fileName; + } +} 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 new file mode 100644 index 00000000..b1073e12 --- /dev/null +++ b/jeecg-module-auto-process/src/main/java/org/jeecg/modules/enums/ErrorType.java @@ -0,0 +1,22 @@ +package org.jeecg.modules.enums; + +public enum ErrorType { + + HEADER_ERROR("this is no header data"), + ACQUISITION_ERROR("this is no acquisition data"), + STATION_ERROR("station_code:"), + 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"); + + private String content; + + ErrorType(String content) { + this.content = content; + } + + public String getContent(){ + return this.content; + } + +} 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 b17fe41e..7dd00ff3 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 @@ -8,11 +8,15 @@ import lombok.extern.slf4j.Slf4j; import org.jeecg.common.constant.StringConstant; import org.jeecg.common.properties.SpectrumPathProperties; import org.jeecg.common.properties.TaskProperties; +import org.jeecg.modules.ErrorLogManager; import org.jeecg.modules.base.entity.configuration.GardsStations; +import org.jeecg.modules.eneity.event.SpectrumErrorEvent; +import org.jeecg.modules.enums.ErrorType; import org.jeecg.modules.exception.StationNotFoundException; import org.jeecg.modules.mapper.GardsStationsMapper; import org.jeecg.modules.service.GardsStationsService; import org.springframework.stereotype.Service; +import java.util.Date; import java.util.Objects; @Slf4j @@ -37,13 +41,10 @@ public class GardsStationsServiceImpl extends ServiceImpl