优化指标查询

This commit is contained in:
huangzj
2023-09-14 13:57:10 +08:00
parent 2cf664276a
commit 36c5de878a
5 changed files with 215 additions and 64 deletions

View File

@@ -2,6 +2,7 @@ package com.njcn.csharmonic.service;
import com.njcn.csharmonic.param.CommonStatisticalQueryParam;
import com.njcn.csharmonic.param.FrequencyStatisticalQueryParam;
import com.njcn.csharmonic.param.ThdDataQueryParm;
import com.njcn.csharmonic.pojo.vo.ThdDataVO;
@@ -34,4 +35,6 @@ public interface StableDataService {
List<ThdDataVO> queryCommonStatisticalByTime(CommonStatisticalQueryParam commonStatisticalQueryParam);
List<ThdDataVO> queryLineCommonStatistical(CommonStatisticalQueryParam commonStatisticalQueryParam);
public List<ThdDataVO> QuerySqlData(FrequencyStatisticalQueryParam frequencyStatisticalQueryParam);
}

View File

@@ -8,6 +8,7 @@ import com.njcn.csdevice.enums.AlgorithmResponseEnum;
import com.njcn.csdevice.pojo.po.CsLinePO;
import com.njcn.csdevice.utils.ReflectUtils;
import com.njcn.csharmonic.param.CommonStatisticalQueryParam;
import com.njcn.csharmonic.param.FrequencyStatisticalQueryParam;
import com.njcn.csharmonic.param.ThdDataQueryParm;
import com.njcn.csharmonic.pojo.vo.ThdDataVO;
import com.njcn.csharmonic.service.StableDataService;
@@ -17,9 +18,14 @@ import com.njcn.influx.pojo.po.PowerQualityData;
import com.njcn.influx.service.CommonService;
import com.njcn.influx.service.HaronicRatioService;
import com.njcn.influx.service.PowerQualityService;
import com.njcn.influxdb.param.InfluxDBPublicParam;
import com.njcn.influxdb.utils.InfluxDbUtils;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.api.EpdFeignClient;
import com.njcn.system.enums.DicDataEnum;
import com.njcn.system.pojo.po.EleEpdPqd;
import lombok.RequiredArgsConstructor;
import org.influxdb.dto.QueryResult;
import org.springframework.beans.BeanUtils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
@@ -52,6 +58,9 @@ public class StableDataServiceImpl implements StableDataService {
private final EpdFeignClient epdFeignClient;
private final CommonService commonService;
private final DecimalFormat df = new DecimalFormat("#0.0000");
private final DicDataFeignClient dicDataFeignClient;
private final InfluxDbUtils influxDbUtils;
@Override
public List<ThdDataVO> queryThdData(String devId, String statisticalName) {
@@ -105,6 +114,8 @@ public class StableDataServiceImpl implements StableDataService {
return thdDataVOList;
}
@Override
public List<ThdDataVO> queryFisrtThdContent(String devId, String statisticalName) {
List<ThdDataVO> thdDataVOList = new ArrayList<>();
@@ -170,8 +181,10 @@ public class StableDataServiceImpl implements StableDataService {
csLinePOList = csLineFeignClient.queryLineByDevId(commonStatisticalQueryParam.getDevId()).getData();
}
String areaId = dicDataFeignClient.getDicDataByCode(DicDataEnum.OUTPUT_SIDE.getCode()).getData().getId();
Optional.ofNullable(csLinePOList).orElseThrow(()-> new BusinessException(AlgorithmResponseEnum.LINE_DATA_ERROR));
collect = csLinePOList.stream().map(CsLinePO::getLineId).collect(Collectors.toList());
collect = csLinePOList.stream().filter(temp->Objects.equals(areaId,temp.getPosition())).map(CsLinePO::getLineId).collect(Collectors.toList());
@@ -208,6 +221,7 @@ public class StableDataServiceImpl implements StableDataService {
return collect1;
}
@Override
public List<ThdDataVO> queryCommonStatisticalByTime(CommonStatisticalQueryParam commonStatisticalQueryParam) {
Optional.ofNullable(commonStatisticalQueryParam.getDevId()).orElseThrow(()-> new BusinessException(AlgorithmResponseEnum.DEVICE_LOSE));
@@ -307,4 +321,77 @@ public class StableDataServiceImpl implements StableDataService {
}
}
@Override
public List<ThdDataVO> QuerySqlData(FrequencyStatisticalQueryParam frequencyStatisticalQueryParam) {
List<String> collect = new ArrayList<>();
List<CsLinePO> csLinePOList = new ArrayList<>();
List<ThdDataVO> thdDataVOList = new ArrayList<>();
if(Objects.isNull(frequencyStatisticalQueryParam.getDevId())){
if(!CollectionUtil.isEmpty(frequencyStatisticalQueryParam.getLineList())){
collect =frequencyStatisticalQueryParam.getLineList();
csLinePOList = csLineFeignClient.queryLineById(collect).getData();
}else {
throw new BusinessException(AlgorithmResponseEnum.LINE_DATA_ERROR);
}
}else {
csLinePOList = csLineFeignClient.queryLineByDevId(frequencyStatisticalQueryParam.getDevId()).getData();
}
String areaId = dicDataFeignClient.getDicDataByCode(DicDataEnum.OUTPUT_SIDE.getCode()).getData().getId();
Optional.ofNullable(csLinePOList).orElseThrow(()-> new BusinessException(AlgorithmResponseEnum.LINE_DATA_ERROR));
List<CsLinePO> collect1 = csLinePOList.stream().filter(temp -> Objects.equals(areaId, temp.getPosition())).collect(Collectors.toList());
/*治理侧监测点*/
CsLinePO csLinePO = collect1.get(0);
EleEpdPqd data = epdFeignClient.selectById(frequencyStatisticalQueryParam.getStatisticalId()).getData();
Optional.ofNullable(data).orElseThrow(()-> new BusinessException(AlgorithmResponseEnum.ELEEPDPQD_DATA_ERROR));
StringBuilder stringBuilder1 = new StringBuilder();
StringBuilder stringBuilder2 = new StringBuilder();
for (int i = frequencyStatisticalQueryParam.getFrequencyStart(); i <=frequencyStatisticalQueryParam.getFrequencyEnd() ; i++) {
if (i==frequencyStatisticalQueryParam.getFrequencyEnd()){
stringBuilder1.append("last("+data.getName()).append("_"+i).append(") AS "+data.getName()).append("_"+i);
} else {
stringBuilder1.append("last("+data.getName()).append("_"+i).append(") AS "+data.getName()).append("_"+i).append(",");
}
}
stringBuilder2.append ("line_id='").append (csLinePO.getLineId()).append("' and value_type = 'avg' group by phasic_type ").append(InfluxDBPublicParam.TIME_ZONE);
String sql1 = "select "+stringBuilder1+" from "+"apf_data"+" where "+stringBuilder2;
QueryResult sqlData = influxDbUtils.query(sql1);
List<QueryResult.Result> queryResults = sqlData.getResults();
if (CollectionUtil.isNotEmpty(queryResults)) {
for (QueryResult.Result result : queryResults) {
if (CollectionUtil.isNotEmpty(result.getSeries())) {
List<QueryResult.Series> seriesList = result.getSeries();
if (CollectionUtil.isNotEmpty(seriesList)) {
//如果查询语句中存在group by会存在多个series
for (QueryResult.Series series : seriesList) {
String key = data.getName();
for (int i = frequencyStatisticalQueryParam.getFrequencyStart(); i <=frequencyStatisticalQueryParam.getFrequencyEnd() ; i++) {
int i1 = i - frequencyStatisticalQueryParam.getFrequencyStart()+1;
Double value = Double.parseDouble(series.getValues().get(0).get(i1).toString());
ThdDataVO thdDataVO = new ThdDataVO();
thdDataVO.setLineId(csLinePO.getLineId());
thdDataVO.setLineName(csLinePO.getName());
thdDataVO.setPhase(series.getTags().get("phasic_type"));
thdDataVO.setStatMethod("avg");
thdDataVO.setStatisticalData(Double.valueOf(df.format(value)));
thdDataVO.setStatisticalIndex(data.getId());
thdDataVO.setStatisticalName(data.getName()+ i +"("+data.getUnit()+")");
thdDataVO.setAnotherName(data.getShowName());
thdDataVO.setUnit(data.getUnit());
thdDataVOList.add(thdDataVO);
}
}
}
}
}
}
return thdDataVOList;
}
}