fix:1.修改解析能谱错误日志存入log/error目录功能结构,若是header、acq错误则文件名称以MSG_ID命名
This commit is contained in:
parent
11f942072b
commit
b5f78b4f41
|
@ -2,17 +2,11 @@ package org.jeecg.modules;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.io.FileUtil;
|
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.constant.StringConstant;
|
||||||
import org.jeecg.common.email.EmailLogEvent;
|
|
||||||
import org.jeecg.common.properties.SpectrumPathProperties;
|
import org.jeecg.common.properties.SpectrumPathProperties;
|
||||||
import org.jeecg.modules.eneity.event.SpectrumErrorEvent;
|
import org.jeecg.modules.eneity.event.SpectrumErrorEvent;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.jeecg.modules.enums.ErrorType;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 邮件过程日志
|
* 邮件过程日志
|
||||||
|
@ -48,6 +42,25 @@ public class ErrorLogManager {
|
||||||
* 把日志写入文件
|
* 把日志写入文件
|
||||||
*/
|
*/
|
||||||
public void write(SpectrumErrorEvent event){
|
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();
|
StringBuilder logFilePath = new StringBuilder();
|
||||||
logFilePath.append(spectrumPathProperties.getRootPath());
|
logFilePath.append(spectrumPathProperties.getRootPath());
|
||||||
logFilePath.append(File.separator);
|
logFilePath.append(File.separator);
|
||||||
|
@ -55,15 +68,15 @@ public class ErrorLogManager {
|
||||||
logFilePath.append(File.separator);
|
logFilePath.append(File.separator);
|
||||||
logFilePath.append("error");
|
logFilePath.append("error");
|
||||||
logFilePath.append(File.separator);
|
logFilePath.append(File.separator);
|
||||||
logFilePath.append(event.getFileName().substring(0,event.getFileName().lastIndexOf(StringConstant.DOT))+SUFFIX);
|
logFilePath.append(fileName);
|
||||||
|
|
||||||
StringBuilder errorContent = new StringBuilder();
|
StringBuilder finalErrorContent = new StringBuilder();
|
||||||
errorContent.append(DateUtil.format(event.getTime(),"yyyy-MM-dd HH:mm:ss"));
|
finalErrorContent.append(DateUtil.format(event.getTime(),"yyyy-MM-dd HH:mm:ss"));
|
||||||
errorContent.append(StringConstant.SPACE);
|
finalErrorContent.append(StringConstant.SPACE);
|
||||||
errorContent.append(ERROR_PREFIX);
|
finalErrorContent.append(ERROR_PREFIX);
|
||||||
errorContent.append(event.getErrorContent());
|
finalErrorContent.append(errorContent);
|
||||||
errorContent.append(System.lineSeparator());
|
finalErrorContent.append(System.lineSeparator());
|
||||||
FileUtil.appendString(errorContent.toString(),logFilePath.toString(),"UTF-8");
|
FileUtil.appendString(finalErrorContent.toString(),logFilePath.toString(),"UTF-8");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -2,27 +2,40 @@ package org.jeecg.modules.eneity.event;
|
||||||
|
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import org.jeecg.modules.enums.ErrorType;
|
import org.jeecg.modules.enums.ErrorType;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
|
||||||
* 能谱解析错误日志事件
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class SpectrumErrorEvent {
|
public class SpectrumErrorEvent {
|
||||||
|
|
||||||
|
@Setter @Getter
|
||||||
private Date time;
|
private Date time;
|
||||||
|
|
||||||
private String errorContent;
|
@Setter @Getter
|
||||||
|
private ErrorType errorType;
|
||||||
|
|
||||||
|
@Setter @Getter
|
||||||
private String fileName;
|
private String fileName;
|
||||||
|
|
||||||
|
@Setter @Getter
|
||||||
|
private String[] formatArgs;
|
||||||
|
|
||||||
public SpectrumErrorEvent() {}
|
public SpectrumErrorEvent() {}
|
||||||
|
|
||||||
public SpectrumErrorEvent(Date time,String errorContent,String fileName) {
|
public SpectrumErrorEvent(Date time,ErrorType errorType,String fileName) {
|
||||||
this.time = time;
|
this.time = time;
|
||||||
this.errorContent = errorContent;
|
this.errorType = errorType;
|
||||||
this.fileName = fileName;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ public enum ErrorType {
|
||||||
|
|
||||||
HEADER_ERROR("this is no header data"),
|
HEADER_ERROR("this is no header data"),
|
||||||
ACQUISITION_ERROR("this is no acquisition data"),
|
ACQUISITION_ERROR("this is no acquisition data"),
|
||||||
STATION_ERROR("station_code:"),
|
STATION_ERROR("station_code:%s=0"),
|
||||||
FILE_REPEAT("file repeat"),
|
FILE_REPEAT("file repeat"),
|
||||||
GAS_OR_DET_ERROR("gas or det file is no exist or is error"),
|
GAS_OR_DET_ERROR("gas or det file is no exist or is error"),
|
||||||
AIR_SAMPLER_FLOW_ERROR("this is no ariSamplerFlow data");
|
AIR_SAMPLER_FLOW_ERROR("this is no ariSamplerFlow data");
|
||||||
|
|
|
@ -42,8 +42,7 @@ public class GardsStationsServiceImpl extends ServiceImpl<GardsStationsMapper, G
|
||||||
final GardsStations station = this.baseMapper.selectOne(gardsStationsQuery);
|
final GardsStations station = this.baseMapper.selectOne(gardsStationsQuery);
|
||||||
if (Objects.isNull(station)) {
|
if (Objects.isNull(station)) {
|
||||||
String errorFileName = fileName.substring(fileName.lastIndexOf("/"));
|
String errorFileName = fileName.substring(fileName.lastIndexOf("/"));
|
||||||
String errorContent = ErrorType.STATION_ERROR.getContent()+site_code+StringConstant.EQUALS+0;
|
ErrorLogManager.getInstance().write(new SpectrumErrorEvent(new Date(),ErrorType.STATION_ERROR,errorFileName,site_code));
|
||||||
ErrorLogManager.getInstance().write(new SpectrumErrorEvent(new Date(),errorContent,errorFileName));
|
|
||||||
log.error("This station does not exist, the number is {}.",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+".");
|
throw new StationNotFoundException("This station does not exist, the number is "+site_code+".");
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ public abstract class AbstractS_D_Q_G_SpectrumHandler extends AbstractSpectrumHa
|
||||||
*/
|
*/
|
||||||
protected void checkAcquisitionBlock(){
|
protected void checkAcquisitionBlock(){
|
||||||
if(this.mailContent.indexOf("#Acquisition") == -1){
|
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");
|
throw new AcquisitionBlockException("acquisition data error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -233,7 +233,7 @@ public abstract class AbstractS_D_Q_G_SpectrumHandler extends AbstractSpectrumHa
|
||||||
this.parsingProcessLog.setFileRepeat(true);
|
this.parsingProcessLog.setFileRepeat(true);
|
||||||
//发送文件重复错误事件,后续统计报告使用
|
//发送文件重复错误事件,后续统计报告使用
|
||||||
spectrumServiceQuotes.getApplicationContext().publishEvent(new RepeatErrorEvent());
|
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");
|
throw new FileRepeatException("file repeat");
|
||||||
}
|
}
|
||||||
} else if (Objects.isNull(query)) { // 如果没有查询出对应的数据 则对数据进行存储操作
|
} else if (Objects.isNull(query)) { // 如果没有查询出对应的数据 则对数据进行存储操作
|
||||||
|
|
|
@ -4,6 +4,7 @@ import cn.hutool.core.io.FileUtil;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.jeecg.common.email.EmailLogEvent;
|
import org.jeecg.common.email.EmailLogEvent;
|
||||||
import org.jeecg.common.email.EmailLogManager;
|
import org.jeecg.common.email.EmailLogManager;
|
||||||
import org.jeecg.common.properties.SpectrumPathProperties;
|
import org.jeecg.common.properties.SpectrumPathProperties;
|
||||||
|
@ -124,7 +125,7 @@ public abstract class AbstractSpectrumHandler extends AbstractChain {
|
||||||
if(this.mailContent.indexOf("#Header") == -1){
|
if(this.mailContent.indexOf("#Header") == -1){
|
||||||
//发送格式化错误事件,后续统计报告使用
|
//发送格式化错误事件,后续统计报告使用
|
||||||
spectrumServiceQuotes.getApplicationContext().publishEvent(new FormatErrorEvent());
|
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");
|
throw new HeaderBlockException("header data error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -304,4 +305,20 @@ public abstract class AbstractSpectrumHandler extends AbstractChain {
|
||||||
SpectrumLogManager.undelSpectrumLogManager.offer(Thread.currentThread().getId(),spectrumLog);
|
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";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,7 +183,7 @@ public class AlertSpectrum extends AbstractSpectrumHandler{
|
||||||
this.isFileRepeat = true;
|
this.isFileRepeat = true;
|
||||||
//发送文件重复错误事件,后续统计报告使用
|
//发送文件重复错误事件,后续统计报告使用
|
||||||
spectrumServiceQuotes.getApplicationContext().publishEvent(new FormatErrorEvent());
|
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");
|
throw new FileRepeatException("file repeat");
|
||||||
}
|
}
|
||||||
this.alertData = super.spectrumServiceQuotes.getAlertSpectrumService().create(this.sourceData, super.spectrumFileRelativePath);
|
this.alertData = super.spectrumServiceQuotes.getAlertSpectrumService().create(this.sourceData, super.spectrumFileRelativePath);
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class HealthStatusSpectrum extends AbstractSpectrumHandler{
|
||||||
|
|
||||||
protected void checkAirSamplerFlowBlock(){
|
protected void checkAirSamplerFlowBlock(){
|
||||||
if(super.mailContent.indexOf("#AirSamplerFlow") == -1){
|
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");
|
throw new AirSamplerFlowException("this is no ariSamplerFlow data");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,7 +194,7 @@ public class Sample_B_Analysis implements BlockConstant {
|
||||||
parsingProcessLog.setFileNotExist(true);
|
parsingProcessLog.setFileNotExist(true);
|
||||||
|
|
||||||
this.spectrumServiceQuotes.getSampleDataService().updateStatus(SampleStatus.FAIL.getValue(),this.sampleData.getInputFileName());
|
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..");
|
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){
|
if(flag){
|
||||||
parsingProcessLog.setFileNotExist(true);
|
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..");
|
throw new FileNotExistException("gas or det file is no exist or is error..");
|
||||||
}
|
}
|
||||||
this.detStruct = EnergySpectrumHandler.getSourceData(this.detFileFinalPath);
|
this.detStruct = EnergySpectrumHandler.getSourceData(this.detFileFinalPath);
|
||||||
|
|
|
@ -82,7 +82,7 @@ public class JeecgAutoProcessApplication extends SpringBootServletInitializer im
|
||||||
ErrorLogManager.init(spectrumPathProperties);
|
ErrorLogManager.init(spectrumPathProperties);
|
||||||
//校验存储目录是否存在,不存在则创建,存在无操作
|
//校验存储目录是否存在,不存在则创建,存在无操作
|
||||||
checkStorageDirectory();
|
checkStorageDirectory();
|
||||||
autoProcessManager.start(systemStartupTime);
|
// autoProcessManager.start(systemStartupTime);
|
||||||
undealHandleManager.start();
|
undealHandleManager.start();
|
||||||
fileSourceHandleManager.start();
|
fileSourceHandleManager.start();
|
||||||
// 删除过期的文件
|
// 删除过期的文件
|
||||||
|
|
Loading…
Reference in New Issue
Block a user