From 69581014357471efe9c0604c64f84c170f7e60b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=A8=E6=9C=A8c?= <857448963@qq.com> Date: Thu, 19 Oct 2023 13:29:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=86=E5=8F=B2=E8=B6=8B=E5=8A=BF=E5=9B=BE?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/HistoryResultServiceImpl.java | 164 +++++++++++++----- 1 file changed, 123 insertions(+), 41 deletions(-) diff --git a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/HistoryResultServiceImpl.java b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/HistoryResultServiceImpl.java index daace674e..875da1dbc 100644 --- a/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/HistoryResultServiceImpl.java +++ b/pqs-harmonic/harmonic-boot/src/main/java/com/njcn/harmonic/service/impl/HistoryResultServiceImpl.java @@ -53,6 +53,7 @@ import org.springframework.util.CollectionUtils; import java.math.BigDecimal; import java.math.RoundingMode; import java.text.SimpleDateFormat; +import java.time.Instant; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.stream.Collectors; @@ -193,8 +194,53 @@ public class HistoryResultServiceImpl implements HistoryResultService { historyDataResultVO.setMaxValue(Collections.max(fValue)); historyDataResultVO.setValue(objectListData); } else { - //按相别分为3组 - List aList = harmonicHistoryDataList.stream() + //按时间分组 + Map> map = harmonicHistoryDataList.stream().collect(Collectors.groupingBy(HarmonicHistoryData::getTime,TreeMap::new, Collectors.toList())); + + Float maxI = null; + Float minI = null; + for (Map.Entry> entry : map.entrySet()) { + List val = entry.getValue(); + Object[] objects = {PubUtils.instantToDate(entry.getKey()),0,0,0}; + //需要保证val的长度为3 + if(val.size()!=3){ + for(int i =0;i<3-val.size();i++){ + HarmonicHistoryData tem = new HarmonicHistoryData(); + tem.setAValue(0f); + val.add(tem); + } + } + + for (HarmonicHistoryData harmonicHistoryData : val) { + if (InfluxDBTableConstant.PHASE_TYPE_A.equalsIgnoreCase(harmonicHistoryData.getPhasicType())) { + + BigDecimal a = BigDecimal.valueOf(harmonicHistoryData.getAValue()).setScale(4, RoundingMode.HALF_UP); + objects[1] =a; + maxI = max(maxI, a.floatValue()); + minI = min(minI, a.floatValue()); + + } else if (InfluxDBTableConstant.PHASE_TYPE_B.equalsIgnoreCase(harmonicHistoryData.getPhasicType())) { + BigDecimal b = BigDecimal.valueOf(harmonicHistoryData.getAValue()).setScale(4, RoundingMode.HALF_UP); + objects[2] = b; + maxI = max(maxI, b.floatValue()); + minI = min(minI, b.floatValue()); + + } else if (InfluxDBTableConstant.PHASE_TYPE_C.equalsIgnoreCase(harmonicHistoryData.getPhasicType())) { + BigDecimal c = BigDecimal.valueOf(harmonicHistoryData.getAValue()).setScale(4, RoundingMode.HALF_UP); + objects[3] = c; + maxI = max(maxI, c.floatValue()); + minI = min(minI, c.floatValue()); + + } + } + List list = new ArrayList<>(Arrays.asList(objects)); + + objectListData.add(list); + + }; + + //下面代码稳定后可删除 + /* List aList = harmonicHistoryDataList.stream() .filter(temp -> temp.getPhasicType().equalsIgnoreCase(InfluxDBTableConstant.PHASE_TYPE_A)) .collect(Collectors.toList()); List bList = harmonicHistoryDataList.stream() @@ -203,9 +249,23 @@ public class HistoryResultServiceImpl implements HistoryResultService { List cList = harmonicHistoryDataList.stream() .filter(temp -> temp.getPhasicType().equalsIgnoreCase(InfluxDBTableConstant.PHASE_TYPE_C)) .collect(Collectors.toList()); - time = aList.stream() - .map(temp -> PubUtils.instantToDate(temp.getTime())) - .collect(Collectors.toList()); + + int maxSize = Math.max(aList.size(), Math.max(bList.size(), cList.size())); + if (maxSize == aList.size()) { + time = aList.stream() + .map(temp -> PubUtils.instantToDate(temp.getTime())) + .collect(Collectors.toList()); + } else if (maxSize == bList.size()) { + time = bList.stream() + .map(temp -> PubUtils.instantToDate(temp.getTime())) + .collect(Collectors.toList()); + } else { + time = cList.stream() + .map(temp -> PubUtils.instantToDate(temp.getTime())) + .collect(Collectors.toList()); + } + + aValue = aList.stream() .map(temp -> BigDecimal.valueOf(temp.getAValue()).setScale(4, RoundingMode.HALF_UP).floatValue()) .collect(Collectors.toList()); @@ -261,8 +321,9 @@ public class HistoryResultServiceImpl implements HistoryResultService { .max(Float::compareTo); if (min.isPresent()) { historyDataResultVO.setMaxValue(max.get()); - } - + }*/ + historyDataResultVO.setMaxValue(maxI); + historyDataResultVO.setMinValue(minI); historyDataResultVO.setTopLimit(queryResultLimitVO.getTopLimit()); historyDataResultVO.setLowerLimit(queryResultLimitVO.getLowerLimit()); historyDataResultVO.setValue(objectListData); @@ -274,6 +335,27 @@ public class HistoryResultServiceImpl implements HistoryResultService { return historyDataResultVO; } + + private Float max(Float ding,Float a){ + if(Objects.isNull(ding)){ + ding = a; + } + if(a>ding){ + ding = a; + } + return ding; + } + + private Float min(Float ding,Float a){ + if(Objects.isNull(ding)){ + ding = a; + } + if(a