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