From cd82ea6c433bc8102f7cc1671cc2299b645c584c Mon Sep 17 00:00:00 2001 From: wr <1754607820@qq.com> Date: Tue, 14 Jan 2025 08:51:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AD=A3=E5=BC=8F=E6=A3=80=E6=B5=8B=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E9=A1=B9=E8=BF=9B=E5=BA=A6=EF=BC=8C=E5=B0=8F=E7=9B=B8?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../script/pojo/enums/ResultUnitEnum.java | 36 +++++++ .../device/script/util/ScriptDtlsDesc.java | 100 ++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 device/src/main/java/com/njcn/gather/device/script/pojo/enums/ResultUnitEnum.java create mode 100644 device/src/main/java/com/njcn/gather/device/script/util/ScriptDtlsDesc.java diff --git a/device/src/main/java/com/njcn/gather/device/script/pojo/enums/ResultUnitEnum.java b/device/src/main/java/com/njcn/gather/device/script/pojo/enums/ResultUnitEnum.java new file mode 100644 index 00000000..386bfe1f --- /dev/null +++ b/device/src/main/java/com/njcn/gather/device/script/pojo/enums/ResultUnitEnum.java @@ -0,0 +1,36 @@ +package com.njcn.gather.device.script.pojo.enums; + +import lombok.Getter; + +/** + * @author caozehui + * @data 2024/11/9 + */ +@Getter +public enum ResultUnitEnum { + + FREQ_UNIT("Hz", "频率"), + V_RELATIVE_UNIT("%Un", "电压"), + V_ABSOLUTELY_UNIT("V", "电压"), + I_RELATIVE_UNIT("%In", "电流"), + I_ABSOLUTELY_UNIT("A", "电流"), + HV_UNIT("%", "谐波电压"), + HI_UNIT("%", "谐波电流"), + HP_UNIT("W", "谐波有功功率"), + HSV_UNIT("%", "间谐波电压"), + HSI_UNIT("%", "间谐波电流"), + VOLTAGE_MAG_UNIT("周波", "暂态持续时间"), + VOLTAGE_DUR_UNIT("%", "暂态深度"), + IMBV_UNIT("%", "电压不平衡度"), + IMBA_UNIT("%", "电流不平衡度"), + + ; + + private String unit; + private String name; + + ResultUnitEnum(String unit, String name) { + this.unit = unit; + this.name = name; + } +} diff --git a/device/src/main/java/com/njcn/gather/device/script/util/ScriptDtlsDesc.java b/device/src/main/java/com/njcn/gather/device/script/util/ScriptDtlsDesc.java new file mode 100644 index 00000000..848e3826 --- /dev/null +++ b/device/src/main/java/com/njcn/gather/device/script/util/ScriptDtlsDesc.java @@ -0,0 +1,100 @@ +package com.njcn.gather.device.script.util; + +import cn.hutool.core.collection.CollUtil; +import com.njcn.gather.device.script.pojo.enums.ResultUnitEnum; +import com.njcn.gather.device.script.pojo.po.PqScriptDtls; + +import java.util.Comparator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author wr + * @description + * @date 2025/1/13 22:05 + */ +public class ScriptDtlsDesc { + public static StringBuffer getStringBuffer(List scriptDtlIndex, Boolean isValueType) { + StringBuffer buffer = new StringBuffer(); + buffer.append("输入:"); + appendValue(scriptDtlIndex, buffer, "Freq", "频率", ResultUnitEnum.FREQ_UNIT.getUnit(), null); + appendValue(scriptDtlIndex, buffer, "VOL", "U", isValueType ? ResultUnitEnum.V_RELATIVE_UNIT.getUnit() : ResultUnitEnum.V_ABSOLUTELY_UNIT.getUnit(), "相角="); + appendValue(scriptDtlIndex, buffer, "CUR", "I", isValueType ? ResultUnitEnum.I_RELATIVE_UNIT.getUnit() : ResultUnitEnum.I_ABSOLUTELY_UNIT.getUnit(), "相角="); + dtlsSetBuffer(scriptDtlIndex, buffer, "Harm_V", "h", ResultUnitEnum.HV_UNIT.getUnit(), true); + dtlsSetBuffer(scriptDtlIndex, buffer, "Harm_I", "h", ResultUnitEnum.HI_UNIT.getUnit(), true); + dtlsSetBuffer(scriptDtlIndex, buffer, "InHarm_V", "i", ResultUnitEnum.HSV_UNIT.getUnit(), false); + dtlsSetBuffer(scriptDtlIndex, buffer, "InHarm_I", "i", ResultUnitEnum.HSI_UNIT.getUnit(), false); + dtlsSetBufferDip(scriptDtlIndex, buffer, "Dip", "暂态", ResultUnitEnum.HSI_UNIT.getUnit()); + dtlsSetBufferFlicker(scriptDtlIndex, buffer, "Flicker", "闪变"); + return buffer; + } + + public static void appendValue(List scriptDtlIndex, StringBuffer buffer, String valueType, String prefix, String unit, String suffix) { + List values = scriptDtlIndex.stream() + .filter(x -> valueType.equals(x.getValueType())) + .sorted(Comparator.comparing(PqScriptDtls::getPhase)) + .collect(Collectors.toList()); + if (CollUtil.isNotEmpty(values)) { + for (PqScriptDtls dtls : values) { + buffer.append(prefix + dtls.getPhase().toLowerCase() + "=" + dtls.getValue() + unit); + if (suffix != null) { + buffer.append("," + suffix + dtls.getAngle() + "° "); + } else { + buffer.append(" "); + } + } + } + } + + + public static void dtlsSetBuffer(List scriptDtlIndex, StringBuffer buffer, String valueType, String name, String unit, Boolean fly) { + LinkedHashMap> harmNumMap = scriptDtlIndex.stream() + .filter(x -> valueType.equals(x.getValueType())) + .sorted(Comparator.comparing(PqScriptDtls::getHarmNum)) + .collect(Collectors.groupingBy(PqScriptDtls::getHarmNum, LinkedHashMap::new, Collectors.toList())); + harmNumMap.forEach((harmNum, value) -> { + if (fly) { + buffer.append(name + String.format("%.0f", harmNum) + "("); + } else { + buffer.append(name + harmNum + "("); + } + appendValues(buffer, value, unit); + }); + } + + private static void dtlsSetBufferDip(List scriptDtlIndex, StringBuffer buffer, String valueType, String name, String unit) { + List list = scriptDtlIndex.stream().filter(x -> valueType.equals(x.getValueType())) + .sorted(Comparator.comparing(PqScriptDtls::getPhase)) + .collect(Collectors.toList()); + if (CollUtil.isNotEmpty(list)) { + buffer.append(name + " "); + for (PqScriptDtls dtls : list) { + buffer.append(dtls.getPhase() + "相(暂态深度=" + dtls.getTransValue() + ResultUnitEnum.VOLTAGE_DUR_UNIT.getUnit() + + ",暂态持续时间=" + dtls.getRetainTime().intValue() + ResultUnitEnum.VOLTAGE_MAG_UNIT.getUnit() + ") "); + } + } + } + + private static void dtlsSetBufferFlicker(List scriptDtlIndex, StringBuffer buffer, String valueType, String name) { + List list = scriptDtlIndex.stream().filter(x -> valueType.equals(x.getValueType())) + .sorted(Comparator.comparing(PqScriptDtls::getPhase)) + .collect(Collectors.toList()); + if (CollUtil.isNotEmpty(list)) { + buffer.append(name + " "); + for (PqScriptDtls dtls : list) { + buffer.append(dtls.getPhase() + "相(变动频度=" + dtls.getChagFre() + + "次/min,变动量=" + dtls.getChagValue() + ResultUnitEnum.VOLTAGE_DUR_UNIT.getUnit() + ") "); + } + } + } + + private static void appendValues(StringBuffer buffer, List values, String unit) { + if (CollUtil.isNotEmpty(values)) { + for (PqScriptDtls dtls : values) { + buffer.append(dtls.getPhase() + "相=" + dtls.getValue() + unit); + } + buffer.append(") "); + } + } +}