diff --git a/detection/src/main/java/com/njcn/gather/freqConverter/service/impl/FreqConverterServiceImpl.java b/detection/src/main/java/com/njcn/gather/freqConverter/service/impl/FreqConverterServiceImpl.java index 57ea9f4d..fabd414f 100644 --- a/detection/src/main/java/com/njcn/gather/freqConverter/service/impl/FreqConverterServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/freqConverter/service/impl/FreqConverterServiceImpl.java @@ -18,11 +18,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; /** @@ -128,11 +124,32 @@ public class FreqConverterServiceImpl extends ServiceImpl> durationPointMap = dipPoints.stream() - .collect(Collectors.groupingBy(TolerantPointVO::getDurationMs)); + .collect(Collectors.groupingBy(TolerantPointVO::getDurationMs, TreeMap::new, Collectors.toList())); + if (durationPointMap.size() < 2) { + return new ArrayList<>(); + } List result = new ArrayList<>(); + + TolerantPointVO firstPoint = new TolerantPointVO(); + + List keyList = durationPointMap.keySet().stream().collect(Collectors.toList()); + Integer i1 = keyList.get(0); + List tolerantPointVOS1 = durationPointMap.get(i1); + Collections.sort(tolerantPointVOS1,Comparator.comparing(TolerantPointVO::getResidualVoltage)); + TolerantPointVO tolerantPointVO1 = tolerantPointVOS1.get(0); + + Integer i2 = keyList.get(1); + List tolerantPointVOS2 = durationPointMap.get(i2); + Collections.sort(tolerantPointVOS2,Comparator.comparing(TolerantPointVO::getResidualVoltage)); + TolerantPointVO tolerantPointVO2 = tolerantPointVOS2.get(0); + + firstPoint.setDurationMs((i1 + i2)/2); + firstPoint.setResidualVoltage((tolerantPointVO1.getResidualVoltage() + tolerantPointVO2.getResidualVoltage()) / 2D); + firstPoint.setTolerant(2); + result.add(firstPoint); + durationPointMap.entrySet().stream() - .sorted(Map.Entry.comparingByKey()) .forEach(entry -> { List sameDurationPoints = entry.getValue().stream() .sorted(Comparator.comparing(TolerantPointVO::getResidualVoltage, Comparator.reverseOrder()))