From 5ee33fabdf0668957fcff2c5ade56c2d26b7279f Mon Sep 17 00:00:00 2001 From: wr <1754607820@qq.com> Date: Tue, 25 Feb 2025 20:57:41 +0800 Subject: [PATCH] =?UTF-8?q?1.=E8=A7=A3=E5=86=B3=E8=AF=AF=E5=B7=AE=E4=B8=BA?= =?UTF-8?q?0=E6=98=AF=E4=B8=8D=E7=AC=A6=E5=90=88=E9=97=AE=E9=A2=98=202.?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=A3=80=E6=B5=8B=E8=84=9A=E6=9C=AC=E5=9B=9E?= =?UTF-8?q?=E6=98=BE=E5=92=8C=E9=80=9A=E8=AE=AF=E8=84=9A=E6=9C=AC=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=80=BC=E9=97=AE=E9=A2=98=203.=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E4=B8=89=E7=9B=B8=E4=B8=8D=E5=B9=B3=E8=A1=A1=E5=BA=A6=E5=85=AC?= =?UTF-8?q?=E5=BC=8F=E5=B7=A5=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/DetectionServiceImpl.java | 2 +- .../service/impl/ResultServiceImpl.java | 6 +- .../script/pojo/param/PqScriptDtlsParam.java | 4 +- .../gather/script/pojo/param/ScriptParam.java | 1 - .../impl/PqScriptCheckDataServiceImpl.java | 1 + .../service/impl/PqScriptDtlsServiceImpl.java | 288 +++++++++++------- .../script/util/ThreePhaseUnbalance.java | 181 +++++++++++ .../njcn/gather/script/util/UnbanUtil.java | 145 --------- .../dictionary/service/IDictTreeService.java | 2 + .../service/impl/DictTreeServiceImpl.java | 11 +- 10 files changed, 371 insertions(+), 270 deletions(-) create mode 100644 detection/src/main/java/com/njcn/gather/script/util/ThreePhaseUnbalance.java delete mode 100644 detection/src/main/java/com/njcn/gather/script/util/UnbanUtil.java 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 221c1ab2..d4d05650 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 @@ -1124,7 +1124,7 @@ public class DetectionServiceImpl { } return BigDecimal.valueOf(devData - channelData); } - return BigDecimal.valueOf(devData); + return BigDecimal.valueOf(0); } public BigDecimal divide(Double devData, Double channelData) { diff --git a/detection/src/main/java/com/njcn/gather/result/service/impl/ResultServiceImpl.java b/detection/src/main/java/com/njcn/gather/result/service/impl/ResultServiceImpl.java index 1b44e97a..faef9a18 100644 --- a/detection/src/main/java/com/njcn/gather/result/service/impl/ResultServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/result/service/impl/ResultServiceImpl.java @@ -176,7 +176,7 @@ public class ResultServiceImpl implements IResultService { subTypeMap.forEach((subKey, subValue) -> { if (!"VOLTAGE".equals(dictTree.getCode())) { TreeDataVO subType = new TreeDataVO(); - subType.setScriptTypeName(subName.get(subKey).replace("XX", dictTree.getName())); + subType.setScriptTypeName(!subName.containsKey(subKey)?"":subName.get(subKey).replace("XX", dictTree.getName())); subType.setScriptTypeCode(subKey); LinkedHashMap> indexMap = subValue.stream() .sorted(Comparator.comparing(PqScriptDtls::getScriptIndex)) @@ -213,13 +213,13 @@ public class ResultServiceImpl implements IResultService { .collect(Collectors.groupingBy(PqScriptDtls::getScriptSubType, LinkedHashMap::new, Collectors.toList())); if (CollUtil.isNotEmpty(subSingleTypeMap)) { TreeDataVO subType = new TreeDataVO(); - subType.setScriptTypeName(subName.get("Single").replace("XX", dictTree.getName())); + subType.setScriptTypeName(!subName.containsKey("Single")?"":subName.get("Single").replace("XX", dictTree.getName())); subType.setScriptTypeCode(dictTree.getCode()); //单影响量下频率准测量集合 List subSingleList = new ArrayList<>(); subSingleTypeMap.forEach((subKey, subValue) -> { TreeDataVO treeDataVO = new TreeDataVO(); - treeDataVO.setScriptTypeName(subName.get(subKey).replace("XX", dictTree.getName())); + treeDataVO.setScriptTypeName(!subName.containsKey(subKey)?"":subName.get(subKey).replace("XX", dictTree.getName())); treeDataVO.setScriptTypeCode(subKey); List subTypeList = new ArrayList<>(); diff --git a/detection/src/main/java/com/njcn/gather/script/pojo/param/PqScriptDtlsParam.java b/detection/src/main/java/com/njcn/gather/script/pojo/param/PqScriptDtlsParam.java index a406f3e3..af5f22a0 100644 --- a/detection/src/main/java/com/njcn/gather/script/pojo/param/PqScriptDtlsParam.java +++ b/detection/src/main/java/com/njcn/gather/script/pojo/param/PqScriptDtlsParam.java @@ -35,7 +35,7 @@ public class PqScriptDtlsParam { private String subType; /** - * 多量响量 + * 检测序号 */ private Integer index; @@ -57,6 +57,8 @@ public class PqScriptDtlsParam { @JSONField(name = "fFreq", ordinal = 6) private Double fFreq; + @JSONField(name = "retryCompute", ordinal = 6) + private Boolean retryCompute = false; /** * 装置下发参数 */ diff --git a/detection/src/main/java/com/njcn/gather/script/pojo/param/ScriptParam.java b/detection/src/main/java/com/njcn/gather/script/pojo/param/ScriptParam.java index b9611b86..ef9f2109 100644 --- a/detection/src/main/java/com/njcn/gather/script/pojo/param/ScriptParam.java +++ b/detection/src/main/java/com/njcn/gather/script/pojo/param/ScriptParam.java @@ -18,7 +18,6 @@ public class ScriptParam { private String scriptId; @ApiModelProperty("检测脚本类型") - @NotBlank(message = DevValidMessage.ID_FORMAT_ERROR) private String scriptType; @ApiModelProperty("检测脚本序号") diff --git a/detection/src/main/java/com/njcn/gather/script/service/impl/PqScriptCheckDataServiceImpl.java b/detection/src/main/java/com/njcn/gather/script/service/impl/PqScriptCheckDataServiceImpl.java index 0ff2e97c..c8118eb6 100644 --- a/detection/src/main/java/com/njcn/gather/script/service/impl/PqScriptCheckDataServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/script/service/impl/PqScriptCheckDataServiceImpl.java @@ -111,6 +111,7 @@ public class PqScriptCheckDataServiceImpl extends ServiceImpl checkDataList = sourceIssue.getCheckDataList(); PqScriptCheckData data; if (CollUtil.isNotEmpty(checkDataList)) { + checkDataList = checkDataList.stream().filter(x -> ObjectUtil.isNotNull(x.getValue())).collect(Collectors.toList()); for (PqScriptDtlsParam.CheckData checkData : checkDataList) { data = new PqScriptCheckData(); data.setScriptId(sourceIssue.getScriptId()); @@ -390,6 +391,15 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl checkDataList = sourceIssue.getCheckDataList(); if (CollUtil.isNotEmpty(checkDataList)) { + Map> checkDataOldMap = new HashMap<>(); + if (sourceIssue.getRetryCompute()) { + PqScriptCheckDataParam param = new PqScriptCheckDataParam(); + param.setScriptId(sourceIssue.getScriptId()); + param.setIndex(sourceIssue.getIndex()); + List checkDataOld = pqScriptCheckDataService.listCheckDataCode(param); + checkDataOldMap = checkDataOld.stream().collect(Collectors.groupingBy(PqScriptCheckData::getValueTypeCode)); + } + List ids = checkDataList.stream().map(PqScriptDtlsParam.CheckData::getValueType).collect(Collectors.toList()); List dictTreeById = dictTreeService.getDictTreeById(ids); Map dicTreeMap = dictTreeById.stream().collect(Collectors.toMap(DictTree::getId, Function.identity())); @@ -401,14 +411,24 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl channelList = sourceIssue.getChannelList(); List list; + List checkArchive; + if (checkDataOldMap.containsKey(codeEnum.getCode())) { + checkArchive = checkDataOldMap.get(codeEnum.getCode()); + } else { + checkArchive = new ArrayList<>(); + } switch (codeEnum) { case FREQ: checkData = new PqScriptDtlsParam.CheckData(); checkData.setErrorFlag(channelListDTO.getErrorFlag()); checkData.setEnable(channelListDTO.getEnable()); - checkData.setValue(sourceIssue.getFFreq()); checkData.setPhase("T"); checkData.setDataType(channelListDTO.getDataType()); + if (CollUtil.isNotEmpty(checkArchive)) { + checkData.setValue(checkArchive.get(0).getValue()); + } else { + checkData.setValue(sourceIssue.getFFreq()); + } checkData.setValueType(channelListDTO.getValueType()); checkData.setPid(channelListDTO.getPid()); info.add(checkData); @@ -417,23 +437,13 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl x.getChannelType().contains("U")).collect(Collectors.toList()); - rmsCheck(info, channelListDTO, list); + rmsCheck(info, channelListDTO, list, checkArchive, false); } break; case DELTA_V: if (CollUtil.isNotEmpty(channelList)) { list = channelList.stream().filter(x -> x.getChannelType().contains("U")).collect(Collectors.toList()); - for (PqScriptDtlsParam.ChannelListDTO listDTO : list) { - checkData = new PqScriptDtlsParam.CheckData(); - checkData.setErrorFlag(channelListDTO.getErrorFlag()); - checkData.setEnable(channelListDTO.getEnable()); - checkData.setValue(0.0); - checkData.setPhase(listDTO.getChannelType().substring(1, 2).toUpperCase()); - checkData.setDataType(channelListDTO.getDataType()); - checkData.setValueType(channelListDTO.getValueType()); - checkData.setPid(channelListDTO.getPid()); - info.add(checkData); - } + rmsCheck(info, channelListDTO, list, checkArchive, true); } break; case VA: @@ -444,7 +454,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl x.getChannelType().contains("U")).collect(Collectors.toList()); - harmCheck(info, channelListDTO, list); + harmCheck(info, channelListDTO, list, checkArchive); } break; case I2_50: if (CollUtil.isNotEmpty(channelList)) { list = channelList.stream().filter(x -> x.getChannelType().contains("I")).collect(Collectors.toList()); - harmCheck(info, channelListDTO, list); + harmCheck(info, channelListDTO, list, checkArchive); } break; case P2_50: @@ -488,12 +498,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl x.getChannelType().contains("U")).collect(Collectors.toList()); - inHarmCheck(info, channelListDTO, list); + inHarmCheck(info, channelListDTO, list, checkArchive); } break; case SI_1_49: if (CollUtil.isNotEmpty(channelList)) { list = channelList.stream().filter(x -> x.getChannelType().contains("I")).collect(Collectors.toList()); - inHarmCheck(info, channelListDTO, list); + inHarmCheck(info, channelListDTO, list, checkArchive); } break; case MAG: @@ -519,11 +524,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl x.getChannelType().contains("I")).collect(Collectors.toList()); - rmsCheck(info, channelListDTO, list); + rmsCheck(info, channelListDTO, list, checkArchive, false); } break; case V_UNBAN: list = channelList.stream().filter(x -> x.getChannelType().contains("U")).collect(Collectors.toList()); - unbanCheck(info, channelListDTO, channelList, list); + unbanCheck(info, channelListDTO, channelList, list, checkArchive); break; case I_UNBAN: list = channelList.stream().filter(x -> x.getChannelType().contains("I")).collect(Collectors.toList()); - unbanCheck(info, channelListDTO, channelList, list); + unbanCheck(info, channelListDTO, channelList, list, checkArchive); break; case PST: if (CollUtil.isNotEmpty(channelList)) { @@ -565,11 +562,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl info, PqScriptDtlsParam.CheckData checkData, PqScriptDtlsParam.CheckData channelListDTO, List checkArchive, PqScriptDtlsParam.ChannelListDTO listDTO) { + setCheckValue(checkArchive, checkData, listDTO); + checkData.setPhase(listDTO.getChannelType().substring(1, 2).toUpperCase()); + checkData.setDataType(channelListDTO.getDataType()); + checkData.setValueType(channelListDTO.getValueType()); + checkData.setPid(channelListDTO.getPid()); + info.add(checkData); + } + @Override public Boolean deleteDtls(ScriptParam param) { this.remove(new LambdaQueryWrapper() @@ -627,7 +629,12 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl info, PqScriptDtlsParam.CheckData channelListDTO, List channelList, List list) { + private void unbanCheck(List info, + PqScriptDtlsParam.CheckData channelListDTO, + List channelList, + List list, + List checkArchive + ) { PqScriptDtlsParam.CheckData checkData; if (CollUtil.isNotEmpty(list)) { PqScriptDtlsParam.ChannelListDTO a = channelList.stream().filter(x -> x.getChannelType().contains("a")).findFirst().get(); @@ -636,7 +643,10 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl info, PqScriptDtlsParam.CheckData channelListDTO, List list) { + private void rmsCheck(List info, + PqScriptDtlsParam.CheckData channelListDTO, + List list, + List checkArchive, + Boolean flyDeltaV + ) { PqScriptDtlsParam.CheckData checkData; for (PqScriptDtlsParam.ChannelListDTO listDTO : list) { checkData = new PqScriptDtlsParam.CheckData(); checkData.setErrorFlag(channelListDTO.getErrorFlag()); checkData.setEnable(channelListDTO.getEnable()); - checkData.setValue(listDTO.getFAmp()); checkData.setPhase(listDTO.getChannelType().substring(1, 2).toUpperCase()); + List collect = checkArchive.stream().filter(x -> x.getPhase().equals(listDTO.getChannelType().substring(1, 2).toUpperCase())).collect(Collectors.toList()); + if (CollUtil.isNotEmpty(collect)) { + checkData.setValue(collect.get(0).getValue()); + } else { + if (flyDeltaV) { + checkData.setValue(0.0); + } else { + checkData.setValue(listDTO.getFAmp()); + } + } checkData.setDataType(channelListDTO.getDataType()); checkData.setValueType(channelListDTO.getValueType()); checkData.setPid(channelListDTO.getPid()); @@ -660,7 +684,11 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl info, PqScriptDtlsParam.CheckData channelListDTO, List uList) { + private void inHarmCheck(List info, + PqScriptDtlsParam.CheckData channelListDTO, + List uList, + List checkArchive + ) { PqScriptDtlsParam.CheckData checkData; for (PqScriptDtlsParam.ChannelListDTO listDTO : uList) { List inharmList = listDTO.getInharmList(); @@ -670,7 +698,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl info, PqScriptDtlsParam.CheckData channelListDTO, List uList) { + private void setCheckValue(List checkArchive, PqScriptDtlsParam.CheckData checkData, PqScriptDtlsParam.ChannelListDTO listDTO) { + List collect = checkArchive.stream().filter(x -> x.getPhase().equals(listDTO.getChannelType().substring(1, 2).toUpperCase())).collect(Collectors.toList()); + if (CollUtil.isNotEmpty(collect)) { + checkData.setValue(collect.get(0).getValue()); + } + checkData.setPhase(listDTO.getChannelType().substring(1, 2).toUpperCase()); + } + + private void harmCheck(List info, + PqScriptDtlsParam.CheckData channelListDTO, + List uList, + List checkArchive + ) { PqScriptDtlsParam.CheckData checkData; for (PqScriptDtlsParam.ChannelListDTO listDTO : uList) { List harmList = listDTO.getHarmList(); @@ -691,6 +731,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl channelListDTOS, PqScriptCheckDataParam checkDataParam) { - for (PqScriptDtls dtls : dtlsList) { + List info = new ArrayList<>(); + info.add("A"); + info.add("B"); + info.add("C"); + for (String phase : info) { + List collect = dtlsList.stream().filter(x -> x.getPhase().equals(phase)).collect(Collectors.toList()); SourceIssue.ChannelListDTO channelListDTO = new SourceIssue.ChannelListDTO(); - channelListDTO.setChannelFlag(true); + channelListDTO.setChannelFlag(false); channelListDTO.setHarmFlag(false); channelListDTO.setInHarmFlag(false); channelListDTO.setDipFlag(false); channelListDTO.setFlickerFlag(false); - channelListDTO.setChannelType(code + dtls.getPhase().toLowerCase()); - channelListDTO.setFAmp(dtls.getValue()); - channelListDTO.setFPhase(dtls.getAngle()); + channelListDTO.setChannelType(code + phase.toLowerCase()); channelListDTO.setHarmList(new ArrayList<>()); channelListDTO.setInharmList(new ArrayList<>()); //暂态数据 @@ -820,57 +866,65 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl phaseList = dtlsOtherList.stream().filter(x -> dtls.getPhase().equals(x.getPhase())) - .sorted(Comparator.comparing(PqScriptDtls::getHarmNum)) - .collect(Collectors.toList()); - if (CollUtil.isNotEmpty(phaseList)) { - //处理谐波类型 - List harmList = phaseList.stream().filter(x -> harm.equals(x.getValueType())) + if (CollUtil.isNotEmpty(collect)) { + PqScriptDtls dtls = collect.get(0); + channelListDTO.setChannelFlag(true); + channelListDTO.setFAmp(dtls.getValue()); + channelListDTO.setFPhase(dtls.getAngle()); + if (CollUtil.isNotEmpty(dtlsOtherList)) { + List phaseList = dtlsOtherList.stream().filter(x -> dtls.getPhase().equals(x.getPhase())) .collect(Collectors.toList()); - if (CollUtil.isNotEmpty(harmList)) { - channelListDTO.setHarmList(getHarmModels(harmList)); - channelListDTO.setHarmFlag(true); - } - //处理间谐波类型 - List inHarmList = phaseList.stream().filter(x -> inHarm.equals(x.getValueType())) - .collect(Collectors.toList()); - if (CollUtil.isNotEmpty(inHarmList)) { - channelListDTO.setInharmList(getInHarmModels(inHarmList)); - channelListDTO.setInHarmFlag(true); - } - //处理暂态数据 - List dipList = phaseList.stream().filter(x -> DIP.equals(x.getValueType())) - .collect(Collectors.toList()); - if (CollUtil.isNotEmpty(dipList)) { - PqScriptDtls dip = dipList.get(0); - dipDataDTO.setFTransValue(dip.getTransValue()); - // 1.0/频率*持续时间(周波)= 暂态持续时间(s) - dipDataDTO.setFRetainTime(NumberUtil.round(1.0 / fFreq * dip.getRetainTime(), 3).doubleValue()); - dipDataDTO.setRetainTime(dip.getRetainTime()); - channelListDTO.setDipFlag(true); - channelListDTO.setDipData(dipDataDTO); - } - //处理闪变数据 - List flickeRList = phaseList.stream().filter(x -> FLICKER.equals(x.getValueType())) - .collect(Collectors.toList()); - if (CollUtil.isNotEmpty(flickeRList)) { - PqScriptDtls flicker = flickeRList.get(0); - - flickerDataDTO.setFChagFre(flicker.getChagFre()); - flickerDataDTO.setFChagValue(flicker.getChagValue()); - - List treeByCode = dictTreeService.getTreeByCode(DetectionCodeEnum.PST.getCode()); - if (CollUtil.isNotEmpty(treeByCode)) { - checkDataParam.setValueType(treeByCode.get(0).getId()); - checkDataParam.setPhase(dtls.getPhase()); - flickerDataDTO.setFlickerValue(pqScriptCheckDataService.getCheckDataValue(checkDataParam)); + if (CollUtil.isNotEmpty(phaseList)) { + //处理谐波类型 + List harmList = phaseList.stream().filter(x -> harm.equals(x.getValueType())) + .filter(x -> ObjectUtil.isNotNull(x.getHarmNum())) + .sorted(Comparator.comparing(PqScriptDtls::getHarmNum)) + .collect(Collectors.toList()); + if (CollUtil.isNotEmpty(harmList)) { + channelListDTO.setHarmList(getHarmModels(harmList)); + channelListDTO.setHarmFlag(true); } - channelListDTO.setFlickerFlag(true); - channelListDTO.setFlickerData(flickerDataDTO); - } + //处理间谐波类型 + List inHarmList = phaseList.stream().filter(x -> inHarm.equals(x.getValueType())) + .filter(x -> ObjectUtil.isNotNull(x.getHarmNum())) + .sorted(Comparator.comparing(PqScriptDtls::getHarmNum)) + .collect(Collectors.toList()); + if (CollUtil.isNotEmpty(inHarmList)) { + channelListDTO.setInharmList(getInHarmModels(inHarmList)); + channelListDTO.setInHarmFlag(true); + } + //处理暂态数据 + List dipList = phaseList.stream().filter(x -> DIP.equals(x.getValueType())) + .collect(Collectors.toList()); + if (CollUtil.isNotEmpty(dipList)) { + PqScriptDtls dip = dipList.get(0); + dipDataDTO.setFTransValue(dip.getTransValue()); + // 1.0/频率*持续时间(周波)= 暂态持续时间(s) + dipDataDTO.setFRetainTime(NumberUtil.round(1.0 / fFreq * dip.getRetainTime(), 3).doubleValue()); + dipDataDTO.setRetainTime(dip.getRetainTime()); + channelListDTO.setDipFlag(true); + channelListDTO.setDipData(dipDataDTO); + } + //处理闪变数据 + List flickeRList = phaseList.stream().filter(x -> FLICKER.equals(x.getValueType())) + .collect(Collectors.toList()); + if (CollUtil.isNotEmpty(flickeRList)) { + PqScriptDtls flicker = flickeRList.get(0); + flickerDataDTO.setFChagFre(flicker.getChagFre()); + flickerDataDTO.setFChagValue(flicker.getChagValue()); + + DictTree dictTreeByCode = dictTreeService.getDictTreeByCode(DetectionCodeEnum.PST.getCode()); + if (ObjectUtil.isNotNull(dictTreeByCode)) { + checkDataParam.setValueType(dictTreeByCode.getId()); + checkDataParam.setPhase(dtls.getPhase()); + flickerDataDTO.setFlickerValue(pqScriptCheckDataService.getCheckDataValue(checkDataParam)); + } + channelListDTO.setFlickerFlag(true); + channelListDTO.setFlickerData(flickerDataDTO); + } + + } } } channelListDTOS.add(channelListDTO); diff --git a/detection/src/main/java/com/njcn/gather/script/util/ThreePhaseUnbalance.java b/detection/src/main/java/com/njcn/gather/script/util/ThreePhaseUnbalance.java new file mode 100644 index 00000000..2a1c2e1b --- /dev/null +++ b/detection/src/main/java/com/njcn/gather/script/util/ThreePhaseUnbalance.java @@ -0,0 +1,181 @@ +package com.njcn.gather.script.util; + +/** + * @author hongawen + * @version 1.0 + * @data 2025/2/25 13:24 + */ + +import java.math.BigDecimal; +import java.math.MathContext; +import java.math.RoundingMode; + +public class ThreePhaseUnbalance { + + // 定义复数类 + static class Complex { + BigDecimal real; // 复数的实部 + BigDecimal imag; // 复数的虚部 + + // 构造函数,初始化复数的实部和虚部 + public Complex(BigDecimal real, BigDecimal imag) { + this.real = real; + this.imag = imag; + } + + // 复数加法 + public Complex add(Complex other) { + return new Complex(this.real.add(other.real), this.imag.add(other.imag)); + } + + // 复数乘法 + public Complex multiply(Complex other) { + BigDecimal real = this.real.multiply(other.real).subtract(this.imag.multiply(other.imag)); + BigDecimal imag = this.real.multiply(other.imag).add(this.imag.multiply(other.real)); + return new Complex(real, imag); + } + + // 复数除以一个实数 + public Complex divide(BigDecimal divisor) { + return new Complex(this.real.divide(divisor, MathContext.DECIMAL128), + this.imag.divide(divisor, MathContext.DECIMAL128)); + } + + // 计算复数的模(幅值) + public BigDecimal magnitude() { + return BigDecimal.valueOf(Math.sqrt(real.multiply(real).add(imag.multiply(imag)).doubleValue())); + } + } + + // 将幅值和角度(角度制)转换为复数 + public static Complex fromPolar(BigDecimal magnitude, BigDecimal angleDegrees) { + double angleRadians = Math.toRadians(angleDegrees.doubleValue()); // 将角度转换为弧度 + BigDecimal real = magnitude.multiply(BigDecimal.valueOf(Math.cos(angleRadians))); // 计算实部 + BigDecimal imag = magnitude.multiply(BigDecimal.valueOf(Math.sin(angleRadians))); // 计算虚部 + return new Complex(real, imag); + } + + // 计算三相电压的对称分量(零序、正序、负序) + public static Complex[] calculateSymmetricalComponents(Complex va, Complex vb, Complex vc) { + // 120度相位因子 a = e^(j120°) = -0.5 + j * sqrt(3)/2 + Complex a = new Complex(BigDecimal.valueOf(-0.5), BigDecimal.valueOf(Math.sqrt(3) / 2)); + // 240度相位因子 a^2 = e^(j240°) = -0.5 - j * sqrt(3)/2 + Complex a2 = a.multiply(a); + + // 零序分量 V0 = (Va + Vb + Vc) / 3 + Complex v0 = va.add(vb).add(vc).divide(BigDecimal.valueOf(3)); + + // 正序分量 V1 = (Va + a * Vb + a^2 * Vc) / 3 + Complex v1 = va.add(a.multiply(vb)).add(a2.multiply(vc)).divide(BigDecimal.valueOf(3)); + + // 负序分量 V2 = (Va + a^2 * Vb + a * Vc) / 3 + Complex v2 = va.add(a2.multiply(vb)).add(a.multiply(vc)).divide(BigDecimal.valueOf(3)); + + // 返回零序、正序、负序分量 + return new Complex[]{v0, v1, v2}; + } + + // 计算三相电压的不平衡度 + public static void calculateUnbalance(Complex v0, Complex v1, Complex v2) { + // 计算零序、正序、负序分量的幅值 + BigDecimal v0Mag = v0.magnitude(); // 零序分量幅值 + BigDecimal v1Mag = v1.magnitude(); // 正序分量幅值 + BigDecimal v2Mag = v2.magnitude(); // 负序分量幅值 + + // 计算不平衡度 + BigDecimal zeroSequenceUnbalance = v1Mag.compareTo(BigDecimal.ZERO) != 0 ? + v0Mag.divide(v1Mag, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)) : BigDecimal.ZERO; + + BigDecimal negativeSequenceUnbalance = v1Mag.compareTo(BigDecimal.ZERO) != 0 ? + v2Mag.divide(v1Mag, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)) : BigDecimal.ZERO; + + BigDecimal positiveSequenceUnbalance = BigDecimal.valueOf(100); // 正序电压不平衡度通常为100% + + // 输出结果,保留2位小数 + System.out.printf("零序电压不平衡度: %.2f%%\n", zeroSequenceUnbalance.setScale(2, RoundingMode.HALF_UP).doubleValue()); + System.out.printf("负序电压不平衡度: %.2f%%\n", negativeSequenceUnbalance.setScale(2, RoundingMode.HALF_UP).doubleValue()); + System.out.printf("正序电压不平衡度: %.2f%%\n", positiveSequenceUnbalance.setScale(2, RoundingMode.HALF_UP).doubleValue()); + } + + /** + * 负序电压不平衡度 + */ + public static double calculateUnbalance(double Ua0, double thetaA, + double Ub0, double thetaB, + double Uc0, double thetaC) { + + // 输入三相电压的幅值和相位角(角度制) + BigDecimal vaMagnitude = new BigDecimal(Ua0); + BigDecimal vaAngle = new BigDecimal(thetaA); + + BigDecimal vbMagnitude =new BigDecimal(Ub0); + BigDecimal vbAngle = new BigDecimal(thetaB); + + BigDecimal vcMagnitude =new BigDecimal(Uc0); + BigDecimal vcAngle = new BigDecimal(thetaC); + + // 将幅值和角度转换为复数 + Complex va = fromPolar(vaMagnitude, vaAngle); + Complex vb = fromPolar(vbMagnitude, vbAngle); + Complex vc = fromPolar(vcMagnitude, vcAngle); + + // 计算对称分量 + Complex[] symmetricalComponents = calculateSymmetricalComponents(va, vb, vc); + Complex v1 = symmetricalComponents[1]; // 正序分量 + Complex v2 = symmetricalComponents[2]; // 负序分量 + + // 计算零序、正序、负序分量的幅值 + BigDecimal v1Mag = v1.magnitude(); // 正序分量幅值 + BigDecimal v2Mag = v2.magnitude(); // 负序分量幅值 + + + BigDecimal negativeSequenceUnbalance = v1Mag.compareTo(BigDecimal.ZERO) != 0 ? + v2Mag.divide(v1Mag, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)) : BigDecimal.ZERO; + + // 输出结果,保留2位小数 + return negativeSequenceUnbalance.setScale(2, RoundingMode.HALF_UP).doubleValue(); + } + + + public static void main(String[] args) { + + // 输入三相电压的幅值和相位角(角度制) + System.out.println("请输入A相电压的幅值(单位:V):"); + BigDecimal vaMagnitude = new BigDecimal(57.74); + System.out.println("请输入A相电压的相位角(单位:度):"); + BigDecimal vaAngle = new BigDecimal(0); + + System.out.println("请输入B相电压的幅值(单位:V):"); + BigDecimal vbMagnitude =new BigDecimal(57.74*0.9); + System.out.println("请输入B相电压的相位角(单位:度):"); + BigDecimal vbAngle = new BigDecimal(-122); + + System.out.println("请输入C相电压的幅值(单位:V):"); + BigDecimal vcMagnitude =new BigDecimal(57.74); + System.out.println("请输入C相电压的相位角(单位:度):"); + BigDecimal vcAngle = new BigDecimal(118); + + // 将幅值和角度转换为复数 + Complex va = fromPolar(vaMagnitude, vaAngle); + Complex vb = fromPolar(vbMagnitude, vbAngle); + Complex vc = fromPolar(vcMagnitude, vcAngle); + + // 计算对称分量 + Complex[] symmetricalComponents = calculateSymmetricalComponents(va, vb, vc); + Complex v0 = symmetricalComponents[0]; // 零序分量 + Complex v1 = symmetricalComponents[1]; // 正序分量 + Complex v2 = symmetricalComponents[2]; // 负序分量 + + // 输出对称分量 + System.out.printf("零序分量: %.2f + j%.2f\n", v0.real.setScale(2, RoundingMode.HALF_UP).doubleValue(), + v0.imag.setScale(2, RoundingMode.HALF_UP).doubleValue()); + System.out.printf("正序分量: %.2f + j%.2f\n", v1.real.setScale(2, RoundingMode.HALF_UP).doubleValue(), + v1.imag.setScale(2, RoundingMode.HALF_UP).doubleValue()); + System.out.printf("负序分量: %.2f + j%.2f\n", v2.real.setScale(2, RoundingMode.HALF_UP).doubleValue(), + v2.imag.setScale(2, RoundingMode.HALF_UP).doubleValue()); + + // 计算并输出不平衡度 + calculateUnbalance(v0, v1, v2); + + } +} diff --git a/detection/src/main/java/com/njcn/gather/script/util/UnbanUtil.java b/detection/src/main/java/com/njcn/gather/script/util/UnbanUtil.java deleted file mode 100644 index a25c7c71..00000000 --- a/detection/src/main/java/com/njcn/gather/script/util/UnbanUtil.java +++ /dev/null @@ -1,145 +0,0 @@ -package com.njcn.gather.script.util; - -import cn.hutool.core.util.NumberUtil; - -/** - * @author wr - * @description - * @date 2025/2/19 14:00 - */ -public class UnbanUtil { - - static class Complex { - double real; - double imag; - - Complex(double real, double imag) { - this.real = real; - this.imag = imag; - } - - Complex add(Complex other) { - return new Complex(this.real + other.real, this.imag + other.imag); - } - - Complex multiply(Complex other) { - double newReal = this.real * other.real - this.imag * other.imag; - double newImag = this.real * other.imag + this.imag * other.real; - return new Complex(newReal, newImag); - } - - Complex divideBy3() { - return new Complex(this.real / 3.0, this.imag / 3.0); - } - - double magnitude() { - return Math.sqrt(real * real + imag * imag); - } - - // 定义旋转因子 - static final Complex J120 = new Complex(-0.5, Math.sqrt(3) / 2); - static final Complex J_MINUS_120 = new Complex(-0.5, -Math.sqrt(3) / 2); - } - - public static Complex[] calculateSequenceComponents(Complex Ua, Complex Ub, Complex Uc) { - // 计算正序分量 - Complex temp1 = Ua.add(Ub.multiply(Complex.J_MINUS_120).add(Uc.multiply(Complex.J120))); - Complex U1 = temp1.divideBy3(); - - // 计算负序分量 - Complex temp2 = Ua.add(Ub.multiply(Complex.J120).add(Uc.multiply(Complex.J_MINUS_120))); - Complex U2 = temp2.divideBy3(); - - // 计算零序分量 - Complex temp0 = Ua.add(Ub).add(Uc); - Complex U0 = temp0.divideBy3(); - - return new Complex[]{U1, U2, U0}; - } - - public static double calculateNegativeSequenceImbalance(Complex U1, Complex U2) { - double U1Mag = U1.magnitude(); - double U2Mag = U2.magnitude(); - return (U2Mag / U1Mag) * 100.0; - } - - public static double calculateZeroSequenceImbalance(Complex U1, Complex U0) { - double U1Mag = U1.magnitude(); - double U0Mag = U0.magnitude(); - return (U0Mag / U1Mag) * 100.0; - } - - public static void main(String[] args) { - // 输入三相电压的幅值和相角 - double Ua0 = 220.0, thetaA = 0.0; // A相 - double Ub0 = 220.0, thetaB = -120.0; // B相 - double Uc0 = 220.0, thetaC = 120.0; // C相 - - // 转换为复数形式 - Complex Ua = new Complex( - Ua0 * Math.cos(thetaA * Math.PI / 180.0), - Ua0 * Math.sin(thetaA * Math.PI / 180.0) - ); - Complex Ub = new Complex( - Ub0 * Math.cos(thetaB * Math.PI / 180.0), - Ub0 * Math.sin(thetaB * Math.PI / 180.0) - ); - Complex Uc = new Complex( - Uc0 * Math.cos(thetaC * Math.PI / 180.0), - Uc0 * Math.sin(thetaC * Math.PI / 180.0) - ); - - // 计算序分量 - Complex[] components = calculateSequenceComponents(Ua, Ub, Uc); - Complex U1 = components[0]; - Complex U2 = components[1]; - Complex U0 = components[2]; - - // 输出结果 - System.out.printf("正序分量 U1: %.2f + j%.2f%n", U1.real, U1.imag); - System.out.printf("负序分量 U2: %.2f + j%.2f%n", U2.real, U2.imag); - System.out.printf("零序分量 U0: %.2f + j%.2f%n", U0.real, U0.imag); - - // 计算不平衡度 - double negativeImbalance = calculateNegativeSequenceImbalance(U1, U2); - double zeroImbalance = calculateZeroSequenceImbalance(U1, U0); - - System.out.printf("负序不平衡度: %.2f%%%n", negativeImbalance); - System.out.printf("零序不平衡度: %.2f%%%n", zeroImbalance); - } - - // 输入三相电压的幅值和相角 - public static double calculateUnbalance(double Ua0, double thetaA, - double Ub0, double thetaB, - double Uc0, double thetaC) { - - - // 转换为复数形式 - Complex Ua = new Complex( - Ua0 * Math.cos(thetaA * Math.PI / 180.0), - Ua0 * Math.sin(thetaA * Math.PI / 180.0) - ); - Complex Ub = new Complex( - Ub0 * Math.cos(thetaB * Math.PI / 180.0), - Ub0 * Math.sin(thetaB * Math.PI / 180.0) - ); - Complex Uc = new Complex( - Uc0 * Math.cos(thetaC * Math.PI / 180.0), - Uc0 * Math.sin(thetaC * Math.PI / 180.0) - ); - - // 计算序分量 - Complex[] components = calculateSequenceComponents(Ua, Ub, Uc); - Complex U1 = components[0]; - Complex U2 = components[1]; - Complex U0 = components[2]; - - // 输出结果 - System.out.printf("正序分量 U1: %.2f + j%.2f%n", U1.real, U1.imag); - System.out.printf("负序分量 U2: %.2f + j%.2f%n", U2.real, U2.imag); - System.out.printf("零序分量 U0: %.2f + j%.2f%n", U0.real, U0.imag); - - // 计算不平衡度 - return NumberUtil.round(calculateNegativeSequenceImbalance(U1, U2), 2).doubleValue(); - } -} \ No newline at end of file diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/service/IDictTreeService.java b/system/src/main/java/com/njcn/gather/system/dictionary/service/IDictTreeService.java index 1518cada..d271d0f3 100644 --- a/system/src/main/java/com/njcn/gather/system/dictionary/service/IDictTreeService.java +++ b/system/src/main/java/com/njcn/gather/system/dictionary/service/IDictTreeService.java @@ -79,4 +79,6 @@ public interface IDictTreeService extends IService { * @return */ List getDictTreeById(List ids); + + DictTree getDictTreeByCode(String code); } diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictTreeServiceImpl.java b/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictTreeServiceImpl.java index 8d12edcb..b3efb696 100644 --- a/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictTreeServiceImpl.java +++ b/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictTreeServiceImpl.java @@ -69,7 +69,7 @@ public class DictTreeServiceImpl extends ServiceImpl i @Override @Transactional(rollbackFor = {Exception.class}) public boolean addDictTree(DictTreeParam dictTreeParam) { - checkRepeat(dictTreeParam,false); + checkRepeat(dictTreeParam, false); boolean result; DictTree dictTree = new DictTree(); BeanUtils.copyProperties(dictTreeParam, dictTree); @@ -92,7 +92,7 @@ public class DictTreeServiceImpl extends ServiceImpl i @Override @Transactional(rollbackFor = {Exception.class}) public boolean updateDictTree(DictTreeParam.UpdateParam param) { - checkRepeat(param,true); + checkRepeat(param, true); boolean result; DictTree dictTree = new DictTree(); BeanUtils.copyProperties(param, dictTree); @@ -179,6 +179,13 @@ public class DictTreeServiceImpl extends ServiceImpl i ); } + @Override + public DictTree getDictTreeByCode(String code) { + return this.getOne(new LambdaQueryWrapper() + .eq(DictTree::getCode, code) + ); + } + // @Override // public List queryAll() { // LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>();