Merge remote-tracking branch 'origin/master'

This commit is contained in:
njcn_dhj
2022-07-07 16:20:20 +08:00
17 changed files with 429 additions and 463 deletions

View File

@@ -50,7 +50,7 @@ public class OnlineRateDataController extends BaseController {
@OperateInfo
@PostMapping("/getOnlineRateDataCensus")
@ApiOperation("终端在线率统计")
@ApiOperation("终端在线率图表")
@ApiImplicitParam(name = "onlineRateCensusParam", value = "终端在线率参数", required = true)
public HttpResult<OnlineRateCensusVO> getOnlineRateDataCensus(@RequestBody @Validated DeviceInfoParam.CompareBusinessParam onlineRateCensusParam){
String methodDescribe = getMethodDescribe("getOnlineRateDataCensus");

View File

@@ -3,12 +3,12 @@ package com.njcn.harmonic.service.impl;
import com.njcn.device.api.GeneralDeviceInfoClient;
import com.njcn.device.pojo.dto.GeneralDeviceDTO;
import com.njcn.device.pojo.param.DeviceInfoParam;
import com.njcn.harmonic.constant.Param;
import com.njcn.harmonic.pojo.dto.ComAssessDTO;
import com.njcn.harmonic.pojo.po.PQSComAssesPO;
import com.njcn.harmonic.pojo.vo.ComAssessVO;
import com.njcn.harmonic.service.ComAssessService;
import com.njcn.harmonic.utils.HarmonicComAssesUtil;
import com.njcn.influxdb.param.InfluxDBPublicParam;
import com.njcn.influxdb.utils.InfluxDbUtils;
import lombok.AllArgsConstructor;
import org.influxdb.dto.QueryResult;
@@ -48,12 +48,13 @@ public class ComAssessServiceImpl implements ComAssessService {
comAssessVO.setMonitors(lineIndexes.size());
if (!CollectionUtils.isEmpty(lineIndexes)) {
List<PQSComAssesPO> pqsComAssesPOS = getComAccessData(lineIndexes, comAccessParam.getSearchBeginTime(), comAccessParam.getSearchEndTime());
setResults(pqsComAssesPOS,comAssessDTOS);
float allComAss = comAssesUtil.getAllComAss(comAssessDTOS);
String lv = getLevel(allComAss);
comAssessVO.setData(allComAss);
comAssessVO.setLevel(lv);
if (!CollectionUtils.isEmpty(pqsComAssesPOS)) {
setResults(pqsComAssesPOS,comAssessDTOS);
float allComAss = comAssesUtil.getAllComAss(comAssessDTOS);
String lv = getLevel(allComAss);
comAssessVO.setData(allComAss);
comAssessVO.setLevel(lv);
}
}
comAssessVOList.add(comAssessVO);
}
@@ -62,6 +63,7 @@ public class ComAssessServiceImpl implements ComAssessService {
return comAssessVOList;
}
//设置保留四位小数
private void setResults(List<PQSComAssesPO> pqsComAssesPOS, List<ComAssessDTO> comAssessDTOS) {
for (int i = 0; i < pqsComAssesPOS.size(); i++) {
float v1 = new BigDecimal(pqsComAssesPOS.get(i).getVuDev1()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
@@ -150,6 +152,7 @@ public class ComAssessServiceImpl implements ComAssessService {
/**
* influxDB查询综合评估相关信息
* 返回每个监测点在时间段的各指标平均数
* @param lineIndexes
* @param searchBeginTime
* @param searchEndTime
@@ -157,26 +160,24 @@ public class ComAssessServiceImpl implements ComAssessService {
private List<PQSComAssesPO> getComAccessData(List<String> lineIndexes, String searchBeginTime, String searchEndTime) {
//组装sql语句
StringBuilder builder = new StringBuilder();
builder.append("MEAN(VU_Dev1)AS VU_Dev1, MEAN(VU_Dev2)AS VU_Dev2, MEAN(VU_Dev3)AS VU_Dev3, MEAN(VU_Dev4)AS VU_Dev4, MEAN(VU_Dev5)AS VU_Dev5, MEAN(Freq_Dev1)AS Freq_Dev1, MEAN(Freq_Dev2)AS Freq_Dev2, MEAN(Freq_Dev3)AS Freq_Dev3, MEAN(Freq_Dev4)AS Freq_Dev4, MEAN(Freq_Dev5)AS Freq_Dev5, MEAN(Data_PST1)AS Data_PST1, MEAN(Data_PST2)AS Data_PST2, MEAN(Data_PST3)AS Data_PST3, MEAN(Data_PST4)AS Data_PST4, MEAN(Data_PST5)AS Data_PST5, MEAN(V_Unbalance1)AS V_Unbalance1, MEAN(V_Unbalance2)AS V_Unbalance2, MEAN(V_Unbalance3)AS V_Unbalance3, MEAN(V_Unbalance4)AS V_Unbalance4, MEAN(V_Unbalance5)AS V_Unbalance5, MEAN(V_THD1)AS V_THD1, MEAN(V_THD2)AS V_THD2, MEAN(V_THD3)AS V_THD3, MEAN(V_THD4)AS V_THD4, MEAN(V_THD5)AS V_THD5, MEAN(Event1)AS Event1, MEAN(Event2)AS Event2, MEAN(Event3)AS Event3, MEAN(Event4)AS Event4, MEAN(Event5)AS Event5");
builder.append("MEAN(vu_dev1)AS vu_dev1, MEAN(vu_dev2)AS vu_dev2, MEAN(vu_dev3)AS vu_dev3, MEAN(vu_dev4)AS vu_dev4, MEAN(vu_dev5)AS vu_dev5, MEAN(freq_dev1)AS freq_dev1, MEAN(freq_dev2)AS freq_dev2, MEAN(freq_dev3)AS freq_dev3, MEAN(freq_dev4)AS freq_dev4, MEAN(freq_dev5)AS freq_dev5, MEAN(data_plt1)AS data_plt1, MEAN(data_plt2)AS data_plt2, MEAN(data_plt3)AS data_plt3, MEAN(data_plt4)AS data_plt4, MEAN(data_plt5)AS data_plt5, MEAN(v_unbalance1)AS v_unbalance1, MEAN(v_unbalance2)AS v_unbalance2, MEAN(v_unbalance3)AS v_unbalance3, MEAN(v_unbalance4)AS v_unbalance4, MEAN(v_unbalance5)AS v_unbalance5, MEAN(v_thd1)AS v_thd1, MEAN(v_thd2)AS v_thd2, MEAN(v_thd3)AS v_thd3, MEAN(v_thd4)AS v_thd4, MEAN(v_thd5)AS v_thd5, MEAN(event1)AS event1, MEAN(event2)AS event2, MEAN(event3)AS event3, MEAN(event4)AS event4, MEAN(event5)AS event5");
StringBuffer string = new StringBuffer();
string.append(Param.TIME + " >= '" + searchBeginTime + Param.START_TIME + "' and " + Param.TIME + " <= '" + searchEndTime + Param.END_TIME + "' and ");
string.append(InfluxDBPublicParam.TIME + " >= '" + searchBeginTime + InfluxDBPublicParam.START_TIME + "' and " + InfluxDBPublicParam.TIME + " <= '" + searchEndTime + InfluxDBPublicParam.END_TIME + "' and ");
for (int i = 0; i < lineIndexes.size(); i++) {
if (lineIndexes.size() - i != 1) {
string.append(Param.LINEID + "='").append(lineIndexes.get(i)).append("' or ");
string.append(InfluxDBPublicParam.LINE_ID + "='").append(lineIndexes.get(i)).append("' or ");
} else {
string.append(Param.LINEID + "='").append(lineIndexes.get(i)).append("' group by " + Param.LINEID);
string.append(InfluxDBPublicParam.LINE_ID + "='").append(lineIndexes.get(i)).append("' group by " + InfluxDBPublicParam.LINE_ID);
}
}
//sql语句
String sql = "SELECT "+ builder +" FROM PQS_COMASSES WHERE " + string;
String sql = "SELECT "+ builder +" FROM "+InfluxDBPublicParam.PQS_COMASSES+" WHERE " + string + InfluxDBPublicParam.TIME_ZONE;
//结果集
System.out.println("--------------->>>>"+sql);
QueryResult result = influxDbUtils.query(sql);
//结果集映射到对象中
InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
List<PQSComAssesPO> pqsComAssesPOS = resultMapper.toPOJO(result, PQSComAssesPO.class);
return pqsComAssesPOS;
}

View File

@@ -9,12 +9,12 @@ import com.njcn.device.api.GeneralDeviceInfoClient;
import com.njcn.device.enums.LineBaseEnum;
import com.njcn.device.pojo.dto.GeneralDeviceDTO;
import com.njcn.device.pojo.param.DeviceInfoParam;
import com.njcn.harmonic.constant.Param;
import com.njcn.harmonic.mapper.IntegrityMapper;
import com.njcn.harmonic.pojo.dto.PublicDTO;
import com.njcn.harmonic.pojo.vo.IntegrityIconVO;
import com.njcn.harmonic.pojo.vo.IntegrityVO;
import com.njcn.harmonic.service.IntegrityService;
import com.njcn.influxdb.param.InfluxDBPublicParam;
import com.njcn.influxdb.utils.InfluxDbUtils;
import com.njcn.poi.excel.ExcelUtil;
import com.njcn.poi.pojo.bo.BaseLineExcelBody;
@@ -29,7 +29,6 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
@@ -325,16 +324,16 @@ public class IntegrityServiceImpl implements IntegrityService {
List<PublicDTO> integrityList = new ArrayList<>();
//组装sql语句
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(Param.TIME + " >= '").append(startTime).append(Param.START_TIME).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append(Param.END_TIME).append("' and (");
stringBuilder.append(InfluxDBPublicParam.TIME + " >= '").append(startTime).append(InfluxDBPublicParam.START_TIME).append("' and ").append(InfluxDBPublicParam.TIME).append(" <= '").append(endTime).append(InfluxDBPublicParam.END_TIME).append("' and (");
for (int i = 0; i < lineList.size(); i++) {
if (lineList.size() - i != 1) {
stringBuilder.append(Param.LINE_INDEX + "='").append(lineList.get(i)).append("' or ");
stringBuilder.append(InfluxDBPublicParam.LINE_ID + "='").append(lineList.get(i)).append("' or ");
} else {
stringBuilder.append(Param.LINE_INDEX + "='").append(lineList.get(i)).append("')");
stringBuilder.append(InfluxDBPublicParam.LINE_ID + "='").append(lineList.get(i)).append("')");
}
}
//sql语句
String sql = "SELECT SUM(" + Param.REAL + ")/SUM(" + Param.DUE + ")*100 AS integrity FROM PQS_INTEGRITY WHERE " + stringBuilder + " group by " + Param.LINE_INDEX + " tz('Asia/Shanghai')";
String sql = "SELECT SUM(" + InfluxDBPublicParam.REAL + ")/SUM(" + InfluxDBPublicParam.DUE + ")*100 AS integrity FROM "+InfluxDBPublicParam.PQS_INTEGRITY+" WHERE " + stringBuilder + " group by " + InfluxDBPublicParam.LINE_ID + " tz('Asia/Shanghai')";
//结果集
QueryResult result = influxDbUtils.query(sql);
//处理结果集
@@ -343,7 +342,7 @@ public class IntegrityServiceImpl implements IntegrityService {
list.forEach(po -> {
PublicDTO publicDTO = new PublicDTO();
List<List<Object>> valueList = po.getValues();
String index = po.getTags().get(Param.LINE_INDEX);
String index = po.getTags().get(InfluxDBPublicParam.LINE_ID);
if (!CollectionUtils.isEmpty(valueList)) {
for (List<Object> value : valueList) {
//数据完整性 保留四位小数

View File

@@ -1,17 +1,16 @@
package com.njcn.harmonic.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.njcn.common.config.GeneralInfo;
import com.njcn.device.api.GeneralDeviceInfoClient;
import com.njcn.device.pojo.dto.GeneralDeviceDTO;
import com.njcn.device.pojo.param.DeviceInfoParam;
import com.njcn.harmonic.constant.Param;
import com.njcn.harmonic.mapper.OnlineRateDataMapper;
import com.njcn.harmonic.pojo.dto.PublicDTO;
import com.njcn.harmonic.pojo.vo.OnlineRateCensusVO;
import com.njcn.harmonic.pojo.vo.OnlineRateVO;
import com.njcn.harmonic.service.OnlineRateDataService;
import com.njcn.influxdb.param.InfluxDBPublicParam;
import com.njcn.influxdb.utils.InfluxDbUtils;
import lombok.AllArgsConstructor;
import org.influxdb.dto.QueryResult;
@@ -21,7 +20,6 @@ import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
@@ -100,43 +98,7 @@ public class OnlineRateDataServiceImpl implements OnlineRateDataService {
onlineRateCensusVO.setSingle(single);
onlineRateCensusVO.setRatio(ratio);
// List<OnlineRateVO> list = new ArrayList<>();
// List<OnlineRateVO> periodList = new ArrayList<>();
// OnlineRateCensusVO onlineRateCensusVO = new OnlineRateCensusVO();
// OnlineRateParam onlineRateParam = new OnlineRateParam();
// BeanUtil.copyProperties(onlineRateCensusParam,onlineRateParam);
// List<String> type = new ArrayList<>();
// List<Double> single = new ArrayList<>();
// List<Double> ratio = new ArrayList<>();
// if (Objects.equals(onlineRateCensusParam.getStatisticalType(),0)){
// list = getOnlineRateData(onlineRateParam).get(0).getChildren();
// } else {
// list = getOnlineRateData(onlineRateParam);
// }
// if (!CollectionUtils.isEmpty(list)){
// list.forEach(onlineRateVO -> {
// type.add(onlineRateVO.getName());
// single.add(onlineRateVO.getOnlineRateData());
// onlineRateCensusVO.setType(type);
// onlineRateCensusVO.setSingle(single);
// });
// }
// if (StringUtils.isNotBlank(onlineRateCensusParam.getPeriodBeginTime()) &&
// StringUtils.isNotBlank(onlineRateCensusParam.getPeriodEndTime())){
// onlineRateParam.setSearchBeginTime(onlineRateCensusParam.getPeriodBeginTime());
// onlineRateParam.setSearchEndTime(onlineRateCensusParam.getPeriodEndTime());
// if (Objects.equals(onlineRateCensusParam.getStatisticalType(),0)){
// periodList = getOnlineRateData(onlineRateParam).get(0).getChildren();
// } else {
// periodList = getOnlineRateData(onlineRateParam);
// }
// if (!CollectionUtils.isEmpty(periodList)) {
// periodList.forEach(onlineRateVO -> {
// ratio.add(onlineRateVO.getOnlineRateData());
// onlineRateCensusVO.setRatio(ratio);
// });
// }
// }
return onlineRateCensusVO;
}
@@ -161,9 +123,9 @@ public class OnlineRateDataServiceImpl implements OnlineRateDataService {
})).collect(Collectors.toList());
}
substationList.stream().peek(item -> item.setChildren(getChildCategoryList(item, deviceList))).collect(Collectors.toList());
setSubstationListOnlineRate(substationList);
powerCompanyList.stream().peek(item -> item.setChildren(getChildCategoryList(item, substationList))).collect(Collectors.toList());
setFatherOnlineRate(substationList);
setFatherOnlineRate(powerCompanyList);
setPowerCompanyListOnlineRate(powerCompanyList);
return powerCompanyList;
}
@@ -183,16 +145,16 @@ public class OnlineRateDataServiceImpl implements OnlineRateDataService {
List<PublicDTO> publicDTOList = new ArrayList<>();
//组装sql语句
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(Param.TIME + " >= '").append(startTime).append(Param.START_TIME).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append(Param.END_TIME).append("' and (");
stringBuilder.append(InfluxDBPublicParam.TIME + " >= '").append(startTime).append(InfluxDBPublicParam.START_TIME).append("' and ").append(InfluxDBPublicParam.TIME).append(" <= '").append(endTime).append(InfluxDBPublicParam.END_TIME).append("' and (");
for (int i = 0; i < deviceIndexes.size(); i++) {
if (deviceIndexes.size() - i != 1) {
stringBuilder.append(Param.DEV_INDEX + "='").append(deviceIndexes.get(i)).append("' or ");
stringBuilder.append(InfluxDBPublicParam.DEV_INDEX + "='").append(deviceIndexes.get(i)).append("' or ");
} else {
stringBuilder.append(Param.DEV_INDEX + "='").append(deviceIndexes.get(i)).append("')");
stringBuilder.append(InfluxDBPublicParam.DEV_INDEX + "='").append(deviceIndexes.get(i)).append("')");
}
}
//sql语句
String sql = "SELECT (SUM(" + Param.ONLINEMIN + ")/(SUM(" + Param.OFFLINEMIN + ")+SUM(" + Param.ONLINEMIN + ")))*100 AS onlineRate FROM pqs_onlinerate WHERE " + stringBuilder + " group by " + Param.DEV_INDEX;
String sql = "SELECT (SUM(" + InfluxDBPublicParam.ONLINEMIN + ")/(SUM(" + InfluxDBPublicParam.OFFLINEMIN + ")+SUM(" + InfluxDBPublicParam.ONLINEMIN + ")))*100 AS onlineRate FROM "+InfluxDBPublicParam.PQS_ONLINERATE+" WHERE " + stringBuilder + " group by " + InfluxDBPublicParam.DEV_INDEX +" tz('Asia/Shanghai')";
//结果集
QueryResult result = influxDbUtils.query(sql);
//处理结果集
@@ -201,7 +163,7 @@ public class OnlineRateDataServiceImpl implements OnlineRateDataService {
list.forEach(po -> {
PublicDTO publicDTO = new PublicDTO();
List<List<Object>> valueList = po.getValues();
String index = po.getTags().get(Param.DEV_INDEX);
String index = po.getTags().get(InfluxDBPublicParam.DEV_INDEX);
if (!CollectionUtils.isEmpty(valueList)) {
for (List<Object> value : valueList) {
//终端在线率 保留两位小数
@@ -216,102 +178,41 @@ public class OnlineRateDataServiceImpl implements OnlineRateDataService {
return publicDTOList;
}
/**
* 父级组装
*/
private void setFatherData(Map<String, List<String>> map, List<OnlineRateVO> list, DeviceInfoParam.BusinessParam onlineRateParam) {
for (String key : map.keySet()) {
if (!CollectionUtils.isEmpty(map.get(key))) {
List<OnlineRateVO> onlineRateVOList = getTreeData(map.get(key), onlineRateParam);
//拼接父级
OnlineRateVO onlineRateVO = new OnlineRateVO();
onlineRateVO.setId("0");
onlineRateVO.setName(key);
onlineRateVO.setLevel(0);
if (CollectionUtil.isNotEmpty(onlineRateVOList)) {
onlineRateVO.setChildren(onlineRateVOList);
}
list.add(onlineRateVO);
setTopOnlineRate(list);
}
}
}
/**
* 计算父级终端在线率
* 计算变电站层级在线率
*/
private void setFatherOnlineRate(List<OnlineRateVO> list) {
private void setSubstationListOnlineRate(List<OnlineRateVO> list) {
list.forEach(item -> {
List<OnlineRateVO> children = item.getChildren();
List<OnlineRateVO> tempList = children.stream().filter(s -> !Objects.equals(s.getOnlineRateData(), 3.14159)).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(tempList)) {
item.setOnlineRateData(tempList.stream().mapToDouble(OnlineRateVO::getOnlineRateData).sum() / children.size());
item.setOnlineRateData(tempList.stream().mapToDouble(OnlineRateVO::getOnlineRateData).sum() / tempList.size());
} else {
item.setOnlineRateData(3.14159);
}
});
}
/**
* 计算供电公司层级在线率
*/
private void setPowerCompanyListOnlineRate(List<OnlineRateVO> list) {
list.forEach(item -> {
List<OnlineRateVO> rateVOS = new ArrayList<>();
item.getChildren().forEach(item1 -> {
item1.getChildren().forEach(item2 -> {
rateVOS.add(item2);
});
});
List<OnlineRateVO> tempList = rateVOS.stream().filter(s -> !Objects.equals(s.getOnlineRateData(), 3.14159)).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(tempList)) {
item.setOnlineRateData(tempList.stream().mapToDouble(OnlineRateVO::getOnlineRateData).sum() / tempList.size());
} else {
item.setOnlineRateData(3.14159);
}
});
}
//变电站
private void setSubstationIntegrity(List<OnlineRateVO> list) {
list.forEach(item -> {
List<OnlineRateVO> children = item.getChildren();
List<OnlineRateVO> result = new ArrayList<>(children);
double aver = result.stream().mapToDouble(OnlineRateVO::getOnlineRateData).average().orElseThrow(IllegalStateException::new);
item.setOnlineRateData(BigDecimal.valueOf(aver).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
});
}
//供电公司
private void setPowerCompanyIntegrity(List<OnlineRateVO> list) {
list.forEach(item -> {
List<OnlineRateVO> result = new ArrayList<>();
List<OnlineRateVO> children = item.getChildren();
children.forEach(item2 -> {
List<OnlineRateVO> children2 = item2.getChildren();
result.addAll(children2);
});
double aver = result.stream().mapToDouble(OnlineRateVO::getOnlineRateData).average().orElseThrow(IllegalStateException::new);
item.setOnlineRateData(BigDecimal.valueOf(aver).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
});
}
//省级
private void setAreaIntegrity(List<OnlineRateVO> list) {
list.forEach(item -> {
List<OnlineRateVO> result = new ArrayList<>();
List<OnlineRateVO> children = item.getChildren();
children.forEach(item2 -> {
List<OnlineRateVO> children2 = item2.getChildren();
children2.forEach(item3 -> {
List<OnlineRateVO> children3 = item3.getChildren();
result.addAll(children3);
});
});
double aver = result.stream().mapToDouble(OnlineRateVO::getOnlineRateData).average().orElseThrow(IllegalStateException::new);
item.setOnlineRateData(BigDecimal.valueOf(aver).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
});
}
private void setTopOnlineRate(List<OnlineRateVO> list) {
list.forEach(item -> {
List<OnlineRateVO> result = new ArrayList<>();
List<OnlineRateVO> children = item.getChildren();
children.forEach(item2 -> {
List<OnlineRateVO> children2 = item2.getChildren();
children2.forEach(item3 -> {
List<OnlineRateVO> children3 = item3.getChildren();
children3.forEach(item4 -> {
List<OnlineRateVO> children4 = item4.getChildren();
result.addAll(children4);
});
});
});
double aver = result.stream().mapToDouble(OnlineRateVO::getOnlineRateData).average().orElseThrow(IllegalStateException::new);
item.setOnlineRateData(BigDecimal.valueOf(aver).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
});
}
}

View File

@@ -9,12 +9,12 @@ import com.njcn.device.api.GeneralDeviceInfoClient;
import com.njcn.device.enums.LineBaseEnum;
import com.njcn.device.pojo.dto.GeneralDeviceDTO;
import com.njcn.device.pojo.param.DeviceInfoParam;
import com.njcn.harmonic.constant.Param;
import com.njcn.harmonic.mapper.SteadyExceedRateMapper;
import com.njcn.harmonic.pojo.po.LimitRatePO;
import com.njcn.harmonic.pojo.vo.SteadyExceedRateCensusVO;
import com.njcn.harmonic.pojo.vo.SteadyExceedRateVO;
import com.njcn.harmonic.service.SteadyExceedRateService;
import com.njcn.influxdb.param.InfluxDBPublicParam;
import com.njcn.influxdb.utils.InfluxDbUtils;
import lombok.AllArgsConstructor;
import org.influxdb.dto.QueryResult;
@@ -172,13 +172,13 @@ public class SteadyExceedRateServiceImpl implements SteadyExceedRateService {
List<String> string = new ArrayList<>();
int beginMouthTime = Integer.parseInt(searchBeginTime.substring(5, 7));
int endMouthTime = Integer.parseInt(searchEndTime.substring(5, 7));
int a =0;
for (int i =0; i<endMouthTime - beginMouthTime + 1; i++) {
int a =0;
if (beginMouthTime<9) {
if (i<9) {
a = beginMouthTime + i;
string.add(searchBeginTime.substring(0, 5)+"0"+a);
} else {
string.add(searchBeginTime.substring(0, 5)+a);
string.add(searchBeginTime.substring(0, 5)+(++a));
}
}
return string;
@@ -312,7 +312,7 @@ public class SteadyExceedRateServiceImpl implements SteadyExceedRateService {
}
/**
* 监测点时间范围统计占比率
* 计算一个监测点时间范围统计占比率
*/
public SteadyExceedRateVO getDataSingleMonitorMoreDay(List<LimitRatePO> qualifiesRate, String lineId) {
SteadyExceedRateVO steadyExceedRateVO = new SteadyExceedRateVO();
@@ -321,7 +321,6 @@ public class SteadyExceedRateServiceImpl implements SteadyExceedRateService {
//从数据里筛选出指定监测点的数据
limitRatePOList = qualifiesRate.stream().filter(
temp -> temp.getLineId().equalsIgnoreCase(lineId)).collect(Collectors.toList());
System.out.println("该监测点当天的信息为>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+limitRatePOList);
if (CollectionUtil.isNotEmpty(limitRatePOList)) {
Map<String, List<SteadyExceedRateVO>> timeMap;
//获取出时间和id获取日统计占比率
@@ -332,7 +331,6 @@ public class SteadyExceedRateServiceImpl implements SteadyExceedRateService {
steadyExceedRateVO.setSteadyExceedRate(rate);
steadyExceedRateVOS.add(steadyExceedRateVO);
}
System.out.println("steadyExceedRateVOS>>>>>>>>>>>>>>>>>>>>>>>>>"+steadyExceedRateVOS);
//求时间范围的占比率平均值
steadyExceedRateVO.setSteadyExceedRate(NumberUtil.round(steadyExceedRateVOS.stream().mapToDouble(SteadyExceedRateVO::getSteadyExceedRate).average().orElse(0), 2).doubleValue());
@@ -357,9 +355,7 @@ public class SteadyExceedRateServiceImpl implements SteadyExceedRateService {
}
if (CollectionUtil.isNotEmpty(steadyResults)) {
//求区域监测点多天的平均值
steadyExceedRateVO.setSteadyExceedRate(
NumberUtil.round(steadyResults.stream().mapToDouble(SteadyExceedRateVO::getSteadyExceedRate).average().orElse(0), 2).doubleValue()
);
steadyExceedRateVO.setSteadyExceedRate(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyExceedRateVO::getSteadyExceedRate).average().orElse(0), 2).doubleValue());
}
return steadyExceedRateVO;
}
@@ -406,24 +402,26 @@ public class SteadyExceedRateServiceImpl implements SteadyExceedRateService {
* @param endTime
*/
private List<LimitRatePO> getQualifiesRate(List<String> lineIndexes, String startTime, String endTime) {
List<LimitRatePO> limitRatePOS = new ArrayList<>();
List<LimitRatePO> limitRatePOS;
//组装sql语句
// StringBuilder string = new StringBuilder();
// string.append(Param.QualityFlag + "='1' and (" + Param.PHASIC_TYPE + "='" + Param.PHASIC_TYPEA + "' or " + Param.PHASIC_TYPE + "='" + Param.PHASIC_TYPEB + "' or " + Param.PHASIC_TYPE + "='" + Param.PHASIC_TYPEC + "') and "+ Param.VALUETYPE + "='AVG' and ");
StringBuilder timeId = new StringBuilder();
timeId.append(Param.PHASIC_TYPE + "='" + Param.PHASIC_TYPET + "' and " + Param.TIME + " >= '" + startTime + Param.START_TIME + "' and " + Param.TIME + " <= '" + endTime + Param.END_TIME + "' and ");
timeId.append(InfluxDBPublicParam.PHASIC_TYPE + "='" + InfluxDBPublicParam.PHASIC_TYPET + "' and " + InfluxDBPublicParam.TIME + " >= '" + startTime + InfluxDBPublicParam.START_TIME + "' and " + InfluxDBPublicParam.TIME + " <= '" + endTime + InfluxDBPublicParam.END_TIME + "' and ");
for (int i = 0; i < lineIndexes.size(); i++) {
if (lineIndexes.size() - i != 1) {
timeId.append(Param.MYINDEX + "='").append(lineIndexes.get(i)).append("' or ");
timeId.append(InfluxDBPublicParam.LINE_ID + "='").append(lineIndexes.get(i)).append("' or ");
} else {
timeId.append(Param.MYINDEX + "='").append(lineIndexes.get(i)).append("' ");
timeId.append(InfluxDBPublicParam.LINE_ID + "='").append(lineIndexes.get(i)).append("' tz('Asia/Shanghai')");
}
}
String a = "SELECT * FROM LIMIT_RATE WHERE time >= '2021-01-01 00:00:00' and time <= '2022-04-30 23:59:59' and MYINDEX='71b900811d9a95811913776d6e725255' or MYINDEX='479bf4e228b5579629454ee99de0b950' or MYINDEX='1e3b8531483b2a8cbee6747f1f641cf9'";
//sql语句
String sql = "SELECT * FROM LIMIT_RATE WHERE " + timeId;
String sql = "SELECT * FROM "+ InfluxDBPublicParam.LIMIT_RATE +" WHERE " + timeId;
//结果集
QueryResult result = influxDbUtils.query(sql);
// if (Objects.isNull(result.getResults().get(0).getSeries())) {
// throw new BusinessException(HarmonicResponseEnum.LIMIT_RATE_ERROR);
// }
//结果集映射到对象中
InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
limitRatePOS = resultMapper.toPOJO(result, LimitRatePO.class);

View File

@@ -6,18 +6,23 @@ import com.njcn.device.api.GeneralDeviceInfoClient;
import com.njcn.device.enums.LineBaseEnum;
import com.njcn.device.pojo.dto.GeneralDeviceDTO;
import com.njcn.device.pojo.param.DeviceInfoParam;
import com.njcn.harmonic.constant.Param;
import com.njcn.harmonic.mapper.SteadyQualifyMapper;
import com.njcn.harmonic.pojo.dto.SteadyQualifyDTO;
import com.njcn.harmonic.pojo.po.LimitRate;
import com.njcn.harmonic.pojo.vo.SteadyQualifyCensusVO;
import com.njcn.harmonic.pojo.vo.SteadyQualifyVO;
import com.njcn.harmonic.service.SteadyQualifyService;
import com.njcn.influxdb.param.InfluxDBPublicParam;
import com.njcn.influxdb.utils.InfluxDbUtils;
import lombok.AllArgsConstructor;
import org.influxdb.dto.QueryResult;
import org.influxdb.impl.InfluxDBResultMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
@@ -53,15 +58,17 @@ public class SteadyQualifyServiceImpl implements SteadyQualifyService {
steadyQualifyVO.setName(generalDeviceDTO.getName());
// List<SteadyQualifyVO> lineData = steadyQualifyMapper.getSteadyQualifyData(lineIndexes);
List<SteadyQualifyDTO> qualifiesRate = getQualifiesRate(lineIndexes, steadyParam.getSearchBeginTime(), steadyParam.getSearchEndTime());
SteadyQualifyVO dataMoreMonitorMoreDay = getDataMoreMonitorMoreDay(qualifiesRate);
steadyQualifyVO.setFlicker(dataMoreMonitorMoreDay.getFlicker());
steadyQualifyVO.setFreqOffset(dataMoreMonitorMoreDay.getFreqOffset());
steadyQualifyVO.setVoltageOffset(dataMoreMonitorMoreDay.getVoltageOffset());
steadyQualifyVO.setVoltageUnbalance(dataMoreMonitorMoreDay.getVoltageUnbalance());
steadyQualifyVO.setNegativeCurrent(dataMoreMonitorMoreDay.getNegativeCurrent());
steadyQualifyVO.setHarmonicVoltage(dataMoreMonitorMoreDay.getHarmonicVoltage());
steadyQualifyVO.setHarmonicCurrent(dataMoreMonitorMoreDay.getHarmonicCurrent());
steadyQualifyVO.setInterHarmonic(dataMoreMonitorMoreDay.getInterHarmonic());
if (!CollectionUtils.isEmpty(qualifiesRate)) {
SteadyQualifyVO dataMoreMonitorMoreDay = getDataMoreMonitorMoreDay(qualifiesRate);
steadyQualifyVO.setFlicker(dataMoreMonitorMoreDay.getFlicker());
steadyQualifyVO.setFreqOffset(dataMoreMonitorMoreDay.getFreqOffset());
steadyQualifyVO.setVoltageOffset(dataMoreMonitorMoreDay.getVoltageOffset());
steadyQualifyVO.setVoltageUnbalance(dataMoreMonitorMoreDay.getVoltageUnbalance());
steadyQualifyVO.setNegativeCurrent(dataMoreMonitorMoreDay.getNegativeCurrent());
steadyQualifyVO.setHarmonicVoltage(dataMoreMonitorMoreDay.getHarmonicVoltage());
steadyQualifyVO.setHarmonicCurrent(dataMoreMonitorMoreDay.getHarmonicCurrent());
steadyQualifyVO.setInterHarmonic(dataMoreMonitorMoreDay.getInterHarmonic());
}
//组装父级数据树
List<SteadyQualifyVO> treeList = getTreeData(lineIndexes, steadyParam);
steadyQualifyVO.setChildren(treeList);
@@ -252,15 +259,41 @@ public class SteadyQualifyServiceImpl implements SteadyQualifyService {
for (SteadyQualifyDTO steadyQualifyDTO : steadyQualifyDTOList) {
steadyQualifyVOS.add(getDataSingleMonitorSingeDay(qualifiesRate, lineId, steadyQualifyDTO.getTime()));
}
//求各项平均值
steadyQualifyVO.setFlicker(NumberUtil.round(steadyQualifyVOS.stream().mapToDouble(SteadyQualifyVO::getFlicker).average().orElse(100), 2).doubleValue());
steadyQualifyVO.setFreqOffset(NumberUtil.round(steadyQualifyVOS.stream().mapToDouble(SteadyQualifyVO::getFreqOffset).average().orElse(100), 2).doubleValue());
steadyQualifyVO.setVoltageOffset(NumberUtil.round(steadyQualifyVOS.stream().mapToDouble(SteadyQualifyVO::getVoltageOffset).average().orElse(100), 2).doubleValue());
steadyQualifyVO.setVoltageUnbalance(NumberUtil.round(steadyQualifyVOS.stream().mapToDouble(SteadyQualifyVO::getVoltageUnbalance).average().orElse(100), 2).doubleValue());
steadyQualifyVO.setNegativeCurrent(NumberUtil.round(steadyQualifyVOS.stream().mapToDouble(SteadyQualifyVO::getNegativeCurrent).average().orElse(100), 2).doubleValue());
steadyQualifyVO.setHarmonicVoltage(NumberUtil.round(steadyQualifyVOS.stream().mapToDouble(SteadyQualifyVO::getHarmonicVoltage).average().orElse(100), 2).doubleValue());
steadyQualifyVO.setHarmonicCurrent(NumberUtil.round(steadyQualifyVOS.stream().mapToDouble(SteadyQualifyVO::getHarmonicCurrent).average().orElse(100), 2).doubleValue());
steadyQualifyVO.setInterHarmonic(NumberUtil.round(steadyQualifyVOS.stream().mapToDouble(SteadyQualifyVO::getInterHarmonic).average().orElse(100), 2).doubleValue());
if (CollectionUtil.isNotEmpty(steadyQualifyVOS)) {
List<SteadyQualifyVO> flicker = steadyQualifyVOS.stream().filter(s -> s.getFlicker() != 3.14159).collect(Collectors.toList());
List<SteadyQualifyVO> freqOffset = steadyQualifyVOS.stream().filter(s -> s.getFreqOffset() != 3.14159).collect(Collectors.toList());
List<SteadyQualifyVO> voltageOffset = steadyQualifyVOS.stream().filter(s -> s.getVoltageOffset() != 3.14159).collect(Collectors.toList());
List<SteadyQualifyVO> voltageUnbalance = steadyQualifyVOS.stream().filter(s -> s.getVoltageUnbalance() != 3.14159).collect(Collectors.toList());
List<SteadyQualifyVO> negativeCurrent = steadyQualifyVOS.stream().filter(s -> s.getNegativeCurrent() != 3.14159).collect(Collectors.toList());
List<SteadyQualifyVO> harmonicVoltage = steadyQualifyVOS.stream().filter(s -> s.getHarmonicVoltage() != 3.14159).collect(Collectors.toList());
List<SteadyQualifyVO> harmonicCurrent = steadyQualifyVOS.stream().filter(s -> s.getHarmonicCurrent() != 3.14159).collect(Collectors.toList());
List<SteadyQualifyVO> interHarmonic = steadyQualifyVOS.stream().filter(s -> s.getInterHarmonic() != 3.14159).collect(Collectors.toList());
//求各项平均值
if (!CollectionUtils.isEmpty(flicker)) {
steadyQualifyVO.setFlicker(NumberUtil.round(steadyQualifyVOS.stream().mapToDouble(SteadyQualifyVO::getFlicker).average().orElse(100), 2).doubleValue());
}
if (!CollectionUtils.isEmpty(freqOffset)) {
steadyQualifyVO.setFreqOffset(NumberUtil.round(steadyQualifyVOS.stream().mapToDouble(SteadyQualifyVO::getFreqOffset).average().orElse(100), 2).doubleValue());
}
if (!CollectionUtils.isEmpty(voltageOffset)) {
steadyQualifyVO.setVoltageOffset(NumberUtil.round(steadyQualifyVOS.stream().mapToDouble(SteadyQualifyVO::getVoltageOffset).average().orElse(100), 2).doubleValue());
}
if (!CollectionUtils.isEmpty(voltageUnbalance)) {
steadyQualifyVO.setVoltageUnbalance(NumberUtil.round(steadyQualifyVOS.stream().mapToDouble(SteadyQualifyVO::getVoltageUnbalance).average().orElse(100), 2).doubleValue());
}
if (!CollectionUtils.isEmpty(negativeCurrent)) {
steadyQualifyVO.setNegativeCurrent(NumberUtil.round(steadyQualifyVOS.stream().mapToDouble(SteadyQualifyVO::getNegativeCurrent).average().orElse(100), 2).doubleValue());
}
if (!CollectionUtils.isEmpty(harmonicVoltage)) {
steadyQualifyVO.setHarmonicVoltage(NumberUtil.round(steadyQualifyVOS.stream().mapToDouble(SteadyQualifyVO::getHarmonicVoltage).average().orElse(100), 2).doubleValue());
}
if (!CollectionUtils.isEmpty(harmonicCurrent)) {
steadyQualifyVO.setHarmonicCurrent(NumberUtil.round(steadyQualifyVOS.stream().mapToDouble(SteadyQualifyVO::getHarmonicCurrent).average().orElse(100), 2).doubleValue());
}
if (!CollectionUtils.isEmpty(flicker)) {
steadyQualifyVO.setInterHarmonic(NumberUtil.round(steadyQualifyVOS.stream().mapToDouble(SteadyQualifyVO::getInterHarmonic).average().orElse(100), 2).doubleValue());
}
}
}
return steadyQualifyVO;
}
@@ -281,15 +314,39 @@ public class SteadyQualifyServiceImpl implements SteadyQualifyService {
}
}
if (CollectionUtil.isNotEmpty(steadyResults)) {
List<SteadyQualifyVO> flicker = steadyResults.stream().filter(s -> s.getFlicker() != 3.14159).collect(Collectors.toList());
List<SteadyQualifyVO> freqOffset = steadyResults.stream().filter(s -> s.getFreqOffset() != 3.14159).collect(Collectors.toList());
List<SteadyQualifyVO> voltageOffset = steadyResults.stream().filter(s -> s.getVoltageOffset() != 3.14159).collect(Collectors.toList());
List<SteadyQualifyVO> voltageUnbalance = steadyResults.stream().filter(s -> s.getVoltageUnbalance() != 3.14159).collect(Collectors.toList());
List<SteadyQualifyVO> negativeCurrent = steadyResults.stream().filter(s -> s.getNegativeCurrent() != 3.14159).collect(Collectors.toList());
List<SteadyQualifyVO> harmonicVoltage = steadyResults.stream().filter(s -> s.getHarmonicVoltage() != 3.14159).collect(Collectors.toList());
List<SteadyQualifyVO> harmonicCurrent = steadyResults.stream().filter(s -> s.getHarmonicCurrent() != 3.14159).collect(Collectors.toList());
List<SteadyQualifyVO> interHarmonic = steadyResults.stream().filter(s -> s.getInterHarmonic() != 3.14159).collect(Collectors.toList());
//求各项平均值
steadyQualifyVO.setFlicker(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getFlicker).average().orElse(100), 2).doubleValue());
steadyQualifyVO.setFreqOffset(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getFreqOffset).average().orElse(100), 2).doubleValue());
steadyQualifyVO.setVoltageOffset(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getVoltageOffset).average().orElse(100), 2).doubleValue());
steadyQualifyVO.setVoltageUnbalance(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getVoltageUnbalance).average().orElse(100), 2).doubleValue());
steadyQualifyVO.setNegativeCurrent(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getNegativeCurrent).average().orElse(100), 2).doubleValue());
steadyQualifyVO.setHarmonicVoltage(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getHarmonicVoltage).average().orElse(100), 2).doubleValue());
steadyQualifyVO.setHarmonicCurrent(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getHarmonicCurrent).average().orElse(100), 2).doubleValue());
steadyQualifyVO.setInterHarmonic(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getInterHarmonic).average().orElse(100), 2).doubleValue());
if (!CollectionUtils.isEmpty(flicker)) {
steadyQualifyVO.setFlicker(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getFlicker).average().orElse(100), 2).doubleValue());
}
if (!CollectionUtils.isEmpty(freqOffset)) {
steadyQualifyVO.setFreqOffset(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getFreqOffset).average().orElse(100), 2).doubleValue());
}
if (!CollectionUtils.isEmpty(voltageOffset)) {
steadyQualifyVO.setVoltageOffset(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getVoltageOffset).average().orElse(100), 2).doubleValue());
}
if (!CollectionUtils.isEmpty(voltageUnbalance)) {
steadyQualifyVO.setVoltageUnbalance(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getVoltageUnbalance).average().orElse(100), 2).doubleValue());
}
if (!CollectionUtils.isEmpty(negativeCurrent)) {
steadyQualifyVO.setNegativeCurrent(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getNegativeCurrent).average().orElse(100), 2).doubleValue());
}
if (!CollectionUtils.isEmpty(harmonicVoltage)) {
steadyQualifyVO.setHarmonicVoltage(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getHarmonicVoltage).average().orElse(100), 2).doubleValue());
}
if (!CollectionUtils.isEmpty(harmonicCurrent)) {
steadyQualifyVO.setHarmonicCurrent(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getHarmonicCurrent).average().orElse(100), 2).doubleValue());
}
if (!CollectionUtils.isEmpty(interHarmonic)) {
steadyQualifyVO.setInterHarmonic(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getInterHarmonic).average().orElse(100), 2).doubleValue());
}
}
return steadyQualifyVO;
}
@@ -304,15 +361,39 @@ public class SteadyQualifyServiceImpl implements SteadyQualifyService {
steadyResults.add(getDataSingleMonitorSingeDay(qualifiesRate, lineId, time));
}
if (CollectionUtil.isNotEmpty(steadyResults)) {
List<SteadyQualifyVO> flicker = steadyResults.stream().filter(s -> s.getFlicker() != 3.14159).collect(Collectors.toList());
List<SteadyQualifyVO> freqOffset = steadyResults.stream().filter(s -> s.getFreqOffset() != 3.14159).collect(Collectors.toList());
List<SteadyQualifyVO> voltageOffset = steadyResults.stream().filter(s -> s.getVoltageOffset() != 3.14159).collect(Collectors.toList());
List<SteadyQualifyVO> voltageUnbalance = steadyResults.stream().filter(s -> s.getVoltageUnbalance() != 3.14159).collect(Collectors.toList());
List<SteadyQualifyVO> negativeCurrent = steadyResults.stream().filter(s -> s.getNegativeCurrent() != 3.14159).collect(Collectors.toList());
List<SteadyQualifyVO> harmonicVoltage = steadyResults.stream().filter(s -> s.getHarmonicVoltage() != 3.14159).collect(Collectors.toList());
List<SteadyQualifyVO> harmonicCurrent = steadyResults.stream().filter(s -> s.getHarmonicCurrent() != 3.14159).collect(Collectors.toList());
List<SteadyQualifyVO> interHarmonic = steadyResults.stream().filter(s -> s.getInterHarmonic() != 3.14159).collect(Collectors.toList());
//求各项平均值
steadyQualifyVO.setFlicker(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getFlicker).average().orElse(100), 2).doubleValue());
steadyQualifyVO.setFreqOffset(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getFreqOffset).average().orElse(100), 2).doubleValue());
steadyQualifyVO.setVoltageOffset(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getVoltageOffset).average().orElse(100), 2).doubleValue());
steadyQualifyVO.setVoltageUnbalance(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getVoltageUnbalance).average().orElse(100), 2).doubleValue());
steadyQualifyVO.setNegativeCurrent(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getNegativeCurrent).average().orElse(100), 2).doubleValue());
steadyQualifyVO.setHarmonicVoltage(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getHarmonicVoltage).average().orElse(100), 2).doubleValue());
steadyQualifyVO.setHarmonicCurrent(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getHarmonicCurrent).average().orElse(100), 2).doubleValue());
steadyQualifyVO.setInterHarmonic(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getInterHarmonic).average().orElse(100), 2).doubleValue());
if (!CollectionUtils.isEmpty(flicker)) {
steadyQualifyVO.setFlicker(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getFlicker).average().orElse(100), 2).doubleValue());
}
if (!CollectionUtils.isEmpty(freqOffset)) {
steadyQualifyVO.setFreqOffset(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getFreqOffset).average().orElse(100), 2).doubleValue());
}
if (!CollectionUtils.isEmpty(voltageOffset)) {
steadyQualifyVO.setVoltageOffset(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getVoltageOffset).average().orElse(100), 2).doubleValue());
}
if (!CollectionUtils.isEmpty(voltageUnbalance)) {
steadyQualifyVO.setVoltageUnbalance(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getVoltageUnbalance).average().orElse(100), 2).doubleValue());
}
if (!CollectionUtils.isEmpty(negativeCurrent)) {
steadyQualifyVO.setNegativeCurrent(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getNegativeCurrent).average().orElse(100), 2).doubleValue());
}
if (!CollectionUtils.isEmpty(harmonicVoltage)) {
steadyQualifyVO.setHarmonicVoltage(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getHarmonicVoltage).average().orElse(100), 2).doubleValue());
}
if (!CollectionUtils.isEmpty(harmonicCurrent)) {
steadyQualifyVO.setHarmonicCurrent(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getHarmonicCurrent).average().orElse(100), 2).doubleValue());
}
if (!CollectionUtils.isEmpty(interHarmonic)) {
steadyQualifyVO.setInterHarmonic(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getInterHarmonic).average().orElse(100), 2).doubleValue());
}
}
return steadyQualifyVO;
}
@@ -327,128 +408,119 @@ public class SteadyQualifyServiceImpl implements SteadyQualifyService {
private List<SteadyQualifyDTO> getQualifiesRate(List<String> lineIndexes, String startTime, String endTime) {
List<SteadyQualifyDTO> qualifyDTOList = new ArrayList<>();
//组装sql语句
// StringBuilder string = new StringBuilder();
// string.append(Param.QualityFlag + "='1' and (" + Param.PHASIC_TYPE + "='" + Param.PHASIC_TYPEA + "' or " + Param.PHASIC_TYPE + "='" + Param.PHASIC_TYPEB + "' or " + Param.PHASIC_TYPE + "='" + Param.PHASIC_TYPEC + "') and "+ Param.VALUETYPE + "='AVG' and ");
StringBuilder timeId = new StringBuilder();
timeId.append(Param.TIME + " >= '" + startTime + Param.START_TIME + "' and " + Param.TIME + " <= '" + endTime + Param.END_TIME + "' and ");
timeId.append(InfluxDBPublicParam.TIME + " >= '" + startTime + InfluxDBPublicParam.START_TIME + "' and " + InfluxDBPublicParam.TIME + " <= '" + endTime + InfluxDBPublicParam.END_TIME + "' and ");
for (int i = 0; i < lineIndexes.size(); i++) {
if (lineIndexes.size() - i != 1) {
timeId.append(Param.MYINDEX + "='").append(lineIndexes.get(i)).append("' or ");
timeId.append(InfluxDBPublicParam.LINE_ID + "='").append(lineIndexes.get(i)).append("' or ");
} else {
timeId.append(Param.MYINDEX + "='").append(lineIndexes.get(i)).append("' ");
timeId.append(InfluxDBPublicParam.LINE_ID + "='").append(lineIndexes.get(i)).append("' tz('Asia/Shanghai')");
}
}
String a = "SELECT * FROM LIMIT_RATE WHERE time >= '2021-01-01 00:00:00' and time <= '2022-04-30 23:59:59' and MYINDEX='bffe97ff541333448358b7b00ed97cdb' or MYINDEX='479bf4e228b5579629454ee99de0b950' or MYINDEX='1e3b8531483b2a8cbee6747f1f641cf9'";
//sql语句
String sql = "SELECT * FROM LIMIT_RATE WHERE " + timeId;
String sql = "SELECT * FROM "+ InfluxDBPublicParam.LIMIT_RATE +" WHERE " + timeId;
//结果集
QueryResult result = influxDbUtils.query(sql);
//处理结果集
if (!CollectionUtils.isEmpty(result.getResults().get(0).getSeries())) {
List<List<Object>> values = result.getResults().get(0).getSeries().get(0).getValues();
values.forEach(list ->{
SteadyQualifyDTO steadyQualifyDTO = new SteadyQualifyDTO();
steadyQualifyDTO.setTime(list.get(0).toString());
steadyQualifyDTO.setMYINDEX(list.get(46).toString());
steadyQualifyDTO.setPhasic_Type(list.get(47).toString());
steadyQualifyDTO.setAllTime(Double.parseDouble(list.get(1).toString()));
steadyQualifyDTO.setFlicker_AllTime(Double.parseDouble(list.get(2).toString()));
steadyQualifyDTO.setFlicker_OverTime(Double.parseDouble(list.get(3).toString()));
steadyQualifyDTO.setFreq_Dev_OverTime(Double.parseDouble(list.get(4).toString()));
steadyQualifyDTO.setIHarm_10_OverTime(Double.parseDouble(list.get(5).toString()));
steadyQualifyDTO.setIHarm_11_OverTime(Double.parseDouble(list.get(6).toString()));
steadyQualifyDTO.setIHarm_12_OverTime(Double.parseDouble(list.get(7).toString()));
steadyQualifyDTO.setIHarm_13_OverTime(Double.parseDouble(list.get(8).toString()));
steadyQualifyDTO.setIHarm_14_OverTime(Double.parseDouble(list.get(9).toString()));
steadyQualifyDTO.setIHarm_15_OverTime(Double.parseDouble(list.get(10).toString()));
steadyQualifyDTO.setIHarm_16_OverTime(Double.parseDouble(list.get(11).toString()));
steadyQualifyDTO.setIHarm_17_OverTime(Double.parseDouble(list.get(12).toString()));
steadyQualifyDTO.setIHarm_18_OverTime(Double.parseDouble(list.get(13).toString()));
steadyQualifyDTO.setIHarm_19_OverTime(Double.parseDouble(list.get(14).toString()));
steadyQualifyDTO.setIHarm_20_OverTime(Double.parseDouble(list.get(15).toString()));
steadyQualifyDTO.setIHarm_21_OverTime(Double.parseDouble(list.get(16).toString()));
steadyQualifyDTO.setIHarm_22_OverTime(Double.parseDouble(list.get(17).toString()));
steadyQualifyDTO.setIHarm_23_OverTime(Double.parseDouble(list.get(18).toString()));
steadyQualifyDTO.setIHarm_24_OverTime(Double.parseDouble(list.get(19).toString()));
steadyQualifyDTO.setIHarm_25_OverTime(Double.parseDouble(list.get(20).toString()));
steadyQualifyDTO.setIHarm_2_OverTime(Double.parseDouble(list.get(21).toString()));
steadyQualifyDTO.setIHarm_3_OverTime(Double.parseDouble(list.get(22).toString()));
steadyQualifyDTO.setIHarm_4_OverTime(Double.parseDouble(list.get(23).toString()));
steadyQualifyDTO.setIHarm_5_OverTime(Double.parseDouble(list.get(24).toString()));
steadyQualifyDTO.setIHarm_6_OverTime(Double.parseDouble(list.get(25).toString()));
steadyQualifyDTO.setIHarm_7_OverTime(Double.parseDouble(list.get(26).toString()));
steadyQualifyDTO.setIHarm_8_OverTime(Double.parseDouble(list.get(27).toString()));
steadyQualifyDTO.setIHarm_9_OverTime(Double.parseDouble(list.get(28).toString()));
steadyQualifyDTO.setI_Neg_OverTime(Double.parseDouble(list.get(29).toString()));
steadyQualifyDTO.setInUHARM_10_OverTime(Double.parseDouble(list.get(30).toString()));
steadyQualifyDTO.setInUHARM_11_OverTime(Double.parseDouble(list.get(31).toString()));
steadyQualifyDTO.setInUHARM_12_OverTime(Double.parseDouble(list.get(32).toString()));
steadyQualifyDTO.setInUHARM_13_OverTime(Double.parseDouble(list.get(33).toString()));
steadyQualifyDTO.setInUHARM_14_OverTime(Double.parseDouble(list.get(34).toString()));
steadyQualifyDTO.setInUHARM_15_OverTime(Double.parseDouble(list.get(35).toString()));
steadyQualifyDTO.setInUHARM_16_OverTime(Double.parseDouble(list.get(36).toString()));
steadyQualifyDTO.setInUHARM_1_OverTime(Double.parseDouble(list.get(37).toString()));
steadyQualifyDTO.setInUHARM_2_OverTime(Double.parseDouble(list.get(38).toString()));
steadyQualifyDTO.setInUHARM_3_OverTime(Double.parseDouble(list.get(39).toString()));
steadyQualifyDTO.setInUHARM_4_OverTime(Double.parseDouble(list.get(40).toString()));
steadyQualifyDTO.setInUHARM_5_OverTime(Double.parseDouble(list.get(41).toString()));
steadyQualifyDTO.setInUHARM_6_OverTime(Double.parseDouble(list.get(42).toString()));
steadyQualifyDTO.setInUHARM_7_OverTime(Double.parseDouble(list.get(43).toString()));
steadyQualifyDTO.setInUHARM_8_OverTime(Double.parseDouble(list.get(44).toString()));
steadyQualifyDTO.setInUHARM_9_OverTime(Double.parseDouble(list.get(45).toString()));
steadyQualifyDTO.setUAberrance_OverTime(Double.parseDouble(list.get(48).toString()));
steadyQualifyDTO.setUBalance_OverTime(Double.parseDouble(list.get(49).toString()));
steadyQualifyDTO.setUHarm_10_OverTime(Double.parseDouble(list.get(50).toString()));
steadyQualifyDTO.setUHarm_11_OverTime(Double.parseDouble(list.get(51).toString()));
steadyQualifyDTO.setUHarm_12_OverTime(Double.parseDouble(list.get(52).toString()));
steadyQualifyDTO.setUHarm_13_OverTime(Double.parseDouble(list.get(53).toString()));
steadyQualifyDTO.setUHarm_14_OverTime(Double.parseDouble(list.get(54).toString()));
steadyQualifyDTO.setUHarm_15_OverTime(Double.parseDouble(list.get(55).toString()));
steadyQualifyDTO.setUHarm_16_OverTime(Double.parseDouble(list.get(56).toString()));
steadyQualifyDTO.setUHarm_17_OverTime(Double.parseDouble(list.get(57).toString()));
steadyQualifyDTO.setUHarm_18_OverTime(Double.parseDouble(list.get(58).toString()));
steadyQualifyDTO.setUHarm_19_OverTime(Double.parseDouble(list.get(59).toString()));
steadyQualifyDTO.setUHarm_20_OverTime(Double.parseDouble(list.get(60).toString()));
steadyQualifyDTO.setUHarm_21_OverTime(Double.parseDouble(list.get(61).toString()));
steadyQualifyDTO.setUHarm_22_OverTime(Double.parseDouble(list.get(62).toString()));
steadyQualifyDTO.setUHarm_23_OverTime(Double.parseDouble(list.get(63).toString()));
steadyQualifyDTO.setUHarm_24_OverTime(Double.parseDouble(list.get(64).toString()));
steadyQualifyDTO.setUHarm_25_OverTime(Double.parseDouble(list.get(65).toString()));
steadyQualifyDTO.setUHarm_2_OverTime(Double.parseDouble(list.get(66).toString()));
steadyQualifyDTO.setUHarm_3_OverTime(Double.parseDouble(list.get(67).toString()));
steadyQualifyDTO.setUHarm_4_OverTime(Double.parseDouble(list.get(68).toString()));
steadyQualifyDTO.setUHarm_5_OverTime(Double.parseDouble(list.get(69).toString()));
steadyQualifyDTO.setUHarm_6_OverTime(Double.parseDouble(list.get(70).toString()));
steadyQualifyDTO.setUHarm_7_OverTime(Double.parseDouble(list.get(71).toString()));
steadyQualifyDTO.setUHarm_8_OverTime(Double.parseDouble(list.get(72).toString()));
steadyQualifyDTO.setUHarm_9_OverTime(Double.parseDouble(list.get(73).toString()));
steadyQualifyDTO.setVoltage_Dev_OverTime(Double.parseDouble(list.get(74).toString()));
//结果集映射到对象中
InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
List<LimitRate> limitRates = influxDBResultMapper.toPOJO(result, LimitRate.class);
limitRates.forEach(list ->{
SteadyQualifyDTO steadyQualifyDTO = new SteadyQualifyDTO();
LocalDateTime localDateTime = LocalDateTime.ofInstant(list.getTime(), ZoneId.systemDefault());
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
steadyQualifyDTO.setTime(dateTimeFormatter.format(localDateTime));
steadyQualifyDTO.setMYINDEX(list.getLineId());
steadyQualifyDTO.setPhasic_Type(list.getPhasicType());
steadyQualifyDTO.setAllTime(Double.parseDouble(list.getAllTime().toString()));
steadyQualifyDTO.setFlicker_AllTime(Double.parseDouble(list.getFlickerAllTime().toString()));
steadyQualifyDTO.setFlicker_OverTime(Double.parseDouble(list.getFlickerOverTime().toString()));
steadyQualifyDTO.setFreq_Dev_OverTime(Double.parseDouble(list.getFreqDevOverTime().toString()));
steadyQualifyDTO.setIHarm_2_OverTime(Double.parseDouble(list.getIHarm2OverTime().toString()));
steadyQualifyDTO.setIHarm_3_OverTime(Double.parseDouble(list.getIHarm3OverTime().toString()));
steadyQualifyDTO.setIHarm_4_OverTime(Double.parseDouble(list.getIHarm4OverTime().toString()));
steadyQualifyDTO.setIHarm_5_OverTime(Double.parseDouble(list.getIHarm5OverTime().toString()));
steadyQualifyDTO.setIHarm_6_OverTime(Double.parseDouble(list.getIHarm6OverTime().toString()));
steadyQualifyDTO.setIHarm_7_OverTime(Double.parseDouble(list.getIHarm7OverTime().toString()));
steadyQualifyDTO.setIHarm_8_OverTime(Double.parseDouble(list.getIHarm8OverTime().toString()));
steadyQualifyDTO.setIHarm_9_OverTime(Double.parseDouble(list.getIHarm9OverTime().toString()));
steadyQualifyDTO.setIHarm_10_OverTime(Double.parseDouble(list.getIHarm10OverTime().toString()));
steadyQualifyDTO.setIHarm_11_OverTime(Double.parseDouble(list.getIHarm11OverTime().toString()));
steadyQualifyDTO.setIHarm_12_OverTime(Double.parseDouble(list.getIHarm12OverTime().toString()));
steadyQualifyDTO.setIHarm_13_OverTime(Double.parseDouble(list.getIHarm13OverTime().toString()));
steadyQualifyDTO.setIHarm_14_OverTime(Double.parseDouble(list.getIHarm14OverTime().toString()));
steadyQualifyDTO.setIHarm_15_OverTime(Double.parseDouble(list.getIHarm15OverTime().toString()));
steadyQualifyDTO.setIHarm_16_OverTime(Double.parseDouble(list.getIHarm16OverTime().toString()));
steadyQualifyDTO.setIHarm_17_OverTime(Double.parseDouble(list.getIHarm17OverTime().toString()));
steadyQualifyDTO.setIHarm_18_OverTime(Double.parseDouble(list.getIHarm18OverTime().toString()));
steadyQualifyDTO.setIHarm_19_OverTime(Double.parseDouble(list.getIHarm19OverTime().toString()));
steadyQualifyDTO.setIHarm_20_OverTime(Double.parseDouble(list.getIHarm20OverTime().toString()));
steadyQualifyDTO.setIHarm_21_OverTime(Double.parseDouble(list.getIHarm21OverTime().toString()));
steadyQualifyDTO.setIHarm_22_OverTime(Double.parseDouble(list.getIHarm22OverTime().toString()));
steadyQualifyDTO.setIHarm_23_OverTime(Double.parseDouble(list.getIHarm23OverTime().toString()));
steadyQualifyDTO.setIHarm_24_OverTime(Double.parseDouble(list.getIHarm24OverTime().toString()));
steadyQualifyDTO.setIHarm_25_OverTime(Double.parseDouble(list.getIHarm25OverTime().toString()));
steadyQualifyDTO.setI_Neg_OverTime(Double.parseDouble(list.getINegOverTime().toString()));
steadyQualifyDTO.setInUHARM_1_OverTime(Double.parseDouble(list.getInuHarm1OverTime().toString()));
steadyQualifyDTO.setInUHARM_2_OverTime(Double.parseDouble(list.getInuHarm2OverTime().toString()));
steadyQualifyDTO.setInUHARM_3_OverTime(Double.parseDouble(list.getInuHarm3OverTime().toString()));
steadyQualifyDTO.setInUHARM_4_OverTime(Double.parseDouble(list.getInuHarm4OverTime().toString()));
steadyQualifyDTO.setInUHARM_5_OverTime(Double.parseDouble(list.getInuHarm5OverTime().toString()));
steadyQualifyDTO.setInUHARM_6_OverTime(Double.parseDouble(list.getInuHarm6OverTime().toString()));
steadyQualifyDTO.setInUHARM_7_OverTime(Double.parseDouble(list.getInuHarm7OverTime().toString()));
steadyQualifyDTO.setInUHARM_8_OverTime(Double.parseDouble(list.getInuHarm8OverTime().toString()));
steadyQualifyDTO.setInUHARM_9_OverTime(Double.parseDouble(list.getInuHarm9OverTime().toString()));
steadyQualifyDTO.setInUHARM_10_OverTime(Double.parseDouble(list.getInuHarm10OverTime().toString()));
steadyQualifyDTO.setInUHARM_11_OverTime(Double.parseDouble(list.getInuHarm11OverTime().toString()));
steadyQualifyDTO.setInUHARM_12_OverTime(Double.parseDouble(list.getInuHarm12OverTime().toString()));
steadyQualifyDTO.setInUHARM_13_OverTime(Double.parseDouble(list.getInuHarm13OverTime().toString()));
steadyQualifyDTO.setInUHARM_14_OverTime(Double.parseDouble(list.getInuHarm14OverTime().toString()));
steadyQualifyDTO.setInUHARM_15_OverTime(Double.parseDouble(list.getInuHarm15OverTime().toString()));
steadyQualifyDTO.setInUHARM_16_OverTime(Double.parseDouble(list.getInuHarm16OverTime().toString()));
steadyQualifyDTO.setUAberrance_OverTime(Double.parseDouble(list.getUAberranceOverTime().toString()));
steadyQualifyDTO.setUBalance_OverTime(Double.parseDouble(list.getUBalanceOverTime().toString()));
steadyQualifyDTO.setUHarm_2_OverTime(Double.parseDouble(list.getUHarm2OverTime().toString()));
steadyQualifyDTO.setUHarm_3_OverTime(Double.parseDouble(list.getUHarm3OverTime().toString()));
steadyQualifyDTO.setUHarm_4_OverTime(Double.parseDouble(list.getUHarm4OverTime().toString()));
steadyQualifyDTO.setUHarm_5_OverTime(Double.parseDouble(list.getUHarm5OverTime().toString()));
steadyQualifyDTO.setUHarm_6_OverTime(Double.parseDouble(list.getUHarm6OverTime().toString()));
steadyQualifyDTO.setUHarm_7_OverTime(Double.parseDouble(list.getUHarm7OverTime().toString()));
steadyQualifyDTO.setUHarm_8_OverTime(Double.parseDouble(list.getUHarm8OverTime().toString()));
steadyQualifyDTO.setUHarm_9_OverTime(Double.parseDouble(list.getUHarm9OverTime().toString()));
steadyQualifyDTO.setUHarm_10_OverTime(Double.parseDouble(list.getUHarm10OverTime().toString()));
steadyQualifyDTO.setUHarm_11_OverTime(Double.parseDouble(list.getUHarm11OverTime().toString()));
steadyQualifyDTO.setUHarm_12_OverTime(Double.parseDouble(list.getUHarm12OverTime().toString()));
steadyQualifyDTO.setUHarm_13_OverTime(Double.parseDouble(list.getUHarm13OverTime().toString()));
steadyQualifyDTO.setUHarm_14_OverTime(Double.parseDouble(list.getUHarm14OverTime().toString()));
steadyQualifyDTO.setUHarm_15_OverTime(Double.parseDouble(list.getUHarm15OverTime().toString()));
steadyQualifyDTO.setUHarm_16_OverTime(Double.parseDouble(list.getUHarm16OverTime().toString()));
steadyQualifyDTO.setUHarm_17_OverTime(Double.parseDouble(list.getUHarm17OverTime().toString()));
steadyQualifyDTO.setUHarm_18_OverTime(Double.parseDouble(list.getUHarm18OverTime().toString()));
steadyQualifyDTO.setUHarm_19_OverTime(Double.parseDouble(list.getUHarm19OverTime().toString()));
steadyQualifyDTO.setUHarm_20_OverTime(Double.parseDouble(list.getUHarm20OverTime().toString()));
steadyQualifyDTO.setUHarm_21_OverTime(Double.parseDouble(list.getUHarm21OverTime().toString()));
steadyQualifyDTO.setUHarm_22_OverTime(Double.parseDouble(list.getUHarm22OverTime().toString()));
steadyQualifyDTO.setUHarm_23_OverTime(Double.parseDouble(list.getUHarm23OverTime().toString()));
steadyQualifyDTO.setUHarm_24_OverTime(Double.parseDouble(list.getUHarm24OverTime().toString()));
steadyQualifyDTO.setUHarm_25_OverTime(Double.parseDouble(list.getUHarm25OverTime().toString()));
steadyQualifyDTO.setVoltage_Dev_OverTime(Double.parseDouble(list.getVoltageDevOverTime().toString()));
qualifyDTOList.add(steadyQualifyDTO);
});
// steadyQualifyDTO.setTime(time);
// if (!CollectionUtils.isEmpty(valueList)){
// for (List<Object> value : valueList) {
// String time = value.get(0).toString();
// double v = Double.parseDouble(value.get(1).toString());
// value.get(2);
// value.get(3);
// //谐波畸变率 保留两位小数
// Double distortion = value.get(1) == null ? null : BigDecimal.valueOf(Double.parseDouble(value.get(1).toString())).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
//
//
// }
// }
qualifyDTOList.add(steadyQualifyDTO);
});
}
return qualifyDTOList;
}
private static double calculate(Double allTime, Double overTime) {
if (allTime >= overTime){
return NumberUtil.round((allTime - overTime) / allTime * 100, 2).doubleValue();
if (allTime == 0) {
return 3.14159;
} else {
if (allTime >= overTime){
return NumberUtil.round((allTime - overTime) / allTime * 100, 2).doubleValue();
}
return 0.0;
}
return 0.0;
}
}

View File

@@ -4,12 +4,12 @@ import com.njcn.common.config.GeneralInfo;
import com.njcn.device.api.GeneralDeviceInfoClient;
import com.njcn.device.pojo.dto.GeneralDeviceDTO;
import com.njcn.device.pojo.param.DeviceInfoParam;
import com.njcn.harmonic.constant.Param;
import com.njcn.harmonic.mapper.TerminalDataMapper;
import com.njcn.harmonic.pojo.dto.PublicDTO;
import com.njcn.harmonic.pojo.vo.TerminalCensusVO;
import com.njcn.harmonic.pojo.vo.TerminalVO;
import com.njcn.harmonic.service.TerminalService;
import com.njcn.influxdb.param.InfluxDBPublicParam;
import com.njcn.influxdb.utils.InfluxDbUtils;
import lombok.AllArgsConstructor;
import org.influxdb.dto.QueryResult;
@@ -151,7 +151,7 @@ public class TerminalServiceImpl implements TerminalService {
/**
* 获取父级每层数据
* 获取树的每层数据
*/
public List<TerminalVO> getTreeData(List<String> deviceIndexes, DeviceInfoParam.BusinessParam terminalParam) {
//终端集合
@@ -160,16 +160,6 @@ public class TerminalServiceImpl implements TerminalService {
List<TerminalVO> substationList = terminalDataMapper.getLineInfoByList(deviceList.stream().map(TerminalVO::getPid).distinct().collect(Collectors.toList()));
//供电公司集合
List<TerminalVO> powerCompanyList = terminalDataMapper.getLineInfoByList(substationList.stream().map(TerminalVO::getPid).distinct().collect(Collectors.toList()));
// //区域集合
// List<TerminalVO> areaList = terminalDataMapper.getLineInfoByList(powerCompanyList.stream().map(TerminalVO::getPid).distinct().collect(Collectors.toList()));
// //区域详情,用来替换区域名称
// List<Area> area = areaFeignClient.areaNameByList(areaList.stream().map(TerminalVO::getName).collect(Collectors.toList())).getData();
// //组装区域名称
// areaList.stream().map(list1 -> area.stream().filter(list2 -> Objects.equals(list1.getName(), list2.getId())).findAny().map(m -> {
// list1.setName(m.getName());
// return list1;
// })).collect(Collectors.toList());
//查询终端的在线率
List<PublicDTO> onlineRateList = getCondition(deviceIndexes, terminalParam.getSearchBeginTime(), terminalParam.getSearchEndTime());
//根据终端集合组装终端的在线率
@@ -191,7 +181,6 @@ public class TerminalServiceImpl implements TerminalService {
powerCompanyList.stream().peek(item -> item.setChildren(getChildCategoryList(item, substationList))).collect(Collectors.toList());
setTreeFlag(powerCompanyList,substationList);
// areaList.stream().peek(item -> item.setChildren(getChildCategoryList(item, powerCompanyList))).collect(Collectors.toList());
setFatherOnlineRate(substationList);
setFatherOnlineRate(powerCompanyList);
// setAreaIntegrity(areaList);
@@ -218,16 +207,16 @@ public class TerminalServiceImpl implements TerminalService {
List<PublicDTO> publicDTOList = new ArrayList<>();
//组装sql语句
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(Param.TIME + " >= '").append(startTime).append(Param.START_TIME).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append(Param.END_TIME).append("' and (");
stringBuilder.append(InfluxDBPublicParam.TIME + " >= '").append(startTime).append(InfluxDBPublicParam.START_TIME).append("' and ").append(InfluxDBPublicParam.TIME).append(" <= '").append(endTime).append(InfluxDBPublicParam.END_TIME).append("' and (");
for (int i = 0; i < deviceIndexes.size(); i++) {
if (deviceIndexes.size() - i != 1) {
stringBuilder.append(Param.DEV_INDEX + "='").append(deviceIndexes.get(i)).append("' or ");
stringBuilder.append(InfluxDBPublicParam.DEV_INDEX + "='").append(deviceIndexes.get(i)).append("' or ");
} else {
stringBuilder.append(Param.DEV_INDEX + "='").append(deviceIndexes.get(i)).append("')");
stringBuilder.append(InfluxDBPublicParam.DEV_INDEX + "='").append(deviceIndexes.get(i)).append("')");
}
}
//sql语句
String sql = "SELECT (SUM(" + Param.ONLINEMIN + ")/(SUM(" + Param.OFFLINEMIN + ")+SUM(" + Param.ONLINEMIN + ")))*100 AS onlineRate FROM PQS_ONLINERATE WHERE " + stringBuilder + " group by " + Param.DEV_INDEX;
String sql = "SELECT (SUM(" + InfluxDBPublicParam.ONLINEMIN + ")/(SUM(" + InfluxDBPublicParam.OFFLINEMIN + ")+SUM(" + InfluxDBPublicParam.ONLINEMIN + ")))*100 AS onlineRate FROM "+InfluxDBPublicParam.PQS_ONLINERATE+" WHERE " + stringBuilder + " group by " + InfluxDBPublicParam.DEV_INDEX + InfluxDBPublicParam.TIME_ZONE;
//结果集
QueryResult result = influxDbUtils.query(sql);
//处理结果集
@@ -236,7 +225,7 @@ public class TerminalServiceImpl implements TerminalService {
list.forEach(po -> {
PublicDTO publicDTO = new PublicDTO();
List<List<Object>> valueList = po.getValues();
String index = po.getTags().get(Param.DEV_INDEX);
String index = po.getTags().get(InfluxDBPublicParam.DEV_INDEX);
if (!CollectionUtils.isEmpty(valueList)) {
for (List<Object> value : valueList) {
//终端在线率 保留两位小数
@@ -252,14 +241,14 @@ public class TerminalServiceImpl implements TerminalService {
}
/**
* 计算级终端在线率
* 计算该子层级终端在线率
*/
private void setFatherOnlineRate(List<TerminalVO> list) {
list.forEach(item -> {
List<TerminalVO> children = item.getChildren();
List<TerminalVO> tempList = children.stream().filter(s -> !Objects.equals(s.getOnlineRateData(), 3.14159)).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(tempList)) {
item.setOnlineRateData(tempList.stream().mapToDouble(TerminalVO::getOnlineRateData).sum() / children.size());
item.setOnlineRateData(tempList.stream().mapToDouble(TerminalVO::getOnlineRateData).sum() / tempList.size());
} else {
item.setOnlineRateData(3.14159);
}
@@ -267,22 +256,5 @@ public class TerminalServiceImpl implements TerminalService {
}
//省级
private void setAreaOnlineRate(List<TerminalVO> list) {
list.forEach(item -> {
List<TerminalVO> result = new ArrayList<>();
List<TerminalVO> children = item.getChildren();
children.forEach(item2 -> {
List<TerminalVO> children2 = item2.getChildren();
children2.forEach(item3 -> {
List<TerminalVO> children3 = item3.getChildren();
result.addAll(children3);
});
});
double aver = result.stream().mapToDouble(TerminalVO::getOnlineRateData).average().orElseThrow(IllegalStateException::new);
item.setOnlineRateData(BigDecimal.valueOf(aver).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
});
}
}