From 061b65be1b2872130ed22264eab174e5171f4696 Mon Sep 17 00:00:00 2001 From: caozehui <2427765068@qq.com> Date: Mon, 1 Jun 2026 09:26: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 --- .../handler/SocketDevResponseService.java | 89 +++++++++++++++++++ .../handler/SocketSourceResponseService.java | 6 ++ .../util/socket/FormalTestManager.java | 5 ++ .../source/pojo/param/PqSourceParam.java | 10 +++ .../njcn/gather/source/pojo/po/PqSource.java | 8 ++ .../plan/pojo/vo/PlanStatisticsVOTest.java | 33 ------- .../pojo/PqSourceCapacityFieldsTest.java | 59 ++++++++++++ 7 files changed, 177 insertions(+), 33 deletions(-) delete mode 100644 detection/src/test/java/com/njcn/gather/plan/pojo/vo/PlanStatisticsVOTest.java create mode 100644 detection/src/test/java/com/njcn/gather/source/pojo/PqSourceCapacityFieldsTest.java diff --git a/detection/src/main/java/com/njcn/gather/detection/handler/SocketDevResponseService.java b/detection/src/main/java/com/njcn/gather/detection/handler/SocketDevResponseService.java index 6573d66f..bd203fab 100644 --- a/detection/src/main/java/com/njcn/gather/detection/handler/SocketDevResponseService.java +++ b/detection/src/main/java/com/njcn/gather/detection/handler/SocketDevResponseService.java @@ -34,6 +34,7 @@ import com.njcn.gather.script.pojo.param.PqScriptIssueParam; import com.njcn.gather.script.pojo.po.SourceIssue; import com.njcn.gather.script.service.IPqScriptCheckDataService; import com.njcn.gather.script.service.IPqScriptDtlsService; +import com.njcn.gather.source.pojo.po.PqSource; import com.njcn.gather.source.service.IPqSourceService; import com.njcn.gather.storage.pojo.param.StorageParam; import com.njcn.gather.storage.pojo.po.SimAndDigHarmonicResult; @@ -1802,6 +1803,94 @@ public class SocketDevResponseService { if (param.getTestItemList().get(1)) { initXiManager(param); } + + FormalTestManager.overload = getOverloadResult(param); + } + + + /** + * 获取过载测试结果 + * + * @return 如果检测到电压过载,overload=1;如果检测到电流过载,overload=2;如果检测到电压&&电流过载,overload=3;反之,overload=4 + */ + private int getOverloadResult(PreDetectionParam param) { + PqSource pqSource = pqSourceService.getPqSourceById(param.getSourceId()); + BigDecimal maxVoltage = pqSource.getMaxVoltage(); + BigDecimal maxCurrent = pqSource.getMaxCurrent(); + + PqScriptIssueParam issueParam = new PqScriptIssueParam(); + issueParam.setSourceId(pqSource.getName()); + issueParam.setPlanId(param.getPlanId()); + issueParam.setDevIds(param.getDevIds()); + issueParam.setScriptId(param.getScriptId()); + issueParam.setIsPhaseSequence(CommonEnum.FORMAL_TEST.getValue()); + List sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam); + + for (int i = 0; i < sourceIssues.size(); i++) { + SourceIssue sourceIssue = sourceIssues.get(i); + List channelList = sourceIssue.getChannelList(); + for (int j = 0; j < channelList.size(); j++) { + SourceIssue.ChannelListDTO channelListDTO = channelList.get(j); + Double fAmp = channelListDTO.getFAmp(); + String channelType = channelListDTO.getChannelType(); + + if (ObjectUtil.isNotNull(fAmp)) { + if (channelType.contains("U")) { + // 电压判断 + if (maxVoltage.compareTo(BigDecimal.valueOf(fAmp)) < 0) { + return 1; + } + } else { + // 电流判断 + if (maxCurrent.compareTo(BigDecimal.valueOf(fAmp)) < 0) { + return 2; + } + } + } + // 暂态判断 + if (channelListDTO.getDipFlag()) { + SourceIssue.ChannelListDTO.DipDataDTO dipData = channelListDTO.getDipData(); + if (ObjectUtil.isNotNull(dipData)) { + Double fTransValue = dipData.getFTransValue(); + if (ObjectUtil.isNotNull(fTransValue) && ObjectUtil.isNotNull(fAmp)) { + if (maxVoltage.compareTo(BigDecimal.valueOf(fTransValue).max(BigDecimal.valueOf(fAmp))) < 0) { + return 1; + } + } + } + } + // 谐波判断 + if (channelListDTO.getHarmFlag()) { + List harmList = channelListDTO.getHarmList(); + double sum = harmList.stream().map(harmModel -> harmModel.getFAmp() * harmModel.getFAmp()).mapToDouble(x -> x).sum(); + if (channelType.contains("U")) { + if (maxVoltage.compareTo(BigDecimal.valueOf(Math.sqrt(1 + sum) * fAmp)) < 0) { + return 1; + } + } else { + if (maxCurrent.compareTo(BigDecimal.valueOf(Math.sqrt(1 + sum) * fAmp)) < 0) { + return 2; + } + } + } + // 间谐波判断 + if (channelListDTO.getInHarmFlag()) { + List inharmList = channelListDTO.getInharmList(); + double sum = inharmList.stream().map(harmModel -> harmModel.getFAmp() * harmModel.getFAmp()).mapToDouble(x -> x).sum(); + if (channelType.contains("U")) { + if (maxVoltage.compareTo(BigDecimal.valueOf(Math.sqrt(1 + sum) * fAmp)) < 0) { + return 1; + } + } else { + if (maxCurrent.compareTo(BigDecimal.valueOf(Math.sqrt(1 + sum) * fAmp)) < 0) { + return 2; + } + } + } + } + } + + return 4; } //初始化系数校验参数 diff --git a/detection/src/main/java/com/njcn/gather/detection/handler/SocketSourceResponseService.java b/detection/src/main/java/com/njcn/gather/detection/handler/SocketSourceResponseService.java index 15eb0853..170ca2c2 100644 --- a/detection/src/main/java/com/njcn/gather/detection/handler/SocketSourceResponseService.java +++ b/detection/src/main/java/com/njcn/gather/detection/handler/SocketSourceResponseService.java @@ -384,6 +384,12 @@ public class SocketSourceResponseService { socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type); SocketManager.sendMsg(param.getUserPageId() + CnSocketUtil.SOURCE_TAG, JSON.toJSONString(socketMsg)); } else { + // 推送过载测试结果 + SocketDataMsg overloadSocketDataMsg = new SocketDataMsg(); + overloadSocketDataMsg.setRequestId("overloadTest"); + overloadSocketDataMsg.setCode(FormalTestManager.overload); + sendWebSocketMessage(param.getUserPageId(), overloadSocketDataMsg); + //todo 前端推送收到的消息暂未处理好 sendWebSocketMessage(param.getUserPageId(), socketDataMsg); //开始设备通讯检测(发送设备初始化) diff --git a/detection/src/main/java/com/njcn/gather/detection/util/socket/FormalTestManager.java b/detection/src/main/java/com/njcn/gather/detection/util/socket/FormalTestManager.java index 9ce8d743..074dc8a4 100644 --- a/detection/src/main/java/com/njcn/gather/detection/util/socket/FormalTestManager.java +++ b/detection/src/main/java/com/njcn/gather/detection/util/socket/FormalTestManager.java @@ -208,4 +208,9 @@ public class FormalTestManager { * 是否进行相序校验 */ public static boolean isXu; + + /** + * 过载信息,如果检测到电压过载,overload=1;如果检测到电流过载,overload=2;如果检测到电压&&电流过载,overload=3;反之,overload=4 + */ + public static int overload; } diff --git a/detection/src/main/java/com/njcn/gather/source/pojo/param/PqSourceParam.java b/detection/src/main/java/com/njcn/gather/source/pojo/param/PqSourceParam.java index 54e3a1c7..783043fc 100644 --- a/detection/src/main/java/com/njcn/gather/source/pojo/param/PqSourceParam.java +++ b/detection/src/main/java/com/njcn/gather/source/pojo/param/PqSourceParam.java @@ -7,8 +7,10 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; +import javax.validation.constraints.DecimalMin; import javax.validation.constraints.NotBlank; import javax.validation.constraints.Pattern; +import java.math.BigDecimal; /** * @author caozehui @@ -51,6 +53,14 @@ public class PqSourceParam { @ApiModelProperty("源参数") private String parameter; + @ApiModelProperty("最大电压") + @DecimalMin("0") + private BigDecimal maxVoltage; + + @ApiModelProperty("最大电流") + @DecimalMin("0") + private BigDecimal maxCurrent; + @Data public static class QueryParam extends BaseParam { diff --git a/detection/src/main/java/com/njcn/gather/source/pojo/po/PqSource.java b/detection/src/main/java/com/njcn/gather/source/pojo/po/PqSource.java index b08ca723..807638ad 100644 --- a/detection/src/main/java/com/njcn/gather/source/pojo/po/PqSource.java +++ b/detection/src/main/java/com/njcn/gather/source/pojo/po/PqSource.java @@ -1,11 +1,13 @@ package com.njcn.gather.source.pojo.po; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.njcn.db.mybatisplus.bo.BaseEntity; import lombok.Data; import lombok.EqualsAndHashCode; import java.io.Serializable; +import java.math.BigDecimal; /** * @author caozehui @@ -46,6 +48,12 @@ public class PqSource extends BaseEntity implements Serializable { */ private String parameter; + @TableField("Max_Voltage") + private BigDecimal maxVoltage; + + @TableField("Max_Current") + private BigDecimal maxCurrent; + /** * 状态:0-删除 1-正常 */ diff --git a/detection/src/test/java/com/njcn/gather/plan/pojo/vo/PlanStatisticsVOTest.java b/detection/src/test/java/com/njcn/gather/plan/pojo/vo/PlanStatisticsVOTest.java deleted file mode 100644 index 1261285a..00000000 --- a/detection/src/test/java/com/njcn/gather/plan/pojo/vo/PlanStatisticsVOTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.njcn.gather.plan.pojo.vo; - -import org.junit.Assert; -import org.junit.Test; - -import java.util.Collections; - -public class PlanStatisticsVOTest { - - @Test - public void shouldExposeQualifiedDeviceCount() { - PlanStatisticsVO statistics = new PlanStatisticsVO(); - - statistics.setQualifiedDeviceCount(6); - - Assert.assertEquals(Integer.valueOf(6), statistics.getQualifiedDeviceCount()); - } - - @Test - public void shouldExposeLinkedFilterOptions() { - PlanStatisticsVO statistics = new PlanStatisticsVO(); - PlanStatisticsOptionVO manufacturer = new PlanStatisticsOptionVO("manufacturer-1", "厂家A"); - PlanStatisticsOptionVO devType = new PlanStatisticsOptionVO("dev-type-1", "PQS-882A"); - - statistics.setManufacturerOptions(Collections.singletonList(manufacturer)); - statistics.setDevTypeOptions(Collections.singletonList(devType)); - - Assert.assertEquals("manufacturer-1", statistics.getManufacturerOptions().get(0).getId()); - Assert.assertEquals("厂家A", statistics.getManufacturerOptions().get(0).getName()); - Assert.assertEquals("dev-type-1", statistics.getDevTypeOptions().get(0).getId()); - Assert.assertEquals("PQS-882A", statistics.getDevTypeOptions().get(0).getName()); - } -} diff --git a/detection/src/test/java/com/njcn/gather/source/pojo/PqSourceCapacityFieldsTest.java b/detection/src/test/java/com/njcn/gather/source/pojo/PqSourceCapacityFieldsTest.java new file mode 100644 index 00000000..d83698af --- /dev/null +++ b/detection/src/test/java/com/njcn/gather/source/pojo/PqSourceCapacityFieldsTest.java @@ -0,0 +1,59 @@ +package com.njcn.gather.source.pojo; + +import cn.hutool.core.bean.BeanUtil; +import com.baomidou.mybatisplus.annotation.TableField; +import com.njcn.gather.source.pojo.param.PqSourceParam; +import com.njcn.gather.source.pojo.po.PqSource; +import org.junit.Assert; +import org.junit.Test; + +import javax.validation.Validation; +import javax.validation.Validator; +import javax.validation.constraints.DecimalMin; +import java.lang.reflect.Field; +import java.math.BigDecimal; + +public class PqSourceCapacityFieldsTest { + + private final Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); + + @Test + public void shouldExposeExplicitCapacityColumnMappings() throws Exception { + Field maxVoltage = PqSource.class.getDeclaredField("maxVoltage"); + Field maxCurrent = PqSource.class.getDeclaredField("maxCurrent"); + + Assert.assertEquals("Max_Voltage", maxVoltage.getAnnotation(TableField.class).value()); + Assert.assertEquals("Max_Current", maxCurrent.getAnnotation(TableField.class).value()); + } + + @Test + public void shouldExposeNonNegativeCapacityValidation() throws Exception { + Field maxVoltage = PqSourceParam.class.getDeclaredField("maxVoltage"); + Field maxCurrent = PqSourceParam.class.getDeclaredField("maxCurrent"); + + Assert.assertEquals("0", maxVoltage.getAnnotation(DecimalMin.class).value()); + Assert.assertEquals("0", maxCurrent.getAnnotation(DecimalMin.class).value()); + + PqSourceParam.UpdateParam param = new PqSourceParam.UpdateParam(); + param.setId("12345678901234567890123456789012"); + param.setPattern("12345678901234567890123456789012"); + param.setType("12345678901234567890123456789012"); + param.setDevType("12345678901234567890123456789012"); + param.setMaxVoltage(new BigDecimal("-1")); + + Assert.assertFalse(validator.validate(param).isEmpty()); + } + + @Test + public void shouldCopyCapacityFieldsFromRequestToEntity() { + PqSourceParam.UpdateParam param = new PqSourceParam.UpdateParam(); + param.setMaxVoltage(new BigDecimal("220.00")); + param.setMaxCurrent(new BigDecimal("5.00")); + + PqSource source = new PqSource(); + BeanUtil.copyProperties(param, source); + + Assert.assertEquals(new BigDecimal("220.00"), source.getMaxVoltage()); + Assert.assertEquals(new BigDecimal("5.00"), source.getMaxCurrent()); + } +}