fix:增加新谱DOS 自动处理

This commit is contained in:
xiaoguangbin 2024-10-10 19:31:20 +08:00
parent 268a465d5b
commit f982643a47
9 changed files with 510 additions and 1 deletions

View File

@ -0,0 +1,86 @@
package org.jeecg.modules.base.entity.original;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
@Data
@TableName(value = "ORIGINAL.GARDS_DOS_DATA")
public class GardsDOSData implements Serializable {
/**
* 台站ID号
*/
@TableField(value = "STATION_ID")
private Integer stationId;
/**
* 台站代码
*/
@Excel(name = "STATION",orderNum = "2")
@TableField(value = "STATION_CODE")
private String stationCode;
/**
* 报警ID号
*/
@TableId(value = "DOS_ID",type = IdType.AUTO)
@Excel(name = "SID",orderNum = "5")
private Integer dosId;
/**
* 状态数据采集开始时间
*/
@TableField(value = "START_TIME")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "START TIME",orderNum = "3",width = 30,format = "yyyy-MM-dd HH:mm:ss")
private Date startTime;
/**
* 时间间隔长度
*/
@TableField(value = "TIME")
private Double time;
/**
* 剂量率
*/
@TableField(value = "DOSERATE")
private Double doseRate;
/**
* 剂量率不确定度
*/
@TableField(value = "UNCERTAINTY")
private Double uncertainty;
/**
* 文件路径
*/
@TableField(value = "INPUT_FILE_NAME")
private String inputFileName;
/**
* 探测器id
*/
@TableField(value = "DETECTOR_ID")
private Integer detectorId;
/**
* 操作时间
*/
@TableField(value = "MODDATE")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date moddate;
}

View File

@ -54,7 +54,11 @@ public enum DataType {
GPS("RMSGPS", ".gps"), GPS("RMSGPS", ".gps"),
RESULT("HRULT", ".result"); RESULT("HRULT", ".result"),
/**
* 溴化镧谱
*/
DOS("RMSDOS", ".dos");
private String type; private String type;

View File

@ -0,0 +1,7 @@
package org.jeecg.modules.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.jeecg.modules.base.entity.original.GardsDOSData;
public interface GardsDosDataMapper extends BaseMapper<GardsDOSData> {
}

View File

@ -0,0 +1,22 @@
package org.jeecg.modules.service;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.base.entity.original.GardsDOSData;
import org.jeecg.modules.native_jni.struct.DOSSpectrumStruct;
import java.util.List;
/**
* 溴化镧数据处理
*/
public interface IDOSSpectrumService extends IService<GardsDOSData> {
/**
* 保存溴化镧数据
* @param struct
* @param fileName
* @return
* @throws Exception
*/
List<GardsDOSData> create(DOSSpectrumStruct struct, String fileName) throws Exception;
}

View File

@ -0,0 +1,83 @@
package org.jeecg.modules.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.apache.commons.compress.utils.Lists;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.NumberFormatUtil;
import org.jeecg.modules.base.entity.configuration.GardsDetectors;
import org.jeecg.modules.base.entity.configuration.GardsStations;
import org.jeecg.modules.base.entity.original.GardsDOSData;
import org.jeecg.modules.base.entity.original.GardsSohData;
import org.jeecg.modules.file.FileOperation;
import org.jeecg.modules.mapper.GardsDosDataMapper;
import org.jeecg.modules.mapper.GardsSohDataMapper;
import org.jeecg.modules.native_jni.struct.DOSSpectrumStruct;
import org.jeecg.modules.native_jni.struct.SOHSpectrumStruct;
import org.jeecg.modules.service.GardsDetectorsService;
import org.jeecg.modules.service.GardsStationsService;
import org.jeecg.modules.service.IDOSSpectrumService;
import org.jeecg.modules.service.ISOHSpectrumService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import java.util.Date;
import java.util.List;
/**
* 溴化镧数据处理
*/
@DS("ora")
@Service
@RequiredArgsConstructor
public class DOSSpectrumServiceImpl extends ServiceImpl<GardsDosDataMapper, GardsDOSData> implements IDOSSpectrumService {
private final GardsStationsService stationsService;
private final GardsDetectorsService detectorsService;
private final NumberFormatUtil numberFormatUtil;
/**
* 保存溴化镧数据
* @param struct
* @param fileName
* @return
* @throws Exception
*/
@Transactional(rollbackFor = Exception.class)
@Override
public List<GardsDOSData> create(DOSSpectrumStruct struct, String fileName) throws Exception{
Assert.notNull(struct.station_code,"此次解析结构体中的台站“台站代码”为空");
Assert.notNull(struct.detector_code,"此次解析结构体中的台站“探测器代码”为空");
//校验台站是否存在不存在则报异常
final GardsStations station = stationsService.check(struct.station_code,fileName);
//校验探测器是否存在不存在则创建
final GardsDetectors detector = detectorsService.check(struct.detector_code);
List<GardsDOSData> list = Lists.newArrayList();
if(struct.dr_record_count > 0){
for(int i=0;i<struct.dr_record_count;i++){
GardsDOSData dosData = new GardsDOSData();
dosData.setStationId(station.getStationId());
dosData.setStationCode(struct.station_code);
dosData.setDetectorId(detector.getDetectorId());
dosData.setStartTime(DateUtils.parseDate(struct.dr_start_date.get(i)+" "+struct.dr_start_time.get(i)));
dosData.setTime(numberFormatUtil.DoubleLimit(struct.dr_interval_duration.get(i).doubleValue()));
dosData.setDoseRate(numberFormatUtil.DoubleLimit(struct.dose_rate.get(i)));
dosData.setUncertainty(numberFormatUtil.DoubleLimit(struct.uncertainty.get(i)));
dosData.setInputFileName(FileOperation.separatorConvert(fileName));
dosData.setModdate(new Date());
list.add(dosData);
}
if(!CollectionUtils.isEmpty(list)){
list.forEach(sohData->{
this.save(sohData);
});
}
}
return list;
}
}

View File

@ -0,0 +1,233 @@
package org.jeecg.modules.spectrum;
import cn.hutool.core.util.ObjectUtil;
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.GardsDOSData;
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;
import org.jeecg.modules.native_jni.EnergySpectrumHandler;
import org.jeecg.modules.native_jni.struct.DOSSpectrumStruct;
import org.springframework.util.CollectionUtils;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
import java.util.Objects;
/**
* 溴化镧谱处理
*/
public class DOSSpectrum extends AbstractSpectrumHandler{
/**
* 解析后的数据
*/
private DOSSpectrumStruct sourceData = null;
/**
* 开始存库时间
*/
private Date startIntoDatabaseTime = null;
/**
* 结束存库时间
*/
private Date endIntoDatabaseTime = null;
private List<GardsDOSData> dosData;
/**
* 设置过滤链路
*/
@Override
protected void setChina() {
AbstractSpectrumHandler spectrumHandler = new GPSSpectrum();
spectrumHandler.initNext(super.spectrumServiceQuotes,super.spectrumFile,super.sourceFilePath,
super.currDataType,super.mailContent,super.emlFileName,
super.spectrumSource,super.returnFileName, super.batchesCounter);
spectrumHandler.setPrevious(this);
super.setNext(spectrumHandler);
}
/**
* 前置检查
*/
@Override
protected void preCheck() {
super.checkHeaderBlock();
this.checkAirSamplerFlowBlock();
}
protected void checkAirSamplerFlowBlock(){
if(super.mailContent.indexOf("#DoseRare") == -1){
ErrorLogManager.getInstance().write(new SpectrumErrorEvent(new Date(), ErrorType.AIR_SAMPLER_FLOW_ERROR,super.spectrumFile.getName(),super.getMsgId()));
throw new AirSamplerFlowException("this is no DoseRare data");
}
}
/**
* 检查规则并处理数据
*/
@Override
public void handler() throws Exception {
if(DataType.DOS.getType().equals(super.currDataType.getType())){
try {
//前置检查
this.preCheck();
//打印当前处理的能谱类型
super.printCurrDataType();
//解析邮件内容
this.parseingEmail();
//修改能谱文件名称
this.updateSpectrumFileName();
//保存PHD文件到savefile
super.saveFileToSavefile();
//结构体数据入库
this.handlerOriginalData();
//把流程日志保存到日志目录
this.saveLogToLogDir();
//若本次文件来自于undel目录解析成功则删除
deleteIfFromUndelFile();
}catch (Exception e){
// 如果解析流程异常 入库开始/结束时间赋初始值
if (ObjectUtil.isNull(this.startIntoDatabaseTime))
this.startIntoDatabaseTime = new Date();
if (ObjectUtil.isNull(this.endIntoDatabaseTime))
this.endIntoDatabaseTime = new Date();
//异常返回文件名称用于报错日志
super.returnFileName.append(super.spectrumFile.getName());
//处理解析失败的文件
super.handleParseingFailFile(e);
throw e;
}
} else {
super.next.handler();
}
}
/**
* 调用dll解析邮件
*/
@Override
protected void parseingEmail() throws Exception {
final DOSSpectrumStruct sourceData = EnergySpectrumHandler.getDOSSourceData(super.spectrumFile.getAbsolutePath());
if(Objects.isNull(sourceData) || StringUtils.isBlank(sourceData.station_code)){
//发送格式化错误事件后续统计报告使用
spectrumServiceQuotes.getApplicationContext().publishEvent(new FormatErrorEvent());
throw new PHD_ReadException("THE PHDFile has some blocks can't be read:"+super.spectrumFile.getAbsolutePath());
}
if(sourceData.dr_record_count <= 0 || sourceData.dr_start_date.size() < 0 || sourceData.dr_start_time.size() < 0){
throw new AirSamplerFlowException("DoseRare data error");
}
this.sourceData = sourceData;
}
/**
* 获取文件保存相对路径
* @return
*/
@Override
protected String getFileSaveRelativePath(){
final int year = LocalDate.now().getYear();
final int month = LocalDate.now().getMonth().getValue();
final SpectrumPathProperties properties = super.spectrumServiceQuotes.getSpectrumPathProperties();
StringBuilder relativePath = new StringBuilder();
relativePath.append(properties.getFilePathMap().get(super.currDataType.getType()));
relativePath.append(File.separator);
relativePath.append(year);
relativePath.append(File.separator);
relativePath.append(month>=10?month:"0"+month);
return relativePath.toString();
}
/**
* 对本地能谱临时文件进行改名
*/
@Override
protected void updateSpectrumFileName() throws FileNotFoundException {
StringBuilder newFileName = new StringBuilder();
newFileName.append(this.sourceData.station_code);
newFileName.append(StringConstant.UNDER_LINE);
newFileName.append(super.currDataType.getType());
newFileName.append(StringConstant.DASH);
newFileName.append(StringUtils.replace(this.sourceData.start_date,StringConstant.SLASH,""));
newFileName.append(StringConstant.UNDER_LINE);
newFileName.append(StringUtils.replace(this.sourceData.start_time,":",""));
newFileName.append(super.currDataType.getSuffix());
if(!super.spectrumFile.exists()){
//发送格式化错误事件后续统计报告使用
spectrumServiceQuotes.getApplicationContext().publishEvent(new FormatErrorEvent());
throw new FileNotFoundException(super.spectrumFile.getAbsolutePath()+" does not exist");
}
super.spectrumFile = FileOperation.rename(super.spectrumFile,newFileName.toString(),true);
//设置能谱文件保存相对路径包含文件名称
String fileSavePath = this.getFileSaveRelativePath();
this.spectrumFileRelativePath = fileSavePath+File.separator+this.spectrumFile.getName();
}
@Override
protected void updateErrorSpectrumFileName() throws FileNotFoundException {
StringBuilder newFileName = new StringBuilder();
newFileName.append(this.sourceData.station_code);
newFileName.append(StringConstant.UNDER_LINE);
newFileName.append(super.currDataType.getType());
newFileName.append(StringConstant.DASH);
newFileName.append(StringUtils.replace(this.sourceData.start_date,StringConstant.SLASH,""));
newFileName.append(StringConstant.UNDER_LINE);
newFileName.append(StringUtils.replace(this.sourceData.start_time,":",""));
newFileName.append(super.currDataType.getSuffix());
if(!super.spectrumFile.exists()){
//发送格式化错误事件后续统计报告使用
spectrumServiceQuotes.getApplicationContext().publishEvent(new FormatErrorEvent());
throw new FileNotFoundException(super.spectrumFile.getAbsolutePath()+" does not exist");
}
super.spectrumFile = FileOperation.rename(super.spectrumFile,newFileName.toString(),true);
}
/**
* 处理原始数据
*/
@Override
protected void handlerOriginalData() throws Exception {
this.startIntoDatabaseTime = new Date();
this.dosData = spectrumServiceQuotes.getDosSpectrumService().create(this.sourceData, super.spectrumFileRelativePath);
this.endIntoDatabaseTime = new Date();
}
/**
* 把流程日志保存到日志目录
*/
@Override
protected void saveLogToLogDir() throws IOException {
//获取健康谱记录ID范围
String sohIdRange = "";
if(!CollectionUtils.isEmpty(this.dosData)){
sohIdRange = this.dosData.get(0).getDosId()+"-"+this.dosData.get(this.dosData.size()-1).getDosId();
}
//组装日志文件内容
StringBuilder logContent = new StringBuilder();
logContent.append("-------------------------- Write Data into Database at ").append(DateUtils.formatDate(this.startIntoDatabaseTime,"yyyy-MM-dd HH:mm:ss")).append(" ---------------------------");
logContent.append(System.lineSeparator()).append(System.lineSeparator());
logContent.append("SOH ID: ").append(sohIdRange).append(" StandardFile:").append(super.spectrumFile.getAbsolutePath());
logContent.append(System.lineSeparator()).append(System.lineSeparator());
logContent.append("------------------- ").append("Write Data into Database Successfully at ").append(DateUtils.formatDate(this.endIntoDatabaseTime,"yyyy-MM-dd HH:mm:ss")).append(" --------------------");
final SpectrumPathProperties properties = this.spectrumServiceQuotes.getSpectrumPathProperties();
final String dirPath = properties.getRootPath()+properties.getLogPath()+File.separator+this.getFileSaveRelativePath();
final String fileName = super.spectrumFile.getName().replace(this.currDataType.getSuffix(),LOG_FILE_SUFFIX);
final String finalPath = dirPath+ File.separator+fileName;
super.sendSpectrumLogToQueue(finalPath,logContent.toString());
}
}

View File

@ -41,6 +41,8 @@ public class SpectrumServiceQuotes {
private final ISOHSpectrumService sohSpectrumService; private final ISOHSpectrumService sohSpectrumService;
private final IDOSSpectrumService dosSpectrumService;
private final IAlertSpectrumService alertSpectrumService; private final IAlertSpectrumService alertSpectrumService;
private final IMetSpectrumService metSpectrumService; private final IMetSpectrumService metSpectrumService;

View File

@ -73,6 +73,13 @@ public class EnergySpectrumHandler {
*/ */
public static native SOHSpectrumStruct getSOHSourceData(String path); public static native SOHSpectrumStruct getSOHSourceData(String path);
/**
* 获取溴化镧谱原始数据
* @param path 能谱文件路径
* @return 能谱原始数据
*/
public static native DOSSpectrumStruct getDOSSourceData(String path);
/** /**
* 获取警告谱原始数据 * 获取警告谱原始数据
* @param path 能谱文件路径 * @param path 能谱文件路径

View File

@ -0,0 +1,65 @@
package org.jeecg.modules.native_jni.struct;
import java.util.List;
/**
* 溴化镧谱结构体
*/
public class DOSSpectrumStruct {
/**
* station code
*/
public String station_code;
/**
* detector code or NA if 1) there is more than one detector or 2) data are from the sam-pling site of a split station
*/
public String detector_code;
/**
* SOH data sampling period start date (yyyy/mm/dd)
*/
public String start_date;
/**
* SOH data sampling period start time (hh:mm:ss)
*/
public String start_time;
/* Air Sampler Flow block */
/**
* dose rate
*/
public List<Double> dose_rate;
/**
* dose rate uncertainty
*/
public List<Double> uncertainty;
/**
* dose data sampling interval start date (yyyy/mm/dd)
*/
public List<String> dr_start_date;
/**
* dose data sampling interval start time (hh:mm:ss)
*/
public List<String> dr_start_time;
/**
* dose data sampling interval duration (s)
*/
public List<Long> dr_interval_duration;
public int dr_record_count;
public DOSSpectrumStruct() {
super();
}
@Override
public String toString() {
return "SOHSpectrumStruct{" +
"station_code='" + station_code + '\'' +
", detector_code='" + detector_code + '\'' +
", dr_start_date=" + dr_start_date +
", dr_start_time=" + dr_start_time +
", dr_interval_duration=" + dr_interval_duration +
", dr_record_count=" + dr_record_count +
'}';
}
}