谐波模块sql语句换成InfluxDBPublicParam

This commit is contained in:
陈超
2022-07-04 22:17:12 +08:00
parent d734473038
commit b561bb78ac
7 changed files with 151 additions and 67 deletions

View File

@@ -240,5 +240,9 @@ public interface InfluxDBPublicParam {
String DEV_INDEX = "dev_id";
/**
* 稳态数据分析字段
*/
String PHASIC_TYPET = "T";
}

View File

@@ -10,7 +10,6 @@ import lombok.Data;
@Data
public class SteadyQualifyDTO {
private String id;
//时间索引
private String time;
//监测点索引

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

@@ -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

@@ -6,12 +6,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.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;
@@ -183,16 +183,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 +201,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) {
//终端在线率 保留两位小数

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;
@@ -411,17 +411,17 @@ public class SteadyExceedRateServiceImpl implements SteadyExceedRateService {
// 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);
//结果集映射到对象中

View File

@@ -6,12 +6,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.SteadyQualifyMapper;
import com.njcn.harmonic.pojo.dto.SteadyQualifyDTO;
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;
@@ -53,15 +53,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 +254,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 +309,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 +356,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,22 +403,24 @@ 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);
// //结果集映射到对象中
// InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
// List<LimitRate> limitRates = influxDBResultMapper.toPOJO(result, LimitRate.class);
//处理结果集
if (!CollectionUtils.isEmpty(result.getResults().get(0).getSeries())) {
List<List<Object>> values = result.getResults().get(0).getSeries().get(0).getValues();
@@ -445,10 +523,14 @@ public class SteadyQualifyServiceImpl implements SteadyQualifyService {
}
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;
}
}