From 7d9991fa2029706d8930b34a86b1e2f376f62311 Mon Sep 17 00:00:00 2001 From: xuyang <748613696@qq.com> Date: Mon, 13 Nov 2023 15:53:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=AE=97=E6=B3=95=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mysql/Impl/line/LimitRateServiceImpl.java | 117 +++++++++++------- 1 file changed, 70 insertions(+), 47 deletions(-) diff --git a/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/mysql/Impl/line/LimitRateServiceImpl.java b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/mysql/Impl/line/LimitRateServiceImpl.java index f904c3b67..98a5c323e 100644 --- a/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/mysql/Impl/line/LimitRateServiceImpl.java +++ b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/mysql/Impl/line/LimitRateServiceImpl.java @@ -20,6 +20,7 @@ import com.njcn.prepare.harmonic.service.mysql.day.IRStatLimitRateDService; import com.njcn.prepare.harmonic.service.mysql.line.LimitRateService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.ListUtils; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @@ -57,8 +58,18 @@ public class LimitRateServiceImpl extends MppServiceImpl limitRateList = new ArrayList<> (); List list = new ArrayList<>(); + List list1 = new ArrayList<>(); + List list2 = new ArrayList<>(); + List list3 = new ArrayList<>(); + List list4 = new ArrayList<>(); + List list5 = new ArrayList<>(); + List list6 = new ArrayList<>(); + List list7 = new ArrayList<>(); + List list8 = new ArrayList<>(); + List list9 = new ArrayList<>(); + List list10 = new ArrayList<>(); + List list11 = new ArrayList<>(); List lineIds = calculatedParam.getIdList(); String startTime = LocalDateTimeUtil.format( LocalDateTimeUtil.beginOfDay(LocalDateTimeUtil.parse(calculatedParam.getDataDate(), DatePattern.NORM_DATE_PATTERN)), @@ -68,35 +79,47 @@ public class LimitRateServiceImpl extends MppServiceImpl map1 = getAllTime(lineIndex,startTime,endTime); - List map2 = getFlickerAllTime(lineIndex,startTime,endTime); - List map3 = getDataHarmRateV(lineIndex,startTime,endTime); - List map4 = getDataI(lineIndex,startTime,endTime); - List map5 = getDataInHarmV(lineIndex,startTime,endTime); - List map6 = getDataV(lineIndex,startTime,endTime); - List map7 = getDataVUnbalance(lineIndex,startTime,endTime); - List map8 = getDataINeg(lineIndex,startTime,endTime); - List map9 = getDataVFreq(lineIndex,startTime,endTime); - List map10 = getDataVDev(lineIndex,startTime,endTime); - List map11 = getDataPlt(lineIndex,startTime,endTime); - - List result = getData(overlimit,map1,map2,map3,map4,map5,map6,map7,map8,map9,map10,map11); - limitRateList.addAll (result); - List collect = result.stream().map (t -> { + //获取所有监测点的限值 + List overLimitList = commTerminalGeneralClient.getAllLineOverLimit().getData(); + Map> overLimitMap = overLimitList.stream().collect(Collectors.groupingBy(Overlimit::getId)); + //以尺寸100分片,查询数据 + List> pendingIds = ListUtils.partition(lineIds,100); + for (List pendingId : pendingIds) { + list1.addAll(getAllTime(pendingId, startTime, endTime)); + list2.addAll(getFlickerAllTime(pendingId, startTime, endTime)); + list3.addAll(getDataHarmRateV(pendingId, startTime, endTime)); + list4.addAll(getDataI(pendingId, startTime, endTime)); + list5.addAll(getDataInHarmV(pendingId, startTime, endTime)); + list6.addAll(getDataVThd(pendingId, startTime, endTime)); + list7.addAll(getDataVUnbalance(pendingId, startTime, endTime)); + list8.addAll(getDataINeg(pendingId, startTime, endTime)); + list9.addAll(getDataVFreq(pendingId, startTime, endTime)); + list10.addAll(getDataVDev(pendingId, startTime, endTime)); + list11.addAll(getDataPlt(pendingId, startTime, endTime)); + } + //数据处理,按监测点分组 + Map> map1 = list1.stream().collect(Collectors.groupingBy(DataV::getLineId)); + Map> map2 = list2.stream().collect(Collectors.groupingBy(DataPlt::getLineId)); + Map> map3 = list3.stream().collect(Collectors.groupingBy(DataHarmRateV::getLineId)); + Map> map4 = list4.stream().collect(Collectors.groupingBy(DataI::getLineId)); + Map> map5 = list5.stream().collect(Collectors.groupingBy(DataInHarmV::getLineId)); + Map> map6 = list6.stream().collect(Collectors.groupingBy(DataV::getLineId)); + Map> map7 = list7.stream().collect(Collectors.groupingBy(DataV::getLineId)); + Map> map8 = list8.stream().collect(Collectors.groupingBy(DataI::getLineId)); + Map> map9 = list9.stream().collect(Collectors.groupingBy(DataV::getLineId)); + Map> map10 = list10.stream().collect(Collectors.groupingBy(DataV::getLineId)); + Map> map11 = list11.stream().collect(Collectors.groupingBy(DataPlt::getLineId)); + for (String item : lineIds) { + List result = getData(overLimitMap.get(item).get(0), map1.get(item), map2.get(item), map3.get(item), map4.get(item), map5.get(item), map6.get(item), map7.get(item), map8.get(item), map9.get(item), map10.get(item), map11.get(item)); + List collect = result.stream().map(t -> { RStatLimitRateDPO po = new RStatLimitRateDPO(); - NjcnBeanUtil.copyPropertiesIgnoreCase (t,po); + NjcnBeanUtil.copyPropertiesIgnoreCase(t, po); po.setTime(LocalDateTimeUtil.parseDate(calculatedParam.getDataDate(), DatePattern.NORM_DATE_PATTERN)); return po; - }).collect (Collectors.toList()); + }).collect(Collectors.toList()); list.addAll(collect); } - if (!CollectionUtils.isEmpty(limitRateList)){ + if (!CollectionUtils.isEmpty(list)){ /*插入mysql*/ statLimitRateDService.saveOrUpdateBatchByMultiId(list,1000); } @@ -111,9 +134,9 @@ public class LimitRateServiceImpl extends MppServiceImpl getAllTime(String lineIndex, String startTime, String endTime) { + public List getAllTime(List lineIndex, String startTime, String endTime) { InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataV.class); - influxQueryWrapper.eq(DataV::getLineId, lineIndex) + influxQueryWrapper.regular(DataV::getLineId, lineIndex) .eq(DataV::getValueType, InfluxDbSqlConstant.AVG_WEB) .eq(DataV::getPhasicType, InfluxDBTableConstant.PHASE_TYPE_A) .eq(DataV::getQualityFlag, InfluxDBTableConstant.NORMAL) @@ -132,9 +155,9 @@ public class LimitRateServiceImpl extends MppServiceImpl getFlickerAllTime(String lineIndex, String startTime, String endTime) { + public List getFlickerAllTime(List lineIndex, String startTime, String endTime) { InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataPlt.class); - influxQueryWrapper.eq(DataPlt::getLineId, lineIndex) + influxQueryWrapper.regular(DataPlt::getLineId, lineIndex) .eq(DataPlt::getPhaseType, InfluxDBTableConstant.PHASE_TYPE_A) .eq(DataPlt::getQualityFlag, InfluxDBTableConstant.NORMAL) .count(DataPlt::getPlt,DataPlt::getFlickerAllTime) @@ -152,9 +175,9 @@ public class LimitRateServiceImpl extends MppServiceImpl getDataHarmRateV(String lineIndex, String startTime, String endTime) { + public List getDataHarmRateV(List lineIndex, String startTime, String endTime) { InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataHarmRateV.class); - influxQueryWrapper.eq(DataHarmRateV::getLineId, lineIndex) + influxQueryWrapper.regular(DataHarmRateV::getLineId, lineIndex) .regular(DataHarmRateV::getPhaseType, Arrays.asList(InfluxDBTableConstant.PHASE_TYPE_A,InfluxDBTableConstant.PHASE_TYPE_B,InfluxDBTableConstant.PHASE_TYPE_C)) .eq(DataHarmRateV::getValueType, InfluxDBTableConstant.CP95) .eq(DataHarmRateV::getQualityFlag, InfluxDBTableConstant.NORMAL) @@ -170,9 +193,9 @@ public class LimitRateServiceImpl extends MppServiceImpl getDataI(String lineIndex, String startTime, String endTime) { + public List getDataI(List lineIndex, String startTime, String endTime) { InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataI.class); - influxQueryWrapper.eq(DataI::getLineId, lineIndex) + influxQueryWrapper.regular(DataI::getLineId, lineIndex) .regular(DataI::getPhaseType, Arrays.asList(InfluxDBTableConstant.PHASE_TYPE_A,InfluxDBTableConstant.PHASE_TYPE_B,InfluxDBTableConstant.PHASE_TYPE_C)) .eq(DataI::getValueType, InfluxDBTableConstant.CP95) .eq(DataI::getQualityFlag, InfluxDBTableConstant.NORMAL) @@ -189,9 +212,9 @@ public class LimitRateServiceImpl extends MppServiceImpl getDataInHarmV(String lineIndex, String startTime, String endTime) { + public List getDataInHarmV(List lineIndex, String startTime, String endTime) { InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataInHarmV.class); - influxQueryWrapper.eq(DataInHarmV::getLineId, lineIndex) + influxQueryWrapper.regular(DataInHarmV::getLineId, lineIndex) .regular(DataInHarmV::getPhaseType, Arrays.asList(InfluxDBTableConstant.PHASE_TYPE_A,InfluxDBTableConstant.PHASE_TYPE_B,InfluxDBTableConstant.PHASE_TYPE_C)) .eq(DataInHarmV::getValueType, InfluxDBTableConstant.CP95) .eq(DataInHarmV::getQualityFlag, InfluxDBTableConstant.NORMAL) @@ -208,9 +231,9 @@ public class LimitRateServiceImpl extends MppServiceImpl getDataV(String lineIndex, String startTime, String endTime) { + public List getDataVThd(List lineIndex, String startTime, String endTime) { InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataV.class); - influxQueryWrapper.eq(DataV::getLineId, lineIndex) + influxQueryWrapper.regular(DataV::getLineId, lineIndex) .eq(DataV::getValueType, InfluxDbSqlConstant.CP95) .regular(DataV::getPhasicType, Arrays.asList(InfluxDBTableConstant.PHASE_TYPE_A,InfluxDBTableConstant.PHASE_TYPE_B,InfluxDBTableConstant.PHASE_TYPE_C)) .eq(DataV::getQualityFlag, InfluxDBTableConstant.NORMAL) @@ -227,9 +250,9 @@ public class LimitRateServiceImpl extends MppServiceImpl getDataVUnbalance(String lineIndex, String startTime, String endTime) { + public List getDataVUnbalance(List lineIndex, String startTime, String endTime) { InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataV.class); - influxQueryWrapper.eq(DataV::getLineId, lineIndex) + influxQueryWrapper.regular(DataV::getLineId, lineIndex) .regular(DataV::getValueType, Arrays.asList(InfluxDbSqlConstant.CP95,InfluxDbSqlConstant.MAX)) .eq(DataV::getPhasicType, InfluxDBTableConstant.PHASE_TYPE_T) .eq(DataV::getQualityFlag, InfluxDBTableConstant.NORMAL) @@ -246,9 +269,9 @@ public class LimitRateServiceImpl extends MppServiceImpl getDataINeg(String lineIndex, String startTime, String endTime) { + public List getDataINeg(List lineIndex, String startTime, String endTime) { InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataI.class); - influxQueryWrapper.eq(DataI::getLineId, lineIndex) + influxQueryWrapper.regular(DataI::getLineId, lineIndex) .eq(DataI::getPhaseType, InfluxDBTableConstant.PHASE_TYPE_T) .regular(DataI::getValueType, Arrays.asList(InfluxDbSqlConstant.CP95,InfluxDbSqlConstant.MAX)) .eq(DataI::getQualityFlag, InfluxDBTableConstant.NORMAL) @@ -265,9 +288,9 @@ public class LimitRateServiceImpl extends MppServiceImpl getDataVFreq(String lineIndex, String startTime, String endTime) { + public List getDataVFreq(List lineIndex, String startTime, String endTime) { InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataV.class); - influxQueryWrapper.eq(DataV::getLineId, lineIndex) + influxQueryWrapper.regular(DataV::getLineId, lineIndex) .regular(DataV::getValueType, Arrays.asList(InfluxDbSqlConstant.MIN,InfluxDbSqlConstant.MAX)) .eq(DataV::getPhasicType, InfluxDBTableConstant.PHASE_TYPE_T) .eq(DataV::getQualityFlag, InfluxDBTableConstant.NORMAL) @@ -284,9 +307,9 @@ public class LimitRateServiceImpl extends MppServiceImpl getDataVDev(String lineIndex, String startTime, String endTime) { + public List getDataVDev(List lineIndex, String startTime, String endTime) { InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataV.class); - influxQueryWrapper.eq(DataV::getLineId, lineIndex) + influxQueryWrapper.regular(DataV::getLineId, lineIndex) .eq(DataV::getValueType, InfluxDbSqlConstant.MAX) .regular(DataV::getPhasicType, Arrays.asList(InfluxDBTableConstant.PHASE_TYPE_A,InfluxDBTableConstant.PHASE_TYPE_B,InfluxDBTableConstant.PHASE_TYPE_C)) .eq(DataV::getQualityFlag, InfluxDBTableConstant.NORMAL) @@ -303,9 +326,9 @@ public class LimitRateServiceImpl extends MppServiceImpl getDataPlt(String lineIndex, String startTime, String endTime) { + public List getDataPlt(List lineIndex, String startTime, String endTime) { InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataPlt.class); - influxQueryWrapper.eq(DataPlt::getLineId, lineIndex) + influxQueryWrapper.regular(DataPlt::getLineId, lineIndex) .regular(DataPlt::getPhaseType, Arrays.asList(InfluxDBTableConstant.PHASE_TYPE_A,InfluxDBTableConstant.PHASE_TYPE_B,InfluxDBTableConstant.PHASE_TYPE_C)) .eq(DataPlt::getQualityFlag, InfluxDBTableConstant.NORMAL) .between(DataPlt::getTime, startTime, endTime);