fix:1.修改解析能谱错误日志存入log/error目录功能结构,若是header、acq错误则文件名称以MSG_ID命名

This commit is contained in:
panbaolin 2024-01-02 14:53:35 +08:00
parent 11f942072b
commit b5f78b4f41
10 changed files with 75 additions and 33 deletions

View File

@ -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();
}
//headeracquisitionariSamplerFlow错误使用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");
}
}

View File

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

View File

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

View File

@ -42,8 +42,7 @@ public class GardsStationsServiceImpl extends ServiceImpl<GardsStationsMapper, G
final GardsStations station = this.baseMapper.selectOne(gardsStationsQuery);
if (Objects.isNull(station)) {
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));
ErrorLogManager.getInstance().write(new SpectrumErrorEvent(new Date(),ErrorType.STATION_ERROR,errorFileName,site_code));
log.error("This station does not exist, the number is {}.",site_code);
throw new StationNotFoundException("This station does not exist, the number is "+site_code+".");
}

View File

@ -78,7 +78,7 @@ public abstract class AbstractS_D_Q_G_SpectrumHandler extends AbstractSpectrumHa
*/
protected void checkAcquisitionBlock(){
if(this.mailContent.indexOf("#Acquisition") == -1){
ErrorLogManager.getInstance().write(new SpectrumErrorEvent(new Date(),ErrorType.ACQUISITION_ERROR.getContent(),super.spectrumFile.getName()));
ErrorLogManager.getInstance().write(new SpectrumErrorEvent(new Date(),ErrorType.ACQUISITION_ERROR,super.spectrumFile.getName(),super.getMsgId()));
throw new AcquisitionBlockException("acquisition data error");
}
}
@ -233,7 +233,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()));
ErrorLogManager.getInstance().write(new SpectrumErrorEvent(new Date(),ErrorType.FILE_REPEAT,super.spectrumFile.getName()));
throw new FileRepeatException("file repeat");
}
} else if (Objects.isNull(query)) { // 如果没有查询出对应的数据 则对数据进行存储操作

View File

@ -4,6 +4,7 @@ import cn.hutool.core.io.FileUtil;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.jeecg.common.email.EmailLogEvent;
import org.jeecg.common.email.EmailLogManager;
import org.jeecg.common.properties.SpectrumPathProperties;
@ -124,7 +125,7 @@ public abstract class AbstractSpectrumHandler extends AbstractChain {
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()));
ErrorLogManager.getInstance().write(new SpectrumErrorEvent(new Date(), ErrorType.HEADER_ERROR,this.spectrumFile.getName(),this.getMsgId()));
throw new HeaderBlockException("header data error");
}
}
@ -304,4 +305,20 @@ public abstract class AbstractSpectrumHandler extends AbstractChain {
SpectrumLogManager.undelSpectrumLogManager.offer(Thread.currentThread().getId(),spectrumLog);
}
}
/**
* 获取MSG_ID
* @return
*/
protected String getMsgId(){
String msgIdBlockName = "MSG_ID";
if(this.mailContent.contains(msgIdBlockName)){
final List<String> 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";
}
}

View File

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

View File

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

View File

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

View File

@ -82,7 +82,7 @@ public class JeecgAutoProcessApplication extends SpringBootServletInitializer im
ErrorLogManager.init(spectrumPathProperties);
//校验存储目录是否存在不存在则创建存在无操作
checkStorageDirectory();
autoProcessManager.start(systemStartupTime);
// autoProcessManager.start(systemStartupTime);
undealHandleManager.start();
fileSourceHandleManager.start();
// 删除过期的文件