From 3fcad5ff76d65ad2bddcb842a3373bfab1aff0dd Mon Sep 17 00:00:00 2001 From: wr <1754607820@qq.com> Date: Thu, 10 Apr 2025 15:25:02 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=9A=82=E6=80=81=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E9=A1=B9=EF=BC=8Cicd=E5=88=86=E9=A1=B9=E5=92=8C?= =?UTF-8?q?=E4=B8=8D=E5=88=86=E9=A1=B9=E5=8A=9F=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../detection/pojo/vo/DetectionData.java | 2 +- .../service/impl/DetectionServiceImpl.java | 139 +++++++++++++++--- .../detection/util/socket/UnitUtil.java | 2 +- .../service/impl/PqScriptDtlsServiceImpl.java | 2 +- .../service/impl/AdHarmonicServiceImpl.java | 17 +-- .../impl/AdNonHarmonicServiceImpl.java | 24 ++- .../log/service/ISysLogAuditService.java | 3 - 7 files changed, 141 insertions(+), 48 deletions(-) diff --git a/detection/src/main/java/com/njcn/gather/detection/pojo/vo/DetectionData.java b/detection/src/main/java/com/njcn/gather/detection/pojo/vo/DetectionData.java index 67ce2c96..bbfcb2f6 100644 --- a/detection/src/main/java/com/njcn/gather/detection/pojo/vo/DetectionData.java +++ b/detection/src/main/java/com/njcn/gather/detection/pojo/vo/DetectionData.java @@ -20,7 +20,7 @@ public class DetectionData { private Double num; /** - * 是否是符合数据 + * 是否是符合数据(1.合格 2.不合格 3.网络超时 4.无法处理 5.不参与误差比较) */ private Integer isData; 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 2ddf7db0..ae0a87b4 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 @@ -303,7 +303,7 @@ public class DetectionServiceImpl { if (devIndex.contains("P")) { type = P; harmCode = DetectionCodeEnum.P2_50.getCode(); - fData = sourceIssue.getFIn() * sourceIssue.getFUn() * 0.01; + fData = (sourceIssue.getFIn() * sourceIssue.getFUn()) * 0.01; } Map>> devHarmMap = devHarmListMap(dev, sourceIssue, dataRule, fundCode, harmCode, num); if (CollUtil.isNotEmpty(devHarmMap)) { @@ -487,7 +487,7 @@ public class DetectionServiceImpl { } } if (P.equals(type)) { - fData = sourceIssue.getFIn() * sourceIssue.getFUn() * 0.01; + fData = (sourceIssue.getFIn() * sourceIssue.getFUn()) * 0.01; harmCode = DetectionCodeEnum.P2_50.getCode(); } Map>> devMap = devHarmListMap(dev, sourceIssue, dataRule, fundCode, harmCode, num); @@ -613,6 +613,14 @@ public class DetectionServiceImpl { /** * 判断值是否在误差范围内,有则进行判断否则则不进行计算(暂态) * + * (假如都符合,则选取最开始合格的,都不合格,取最开始不合格的) + * 方案一 分项问题 + * 分别计算各个相别是否合格 + * 不合格电压幅值的层级最高 + * + * 方案二 不分项问题 + * 以电压幅值最低的作为比较相别 + * * @param dev 处理过后的数据 * @param errDtlsCheckData 误差体系 * @param sourceIssue 源下发所对应的参数 @@ -635,14 +643,80 @@ public class DetectionServiceImpl { //暂态电压下多少就是多少 List magErrList = errDtlsCheckData.stream().filter(x -> MAG.equals(x.getValueTypeCode())).collect(Collectors.toList()); List durErrList = errDtlsCheckData.stream().filter(x -> DUR.equals(x.getValueTypeCode())).collect(Collectors.toList()); - AdNonHarmonicResult magResult = voltageResult(dev.get(0).getId(), devIdMapComm, sourceIssue, dataRule, mag, magErrList, sourceIssue.getFUn(), MAG); AdNonHarmonicResult durResult = voltageResult(dev.get(0).getId(), devIdMapComm, sourceIssue, dataRule, dur, durErrList, sourceIssue.getFFreq(), DUR); + if (CollUtil.isNotEmpty(mag.get(TYPE_B)) && CollUtil.isNotEmpty(mag.get(TYPE_C))) { + conclusion(magResult, durResult); + } detectionDataDealService.acceptAdNonResult(Arrays.asList(magResult, durResult), code); List numbers = Arrays.asList(magResult.getResultFlag(), durResult.getResultFlag()).stream().distinct().collect(Collectors.toList()); return getInteger(numbers); } + /** + * @param magResult 电压幅值结果 + * @param durResult 持续时间结果 + * @Description: + * @Author: wr + * @Date: 2025/4/9 18:54 + */ + private void conclusion(AdNonHarmonicResult magResult, AdNonHarmonicResult durResult) { + if (magResult.getResultFlag() == 1) { + if (durResult.getResultFlag() != 2) { + setTValueBasedOnAValue(magResult, durResult); + } else { + setTValueBasedOnAValue(magResult, durResult, false); + } + } else if (magResult.getResultFlag() == 2) { + setTValueBasedOnAValue(magResult, durResult, true); + } else { + setTValueBasedOnAValue(magResult, durResult); + } + } + + private void setTValueBasedOnAValue(AdNonHarmonicResult magResult, AdNonHarmonicResult durResult, Boolean isMag) { + DetectionData a; + DetectionData b; + DetectionData c; + if (isMag) { + a = JSON.parseObject(magResult.getAValue(), DetectionData.class); + b = JSON.parseObject(magResult.getBValue(), DetectionData.class); + c = JSON.parseObject(magResult.getCValue(), DetectionData.class); + } else { + a = JSON.parseObject(durResult.getAValue(), DetectionData.class); + b = JSON.parseObject(durResult.getBValue(), DetectionData.class); + c = JSON.parseObject(durResult.getCValue(), DetectionData.class); + } + if (a.getIsData() == 2) { + setTValueBasedOnAValue(magResult, durResult); + } else if (b.getIsData() == 2) { + setTValueBasedOnBValue(magResult, durResult); + } else if (c.getIsData() == 2) { + setTValueBasedOnCValue(magResult, durResult); + } + } + + /** + * @param magResult 电压幅值结果 + * @param durResult 持续时间结果 + * @Description: + * @Author: wr + */ + private void setTValueBasedOnAValue(AdNonHarmonicResult magResult, AdNonHarmonicResult durResult) { + magResult.setTValue(magResult.getAValue()); + durResult.setTValue(durResult.getAValue()); + } + + private void setTValueBasedOnBValue(AdNonHarmonicResult magResult, AdNonHarmonicResult durResult) { + magResult.setTValue(magResult.getBValue()); + durResult.setTValue(durResult.getBValue()); + } + + private void setTValueBasedOnCValue(AdNonHarmonicResult magResult, AdNonHarmonicResult durResult) { + magResult.setTValue(magResult.getCValue()); + durResult.setTValue(durResult.getCValue()); + } + /** * @param devId 装置监测点id(ip_通道) * @param devIdMapComm ip_通道,装置名称 @@ -683,13 +757,6 @@ public class DetectionServiceImpl { magErrList = errDtlsCheckData.get(0).getErrSysDtls(); } } - //取出源所对应的相别信息 - List channelTypeAList = sourceIssue.getChannelList().stream() - .filter(x -> ("Ua").equals(x.getChannelType())) - .collect(Collectors.toList()); - DetectionData a = setDetectionData(isQualified, valueTypeCode, dataRule, mag, fData, dur, magErrList, channelTypeAList, TYPE_A); - result.setAValue(JSON.toJSONString(a)); - List channelTypeBList = sourceIssue.getChannelList().stream() .filter(x -> ("Ub").equals(x.getChannelType())) .collect(Collectors.toList()); @@ -703,18 +770,47 @@ public class DetectionServiceImpl { DetectionData c = setDetectionData(isQualified, valueTypeCode, dataRule, mag, fData, dur, magErrList, channelTypeCList, TYPE_C); result.setCValue(JSON.toJSONString(c)); - result.setResultFlag(setResultFlag(Arrays.asList(a, b, c))); + if (CollUtil.isNotEmpty(mag.get(TYPE_B)) &&CollUtil.isNotEmpty(mag.get(TYPE_C))) { + //取出源所对应的相别信息 + List channelTypeAList = sourceIssue.getChannelList().stream() + .filter(x -> ("Ua").equals(x.getChannelType())) + .collect(Collectors.toList()); + DetectionData a = setDetectionData(isQualified, valueTypeCode, dataRule, mag, fData, dur, magErrList, channelTypeAList, TYPE_A); + result.setAValue(JSON.toJSONString(a)); + result.setResultFlag(setResultFlag(Arrays.asList(a, b, c))); + }else { + List channelTypeAList = sourceIssue.getChannelList().stream() + .filter(x -> x.getChannelType().contains("U")) + .sorted(Comparator.comparing( + x -> Optional.ofNullable(x.getDipData()) + .map(SourceIssue.ChannelListDTO.DipDataDTO::getFTransValue) + .orElse(Double.NaN) + )) + .collect(Collectors.toList()); + DetectionData a = setDetectionData(isQualified, valueTypeCode, dataRule, mag, fData, dur, magErrList, channelTypeAList, TYPE_A); + result.setAValue(JSON.toJSONString(a)); + result.setTValue(JSON.toJSONString(a)); + result.setResultFlag(a.getIsData()); + } return result; } - private DetectionData setDetectionData(Integer isQualified, String valueTypeCode, DictDataEnum dataRule, Map> mag, Double fData, String dur, List magErrList, List channelTypeCList, String typeC) { + private DetectionData setDetectionData(Integer isQualified, + String valueTypeCode, + DictDataEnum dataRule, + Map> mag, + Double fData, + String dur, + List magErrList, + List channelTypeCList, + String typeC) { DetectionData c; if (DUR.equals(dur)) { c = rangeDURComparisonList(mag.get(typeC), isQualified, valueTypeCode, magErrList, fData, channelTypeCList.get(0).getDipData().getRetainTime(), dataRule); } else { List ampData = mag.get(typeC).stream() .filter(x -> ObjectUtil.isNotNull(x)) - .map(x -> x * channelTypeCList.get(0).getFAmp() * 0.01) + .map(x -> NumberUtil.round(x * channelTypeCList.get(0).getFAmp() * 0.01, 4).doubleValue()) .collect(Collectors.toList()); c = rangeComparisonList(ampData, isQualified, valueTypeCode, magErrList, fData, channelTypeCList.get(0).getDipData().getFTransValue(), dataRule); } @@ -1125,8 +1221,8 @@ public class DetectionServiceImpl { nf.setMaximumFractionDigits(6); nf.setGroupingUsed(false); detectionData.setUnit(unit(valueTypeCode, errSysDtl.getErrorValueType())); - detectionData.setRadius(nf.format(BigDecimal.valueOf(1.0 / data * (channelData - errSysDtl.getMaxErrorValue()))) - + "~" + nf.format(BigDecimal.valueOf(1.0 / data * (channelData + errSysDtl.getMaxErrorValue())))); + detectionData.setRadius(nf.format(BigDecimal.valueOf(-1.0 / data)) + + "~" + nf.format(BigDecimal.valueOf(1.0 / data))); List qualifiedList = list.stream() .filter(x -> NumberUtil.isIn(BigDecimal.valueOf(x.doubleValue()), BigDecimal.valueOf(1.0 / data * (channelData - errSysDtl.getMaxErrorValue())), @@ -1134,14 +1230,14 @@ public class DetectionServiceImpl { ).collect(Collectors.toList()); if (CollUtil.isNotEmpty(qualifiedList)) { BigDecimal subtract = BigDecimal.valueOf(qualifiedList.get(0)) - .subtract(BigDecimal.valueOf(1.0 / data * (channelData - errSysDtl.getMaxErrorValue()))); + .subtract(BigDecimal.valueOf(1.0 / data * (channelData))); detectionData.setErrorData(subtract); } else { BigDecimal subtract = BigDecimal.valueOf(list.get(0)) - .subtract(BigDecimal.valueOf(1.0 / data * (channelData - errSysDtl.getMaxErrorValue()))); + .subtract(BigDecimal.valueOf(1.0 / data * (channelData))); detectionData.setErrorData(subtract); } - isData(dataRule, qualifiedList, detectionData, qualifiedList); + isData(dataRule, list, detectionData, qualifiedList); } } return detectionData; @@ -1157,7 +1253,8 @@ public class DetectionServiceImpl { * @param devData 装置上送值 * @return */ - public Boolean rangeComparison(Double startValue, Integer startFlag, Double endValue, Integer endFlag, Double devData) { + public Boolean rangeComparison(Double startValue, Integer startFlag, Double endValue, Integer endFlag, Double + devData) { Boolean minBool = null; Boolean maxBool = null; if (ObjectUtil.isNotNull(startValue)) { @@ -1288,7 +1385,9 @@ public class DetectionServiceImpl { * @param harm 基波信息 * @param fund 2-50次谐波信息 */ - public void harmPut(String type, Map>> map, List harmNum, DevData.SqlDataHarmDTO harm, String fund, Integer num) { + public void harmPut(String + type, Map>> map, List harmNum, DevData.SqlDataHarmDTO + harm, String fund, Integer num) { if (map.containsKey(type)) { Map> integerListMap = map.get(type); for (Double i : harmNum) { diff --git a/detection/src/main/java/com/njcn/gather/detection/util/socket/UnitUtil.java b/detection/src/main/java/com/njcn/gather/detection/util/socket/UnitUtil.java index 6678714c..53c33d9f 100644 --- a/detection/src/main/java/com/njcn/gather/detection/util/socket/UnitUtil.java +++ b/detection/src/main/java/com/njcn/gather/detection/util/socket/UnitUtil.java @@ -41,7 +41,7 @@ public class UnitUtil { unit = "P"; } if (DetectionCodeEnum.MAG.getCode().equals(code)) { - unit = "%"; + unit = "V"; } if (DetectionCodeEnum.DUR.getCode().equals(code)) { unit = "s"; diff --git a/detection/src/main/java/com/njcn/gather/script/service/impl/PqScriptDtlsServiceImpl.java b/detection/src/main/java/com/njcn/gather/script/service/impl/PqScriptDtlsServiceImpl.java index 0017928d..80ea98d6 100644 --- a/detection/src/main/java/com/njcn/gather/script/service/impl/PqScriptDtlsServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/script/service/impl/PqScriptDtlsServiceImpl.java @@ -1039,7 +1039,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl implements AdHarmonicService { private final AdNonHarmonicMapper adNonHarmonicMapper; - private final IDictDataService dictDataService; private final DictTreeMapper dictTreeMapper; @Override @@ -101,15 +100,15 @@ public class AdHarmonicServiceImpl extends ServiceImpl numbers) { List isData = numbers.stream().filter(Objects::nonNull) - .filter(x -> ObjectUtil.isNotNull(x.getData())) - .map(RawResultDataVO.DetectionData::getIsData) - .distinct() - .collect(Collectors.toList()); + .filter(x -> ObjectUtil.isNotNull(x.getData())) + .map(RawResultDataVO.DetectionData::getIsData) + .distinct() + .collect(Collectors.toList()); return getInteger(isData); } diff --git a/storage/src/main/java/com/njcn/gather/storage/service/impl/AdNonHarmonicServiceImpl.java b/storage/src/main/java/com/njcn/gather/storage/service/impl/AdNonHarmonicServiceImpl.java index 18af7c92..0069b3d7 100644 --- a/storage/src/main/java/com/njcn/gather/storage/service/impl/AdNonHarmonicServiceImpl.java +++ b/storage/src/main/java/com/njcn/gather/storage/service/impl/AdNonHarmonicServiceImpl.java @@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.date.DatePattern; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.github.yulichang.wrapper.MPJLambdaWrapper; @@ -24,10 +25,7 @@ import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; @@ -77,12 +75,12 @@ public class AdNonHarmonicServiceImpl extends ServiceImpl rawDataVOS = new ArrayList<>(); for (AdNonHarmonicResult result : value) { RawDataVO dataVO = new RawDataVO(); - dataVO.setUnit(unit(dictTree.getCode())); + dataVO.setUnit(dictTree.getCode().equals("MAG")?"%":unit(dictTree.getCode())); dataVO.setTime(result.getTimeId().format(DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN))); - dataVO.setDataA(ObjectUtil.isNotNull(result.getAValue()) ? new BigDecimal(result.getAValue()).toPlainString() : null); - dataVO.setDataB(ObjectUtil.isNotNull(result.getBValue()) ? new BigDecimal(result.getBValue()).toPlainString() : null); - dataVO.setDataC(ObjectUtil.isNotNull(result.getCValue()) ? new BigDecimal(result.getCValue()).toPlainString() : null); - dataVO.setDataT(ObjectUtil.isNotNull(result.getTValue()) ? new BigDecimal(result.getTValue()).toPlainString() : null); + dataVO.setDataA(StrUtil.isNotBlank(result.getAValue()) ? new BigDecimal(result.getAValue()).toPlainString() : null); + dataVO.setDataB(StrUtil.isNotBlank(result.getBValue()) ? new BigDecimal(result.getBValue()).toPlainString() : null); + dataVO.setDataC(StrUtil.isNotBlank(result.getCValue()) ? new BigDecimal(result.getCValue()).toPlainString() : null); + dataVO.setDataT(StrUtil.isNotBlank(result.getTValue()) ? new BigDecimal(result.getTValue()).toPlainString() : null); rawDataVOS.add(dataVO); } info.put(dictTree.getName(), rawDataVOS); @@ -104,11 +102,11 @@ public class AdNonHarmonicServiceImpl extends ServiceImpl adHarmonicResults = this.getBaseMapper().selectJoinList(AdNonHarmonicResult.class, wrapper); Map info = new LinkedHashMap<>(2); - Map adTypeMap = adHarmonicResults.stream().collect(Collectors.toMap(AdNonHarmonicResult::getAdType, Function.identity())); + Map adTypeMap = adHarmonicResults.stream() + .sorted(Comparator.comparing(AdNonHarmonicResult::getResultFlag)) + .collect(Collectors.toMap(AdNonHarmonicResult::getAdType, Function.identity(), (a, b) -> a, LinkedHashMap::new)); List dictTreeById = dictTreeService.getDictTreeById(new ArrayList<>(adTypeMap.keySet())); - Map dictTreeByName = dictTreeById.stream().collect(Collectors.toMap(DictTree::getId, Function.identity())); - adTypeMap.forEach((key, result) -> { if (dictTreeByName.containsKey(key)) { DictTree treeName = dictTreeByName.get(key); @@ -234,7 +232,7 @@ public class AdNonHarmonicServiceImpl extends ServiceImpl