From c10d54e79a598df2bb8a7f29fd88372ff2205827 Mon Sep 17 00:00:00 2001 From: caozehui <2427765068@qq.com> Date: Fri, 30 Jan 2026 16:11:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/DetectionServiceImpl.java | 248 ++++++++++++------ 1 file changed, 169 insertions(+), 79 deletions(-) diff --git a/detection/src/main/java/com/njcn/gather/detection/service/impl/DetectionServiceImpl.java b/detection/src/main/java/com/njcn/gather/detection/service/impl/DetectionServiceImpl.java index 85582330..9ab29643 100644 --- a/detection/src/main/java/com/njcn/gather/detection/service/impl/DetectionServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/detection/service/impl/DetectionServiceImpl.java @@ -41,6 +41,7 @@ import com.njcn.gather.util.StorageUtil; import lombok.AllArgsConstructor; import lombok.Data; import lombok.RequiredArgsConstructor; +import lombok.extern.log4j.Log4j; import org.apache.commons.collections4.CollectionUtils; import org.springframework.stereotype.Service; @@ -60,6 +61,7 @@ import java.util.stream.Stream; * @description * @date 2024/12/20 13:52 */ +@Log4j @Service @RequiredArgsConstructor public class DetectionServiceImpl { @@ -2286,14 +2288,59 @@ public class DetectionServiceImpl { public Map>> devListMap(Map>> phaseValueList, DictDataEnum dataRule, boolean isRemoveMaxElement) { Map>> resultMap = new HashMap<>(3); - List aDev = BeanUtil.copyToList(phaseValueList.get(TYPE_A).get(0), Double.class); - List aStandardDev = BeanUtil.copyToList(phaseValueList.get(TYPE_A).get(1), Double.class); - List bDev = BeanUtil.copyToList(phaseValueList.get(TYPE_B).get(0), Double.class); - List bStandardDev = BeanUtil.copyToList(phaseValueList.get(TYPE_B).get(1), Double.class); - List cDev = BeanUtil.copyToList(phaseValueList.get(TYPE_C).get(0), Double.class); - List cStandardDev = BeanUtil.copyToList(phaseValueList.get(TYPE_C).get(1), Double.class); - List tDev = BeanUtil.copyToList(phaseValueList.get(TYPE_T).get(0), Double.class); - List tStandardDev = BeanUtil.copyToList(phaseValueList.get(TYPE_T).get(1), Double.class); + List aDev = new ArrayList<>(); + List aStandardDev = new ArrayList<>(); + + if (phaseValueList.containsKey(TYPE_A)) { + if (phaseValueList.get(TYPE_A).size() >= 1) { + aDev.addAll(BeanUtil.copyToList(phaseValueList.get(TYPE_A).get(0), Double.class)); + aStandardDev.addAll(BeanUtil.copyToList(phaseValueList.get(TYPE_A).get(1), Double.class)); + } else { + log.error("数据异常,phaseValueList.get(TYPE_A).size()=" + phaseValueList.get(TYPE_A).size()); + } + } else { + log.equals("数据异常,phaseValueList.containsKey(TYPE_A)=" + phaseValueList.containsKey(TYPE_A)); + } + + List bDev = new ArrayList<>(); + List bStandardDev = new ArrayList<>(); + + if (phaseValueList.containsKey(TYPE_B)) { + if (phaseValueList.get(TYPE_B).size() >= 1) { + bDev.addAll(BeanUtil.copyToList(phaseValueList.get(TYPE_B).get(0), Double.class)); + bStandardDev.addAll(BeanUtil.copyToList(phaseValueList.get(TYPE_B).get(1), Double.class)); + } else { + log.error("数据异常,phaseValueList.get(TYPE_B).size()=" + phaseValueList.get(TYPE_B).size()); + } + } else { + log.equals("数据异常,phaseValueList.containsKey(TYPE_B)=" + phaseValueList.containsKey(TYPE_B)); + } + + List cDev = new ArrayList<>(); + List cStandardDev = new ArrayList<>(); + if (phaseValueList.containsKey(TYPE_C)) { + if (phaseValueList.get(TYPE_C).size() >= 1) { + cDev.addAll(BeanUtil.copyToList(phaseValueList.get(TYPE_C).get(0), Double.class)); + cStandardDev.addAll(BeanUtil.copyToList(phaseValueList.get(TYPE_C).get(1), Double.class)); + } else { + log.error("数据异常,phaseValueList.get(TYPE_C).size()=" + phaseValueList.get(TYPE_C).size()); + } + } else { + log.equals("数据异常,phaseValueList.containsKey(TYPE_C)=" + phaseValueList.containsKey(TYPE_C)); + } + + List tDev = new ArrayList<>(); + List tStandardDev = new ArrayList<>(); + if (phaseValueList.containsKey(TYPE_T)) { + if (phaseValueList.get(TYPE_T).size() >= 1) { + tDev.addAll(BeanUtil.copyToList(phaseValueList.get(TYPE_T).get(0), Double.class)); + tStandardDev.addAll(BeanUtil.copyToList(phaseValueList.get(TYPE_T).get(1), Double.class)); + } else { + log.error("数据异常,phaseValueList.get(TYPE_T).size()=" + phaseValueList.get(TYPE_T).size()); + } + } else { + log.equals("数据异常,phaseValueList.containsKey(TYPE_T)=" + phaseValueList.containsKey(TYPE_T)); + } if (isRemoveMaxElement) { List aErrorValueList = new ArrayList<>(); @@ -2350,12 +2397,12 @@ public class DetectionServiceImpl { tDev.addAll(newArray); } - List aIdxs = DetectionUtil.sort(aStandardDev, false); - List bIdxs = DetectionUtil.sort(bStandardDev, false); - List cIdxs = DetectionUtil.sort(cStandardDev, false); - List tIdxs = DetectionUtil.sort(tStandardDev, false); switch (dataRule) { - case SECTION_VALUE: + case SECTION_VALUE: { + List aIdxs = DetectionUtil.sort(aStandardDev, false); + List bIdxs = DetectionUtil.sort(bStandardDev, false); + List cIdxs = DetectionUtil.sort(cStandardDev, false); + List tIdxs = DetectionUtil.sort(tStandardDev, false); if (aStandardDev.size() > 2) { aStandardDev.remove(0); aStandardDev.remove(aStandardDev.size() - 1); @@ -2363,7 +2410,6 @@ public class DetectionServiceImpl { aDev.clear(); aDev.addAll(newArray); } - if (bStandardDev.size() > 2) { bStandardDev.remove(0); bStandardDev.remove(bStandardDev.size() - 1); @@ -2371,7 +2417,6 @@ public class DetectionServiceImpl { bDev.clear(); bDev.addAll(newArray); } - if (cStandardDev.size() > 2) { cStandardDev.remove(0); cStandardDev.remove(cStandardDev.size() - 1); @@ -2379,7 +2424,6 @@ public class DetectionServiceImpl { cDev.clear(); cDev.addAll(newArray); } - if (tStandardDev.size() > 2) { tStandardDev.remove(0); tStandardDev.remove(tStandardDev.size() - 1); @@ -2387,8 +2431,13 @@ public class DetectionServiceImpl { tDev.clear(); tDev.addAll(newArray); } - break; - case CP95_VALUE: + } + break; + case CP95_VALUE: { + List aIdxs = DetectionUtil.sort(aStandardDev, false); + List bIdxs = DetectionUtil.sort(bStandardDev, false); + List cIdxs = DetectionUtil.sort(cStandardDev, false); + List tIdxs = DetectionUtil.sort(tStandardDev, false); if (CollUtil.isNotEmpty(aStandardDev)) { int cp95Idx = DetectionUtil.getCP95Idx(aStandardDev); aStandardDev = Collections.singletonList(aStandardDev.get(cp95Idx)); @@ -2399,20 +2448,18 @@ public class DetectionServiceImpl { bStandardDev = Collections.singletonList(bStandardDev.get(cp95Idx)); bDev = Collections.singletonList(bDev.get(bIdxs.get(cp95Idx))); } - if (CollUtil.isNotEmpty(cStandardDev)) { int cp95Idx = DetectionUtil.getCP95Idx(cStandardDev); cStandardDev = Collections.singletonList(cStandardDev.get(cp95Idx)); cDev = Collections.singletonList(cDev.get(cIdxs.get(cp95Idx))); } - if (CollUtil.isNotEmpty(tStandardDev)) { int cp95Idx = DetectionUtil.getCP95Idx(tStandardDev); tStandardDev = Collections.singletonList(tStandardDev.get(cp95Idx)); tDev = Collections.singletonList(tDev.get(tIdxs.get(cp95Idx))); } - - break; + } + break; case AVG_VALUE: aDev = DetectionUtil.getAvgDoubles(aDev); bDev = DetectionUtil.getAvgDoubles(bDev); @@ -2425,54 +2472,82 @@ public class DetectionServiceImpl { tStandardDev = DetectionUtil.getAvgDoubles(tStandardDev); break; case Own_value: - List newArray = DetectionUtil.getNewArray(aDev, aIdxs); - aDev.clear(); - aDev.addAll(newArray); - - newArray = DetectionUtil.getNewArray(bDev, bIdxs); - bDev.clear(); - bDev.addAll(newArray); - - newArray = DetectionUtil.getNewArray(cDev, cIdxs); - cDev.clear(); - cDev.addAll(newArray); - - newArray = DetectionUtil.getNewArray(tDev, tIdxs); - tDev.clear(); - tDev.addAll(newArray); break; case AT_WILL_VALUE: - if (CollUtil.isNotEmpty(aStandardDev)) { - aStandardDev = aStandardDev.subList(0, 1); - } - if (CollUtil.isNotEmpty(aDev)) { - Double v = aDev.get(aIdxs.get(0)); - aDev.clear(); - aDev.add(v); - } - if (CollUtil.isNotEmpty(bStandardDev)) { - bStandardDev = bStandardDev.subList(0, 1); - } - if (CollUtil.isNotEmpty(bDev)) { - Double v = bDev.get(bIdxs.get(0)); - bDev.clear(); - bDev.add(v); - } - if (CollUtil.isNotEmpty(cStandardDev)) { - cStandardDev = cStandardDev.subList(0, 1); - } - if (CollUtil.isNotEmpty(cDev)) { - Double v = cDev.get(cIdxs.get(0)); - cDev.clear(); - cDev.add(v); - } - if (CollUtil.isNotEmpty(tStandardDev)) { - tStandardDev = tStandardDev.subList(0, 1); - } - if (CollUtil.isNotEmpty(tDev)) { - Double v = tDev.get(tIdxs.get(0)); - tDev.clear(); - tDev.add(v); + if (isRemoveMaxElement) { + if (CollUtil.isNotEmpty(aStandardDev) && CollUtil.isNotEmpty(aDev)) { + aStandardDev = aStandardDev.subList(aStandardDev.size() - 1, aStandardDev.size()); + aDev = aDev.subList(aDev.size() - 1, aDev.size()); + } + if (CollUtil.isNotEmpty(bStandardDev) && CollUtil.isNotEmpty(bDev)) { + bStandardDev = bStandardDev.subList(bStandardDev.size() - 1, bStandardDev.size()); + bDev = bDev.subList(bDev.size() - 1, bDev.size()); + } + if (CollUtil.isNotEmpty(cStandardDev) && CollUtil.isNotEmpty(cDev)) { + cStandardDev = cStandardDev.subList(cStandardDev.size() - 1, cStandardDev.size()); + cDev = cDev.subList(cDev.size() - 1, cDev.size()); + } + if (CollUtil.isNotEmpty(tStandardDev) && CollUtil.isNotEmpty(tDev)) { + tStandardDev = tStandardDev.subList(tStandardDev.size() - 1, tStandardDev.size()); + tDev = tDev.subList(tDev.size() - 1, tDev.size()); + } + } else { + List aErrorValueList = new ArrayList<>(); + List bErrorValueList = new ArrayList<>(); + List cErrorValueList = new ArrayList<>(); + List tErrorValueList = new ArrayList<>(); + for (int i = 0; i < aStandardDev.size(); i++) { + aErrorValueList.add(Math.abs(aStandardDev.get(i) - aDev.get(i))); + } + for (int i = 0; i < bStandardDev.size(); i++) { + bErrorValueList.add(Math.abs(bStandardDev.get(i) - bDev.get(i))); + } + for (int i = 0; i < cStandardDev.size(); i++) { + cErrorValueList.add(Math.abs(cStandardDev.get(i) - cDev.get(i))); + } + for (int i = 0; i < tStandardDev.size(); i++) { + tErrorValueList.add(Math.abs(tStandardDev.get(i) - tDev.get(i))); + } + List aErrorValueIdxs = DetectionUtil.sort(aErrorValueList, true); + List bErrorValueIdxs = DetectionUtil.sort(bErrorValueList, true); + List cErrorValueIdxs = DetectionUtil.sort(cErrorValueList, true); + List tErrorValueIdxs = DetectionUtil.sort(tErrorValueList, true); + + if (CollUtil.isNotEmpty(aStandardDev) && CollUtil.isNotEmpty(aDev)) { + Double v = aStandardDev.get(aErrorValueIdxs.get(0)); + aStandardDev.clear(); + aStandardDev.add(v); + v = aDev.get(aErrorValueIdxs.get(0)); + aDev.clear(); + aDev.add(v); + } + + if (CollUtil.isNotEmpty(bStandardDev) && CollUtil.isNotEmpty(bDev)) { + Double v = bStandardDev.get(bErrorValueIdxs.get(0)); + bStandardDev.clear(); + bStandardDev.add(v); + v = bDev.get(bErrorValueIdxs.get(0)); + bDev.clear(); + bDev.add(v); + } + + if (CollUtil.isNotEmpty(cStandardDev) && CollUtil.isNotEmpty(cDev)) { + Double v = cStandardDev.get(cErrorValueIdxs.get(0)); + cStandardDev.clear(); + cStandardDev.add(v); + v = cDev.get(cErrorValueIdxs.get(0)); + cDev.clear(); + cDev.add(v); + } + + if (CollUtil.isNotEmpty(tStandardDev) && CollUtil.isNotEmpty(tDev)) { + Double v = tStandardDev.get(tErrorValueIdxs.get(0)); + tStandardDev.clear(); + tStandardDev.add(v); + v = tDev.get(tErrorValueIdxs.get(0)); + tDev.clear(); + tDev.add(v); + } } break; } @@ -2647,9 +2722,10 @@ public class DetectionServiceImpl { } if (CollUtil.isNotEmpty(value)) { - List idx = DetectionUtil.sort(value, false); + switch (dataRule) { - case SECTION_VALUE: + case SECTION_VALUE: { + List idx = DetectionUtil.sort(value, false); if (value.size() > 2) { value.remove(0); value.remove(value.size() - 1); @@ -2657,9 +2733,11 @@ public class DetectionServiceImpl { devPhaseHarmData.clear(); devPhaseHarmData.addAll(newArray); } - break; + } + break; case CP95_VALUE: if (CollUtil.isNotEmpty(value)) { + List idx = DetectionUtil.sort(value, false); int cp95Idx = DetectionUtil.getCP95Idx(value); List newValue = Collections.singletonList(value.get(cp95Idx)); value.clear(); @@ -2678,18 +2756,30 @@ public class DetectionServiceImpl { devPhaseHarmData.addAll(devAvgData); break; case Own_value: - List newArray = DetectionUtil.getNewArray(devPhaseHarmData, idx); - devPhaseHarmData.clear(); - devPhaseHarmData.addAll(newArray); break; case AT_WILL_VALUE: - if (CollUtil.isNotEmpty(value)) { - Double v = value.get(0); + if (isRemoveMaxElement) { + if (CollUtil.isNotEmpty(value)) { + Double v = value.get(value.size() - 1); + value.clear(); + value.add(v); + } + if (CollUtil.isNotEmpty(devPhaseHarmData)) { + Double v = devPhaseHarmData.get(devPhaseHarmData.size() - 1); + devPhaseHarmData.clear(); + devPhaseHarmData.add(v); + } + } else { + List errorValueList = new ArrayList<>(); + for (int i = 0; i < value.size(); i++) { + errorValueList.add(Math.abs(value.get(i) - devPhaseHarmData.get(i))); + } + + List idxErrorValueList = DetectionUtil.sort(errorValueList, true); + Double v = value.get(idxErrorValueList.get(0)); value.clear(); value.add(v); - } - if (CollUtil.isNotEmpty(devPhaseHarmData)) { - Double v = devPhaseHarmData.get(idx.get(0)); + v = devPhaseHarmData.get(idxErrorValueList.get(0)); devPhaseHarmData.clear(); devPhaseHarmData.add(v); }