From 7ab5b9a5017d61ec8f6c6e40f45a7e86ba5a9557 Mon Sep 17 00:00:00 2001 From: caozehui <2427765068@qq.com> Date: Thu, 7 May 2026 15:21:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=AA=E5=90=91=E7=BA=B5=E5=90=91=E5=AE=9E?= =?UTF-8?q?=E6=97=B6=E6=89=93=E7=89=B9=E6=80=A7=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/SocketFreqConverterService.java | 69 +++++++++++++++---- .../config/FreqConverterConfig.java | 2 + .../IPqFreqConverterTestResService.java | 3 + .../PqFreqConverterTestResServiceImpl.java | 29 ++++++++ entrance/src/main/resources/application.yml | 6 +- 5 files changed, 94 insertions(+), 15 deletions(-) diff --git a/detection/src/main/java/com/njcn/gather/detection/handler/SocketFreqConverterService.java b/detection/src/main/java/com/njcn/gather/detection/handler/SocketFreqConverterService.java index 5d0ed3b9..fd3c691d 100644 --- a/detection/src/main/java/com/njcn/gather/detection/handler/SocketFreqConverterService.java +++ b/detection/src/main/java/com/njcn/gather/detection/handler/SocketFreqConverterService.java @@ -342,21 +342,64 @@ public class SocketFreqConverterService { } } } else { - if (this.lastTolerancePoint.getTolerant() == 1 && testRes.getTolerant() == 0) { - TolerantPointVO featurePointVO = new TolerantPointVO(); + if (testRes.getTolerant() == 0) { + if (this.lastTolerancePoint.getTolerant() == 1) { + TolerantPointVO featurePointVO = new TolerantPointVO(); - featurePointVO.setResidualVoltage((task.getPqDipData().getResidualVoltage() + this.lastTolerancePoint.getResidualVoltage()) / 2D); - featurePointVO.setDurationMs(Integer.valueOf((task.getPqDipData().getDurationMs().intValue() + this.lastTolerancePoint.getDurationMs().intValue()) / 2)); - featurePointVO.setTolerant(2); - socketDataMsg.setData(JSON.toJSONString(featurePointVO)); - WebServiceManager.sendMsg(this.userId, JSON.toJSONString(socketDataMsg)); + featurePointVO.setResidualVoltage((task.getPqDipData().getResidualVoltage() + this.lastTolerancePoint.getResidualVoltage()) / 2D); + featurePointVO.setDurationMs(Integer.valueOf((task.getPqDipData().getDurationMs().intValue() + this.lastTolerancePoint.getDurationMs().intValue()) / 2)); + featurePointVO.setTolerant(2); + socketDataMsg.setData(JSON.toJSONString(featurePointVO)); + WebServiceManager.sendMsg(this.userId, JSON.toJSONString(socketDataMsg)); - PqFreqConverterTestRes featureTestRes = new PqFreqConverterTestRes(); - featureTestRes.setId(IdUtil.fastSimpleUUID()); - featureTestRes.setDurationMs(featurePointVO.getDurationMs()); - featureTestRes.setResidualVoltage(featurePointVO.getResidualVoltage()); - featureTestRes.setTolerant(2); - saveTestResList.add(featureTestRes); + PqFreqConverterTestRes featureTestRes = new PqFreqConverterTestRes(); + featureTestRes.setId(IdUtil.fastSimpleUUID()); + featureTestRes.setDurationMs(featurePointVO.getDurationMs()); + featureTestRes.setResidualVoltage(featurePointVO.getResidualVoltage()); + featureTestRes.setTolerant(2); + saveTestResList.add(featureTestRes); + } + + // 从数据库按照列查询距离该暂降点最近的一个暂降点 + if (freqConverterConfig.getDirection() == 0) { + PqFreqConverterTestRes lastByDuration = pqFreqConverterTestResService.getLastByDuration(suffix, task.getPqDipData().getDurationMs()); + if (ObjectUtil.isNotNull(lastByDuration) && lastByDuration.getTolerant() == 1) { + TolerantPointVO featurePointVO = new TolerantPointVO(); + + featurePointVO.setResidualVoltage((task.getPqDipData().getResidualVoltage() + lastByDuration.getResidualVoltage()) / 2D); + featurePointVO.setDurationMs(Integer.valueOf((task.getPqDipData().getDurationMs().intValue() + lastByDuration.getDurationMs().intValue()) / 2)); + featurePointVO.setTolerant(2); + socketDataMsg.setData(JSON.toJSONString(featurePointVO)); + WebServiceManager.sendMsg(this.userId, JSON.toJSONString(socketDataMsg)); + + PqFreqConverterTestRes featureTestRes = new PqFreqConverterTestRes(); + featureTestRes.setId(IdUtil.fastSimpleUUID()); + featureTestRes.setDurationMs(featurePointVO.getDurationMs()); + featureTestRes.setResidualVoltage(featurePointVO.getResidualVoltage()); + featureTestRes.setTolerant(2); + saveTestResList.add(featureTestRes); + } + } + // 从数据库按照行查询距离该暂降点最近的一个暂降点 + if (freqConverterConfig.getDirection() == 0) { + PqFreqConverterTestRes lastByResidualVoltage = pqFreqConverterTestResService.getLastByResidualVoltage(suffix, task.getPqDipData().getResidualVoltage()); + if (ObjectUtil.isNotNull(lastByResidualVoltage) && lastByResidualVoltage.getTolerant() == 1) { + TolerantPointVO featurePointVO = new TolerantPointVO(); + + featurePointVO.setResidualVoltage((task.getPqDipData().getResidualVoltage() + lastByResidualVoltage.getResidualVoltage()) / 2D); + featurePointVO.setDurationMs(Integer.valueOf((task.getPqDipData().getDurationMs().intValue() + lastByResidualVoltage.getDurationMs().intValue()) / 2)); + featurePointVO.setTolerant(2); + socketDataMsg.setData(JSON.toJSONString(featurePointVO)); + WebServiceManager.sendMsg(this.userId, JSON.toJSONString(socketDataMsg)); + + PqFreqConverterTestRes featureTestRes = new PqFreqConverterTestRes(); + featureTestRes.setId(IdUtil.fastSimpleUUID()); + featureTestRes.setDurationMs(featurePointVO.getDurationMs()); + featureTestRes.setResidualVoltage(featurePointVO.getResidualVoltage()); + featureTestRes.setTolerant(2); + saveTestResList.add(featureTestRes); + } + } } } } diff --git a/detection/src/main/java/com/njcn/gather/freqConverter/config/FreqConverterConfig.java b/detection/src/main/java/com/njcn/gather/freqConverter/config/FreqConverterConfig.java index 728a0fef..8a258f1e 100644 --- a/detection/src/main/java/com/njcn/gather/freqConverter/config/FreqConverterConfig.java +++ b/detection/src/main/java/com/njcn/gather/freqConverter/config/FreqConverterConfig.java @@ -16,4 +16,6 @@ public class FreqConverterConfig { private Integer tolerant; private Integer dt; private Integer direction; + private Integer allowErrorDuration; + private Double allowErrorResidualVoltage; } diff --git a/detection/src/main/java/com/njcn/gather/freqConverter/service/IPqFreqConverterTestResService.java b/detection/src/main/java/com/njcn/gather/freqConverter/service/IPqFreqConverterTestResService.java index 7a5040be..4eddb85b 100644 --- a/detection/src/main/java/com/njcn/gather/freqConverter/service/IPqFreqConverterTestResService.java +++ b/detection/src/main/java/com/njcn/gather/freqConverter/service/IPqFreqConverterTestResService.java @@ -53,4 +53,7 @@ public interface IPqFreqConverterTestResService extends IService listTestRes(Integer suffix); + PqFreqConverterTestRes getLastByDuration(Integer suffix, Integer durationMs); + + PqFreqConverterTestRes getLastByResidualVoltage(Integer suffix, Double residualVoltage); } diff --git a/detection/src/main/java/com/njcn/gather/freqConverter/service/impl/PqFreqConverterTestResServiceImpl.java b/detection/src/main/java/com/njcn/gather/freqConverter/service/impl/PqFreqConverterTestResServiceImpl.java index 9b614640..04bb2aea 100644 --- a/detection/src/main/java/com/njcn/gather/freqConverter/service/impl/PqFreqConverterTestResServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/freqConverter/service/impl/PqFreqConverterTestResServiceImpl.java @@ -1,10 +1,13 @@ package com.njcn.gather.freqConverter.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler; +import com.njcn.gather.freqConverter.config.FreqConverterConfig; import com.njcn.gather.freqConverter.mapper.PqFreqConverterTestResMapper; import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterTestRes; import com.njcn.gather.freqConverter.service.IPqFreqConverterTestResService; +import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; import java.util.List; @@ -14,7 +17,10 @@ import java.util.List; * @data 2026-04-14 */ @Service +@AllArgsConstructor public class PqFreqConverterTestResServiceImpl extends ServiceImpl implements IPqFreqConverterTestResService { + private final FreqConverterConfig freqConverterConfig; + @Override public void clearAllData(Integer suffix) { DynamicTableNameHandler.setTableName(PqFreqConverterConfigServiceImpl.PQ_FREQ_CONVERTER_TEST_RES_TB_PREFIX + suffix); @@ -51,4 +57,27 @@ public class PqFreqConverterTestResServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.between(PqFreqConverterTestRes::getDurationMs, durationMs - freqConverterConfig.getAllowErrorDuration(), durationMs + freqConverterConfig.getAllowErrorDuration()) + .orderByAsc(PqFreqConverterTestRes::getResidualVoltage) + .last("limit 1"); + PqFreqConverterTestRes result = this.getOne(queryWrapper); + DynamicTableNameHandler.remove(); + return result; + } + + @Override + public PqFreqConverterTestRes getLastByResidualVoltage(Integer suffix, Double residualVoltage) { + DynamicTableNameHandler.setTableName(PqFreqConverterConfigServiceImpl.PQ_FREQ_CONVERTER_TEST_RES_TB_PREFIX + suffix); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.between(PqFreqConverterTestRes::getResidualVoltage, residualVoltage - freqConverterConfig.getAllowErrorResidualVoltage(), residualVoltage + freqConverterConfig.getAllowErrorDuration()) + .orderByDesc(PqFreqConverterTestRes::getDurationMs) + .last("limit 1"); + PqFreqConverterTestRes result = this.getOne(queryWrapper); + DynamicTableNameHandler.remove(); + return result; + } } diff --git a/entrance/src/main/resources/application.yml b/entrance/src/main/resources/application.yml index 2f08473d..bc2fb607 100644 --- a/entrance/src/main/resources/application.yml +++ b/entrance/src/main/resources/application.yml @@ -9,7 +9,7 @@ spring: # url: jdbc:mysql://192.168.1.24:13306/pqs91002?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true # username: root # password: njcnpqs - url: jdbc:mysql://192.168.1.24:13306/pqs9100?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true + url: jdbc:mysql://192.168.1.24:13306/pqs9100_hn?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true username: root password: njcnpqs #初始化建立物理连接的个数、最小、最大连接数 @@ -131,4 +131,6 @@ freq-converter: schedule-period: 200 #定时器运行间隔 tolerant: 1 #耐受状态 dt: 200 #延迟时间ms - direction: 1 #0为横向1为纵向 \ No newline at end of file + direction: 1 #0为横向1为纵向 + allow-error-duration: 6 #暂态持续时间允许最大误差ms + allow-error-vesidual-voltage: 2.0 #暂态幅值允许最多误差% \ No newline at end of file