From 46f521c7a7f8fc7343ca8ff253b120fe8558f587 Mon Sep 17 00:00:00 2001 From: hzj <826100833@qq.com> Date: Fri, 10 Apr 2026 13:32:36 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=90=E6=B3=A2=E9=A2=91=E8=B0=B1=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2Influxdb=E5=88=86=E9=92=9F=E6=95=B0=E6=8D=AE=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=88=90=E6=9F=A5=E8=AF=A2mysql=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/njcn/common/utils/PubUtils.java | 26 ++++++ .../service/impl/HarmInHarmServiceImpl.java | 85 ++++++++++++++----- 2 files changed, 92 insertions(+), 19 deletions(-) diff --git a/pqs-common/common-core/src/main/java/com/njcn/common/utils/PubUtils.java b/pqs-common/common-core/src/main/java/com/njcn/common/utils/PubUtils.java index 650ea0acb..017371116 100644 --- a/pqs-common/common-core/src/main/java/com/njcn/common/utils/PubUtils.java +++ b/pqs-common/common-core/src/main/java/com/njcn/common/utils/PubUtils.java @@ -15,6 +15,7 @@ import com.njcn.common.pojo.exception.BusinessException; import lombok.Data; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Type; import java.math.BigDecimal; @@ -32,6 +33,7 @@ import java.util.*; import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; import static java.lang.Integer.parseInt; @@ -281,6 +283,30 @@ public class PubUtils { } } + /** + * 用于获取对象中,前缀一样,后缀为2~50的属性值 + * + * @param methodPrefix 方法前缀 + * @param number 方法后缀 + * @return 对象属性值 + */ + public static Double getValueByMethodDouble(List data ,Class clazz, String methodPrefix, Integer number) { + try { + Method method = clazz.getMethod(methodPrefix + number); + OptionalDouble average = data.stream().mapToDouble(temp -> { + try { + return (Double) method.invoke(temp); + } catch (Exception e) { + throw new BusinessException(CommonResponseEnum.REFLECT_METHOD_EXCEPTION); + } + }).average(); + return average.orElse(0.0); + + } catch (Exception e) { + throw new BusinessException(CommonResponseEnum.REFLECT_METHOD_EXCEPTION); + } + } + public static List getStartTimeEndTime(String beginDate, String endDate) throws Exception { diff --git a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/HarmInHarmServiceImpl.java b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/HarmInHarmServiceImpl.java index 2df942ee1..96cb71ead 100644 --- a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/HarmInHarmServiceImpl.java +++ b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/HarmInHarmServiceImpl.java @@ -1,12 +1,20 @@ package com.njcn.harmonic.service.impl; +import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.njcn.common.utils.HarmonicTimesUtil; import com.njcn.common.utils.PubUtils; import com.njcn.device.pq.api.LineFeignClient; import com.njcn.device.biz.pojo.po.Overlimit; +import com.njcn.harmonic.common.mapper.RStatDataHarmRateVDMapper; +import com.njcn.harmonic.common.mapper.RStatDataIDMapper; import com.njcn.harmonic.constant.Param; +import com.njcn.harmonic.mapper.RStatDataHarmRateIDMapper; import com.njcn.harmonic.pojo.param.HarmInHarmParam; +import com.njcn.harmonic.pojo.po.day.RStatDataHarmrateIDPO; +import com.njcn.harmonic.pojo.po.day.RStatDataHarmrateVDPO; +import com.njcn.harmonic.pojo.po.day.RStatDataIDPO; import com.njcn.harmonic.pojo.vo.HarmInHarmVO; import com.njcn.harmonic.service.HarmInHarmService; import com.njcn.influx.pojo.constant.InfluxDBTableConstant; @@ -21,6 +29,7 @@ import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Objects; @@ -41,7 +50,8 @@ public class HarmInHarmServiceImpl implements HarmInHarmService { private final IDataIService dataIService; - + private final RStatDataHarmRateVDMapper dataHarmRateVDMapper; + private final RStatDataIDMapper dataIDMapper; @Override public HarmInHarmVO getHarmInHarmData(HarmInHarmParam harmInHarmParam) { HarmInHarmVO harmInHarmVO = new HarmInHarmVO(); @@ -77,33 +87,70 @@ public class HarmInHarmServiceImpl implements HarmInHarmService { List floatList = new ArrayList<>(); if (StrUtil.isNotBlank(lineId)) { if (harmState == 0) { - InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataHarmRateV.class); - influxQueryWrapper.meanSamePrefixAndSuffix("v_", "", HarmonicTimesUtil.harmonicTimesList(2, 50, 1)) - .between(DataHarmRateV::getTime, startTime, endTime) - .eq(DataHarmRateV::getLineId, lineId) - .eq(DataHarmRateV::getValueType, InfluxDBTableConstant.CP95) - .ne(DataHarmRateV::getPhaseType, InfluxDBTableConstant.PHASE_TYPE_T); - DataHarmRateV dataHarmRateV = dataHarmRateVService.getMeanAllTimesData(influxQueryWrapper); - if (Objects.nonNull(dataHarmRateV)) { +// InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataHarmRateV.class); +// influxQueryWrapper.meanSamePrefixAndSuffix("v_", "", HarmonicTimesUtil.harmonicTimesList(2, 50, 1)) +// .between(DataHarmRateV::getTime, startTime, endTime) +// .eq(DataHarmRateV::getLineId, lineId) +// .eq(DataHarmRateV::getValueType, InfluxDBTableConstant.CP95) +// .ne(DataHarmRateV::getPhaseType, InfluxDBTableConstant.PHASE_TYPE_T); +// DataHarmRateV dataHarmRateV = dataHarmRateVService.getMeanAllTimesData(influxQueryWrapper); +// if (Objects.nonNull(dataHarmRateV)) { +// for (int i = 2; i < 51; i++) { +// floatList.add(PubUtils.getValueByMethodDouble(dataHarmRateV, "getV", i).floatValue()); +// } +// }else { +// for (int i = 2; i < 51; i++) { +// floatList.add(null); +// } +// } + //转换成查mysql统计数据,分钟数据没有值 + List harmV = dataHarmRateVDMapper.selectList(new LambdaQueryWrapper() + .eq(RStatDataHarmrateVDPO::getLineId, lineId) + .eq(RStatDataHarmrateVDPO::getValueType,"CP95") + .in(RStatDataHarmrateVDPO::getPhaseType, Arrays.asList("A","B","C")) + .ge(RStatDataHarmrateVDPO::getTime, DateUtil.beginOfDay(DateUtil.parse(startTime))) + .le(RStatDataHarmrateVDPO::getTime, DateUtil.endOfDay(DateUtil.parse(endTime))) + ); + + if (Objects.nonNull(harmV)) { for (int i = 2; i < 51; i++) { - floatList.add(PubUtils.getValueByMethodDouble(dataHarmRateV, "getV", i).floatValue()); + floatList.add(PubUtils.getValueByMethodDouble(harmV,RStatDataHarmrateVDPO.class, "getV", i).floatValue()); } }else { for (int i = 2; i < 51; i++) { floatList.add(null); } } + } else { - InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataI.class); - influxQueryWrapper.meanSamePrefixAndSuffix("i_", "", HarmonicTimesUtil.harmonicTimesList(2, 50, 1)) - .between(DataHarmRateV::getTime, startTime, endTime) - .eq(DataHarmRateV::getLineId, lineId) - .eq(DataHarmRateV::getValueType, InfluxDBTableConstant.CP95) - .ne(DataHarmRateV::getPhaseType, InfluxDBTableConstant.PHASE_TYPE_T); - DataI dataI = dataIService.getMeanAllTimesData(influxQueryWrapper); - if (Objects.nonNull(dataI)) { +// InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataI.class); +// influxQueryWrapper.meanSamePrefixAndSuffix("i_", "", HarmonicTimesUtil.harmonicTimesList(2, 50, 1)) +// .between(DataHarmRateV::getTime, startTime, endTime) +// .eq(DataHarmRateV::getLineId, lineId) +// .eq(DataHarmRateV::getValueType, InfluxDBTableConstant.CP95) +// .ne(DataHarmRateV::getPhaseType, InfluxDBTableConstant.PHASE_TYPE_T); +// DataI dataI = dataIService.getMeanAllTimesData(influxQueryWrapper); +// if (Objects.nonNull(dataI)) { +// for (int i = 2; i < 51; i++) { +// floatList.add(PubUtils.getValueByMethodDouble(dataI, "getI", i).floatValue()); +// } +// }else { +// for (int i = 2; i < 51; i++) { +// floatList.add(null); +// } +// } + + //转换成查mysql统计数据,分钟数据没有值 + List harmI = dataIDMapper.selectList(new LambdaQueryWrapper() + .eq(RStatDataIDPO::getLineId, lineId) + .eq(RStatDataIDPO::getValueType,"CP95") + .in(RStatDataIDPO::getPhaseType, Arrays.asList("A","B","C")) + .ge(RStatDataIDPO::getTime, DateUtil.beginOfDay(DateUtil.parse(startTime))) + .le(RStatDataIDPO::getTime, DateUtil.endOfDay(DateUtil.parse(endTime))) + ); + if (Objects.nonNull(harmI)) { for (int i = 2; i < 51; i++) { - floatList.add(PubUtils.getValueByMethodDouble(dataI, "getI", i).floatValue()); + floatList.add(PubUtils.getValueByMethodDouble(harmI,RStatDataIDPO.class, "getI", i).floatValue()); } }else { for (int i = 2; i < 51; i++) {