diff --git a/pqs-common/common-influxdb/src/main/java/com/njcn/influxdb/param/InfluxDBPublicParam.java b/pqs-common/common-influxdb/src/main/java/com/njcn/influxdb/param/InfluxDBPublicParam.java index 916c0f798..8f8816b3b 100644 --- a/pqs-common/common-influxdb/src/main/java/com/njcn/influxdb/param/InfluxDBPublicParam.java +++ b/pqs-common/common-influxdb/src/main/java/com/njcn/influxdb/param/InfluxDBPublicParam.java @@ -240,5 +240,9 @@ public interface InfluxDBPublicParam { String DEV_INDEX = "dev_id"; + /** + * 稳态数据分析字段 + */ + String PHASIC_TYPET = "T"; } diff --git a/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/dto/SteadyQualifyDTO.java b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/dto/SteadyQualifyDTO.java index 3c71cf42a..a09790885 100644 --- a/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/dto/SteadyQualifyDTO.java +++ b/pqs-harmonic/harmonic-api/src/main/java/com/njcn/harmonic/pojo/dto/SteadyQualifyDTO.java @@ -10,7 +10,6 @@ import lombok.Data; @Data public class SteadyQualifyDTO { - private String id; //时间索引 private String time; //监测点索引 diff --git a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/controller/OnlineRateDataController.java b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/controller/OnlineRateDataController.java index f55431608..0e7778d7b 100644 --- a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/controller/OnlineRateDataController.java +++ b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/controller/OnlineRateDataController.java @@ -50,7 +50,7 @@ public class OnlineRateDataController extends BaseController { @OperateInfo @PostMapping("/getOnlineRateDataCensus") - @ApiOperation("终端在线率统计") + @ApiOperation("终端在线率图表") @ApiImplicitParam(name = "onlineRateCensusParam", value = "终端在线率参数", required = true) public HttpResult getOnlineRateDataCensus(@RequestBody @Validated DeviceInfoParam.CompareBusinessParam onlineRateCensusParam){ String methodDescribe = getMethodDescribe("getOnlineRateDataCensus"); diff --git a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/IntegrityServiceImpl.java b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/IntegrityServiceImpl.java index abbf87ace..48e35905b 100644 --- a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/IntegrityServiceImpl.java +++ b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/IntegrityServiceImpl.java @@ -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 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> 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 value : valueList) { //数据完整性 保留四位小数 diff --git a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/OnlineRateDataServiceImpl.java b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/OnlineRateDataServiceImpl.java index 4dbb5ba06..2a4ec9459 100644 --- a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/OnlineRateDataServiceImpl.java +++ b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/OnlineRateDataServiceImpl.java @@ -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 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> 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 value : valueList) { //终端在线率 保留两位小数 diff --git a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/SteadyExceedRateServiceImpl.java b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/SteadyExceedRateServiceImpl.java index a3f1b1ac8..ee731e216 100644 --- a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/SteadyExceedRateServiceImpl.java +++ b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/SteadyExceedRateServiceImpl.java @@ -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 = 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= '" + 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); //结果集映射到对象中 diff --git a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/SteadyQualifyServiceImpl.java b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/SteadyQualifyServiceImpl.java index 677884ebc..e6d468aa0 100644 --- a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/SteadyQualifyServiceImpl.java +++ b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/SteadyQualifyServiceImpl.java @@ -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 lineData = steadyQualifyMapper.getSteadyQualifyData(lineIndexes); List 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 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 flicker = steadyQualifyVOS.stream().filter(s -> s.getFlicker() != 3.14159).collect(Collectors.toList()); + List freqOffset = steadyQualifyVOS.stream().filter(s -> s.getFreqOffset() != 3.14159).collect(Collectors.toList()); + List voltageOffset = steadyQualifyVOS.stream().filter(s -> s.getVoltageOffset() != 3.14159).collect(Collectors.toList()); + List voltageUnbalance = steadyQualifyVOS.stream().filter(s -> s.getVoltageUnbalance() != 3.14159).collect(Collectors.toList()); + List negativeCurrent = steadyQualifyVOS.stream().filter(s -> s.getNegativeCurrent() != 3.14159).collect(Collectors.toList()); + List harmonicVoltage = steadyQualifyVOS.stream().filter(s -> s.getHarmonicVoltage() != 3.14159).collect(Collectors.toList()); + List harmonicCurrent = steadyQualifyVOS.stream().filter(s -> s.getHarmonicCurrent() != 3.14159).collect(Collectors.toList()); + List 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 flicker = steadyResults.stream().filter(s -> s.getFlicker() != 3.14159).collect(Collectors.toList()); + List freqOffset = steadyResults.stream().filter(s -> s.getFreqOffset() != 3.14159).collect(Collectors.toList()); + List voltageOffset = steadyResults.stream().filter(s -> s.getVoltageOffset() != 3.14159).collect(Collectors.toList()); + List voltageUnbalance = steadyResults.stream().filter(s -> s.getVoltageUnbalance() != 3.14159).collect(Collectors.toList()); + List negativeCurrent = steadyResults.stream().filter(s -> s.getNegativeCurrent() != 3.14159).collect(Collectors.toList()); + List harmonicVoltage = steadyResults.stream().filter(s -> s.getHarmonicVoltage() != 3.14159).collect(Collectors.toList()); + List harmonicCurrent = steadyResults.stream().filter(s -> s.getHarmonicCurrent() != 3.14159).collect(Collectors.toList()); + List 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 flicker = steadyResults.stream().filter(s -> s.getFlicker() != 3.14159).collect(Collectors.toList()); + List freqOffset = steadyResults.stream().filter(s -> s.getFreqOffset() != 3.14159).collect(Collectors.toList()); + List voltageOffset = steadyResults.stream().filter(s -> s.getVoltageOffset() != 3.14159).collect(Collectors.toList()); + List voltageUnbalance = steadyResults.stream().filter(s -> s.getVoltageUnbalance() != 3.14159).collect(Collectors.toList()); + List negativeCurrent = steadyResults.stream().filter(s -> s.getNegativeCurrent() != 3.14159).collect(Collectors.toList()); + List harmonicVoltage = steadyResults.stream().filter(s -> s.getHarmonicVoltage() != 3.14159).collect(Collectors.toList()); + List harmonicCurrent = steadyResults.stream().filter(s -> s.getHarmonicCurrent() != 3.14159).collect(Collectors.toList()); + List 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 getQualifiesRate(List lineIndexes, String startTime, String endTime) { List 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 limitRates = influxDBResultMapper.toPOJO(result, LimitRate.class); + //处理结果集 if (!CollectionUtils.isEmpty(result.getResults().get(0).getSeries())) { List> 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; } }