fix:1.修改解析能谱错误日志存入log/error目录

This commit is contained in:
panbaolin 2023-12-31 20:45:06 +08:00
parent 497d910ede
commit 0a2a2c2260
11 changed files with 197 additions and 18 deletions

View File

@ -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");
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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<GardsStationsMapper, G
gardsStationsQuery.eq(GardsStations::getStationCode,site_code);
final GardsStations station = this.baseMapper.selectOne(gardsStationsQuery);
if (Objects.isNull(station)) {
StringBuilder logContent = new StringBuilder();
logContent.append("station_code:"+site_code+"=0");
logContent.append(StringConstant.SPACE);
logContent.append(taskProperties.getUndealFileTimeOut());
String errorFileName = fileName.substring(fileName.lastIndexOf("/"));
String errorContent = ErrorType.STATION_ERROR.getContent()+site_code+StringConstant.EQUALS+0;
ErrorLogManager.getInstance().write(new SpectrumErrorEvent(new Date(),errorContent,errorFileName));
log.error("This station does not exist, the number is {}.",site_code);
// LogFileUtil.errorLog(spectrumServiceQuotes.getSpectrumPathProperties().getRootPath() + File.separator + spectrumServiceQuotes.getSpectrumPathProperties().getLogPath(), finalFileName.toString(), warning);
throw new StationNotFoundException("This station does not exist, the number is "+site_code+".");
}
return station;

View File

@ -9,11 +9,14 @@ 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.ErrorLogManager;
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.eneity.event.SpectrumErrorEvent;
import org.jeecg.modules.enums.ErrorType;
import org.jeecg.modules.exception.*;
import org.jeecg.modules.native_jni.EnergySpectrumHandler;
import org.jeecg.modules.native_jni.struct.EnergySpectrumStruct;
@ -64,27 +67,18 @@ public abstract class AbstractS_D_Q_G_SpectrumHandler extends AbstractSpectrumHa
/**
* 前置检查
*/
@Override
protected void preCheck() {
this.checkHeaderBlock();
super.checkHeaderBlock();
this.checkAcquisitionBlock();
}
/**
* 检查此邮件是否包含#Header block
*/
protected void checkHeaderBlock(){
if(this.mailContent.indexOf("#Header") == -1){
//发送格式化错误事件后续统计报告使用
spectrumServiceQuotes.getApplicationContext().publishEvent(new FormatErrorEvent());
throw new HeaderBlockException("header data error");
}
}
/**
* 检查此邮件是否包含#Acquisition block
*/
protected void checkAcquisitionBlock(){
if(this.mailContent.indexOf("#Acquisition") == -1){
ErrorLogManager.getInstance().write(new SpectrumErrorEvent(new Date(),ErrorType.ACQUISITION_ERROR.getContent(),super.spectrumFile.getName()));
throw new AcquisitionBlockException("acquisition data error");
}
}
@ -237,6 +231,7 @@ public abstract class AbstractS_D_Q_G_SpectrumHandler extends AbstractSpectrumHa
this.parsingProcessLog.setFileRepeat(true);
//发送文件重复错误事件后续统计报告使用
spectrumServiceQuotes.getApplicationContext().publishEvent(new RepeatErrorEvent());
ErrorLogManager.getInstance().write(new SpectrumErrorEvent(new Date(),ErrorType.FILE_REPEAT.getContent(),super.spectrumFile.getName()));
throw new FileRepeatException("file repeat");
}
DataSourceSwitcher.switchToOracle();

View File

@ -7,14 +7,20 @@ import org.apache.commons.io.FileUtils;
import org.jeecg.common.email.EmailLogEvent;
import org.jeecg.common.email.EmailLogManager;
import org.jeecg.common.properties.SpectrumPathProperties;
import org.jeecg.modules.ErrorLogManager;
import org.jeecg.modules.base.enums.DataType;
import org.jeecg.modules.eneity.event.FormatErrorEvent;
import org.jeecg.modules.eneity.event.SpectrumErrorEvent;
import org.jeecg.modules.eneity.event.SpectrumLog;
import org.jeecg.modules.enums.ErrorType;
import org.jeecg.modules.enums.SpectrumSource;
import org.jeecg.modules.exception.FileRepeatException;
import org.jeecg.modules.exception.HeaderBlockException;
import org.jeecg.modules.file.FileOperation;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
@ -106,6 +112,23 @@ public abstract class AbstractSpectrumHandler extends AbstractChain {
this.setChina();
}
/**
* 前置检查
*/
protected abstract void preCheck();
/**
* 检查此邮件是否包含#Header block
*/
protected void checkHeaderBlock(){
if(this.mailContent.indexOf("#Header") == -1){
//发送格式化错误事件后续统计报告使用
spectrumServiceQuotes.getApplicationContext().publishEvent(new FormatErrorEvent());
ErrorLogManager.getInstance().write(new SpectrumErrorEvent(new Date(), ErrorType.HEADER_ERROR.getContent(),this.spectrumFile.getName()));
throw new HeaderBlockException("header data error");
}
}
/**
* 检查规则并处理数据
*/

View File

@ -4,10 +4,13 @@ import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.constant.StringConstant;
import org.jeecg.common.properties.SpectrumPathProperties;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.ErrorLogManager;
import org.jeecg.modules.base.entity.original.GardsAlertData;
import org.jeecg.modules.base.enums.DataType;
import org.jeecg.modules.eneity.event.FormatErrorEvent;
import org.jeecg.modules.eneity.event.RepeatErrorEvent;
import org.jeecg.modules.eneity.event.SpectrumErrorEvent;
import org.jeecg.modules.enums.ErrorType;
import org.jeecg.modules.exception.FileRepeatException;
import org.jeecg.modules.exception.PHD_ReadException;
import org.jeecg.modules.file.FileOperation;
@ -54,6 +57,13 @@ public class AlertSpectrum extends AbstractSpectrumHandler{
super.setNext(spectrumHandler);
}
/**
* 前置检查
*/
@Override
protected void preCheck() {
}
/**
* 检查规则并处理数据
*/
@ -173,6 +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()));
throw new FileRepeatException("file repeat");
}
this.alertData = super.spectrumServiceQuotes.getAlertSpectrumService().create(this.sourceData, super.spectrumFileRelativePath);

View File

@ -4,9 +4,12 @@ import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.constant.StringConstant;
import org.jeecg.common.properties.SpectrumPathProperties;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.ErrorLogManager;
import org.jeecg.modules.base.entity.original.GardsSohData;
import org.jeecg.modules.base.enums.DataType;
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.AirSamplerFlowException;
import org.jeecg.modules.exception.PHD_ReadException;
import org.jeecg.modules.file.FileOperation;
@ -46,8 +49,18 @@ public class HealthStatusSpectrum extends AbstractSpectrumHandler{
protected void setChina() {
}
/**
* 前置检查
*/
@Override
protected void preCheck() {
super.checkHeaderBlock();
this.checkAirSamplerFlowBlock();
}
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()));
throw new AirSamplerFlowException("this is no ariSamplerFlow data");
}
}
@ -59,6 +72,8 @@ public class HealthStatusSpectrum extends AbstractSpectrumHandler{
public void handler() throws Exception {
if(DataType.SOH.getType().equals(super.currDataType.getType())){
try {
//前置检查
this.preCheck();
//打印当前处理的能谱类型
super.printCurrDataType();
//解析邮件内容

View File

@ -49,6 +49,14 @@ public class MetSpectrum extends AbstractSpectrumHandler{
super.setNext(spectrumHandler);
}
/**
* 前置检查
*/
@Override
protected void preCheck() {
}
/**
* 检查规则并处理数据
*/

View File

@ -8,11 +8,14 @@ import org.jeecg.common.constant.StringConstant;
import org.jeecg.common.properties.SpectrumPathProperties;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.NumberFormatUtil;
import org.jeecg.modules.ErrorLogManager;
import org.jeecg.modules.base.dto.Info;
import org.jeecg.modules.base.entity.original.GardsSampleData;
import org.jeecg.modules.base.entity.rnauto.GardsAnalyses;
import org.jeecg.modules.base.enums.*;
import org.jeecg.modules.config.datasource.DataSourceSwitcher;
import org.jeecg.modules.eneity.event.SpectrumErrorEvent;
import org.jeecg.modules.enums.ErrorType;
import org.jeecg.modules.exception.BAnalyseException;
import org.jeecg.modules.exception.FileNotExistException;
import org.jeecg.modules.file.FileOperation;
@ -191,6 +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));
throw new FileNotExistException("gas or det file is no exist or is error..");
}
}
@ -261,6 +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));
throw new FileNotExistException("gas or det file is no exist or is error..");
}
this.detStruct = EnergySpectrumHandler.getSourceData(this.detFileFinalPath);

View File

@ -78,6 +78,8 @@ public class JeecgAutoProcessApplication extends SpringBootServletInitializer im
checkTempStorageDirectory();
//初始化邮箱邮件声明周期日志
EmailLogManager.init(spectrumPathProperties);
//初始化能谱解析错误日志管理器
ErrorLogManager.init(spectrumPathProperties);
//校验存储目录是否存在不存在则创建存在无操作
checkStorageDirectory();
autoProcessManager.start(systemStartupTime);