新增加GPS谱数据的内容解析及保存
This commit is contained in:
parent
cf2fe9dd8e
commit
a730178204
|
@ -0,0 +1,44 @@
|
|||
package org.jeecg.modules.base.entity.original;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@TableName("ORIGINAL.GARDS_GPS_DATA")
|
||||
public class GardsGPSData implements Serializable {
|
||||
|
||||
@TableField(value = "STATION_ID")
|
||||
private Integer stationId;
|
||||
|
||||
@TableField(value = "STATION_CODE")
|
||||
private String stationCode;
|
||||
|
||||
@TableField(value = "GPS_ID")
|
||||
private Integer gpsId;
|
||||
|
||||
@TableField(value = "LON")
|
||||
private Double lon;
|
||||
|
||||
@TableField(value = "LAT")
|
||||
private Double lat;
|
||||
|
||||
@TableField(value = "RECORD_TIME")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date recordTime;
|
||||
|
||||
@TableField(value = "TIME_SPAN")
|
||||
private Integer timeSpan;
|
||||
|
||||
@TableField(value = "MODDATE")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date moddate;
|
||||
|
||||
}
|
|
@ -50,7 +50,9 @@ public enum DataType {
|
|||
*/
|
||||
GASBKPHD("GASBKPHD",".PHD"),
|
||||
SPHDP("SPHDP", ".PHD"),
|
||||
SPHDF("SPHDF", ".PHD");
|
||||
SPHDF("SPHDF", ".PHD"),
|
||||
|
||||
GPS("RMSGPS", ".gps");
|
||||
|
||||
private String type;
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package org.jeecg.modules.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.jeecg.modules.base.entity.original.GardsGPSData;
|
||||
|
||||
public interface GardsGPSDataMapper extends BaseMapper<GardsGPSData> {
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package org.jeecg.modules.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.jeecg.modules.base.entity.original.GardsGPSData;
|
||||
import org.jeecg.modules.native_jni.struct.GPSSpectrumStruct;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IGardsGPSDataService extends IService<GardsGPSData> {
|
||||
|
||||
List<GardsGPSData> create(GPSSpectrumStruct sourceData, String fileName);
|
||||
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
package org.jeecg.modules.service.impl;
|
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.jeecg.common.util.DateUtils;
|
||||
import org.jeecg.modules.base.entity.configuration.GardsStations;
|
||||
import org.jeecg.modules.base.entity.original.GardsGPSData;
|
||||
import org.jeecg.modules.exception.StationNotFoundException;
|
||||
import org.jeecg.modules.mapper.GardsGPSDataMapper;
|
||||
import org.jeecg.modules.native_jni.struct.GPSSpectrumStruct;
|
||||
import org.jeecg.modules.service.GardsStationsService;
|
||||
import org.jeecg.modules.service.IGardsGPSDataService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
@DS("ora")
|
||||
public class GardsGPSDataServiceImpl extends ServiceImpl<GardsGPSDataMapper, GardsGPSData> implements IGardsGPSDataService {
|
||||
|
||||
@Autowired
|
||||
private GardsStationsService stationsService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public List<GardsGPSData> create(GPSSpectrumStruct sourceData, String fileName) {
|
||||
List<GardsGPSData> dataList = new LinkedList<>();
|
||||
try {
|
||||
//根据台站编码查询台站id
|
||||
GardsStations station = stationsService.check(sourceData.stationCode, fileName);
|
||||
if (Objects.nonNull(station)) {
|
||||
//遍历时间和经纬度数据
|
||||
for (int i=0; i<sourceData.recordDateList.size(); i++) {
|
||||
GardsGPSData data = new GardsGPSData();
|
||||
data.setStationId(station.getStationId());
|
||||
data.setStationCode(sourceData.stationCode);
|
||||
//拼接记录时间
|
||||
if (StringUtils.isNotBlank(sourceData.recordDateList.get(i)) && StringUtils.isNotBlank(sourceData.recordTimeList.get(i))) {
|
||||
String recordTimeStr = sourceData.recordDateList.get(i) + StringPool.SPACE + sourceData.recordTimeList.get(i);
|
||||
data.setRecordTime(DateUtils.parseDate(recordTimeStr));
|
||||
} else {
|
||||
data.setRecordTime(null);
|
||||
}
|
||||
//时间间隔
|
||||
data.setTimeSpan(StringUtils.isNotBlank(sourceData.spanTimeList.get(i))?Integer.valueOf(sourceData.spanTimeList.get(i)):0);
|
||||
//经度
|
||||
data.setLon(StringUtils.isNotBlank(sourceData.lonList.get(i))?Double.valueOf(sourceData.lonList.get(i)):null);
|
||||
//纬度
|
||||
data.setLat(StringUtils.isNotBlank(sourceData.latList.get(i))?Double.valueOf(sourceData.latList.get(i)):null);
|
||||
dataList.add(data);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(dataList)) {
|
||||
this.saveBatch(dataList);
|
||||
}
|
||||
}
|
||||
return dataList;
|
||||
} catch (StationNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,251 @@
|
|||
package org.jeecg.modules.spectrum;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.jeecg.common.properties.SpectrumPathProperties;
|
||||
import org.jeecg.common.util.DateUtils;
|
||||
import org.jeecg.modules.ErrorLogManager;
|
||||
import org.jeecg.modules.base.entity.original.GardsGPSData;
|
||||
import org.jeecg.modules.base.enums.DataType;
|
||||
import org.jeecg.modules.base.enums.SampleFileHeader;
|
||||
import org.jeecg.modules.eneity.event.FormatErrorEvent;
|
||||
import org.jeecg.modules.eneity.event.SpectrumErrorEvent;
|
||||
import org.jeecg.modules.enums.ErrorType;
|
||||
import org.jeecg.modules.file.FileOperation;
|
||||
import org.jeecg.modules.native_jni.struct.GPSSpectrumStruct;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class GPSSpectrum extends AbstractSpectrumHandler{
|
||||
|
||||
private List<String> lines = null;
|
||||
|
||||
private GPSSpectrumStruct sourceData = null;
|
||||
/**
|
||||
* 开始存库时间
|
||||
*/
|
||||
private Date startIntoDatabaseTime = null;
|
||||
/**
|
||||
* 结束存库时间
|
||||
*/
|
||||
private Date endIntoDatabaseTime = null;
|
||||
|
||||
private List<GardsGPSData> gpsData = null;
|
||||
|
||||
/**
|
||||
* 设置过滤链路
|
||||
*/
|
||||
@Override
|
||||
protected void setChina() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 前置检查
|
||||
*/
|
||||
@Override
|
||||
protected void preCheck() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handler() throws Exception {
|
||||
if(DataType.GPS.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){
|
||||
//异常返回文件名称用于报错日志
|
||||
super.returnFileName.append(super.spectrumFile.getName());
|
||||
//处理解析失败的文件
|
||||
super.handleParseingFailFile(e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析邮件内容
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
protected void parseingEmail() throws Exception {
|
||||
this.sourceData = new GPSSpectrumStruct();
|
||||
//从第第五行开始遍历文件内容
|
||||
for (int i=0; i< lines.size(); i++) {
|
||||
String lineContent = lines.get(i);
|
||||
//初始下标是0 0不进行读取
|
||||
int index = 0;
|
||||
//判断当前行是否包含begin 如果包含 从当前行开始向后读取4行
|
||||
if (lineContent.contains(SampleFileHeader.BEGIN.getMessage())) {
|
||||
index = i + 4;
|
||||
}
|
||||
//切割任意类型空格 获取行内容
|
||||
List<String> contents = Arrays.asList(lineContent.split("\\s+"));
|
||||
//固定格式BEGIN 后的第五行的数据是台站编码
|
||||
if (index > 0 && i == index) {
|
||||
if (StringUtils.isNotBlank(contents.get(0))) {
|
||||
this.sourceData.stationCode = contents.get(0);
|
||||
} else {
|
||||
this.sourceData.stationCode = "";
|
||||
}
|
||||
if (StringUtils.isNotBlank(contents.get(1))) {
|
||||
this.sourceData.receiveDate = contents.get(1);
|
||||
} else {
|
||||
this.sourceData.receiveDate = "";
|
||||
}
|
||||
if (StringUtils.isNotBlank(contents.get(2))) {
|
||||
this.sourceData.receiveTime = contents.get(2);
|
||||
} else {
|
||||
this.sourceData.receiveTime = "";
|
||||
}
|
||||
} else if (index > 0 && i > index) {
|
||||
if (!contents.contains(SampleFileHeader.STOP.getMessage()) ) {
|
||||
if (StringUtils.isNotBlank(contents.get(0))) {
|
||||
//记录日期
|
||||
this.sourceData.recordDateList.add(contents.get(0));
|
||||
} else {
|
||||
//记录日期
|
||||
this.sourceData.recordDateList.add("");
|
||||
}
|
||||
if (StringUtils.isNotBlank(contents.get(1))) {
|
||||
//记录时间
|
||||
this.sourceData.recordTimeList.add(contents.get(1));
|
||||
} else {
|
||||
//记录时间
|
||||
this.sourceData.recordTimeList.add("");
|
||||
}
|
||||
if (StringUtils.isNotBlank(contents.get(2))) {
|
||||
//数据采集间隔持续时间
|
||||
this.sourceData.spanTimeList.add(contents.get(2));
|
||||
} else {
|
||||
//数据采集间隔持续时间
|
||||
this.sourceData.spanTimeList.add("");
|
||||
}
|
||||
if (StringUtils.isNotBlank(contents.get(3))) {
|
||||
//经度
|
||||
this.sourceData.lonList.add(contents.get(3));
|
||||
} else {
|
||||
//经度
|
||||
this.sourceData.lonList.add("");
|
||||
}
|
||||
if (StringUtils.isNotBlank(contents.get(4))) {
|
||||
//纬度
|
||||
this.sourceData.latList.add(contents.get(4));
|
||||
} else {
|
||||
//纬度
|
||||
this.sourceData.latList.add("");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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.stationCode);
|
||||
newFileName.append(StringPool.UNDERSCORE);
|
||||
newFileName.append(super.currDataType.getType());
|
||||
newFileName.append(StringPool.DASH);
|
||||
newFileName.append(this.sourceData.receiveDate.replace(StringPool.SLASH, ""));
|
||||
newFileName.append(StringPool.UNDERSCORE);
|
||||
newFileName.append(this.sourceData.receiveTime.replace(StringPool.COLON, ""));
|
||||
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.stationCode);
|
||||
newFileName.append(StringPool.UNDERSCORE);
|
||||
newFileName.append(super.currDataType.getType());
|
||||
newFileName.append(StringPool.DASH);
|
||||
newFileName.append(this.sourceData.receiveDate.replace(StringPool.SLASH, ""));
|
||||
newFileName.append(StringPool.UNDERSCORE);
|
||||
newFileName.append(this.sourceData.receiveTime.replace(StringPool.COLON, ""));
|
||||
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.gpsData = spectrumServiceQuotes.getGardsGPSDataService().create(this.sourceData, super.spectrumFileRelativePath);
|
||||
this.endIntoDatabaseTime = new Date();
|
||||
}
|
||||
|
||||
/**
|
||||
* 把流程日志保存到日志目录
|
||||
*/
|
||||
@Override
|
||||
protected void saveLogToLogDir() throws IOException {
|
||||
//获取健康谱记录ID范围
|
||||
String gpsIdRange = "";
|
||||
if(!CollectionUtils.isEmpty(this.gpsData)){
|
||||
gpsIdRange = this.gpsData.get(0).getGpsId()+"-"+this.gpsData.get(this.gpsData.size()-1).getGpsId();
|
||||
}
|
||||
//组装日志文件内容
|
||||
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("GPS ID: ").append(gpsIdRange).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());
|
||||
}
|
||||
}
|
|
@ -48,6 +48,12 @@ public class HealthStatusSpectrum extends AbstractSpectrumHandler{
|
|||
*/
|
||||
@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);
|
||||
spectrumHandler.setPrevious(this);
|
||||
super.setNext(spectrumHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -85,6 +85,8 @@ public class SpectrumServiceQuotes {
|
|||
private final RedisUtil redisUtil;
|
||||
|
||||
private final MaximumPoolSizeProperties maximumPoolSizeProperties;
|
||||
|
||||
private final IGardsGPSDataService gardsGPSDataService;
|
||||
/**
|
||||
* 原始库插入数据锁
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package org.jeecg.modules.native_jni.struct;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class GPSSpectrumStruct {
|
||||
|
||||
public String stationCode;
|
||||
|
||||
public String receiveDate;
|
||||
|
||||
public String receiveTime;
|
||||
|
||||
public List<String> recordDateList;
|
||||
|
||||
public List<String> recordTimeList;
|
||||
|
||||
public List<String> spanTimeList;
|
||||
|
||||
public List<String> lonList;
|
||||
|
||||
public List<String> latList;
|
||||
|
||||
public GPSSpectrumStruct() {
|
||||
recordDateList = new LinkedList<>();
|
||||
recordTimeList = new LinkedList<>();
|
||||
spanTimeList = new LinkedList<>();
|
||||
lonList = new LinkedList<>();
|
||||
latList = new LinkedList<>();
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user