fix:
1.修改波形事件关联功能,添加过滤浓度逻辑
This commit is contained in:
parent
61fdb7a0e8
commit
9f2d0770ca
|
|
@ -0,0 +1,26 @@
|
|||
package org.jeecg.common.constant.enums;
|
||||
|
||||
/**
|
||||
* IDC和NDC关联波形事件结果类型
|
||||
*/
|
||||
public enum WaveformEventResultTypeEnum {
|
||||
|
||||
/**
|
||||
* IDC 关联结果
|
||||
*/
|
||||
IDC(1),
|
||||
/**
|
||||
* NDC 关联结果
|
||||
*/
|
||||
NDC(2);
|
||||
|
||||
private Integer key;
|
||||
|
||||
WaveformEventResultTypeEnum(Integer key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public Integer getKey(){
|
||||
return this.key;
|
||||
}
|
||||
}
|
||||
|
|
@ -21,6 +21,10 @@ public class DataFusionProperties {
|
|||
* srs文件的上级目录有可能是flexpart.x.ecmwf.l1或flexpart.x.ncep.l1
|
||||
*/
|
||||
private String srmParentDir;
|
||||
/**
|
||||
* 浓度值过滤条件
|
||||
*/
|
||||
private String filterConditions;
|
||||
/**
|
||||
* 溯源时间
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
package org.jeecg.modules.base.entity.rnauto;
|
||||
|
||||
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 java.util.Date;
|
||||
|
||||
/**
|
||||
* 关联波形事件结果
|
||||
*/
|
||||
@Data
|
||||
@TableName("RNAUTO.GARDS_WAVEFORM_EVENT_RESULT")
|
||||
public class GardsWaveformEventResult {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableField(value = "SAMPLE_ID")
|
||||
private Integer sampleId;
|
||||
|
||||
/**
|
||||
* idc事件
|
||||
*/
|
||||
@TableField(value = "ORID")
|
||||
private Integer orid;
|
||||
|
||||
/**
|
||||
* 1-IDC关联数量,2-NDC关联数量
|
||||
*/
|
||||
@TableField(value = "TYPE")
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date moddate;
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package org.jeecg.modules.base.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.jeecg.modules.base.entity.rnauto.GardsWaveformEventResult;
|
||||
|
||||
public interface GardsWaveformEventResultMapper extends BaseMapper<GardsWaveformEventResult> {
|
||||
|
||||
}
|
||||
|
|
@ -15,6 +15,7 @@ import org.jeecg.common.system.query.PageRequest;
|
|||
import org.jeecg.modules.base.entity.rnauto.GardsWaveformEvent;
|
||||
import org.jeecg.modules.base.mapper.GardsAnalysesMapper;
|
||||
import org.jeecg.modules.base.mapper.GardsWaveformEventMapper;
|
||||
import org.jeecg.modules.base.mapper.GardsWaveformEventResultMapper;
|
||||
import org.jeecg.modules.base.mapper.OriginMapper;
|
||||
import org.jeecg.modules.base.vo.GardsSampleInfoVO;
|
||||
import org.jeecg.service.AssociatedWaveformService;
|
||||
|
|
@ -47,6 +48,7 @@ public class AssociatedWaveformServiceImpl extends ServiceImpl<GardsWaveformEven
|
|||
private final OriginMapper originMapper;
|
||||
private final DataSourceTransactionManager transactionManager;
|
||||
private final TransactionDefinition transactionDefinition;
|
||||
private final GardsWaveformEventResultMapper waveformEventResultMapper;
|
||||
|
||||
/**
|
||||
* 分页查询关联波形数据
|
||||
|
|
@ -90,6 +92,7 @@ public class AssociatedWaveformServiceImpl extends ServiceImpl<GardsWaveformEven
|
|||
dataFusionProperties,
|
||||
this.baseMapper,
|
||||
originMapper,
|
||||
waveformEventResultMapper,
|
||||
sampleInfo.getSampleId(),
|
||||
sampleInfo.getAcqEndTime(),
|
||||
sampleInfo.getStationCode());
|
||||
|
|
|
|||
|
|
@ -10,7 +10,9 @@ import org.jeecg.common.properties.DataFusionProperties;
|
|||
import org.jeecg.config.datasource.DataSourceSwitcher;
|
||||
import org.jeecg.modules.base.entity.Origin;
|
||||
import org.jeecg.modules.base.entity.rnauto.GardsWaveformEvent;
|
||||
import org.jeecg.modules.base.entity.rnauto.GardsWaveformEventResult;
|
||||
import org.jeecg.modules.base.mapper.GardsWaveformEventMapper;
|
||||
import org.jeecg.modules.base.mapper.GardsWaveformEventResultMapper;
|
||||
import org.jeecg.modules.base.mapper.OriginMapper;
|
||||
import org.jeecg.vo.SRSRecord;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
|
|
@ -23,6 +25,7 @@ import java.math.RoundingMode;
|
|||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
|
@ -37,6 +40,7 @@ public class AssociatedWaveformTaskExec extends Thread{
|
|||
private TransactionDefinition transactionDefinition;
|
||||
private DataFusionProperties dataFusionProperties;
|
||||
private GardsWaveformEventMapper waveformEventMapper;
|
||||
private GardsWaveformEventResultMapper waveformEventResultMapper;
|
||||
private OriginMapper originMapper;
|
||||
private Integer sampleId;
|
||||
private Date acqEndTime;
|
||||
|
|
@ -45,11 +49,6 @@ public class AssociatedWaveformTaskExec extends Thread{
|
|||
private File ndcSrsFile = null;
|
||||
private List<String> idcSrsContents;
|
||||
private List<String> ndcSrsContents;
|
||||
//idc srs关联到的波形事件信息
|
||||
private Integer idcEvents;
|
||||
//ndc srs关联到的波形事件信息
|
||||
private Integer ndcEvents;
|
||||
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
|
|
@ -60,14 +59,16 @@ public class AssociatedWaveformTaskExec extends Thread{
|
|||
DataFusionProperties dataFusionProperties,
|
||||
GardsWaveformEventMapper waveformEventMapper,
|
||||
OriginMapper originMapper,
|
||||
Integer sampleId,
|
||||
Date acqEndTime,
|
||||
String stationCode){
|
||||
GardsWaveformEventResultMapper waveformEventResultMapper,
|
||||
Integer sampleId,
|
||||
Date acqEndTime,
|
||||
String stationCode){
|
||||
this.transactionManager = transactionManager;
|
||||
this.transactionDefinition = transactionDefinition;
|
||||
this.dataFusionProperties = dataFusionProperties;
|
||||
this.waveformEventMapper = waveformEventMapper;
|
||||
this.originMapper = originMapper;
|
||||
this.waveformEventResultMapper = waveformEventResultMapper;
|
||||
this.sampleId = sampleId;
|
||||
this.acqEndTime = acqEndTime;
|
||||
this.stationCode = stationCode;
|
||||
|
|
@ -126,14 +127,22 @@ public class AssociatedWaveformTaskExec extends Thread{
|
|||
* 关联波形数据
|
||||
*/
|
||||
private void associationWaveform(){
|
||||
Integer idcEvents = this.associationSrs(this.idcSrsContents);
|
||||
Integer ndcEvents = this.associationSrs(this.ndcSrsContents);
|
||||
Set<Integer> idcEvents = this.associationSrs(this.idcSrsContents);
|
||||
Set<Integer> ndcEvents = this.associationSrs(this.ndcSrsContents);
|
||||
DataSourceSwitcher.switchToOracle();
|
||||
final TransactionStatus transactionStatus = this.transactionManager.getTransaction(this.transactionDefinition);
|
||||
try {
|
||||
//保存关联结果
|
||||
if (CollUtil.isNotEmpty(idcEvents)){
|
||||
this.saveWaveformEventResult(idcEvents,WaveformEventResultTypeEnum.IDC.getKey());
|
||||
}
|
||||
if (CollUtil.isNotEmpty(ndcEvents)){
|
||||
this.saveWaveformEventResult(ndcEvents,WaveformEventResultTypeEnum.NDC.getKey());
|
||||
}
|
||||
//修改关联结果统计
|
||||
GardsWaveformEvent waveformEvent = this.waveformEventMapper.selectById(sampleId);
|
||||
waveformEvent.setIdcEvents(idcEvents);
|
||||
waveformEvent.setNdcEvents(ndcEvents);
|
||||
waveformEvent.setIdcEvents(idcEvents.size());
|
||||
waveformEvent.setNdcEvents(ndcEvents.size());
|
||||
waveformEvent.setDescription(Strings.EMPTY);
|
||||
waveformEvent.setModdate(new Date());
|
||||
waveformEvent.setStatus(AssociatedWaveformTaskEnum.COMPLETE.getValue());
|
||||
|
|
@ -147,10 +156,7 @@ public class AssociatedWaveformTaskExec extends Thread{
|
|||
/**
|
||||
* 关联idc srs文件
|
||||
*/
|
||||
private Integer associationSrs(List<String> srsContents){
|
||||
if (CollUtil.isEmpty(srsContents)) {
|
||||
return 0;
|
||||
}
|
||||
private Set<Integer> associationSrs(List<String> srsContents){
|
||||
// 台站经度 台站纬度 开始测量日期 小时 结束测量时间 小时 系数 总共模拟时长 小时数 网格大小 台站编码
|
||||
// 139.08 36.30 20241203 12 20241203 18 0.1300000E+16 336 1 1 0.50 0.50 "JPX38"
|
||||
String[] firstLine = srsContents.get(0).split("\\s+");
|
||||
|
|
@ -161,6 +167,8 @@ public class AssociatedWaveformTaskExec extends Thread{
|
|||
LocalDateTime endTime = LocalDateTime.ofInstant(this.acqEndTime.toInstant(), ZoneId.of("Asia/Shanghai"));
|
||||
endTime = endTime.withMinute(0).withSecond(0);
|
||||
LocalDateTime startTime = endTime.minusHours(totalHour).minusHours(dataFusionProperties.getTraceabilityTime()*24);
|
||||
System.out.println(startTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
System.out.println(endTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
//查询范围内波形事件
|
||||
List<Origin> origins = this.selectOriginByTime(startTime,endTime);
|
||||
//处理srs文件中的坐标记录格式化成对象
|
||||
|
|
@ -170,8 +178,8 @@ public class AssociatedWaveformTaskExec extends Thread{
|
|||
.collect(Collectors.groupingBy(record ->
|
||||
new AbstractMap.SimpleImmutableEntry<>(record.getLon(), record.getLat())
|
||||
));
|
||||
Integer totalEvents = this.queryWaveform(origins, srsRecordsGroup, gridSize);
|
||||
return totalEvents;
|
||||
Set<Integer> events = this.queryWaveform(origins, srsRecordsGroup, gridSize);
|
||||
return events;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -240,19 +248,26 @@ public class AssociatedWaveformTaskExec extends Thread{
|
|||
private List<SRSRecord> buildSRSRecord(List<String> contents,Integer hourlyCoefficient,LocalDateTime acqEndTime){
|
||||
List<SRSRecord> list = contents.parallelStream().skip(1).map(content->{
|
||||
String[] line = content.split("\\s+");
|
||||
SRSRecord srsRecord = new SRSRecord();
|
||||
srsRecord.setLat(Double.parseDouble(line[1]));
|
||||
srsRecord.setLon(Double.parseDouble(line[2]));
|
||||
srsRecord.setHour(Integer.parseInt(line[3])*hourlyCoefficient);
|
||||
srsRecord.setConc(line[4]);
|
||||
LocalDateTime endTime = acqEndTime.minusHours(srsRecord.getHour());
|
||||
LocalDateTime startTime = acqEndTime.minusHours(srsRecord.getHour()+dataFusionProperties.getTraceabilityTime()*24);
|
||||
long startSecond = startTime.atZone(ZoneId.of("Asia/Shanghai")).toEpochSecond();
|
||||
long endSecond = endTime.atZone(ZoneId.of("Asia/Shanghai")).toEpochSecond();
|
||||
srsRecord.setStartSecond(startSecond);
|
||||
srsRecord.setEndSecond(endSecond);
|
||||
return srsRecord;
|
||||
}).toList();
|
||||
BigDecimal val1 = new BigDecimal(line[4]);
|
||||
BigDecimal val2 = new BigDecimal(dataFusionProperties.getFilterConditions());
|
||||
//过滤掉比较小的值
|
||||
if(val1.compareTo(val2) > 0){
|
||||
SRSRecord srsRecord = new SRSRecord();
|
||||
srsRecord.setLat(Double.parseDouble(line[1]));
|
||||
srsRecord.setLon(Double.parseDouble(line[2]));
|
||||
srsRecord.setHour(Integer.parseInt(line[3])*hourlyCoefficient);
|
||||
srsRecord.setConc(line[4]);
|
||||
LocalDateTime endTime = acqEndTime.minusHours(srsRecord.getHour());
|
||||
LocalDateTime startTime = acqEndTime.minusHours(srsRecord.getHour()+dataFusionProperties.getTraceabilityTime()*24);
|
||||
long startSecond = startTime.atZone(ZoneId.of("Asia/Shanghai")).toEpochSecond();
|
||||
long endSecond = endTime.atZone(ZoneId.of("Asia/Shanghai")).toEpochSecond();
|
||||
srsRecord.setStartSecond(startSecond);
|
||||
srsRecord.setEndSecond(endSecond);
|
||||
return srsRecord;
|
||||
}
|
||||
return null;
|
||||
}).filter(Objects::nonNull)
|
||||
.toList();
|
||||
return list;
|
||||
}
|
||||
|
||||
|
|
@ -260,8 +275,8 @@ public class AssociatedWaveformTaskExec extends Thread{
|
|||
* 根据经纬度及时间查询范围内的波形数据,并进行计数,最后的计数就是关联的波形结果
|
||||
* @param srsRecordsGroup
|
||||
*/
|
||||
private Integer queryWaveform(List<Origin> origins,Map<Map.Entry<Double, Double>, List<SRSRecord>> srsRecordsGroup,Double gridSize){
|
||||
Set<Integer> idcOrids = ConcurrentHashMap.newKeySet();
|
||||
private Set<Integer> queryWaveform(List<Origin> origins,Map<Map.Entry<Double, Double>, List<SRSRecord>> srsRecordsGroup,Double gridSize){
|
||||
Set<Integer> result = ConcurrentHashMap.newKeySet();
|
||||
if (CollUtil.isNotEmpty(srsRecordsGroup) && CollUtil.isNotEmpty(origins)){
|
||||
srsRecordsGroup.forEach((key,srsRecords)->{
|
||||
double leftLon = Math.floor(key.getKey() / gridSize) * gridSize;
|
||||
|
|
@ -275,12 +290,12 @@ public class AssociatedWaveformTaskExec extends Thread{
|
|||
origin.getLat() >= bottomLat && origin.getLat() < topLat &&
|
||||
origin.getTime() >= record.getStartSecond() && origin.getTime() <= record.getEndSecond())
|
||||
.map(Origin::getOrid).collect(Collectors.toSet());
|
||||
idcOrids.addAll(orids);
|
||||
result.addAll(orids);
|
||||
});
|
||||
});
|
||||
return idcOrids.size();
|
||||
return result;
|
||||
}
|
||||
return idcOrids.size();
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -338,6 +353,32 @@ public class AssociatedWaveformTaskExec extends Thread{
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存关联结果
|
||||
* @param orids
|
||||
*/
|
||||
private void saveWaveformEventResult(Set<Integer> orids,Integer type){
|
||||
DataSourceSwitcher.switchToOracle();
|
||||
final TransactionStatus transactionStatus = this.transactionManager.getTransaction(this.transactionDefinition);
|
||||
try {
|
||||
if(CollUtil.isNotEmpty(orids)){
|
||||
List<GardsWaveformEventResult> waveformEventResults = new ArrayList<>();
|
||||
orids.forEach(orid->{
|
||||
GardsWaveformEventResult waveformEventResult = new GardsWaveformEventResult();
|
||||
waveformEventResult.setSampleId(this.sampleId);
|
||||
waveformEventResult.setOrid(orid);
|
||||
waveformEventResult.setType(type);
|
||||
waveformEventResult.setModdate(new Date());
|
||||
waveformEventResults.add(waveformEventResult);
|
||||
});
|
||||
this.waveformEventResultMapper.insert(waveformEventResults);
|
||||
this.transactionManager.commit(transactionStatus);
|
||||
}
|
||||
}finally {
|
||||
DataSourceSwitcher.clearDataSource();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取srm文件
|
||||
* @param gzFile
|
||||
|
|
@ -383,4 +424,17 @@ public class AssociatedWaveformTaskExec extends Thread{
|
|||
}
|
||||
this.updateTaskStatus(this.sampleId,taskStatus);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
LocalDateTime endTime = LocalDateTime.of(2024,12, 3,18, 0, 0);
|
||||
LocalDateTime startTime = endTime.minusDays(74);
|
||||
|
||||
long startSecond = startTime.atZone(ZoneId.of("Asia/Shanghai")).toEpochSecond();
|
||||
long endSecond = endTime.atZone(ZoneId.of("Asia/Shanghai")).toEpochSecond();
|
||||
|
||||
System.out.println(startSecond);
|
||||
System.out.println(endSecond);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user