fix:1.优化Alert、Met、SOH谱存储数据校验保障和S、D、Q、G谱使用一致便于统一异常处理

This commit is contained in:
panbaolin 2023-10-25 13:51:41 +08:00
parent 7350b50c23
commit 79300438d8
3 changed files with 20 additions and 32 deletions

View File

@ -10,8 +10,8 @@ import org.jeecg.modules.base.entity.configuration.GardsStations;
import org.jeecg.modules.base.entity.original.GardsAlertData; import org.jeecg.modules.base.entity.original.GardsAlertData;
import org.jeecg.modules.file.FileOperation; import org.jeecg.modules.file.FileOperation;
import org.jeecg.modules.mapper.GardsAlertDataMapper; import org.jeecg.modules.mapper.GardsAlertDataMapper;
import org.jeecg.modules.mapper.GardsStationsMapper;
import org.jeecg.modules.native_jni.struct.AlertSpectrumStruct; import org.jeecg.modules.native_jni.struct.AlertSpectrumStruct;
import org.jeecg.modules.service.GardsStationsService;
import org.jeecg.modules.service.IAlertSpectrumService; import org.jeecg.modules.service.IAlertSpectrumService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -25,7 +25,7 @@ import org.springframework.util.Assert;
@RequiredArgsConstructor @RequiredArgsConstructor
public class AlertSpectrumServiceImpl extends ServiceImpl<GardsAlertDataMapper, GardsAlertData> implements IAlertSpectrumService { public class AlertSpectrumServiceImpl extends ServiceImpl<GardsAlertDataMapper, GardsAlertData> implements IAlertSpectrumService {
private final GardsStationsMapper gardsStationsMapper; private final GardsStationsService stationsService;
/** /**
* 保存报警谱信息 * 保存报警谱信息
@ -38,14 +38,11 @@ public class AlertSpectrumServiceImpl extends ServiceImpl<GardsAlertDataMapper,
public GardsAlertData create(AlertSpectrumStruct struct, String fileName) throws Exception{ public GardsAlertData create(AlertSpectrumStruct struct, String fileName) throws Exception{
Assert.notNull(struct.station_code,"此次解析结构体中的台站“台站代码”为空"); Assert.notNull(struct.station_code,"此次解析结构体中的台站“台站代码”为空");
LambdaQueryWrapper<GardsStations> gardsStationsQuery = new LambdaQueryWrapper<>(); //校验台站是否存在不存在则报异常
gardsStationsQuery.select(GardsStations::getStationId); final GardsStations station = stationsService.check(struct.station_code);
gardsStationsQuery.eq(GardsStations::getStationCode,struct.station_code);
final GardsStations stations = gardsStationsMapper.selectOne(gardsStationsQuery);
Assert.notNull(stations,"此台站代码:"+struct.station_code+"所属台站不存在");
GardsAlertData alertData = new GardsAlertData(); GardsAlertData alertData = new GardsAlertData();
alertData.setStationId(stations.getStationId()); alertData.setStationId(station.getStationId());
alertData.setStationCode(struct.station_code); alertData.setStationCode(struct.station_code);
alertData.setTime(DateUtils.parseDate(struct.date+" "+struct.time)); alertData.setTime(DateUtils.parseDate(struct.date+" "+struct.time));
alertData.setAlertType(struct.alert_type); alertData.setAlertType(struct.alert_type);

View File

@ -12,6 +12,7 @@ import org.jeecg.modules.file.FileOperation;
import org.jeecg.modules.mapper.GardsMetDataMapper; import org.jeecg.modules.mapper.GardsMetDataMapper;
import org.jeecg.modules.mapper.GardsStationsMapper; import org.jeecg.modules.mapper.GardsStationsMapper;
import org.jeecg.modules.native_jni.struct.MetSpectrumStruct; import org.jeecg.modules.native_jni.struct.MetSpectrumStruct;
import org.jeecg.modules.service.GardsStationsService;
import org.jeecg.modules.service.IMetSpectrumService; import org.jeecg.modules.service.IMetSpectrumService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -29,7 +30,7 @@ import java.util.List;
@RequiredArgsConstructor @RequiredArgsConstructor
public class MetSpectrumServiceImpl extends ServiceImpl<GardsMetDataMapper, GardsMetData> implements IMetSpectrumService { public class MetSpectrumServiceImpl extends ServiceImpl<GardsMetDataMapper, GardsMetData> implements IMetSpectrumService {
private final GardsStationsMapper gardsStationsMapper; private final GardsStationsService stationsService;
/** /**
* 保存气象谱数据 * 保存气象谱数据
@ -43,16 +44,13 @@ public class MetSpectrumServiceImpl extends ServiceImpl<GardsMetDataMapper, Gard
public List<GardsMetData> create(MetSpectrumStruct struct,String fileName) throws Exception{ public List<GardsMetData> create(MetSpectrumStruct struct,String fileName) throws Exception{
Assert.notNull(struct.station_code,"此次解析结构体中的台站“台站代码”为空"); Assert.notNull(struct.station_code,"此次解析结构体中的台站“台站代码”为空");
LambdaQueryWrapper<GardsStations> gardsStationsQuery = new LambdaQueryWrapper<>(); //校验台站是否存在不存在则报异常
gardsStationsQuery.select(GardsStations::getStationId); final GardsStations station = stationsService.check(struct.station_code);
gardsStationsQuery.eq(GardsStations::getStationCode,struct.station_code);
final GardsStations stations = gardsStationsMapper.selectOne(gardsStationsQuery);
Assert.notNull(stations,"此台站代码:"+struct.station_code+"所属台站不存在");
List<GardsMetData> list = Lists.newArrayList(); List<GardsMetData> list = Lists.newArrayList();
if(struct.record_count > 0){ if(struct.record_count > 0){
for(int i=0;i<struct.record_count;i++){ for(int i=0;i<struct.record_count;i++){
GardsMetData metData = new GardsMetData(); GardsMetData metData = new GardsMetData();
metData.setStationId(stations.getStationId()); metData.setStationId(station.getStationId());
metData.setStationCode(struct.station_code); metData.setStationCode(struct.station_code);
metData.setStartTime(DateUtils.parseDate(struct.met_start_date.get(i)+" "+struct.met_start_time.get(i))); metData.setStartTime(DateUtils.parseDate(struct.met_start_date.get(i)+" "+struct.met_start_time.get(i)));
metData.setEndTime(DateUtils.parseDate(struct.met_end_date.get(i)+" "+struct.met_end_time.get(i))); metData.setEndTime(DateUtils.parseDate(struct.met_end_date.get(i)+" "+struct.met_end_time.get(i)));

View File

@ -10,16 +10,15 @@ import org.jeecg.modules.base.entity.configuration.GardsDetectors;
import org.jeecg.modules.base.entity.configuration.GardsStations; import org.jeecg.modules.base.entity.configuration.GardsStations;
import org.jeecg.modules.base.entity.original.GardsSohData; import org.jeecg.modules.base.entity.original.GardsSohData;
import org.jeecg.modules.file.FileOperation; import org.jeecg.modules.file.FileOperation;
import org.jeecg.modules.mapper.GardsDetectorsMapper;
import org.jeecg.modules.mapper.GardsSohDataMapper; import org.jeecg.modules.mapper.GardsSohDataMapper;
import org.jeecg.modules.mapper.GardsStationsMapper;
import org.jeecg.modules.native_jni.struct.SOHSpectrumStruct; 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.ISOHSpectrumService; import org.jeecg.modules.service.ISOHSpectrumService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -31,8 +30,8 @@ import java.util.List;
@RequiredArgsConstructor @RequiredArgsConstructor
public class SOHSpectrumServiceImpl extends ServiceImpl<GardsSohDataMapper, GardsSohData> implements ISOHSpectrumService { public class SOHSpectrumServiceImpl extends ServiceImpl<GardsSohDataMapper, GardsSohData> implements ISOHSpectrumService {
private final GardsStationsMapper gardsStationsMapper; private final GardsStationsService stationsService;
private final GardsDetectorsMapper gardsDetectorsMapper; private final GardsDetectorsService detectorsService;
/** /**
* 保存健康谱数据 * 保存健康谱数据
@ -47,29 +46,23 @@ public class SOHSpectrumServiceImpl extends ServiceImpl<GardsSohDataMapper, Gard
Assert.notNull(struct.station_code,"此次解析结构体中的台站“台站代码”为空"); Assert.notNull(struct.station_code,"此次解析结构体中的台站“台站代码”为空");
Assert.notNull(struct.detector_code,"此次解析结构体中的台站“探测器代码”为空"); Assert.notNull(struct.detector_code,"此次解析结构体中的台站“探测器代码”为空");
LambdaQueryWrapper<GardsStations> gardsStationsQuery = new LambdaQueryWrapper<>(); //校验台站是否存在不存在则报异常
gardsStationsQuery.select(GardsStations::getStationId); final GardsStations station = stationsService.check(struct.station_code);
gardsStationsQuery.eq(GardsStations::getStationCode,struct.station_code); //校验探测器是否存在不存在则创建
final GardsStations stations = gardsStationsMapper.selectOne(gardsStationsQuery); final GardsDetectors detector = detectorsService.check(struct.detector_code);
Assert.notNull(stations,"此台站代码:"+struct.station_code+"所属台站不存在");
LambdaQueryWrapper<GardsDetectors> gardsGardsDetectorsQuery = new LambdaQueryWrapper<>();
gardsGardsDetectorsQuery.select(GardsDetectors::getDetectorId);
gardsGardsDetectorsQuery.eq(GardsDetectors::getDetectorCode,struct.detector_code);
final GardsDetectors gardsDetectors = gardsDetectorsMapper.selectOne(gardsGardsDetectorsQuery);
Assert.notNull(gardsDetectors,"此探测器代码:"+struct.detector_code+"所属探测器不存在");
List<GardsSohData> list = Lists.newArrayList(); List<GardsSohData> list = Lists.newArrayList();
if(struct.af_record_count > 0){ if(struct.af_record_count > 0){
for(int i=0;i<struct.af_record_count;i++){ for(int i=0;i<struct.af_record_count;i++){
GardsSohData sohData = new GardsSohData(); GardsSohData sohData = new GardsSohData();
sohData.setStationId(stations.getStationId()); sohData.setStationId(station.getStationId());
sohData.setStationCode(struct.station_code); sohData.setStationCode(struct.station_code);
sohData.setStartTime(DateUtils.parseDate(struct.af_start_date.get(i)+" "+struct.af_start_time.get(i))); sohData.setStartTime(DateUtils.parseDate(struct.af_start_date.get(i)+" "+struct.af_start_time.get(i)));
sohData.setTime(struct.af_interval_duration.get(i).doubleValue()); sohData.setTime(struct.af_interval_duration.get(i).doubleValue());
sohData.setAvgflowrate(struct.average_flow_rate.get(i)); sohData.setAvgflowrate(struct.average_flow_rate.get(i));
sohData.setFlowratedev(struct.flow_rate_standard_deviation.get(i)); sohData.setFlowratedev(struct.flow_rate_standard_deviation.get(i));
sohData.setInputFileName(FileOperation.separatorConvert(fileName)); sohData.setInputFileName(FileOperation.separatorConvert(fileName));
sohData.setDetectorId(gardsDetectors.getDetectorId()); sohData.setDetectorId(detector.getDetectorId());
sohData.setModdate(new Date()); sohData.setModdate(new Date());
list.add(sohData); list.add(sohData);
} }