From 2293d81b71e590c53087e3bdc7fa8d4cf6b7dd9c Mon Sep 17 00:00:00 2001 From: caozehui <2427765068@qq.com> Date: Tue, 14 Apr 2026 14:51:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A8=E6=80=81=E5=88=9B=E5=BB=BA=E8=A1=A8?= =?UTF-8?q?=E7=BB=93=E6=9E=84=E3=80=81=E5=85=A5=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PreDetectionController.java | 23 ++++++ .../SocketFreqConverterDevService.java | 14 +++- .../handler/SocketFreqConverterService.java | 10 ++- .../pojo/enums/DetectionResponseEnum.java | 3 +- .../service/PreDetectionService.java | 8 +- .../service/impl/PreDetectionServiceImpl.java | 39 +++++++++- .../detection/util/socket/CnSocketUtil.java | 2 + .../util/socket/FormalTestManager.java | 4 + .../gather/dip/mapper/PqDipDataMapper.java | 4 +- .../njcn/gather/dip/pojo/po/PqDipData.java | 11 +-- .../gather/dip/service/IPqDipDataService.java | 12 +++ .../service/impl/PqDipDataServiceImpl.java | 19 +++++ .../controller/FreqConverterController.java | 24 ++++-- .../pojo/param/PqFreqConverterParam.java | 2 +- .../pojo/po/FreqConverterStatus.java | 10 +-- .../service/IFreqConverterService.java | 16 ++-- .../IPqFreqConverterConfigService.java | 7 +- .../impl/FreqConverterServiceImpl.java | 38 ++++++++-- .../PqFreqConverterConfigServiceImpl.java | 76 +++++++++++++++++-- entrance/src/main/resources/application.yml | 11 ++- .../gather/storage/mapper/TableGenMapper.java | 2 + .../storage/mapper/mapping/TableGenMapper.xml | 4 + 22 files changed, 268 insertions(+), 71 deletions(-) diff --git a/detection/src/main/java/com/njcn/gather/detection/controller/PreDetectionController.java b/detection/src/main/java/com/njcn/gather/detection/controller/PreDetectionController.java index f3b2700a..4cd63a77 100644 --- a/detection/src/main/java/com/njcn/gather/detection/controller/PreDetectionController.java +++ b/detection/src/main/java/com/njcn/gather/detection/controller/PreDetectionController.java @@ -10,6 +10,7 @@ import com.njcn.gather.detection.pojo.param.ContrastDetectionParam; import com.njcn.gather.detection.pojo.param.PreDetectionParam; import com.njcn.gather.detection.pojo.param.SimulateDetectionParam; import com.njcn.gather.detection.service.PreDetectionService; +import com.njcn.gather.detection.util.socket.CnSocketUtil; import com.njcn.web.controller.BaseController; import com.njcn.web.utils.HttpResultUtil; import io.swagger.annotations.Api; @@ -176,4 +177,26 @@ public class PreDetectionController extends BaseController { preDetectionService.startCoefficient(); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); } + + @OperateInfo(info = LogEnum.SYSTEM_COMMON) + @GetMapping("/startFreqConverter") + @ApiOperation("开启变频器测试") + public HttpResult startFreqConverter(@RequestParam("loginName") String loginName, @RequestParam("converterId") String converterId, @RequestParam("monitorId") String monitorId) { + String methodDescribe = getMethodDescribe("startFreqConverter"); + LogUtil.njcnDebug(log, "{}", methodDescribe); + + preDetectionService.startFreqConverter(loginName, converterId, monitorId); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + } + + @OperateInfo(info = LogEnum.SYSTEM_COMMON) + @GetMapping("/stopFreqConverter") + @ApiOperation("关闭变频器测试") + public HttpResult stopFreqConverter(@RequestParam("loginName") String loginName) { + String methodDescribe = getMethodDescribe("stopFreqConverter"); + LogUtil.njcnDebug(log, "{}", methodDescribe); + + preDetectionService.stopFreqConverter(loginName + CnSocketUtil.FREQ_CONVERTER_TAG, loginName + CnSocketUtil.DEV_TAG); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + } } diff --git a/detection/src/main/java/com/njcn/gather/detection/handler/SocketFreqConverterDevService.java b/detection/src/main/java/com/njcn/gather/detection/handler/SocketFreqConverterDevService.java index 9765264b..244cc325 100644 --- a/detection/src/main/java/com/njcn/gather/detection/handler/SocketFreqConverterDevService.java +++ b/detection/src/main/java/com/njcn/gather/detection/handler/SocketFreqConverterDevService.java @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.ListUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; +import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler; import com.njcn.gather.detection.pojo.enums.DetectionCodeEnum; import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum; import com.njcn.gather.detection.pojo.enums.SourceResponseCodeEnum; @@ -22,6 +23,7 @@ import com.njcn.gather.device.pojo.vo.PreDetection; import com.njcn.gather.device.service.IPqDevService; import com.njcn.gather.dip.pojo.po.PqDipData; import com.njcn.gather.dip.service.IPqDipDataService; +import com.njcn.gather.freqConverter.service.IPqFreqConverterConfigService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -39,6 +41,8 @@ public class SocketFreqConverterDevService { private final SocketConnectionConfig socketConnectionConfig; private final IPqDevService pqDevService; private final IPqDipDataService pqDipDataService; + private final IPqFreqConverterConfigService pqFreqConverterConfigService; + private String monitorId; /** * 连接设备Socket @@ -61,6 +65,8 @@ public class SocketFreqConverterDevService { private void init(String converterId, String monitorId) { FormalTestManager.freqConverterDevStep = null; FormalTestManager.stopFlag = false; + pqDipDataService.clearAllData(FormalTestManager.freqConverterTableSuffix); + this.monitorId = monitorId; } /** @@ -185,14 +191,14 @@ public class SocketFreqConverterDevService { return JSON.toJSONString(payload); } - private void sendGetDipDataMsg(String monitorId) { + private void sendGetDipDataMsg(String devTag) { SocketMsg socketMsg = new SocketMsg<>(); socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue()); socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue()); DevPhaseSequenceParam phaseSequenceParam = new DevPhaseSequenceParam(); // 设置监测点ID列表 - phaseSequenceParam.setMoniterIdList(ListUtil.of(monitorId)); + phaseSequenceParam.setMoniterIdList(ListUtil.of(this.monitorId)); // 设置数据类型列表 phaseSequenceParam.setDataType(ListUtil.of("avg$MAG", "avg$DUR")); @@ -202,7 +208,7 @@ public class SocketFreqConverterDevService { phaseSequenceParam.setIgnoreCount(0); socketMsg.setData(JSON.toJSONString(phaseSequenceParam)); socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_DATA_REQUEST_03.getValue()); - SocketManager.sendMsg(monitorId, JSON.toJSONString(socketMsg)); + SocketManager.sendMsg(devTag, JSON.toJSONString(socketMsg)); } private void sendQuitMsg(String devTag, SourceOperateCodeEnum operateCodeEnum) { @@ -240,7 +246,9 @@ public class SocketFreqConverterDevService { pqDipData.setStartTime(LocalDateTime.parse(devData.getTime())); pqDipData.setResidualVoltage(residualVoltage); pqDipData.setDurationMs(durationMs); + DynamicTableNameHandler.setTableName("pq_dip_data_" + FormalTestManager.freqConverterTableSuffix); pqDipDataService.save(pqDipData); + DynamicTableNameHandler.remove(); } private Double getSqlDataValue(DevData.SqlDataDTO.ListDTO listDTO) { 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 3a30eb03..fbcab947 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 @@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.alibaba.fastjson.JSON; +import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler; import com.njcn.gather.detection.pojo.dto.FreqConverterRespDTO; import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum; import com.njcn.gather.detection.pojo.vo.SocketMsg; @@ -99,7 +100,9 @@ public class SocketFreqConverterService { private void init(String converterId, String monitorId) { FormalTestManager.freqConverterStep = null; - FormalTestManager.pairsIpMap.put(converterId, monitorId); + Integer suffix = pqFreqConverterConfigService.getSuffix(converterId); + freqConverterService.clearAllData(suffix); + FormalTestManager.freqConverterTableSuffix = suffix; clearScheduleTask(); } @@ -159,7 +162,6 @@ public class SocketFreqConverterService { } else { FormalTestManager.stopFlag = false; } - FormalTestManager.pairsIpMap.clear(); if (removeSocket) { SocketManager.removeUser(converterChannelTag); } else { @@ -170,7 +172,7 @@ public class SocketFreqConverterService { private void handleInitSerial(String converterChannelTag, FreqConverterRespDTO respDTO) { if (respDTO.getCode() == 0 && respDTO.getSuccess()) { FormalTestManager.freqConverterStep = SourceOperateCodeEnum.CMD_GET_DEVICE_STATUS; - freqConverterService.clearAllData(); + if (Objects.isNull(FormalTestManager.scheduler)) { FormalTestManager.scheduler = Executors.newScheduledThreadPool(1); FormalTestManager.scheduledFuture = FormalTestManager.scheduler.scheduleAtFixedRate(() -> { @@ -195,7 +197,7 @@ public class SocketFreqConverterService { } else { FormalTestManager.stopFlag = false; } - freqConverterService.saveFreqConverterStatus(freqConverterStatus); + freqConverterService.saveFreqConverterStatus(FormalTestManager.freqConverterTableSuffix,freqConverterStatus); } private void handleCloseSerial(String converterChannelTag, FreqConverterRespDTO respDTO) { diff --git a/detection/src/main/java/com/njcn/gather/detection/pojo/enums/DetectionResponseEnum.java b/detection/src/main/java/com/njcn/gather/detection/pojo/enums/DetectionResponseEnum.java index 64b4ceb9..a96f55fe 100644 --- a/detection/src/main/java/com/njcn/gather/detection/pojo/enums/DetectionResponseEnum.java +++ b/detection/src/main/java/com/njcn/gather/detection/pojo/enums/DetectionResponseEnum.java @@ -19,7 +19,8 @@ public enum DetectionResponseEnum { SCRIPT_CHECK_DATA_NOT_EXIST("A020040","测试脚本项暂无配置" ), - EXCEED_MAX_TIME("A020041","检测次数超出最大限制!" ); + EXCEED_MAX_TIME("A020041","检测次数超出最大限制!" ), + SOCKET_CONNECT_TIMEOUT("A020042","socket连接超时!"); private final String code; private final String message; diff --git a/detection/src/main/java/com/njcn/gather/detection/service/PreDetectionService.java b/detection/src/main/java/com/njcn/gather/detection/service/PreDetectionService.java index 0dd75a53..e37bed66 100644 --- a/detection/src/main/java/com/njcn/gather/detection/service/PreDetectionService.java +++ b/detection/src/main/java/com/njcn/gather/detection/service/PreDetectionService.java @@ -4,9 +4,6 @@ import com.njcn.gather.detection.pojo.param.ContrastDetectionParam; import com.njcn.gather.detection.pojo.param.PreDetectionParam; import com.njcn.gather.detection.pojo.param.SimulateDetectionParam; -import java.util.List; -import java.util.Map; - /** * @author wr @@ -55,7 +52,6 @@ public interface PreDetectionService { void closeTestSimulate(SimulateDetectionParam param); /** - * * @param param */ void startContrastTest(ContrastDetectionParam param); @@ -68,4 +64,8 @@ public interface PreDetectionService { boolean getCanCoefficient(); void startCoefficient(); + + void startFreqConverter(String name, String converterId, String monitorId); + + void stopFreqConverter(String converterId, String monitorId); } diff --git a/detection/src/main/java/com/njcn/gather/detection/service/impl/PreDetectionServiceImpl.java b/detection/src/main/java/com/njcn/gather/detection/service/impl/PreDetectionServiceImpl.java index 87cd8833..5f0b26d0 100644 --- a/detection/src/main/java/com/njcn/gather/detection/service/impl/PreDetectionServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/detection/service/impl/PreDetectionServiceImpl.java @@ -6,9 +6,7 @@ import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.njcn.common.pojo.exception.BusinessException; -import com.njcn.gather.detection.handler.SocketContrastResponseService; -import com.njcn.gather.detection.handler.SocketDevResponseService; -import com.njcn.gather.detection.handler.SocketSourceResponseService; +import com.njcn.gather.detection.handler.*; import com.njcn.gather.detection.pojo.constant.DetectionCommunicateConstant; import com.njcn.gather.detection.pojo.enums.DetectionResponseEnum; import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum; @@ -76,6 +74,8 @@ public class PreDetectionServiceImpl implements PreDetectionService { private final SocketDevResponseService socketDevResponseService; private final SocketSourceResponseService socketSourceResponseService; private final SocketContrastResponseService socketContrastResponseService; + private final SocketFreqConverterService socketFreqConverterService; + private final SocketFreqConverterDevService socketFreqConverterDevService; private final IPqScriptCheckDataService iPqScriptCheckDataService; private final SocketManager socketManager; private final ISysTestConfigService sysTestConfigService; @@ -393,6 +393,37 @@ public class PreDetectionServiceImpl implements PreDetectionService { } } + @Override + public void startFreqConverter(String loginName, String converterId, String monitorId) { + String freqConverterTag = loginName + CnSocketUtil.FREQ_CONVERTER_TAG; + String devTag = loginName + CnSocketUtil.DEV_TAG; + socketFreqConverterService.connectSocket(freqConverterTag); + //socketFreqConverterDevService.connectSocket(devTag); + + long startTime = System.currentTimeMillis(); + long timeout = 3000; // 3秒超时时间 + while (true) { +// if (SocketManager.isChannelActive(freqConverterTag) && SocketManager.isChannelActive(devTag)) { + if (SocketManager.isChannelActive(freqConverterTag)) { + socketFreqConverterService.connectionFreqConverter(freqConverterTag, converterId, monitorId); + //socketFreqConverterDevService.connectionDev(devTag, converterId, monitorId); + break; + } + + // 检查是否超时 + if (System.currentTimeMillis() - startTime > timeout) { + throw new BusinessException(DetectionResponseEnum.SOCKET_CONNECT_TIMEOUT); + } + } + + } + + @Override + public void stopFreqConverter(String converterTag, String devTag) { + socketFreqConverterService.stopTest(converterTag, devTag); + socketFreqConverterDevService.stopTest(converterTag, converterTag); + } + /** * 比对式-与通信模块进行连接 * @@ -451,4 +482,4 @@ public class PreDetectionServiceImpl implements PreDetectionService { } } -} \ No newline at end of file +} diff --git a/detection/src/main/java/com/njcn/gather/detection/util/socket/CnSocketUtil.java b/detection/src/main/java/com/njcn/gather/detection/util/socket/CnSocketUtil.java index 090a7da6..ff66e737 100644 --- a/detection/src/main/java/com/njcn/gather/detection/util/socket/CnSocketUtil.java +++ b/detection/src/main/java/com/njcn/gather/detection/util/socket/CnSocketUtil.java @@ -14,6 +14,8 @@ import com.njcn.gather.detection.util.socket.websocket.WebServiceManager; */ public class CnSocketUtil { + public final static String FREQ_CONVERTER_TAG="_FreqConverter"; + public final static String DEV_TAG = "_Dev"; public final static String CONTRAST_DEV_TAG = "_Contrast_Dev"; 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 7e310de0..5a3606d9 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 @@ -33,6 +33,10 @@ public class FormalTestManager { public static SourceOperateCodeEnum freqConverterStep; public static SourceOperateCodeEnum freqConverterDevStep; + /** + * 变频器存放数据的表后缀 + */ + public static Integer freqConverterTableSuffix; /** * key:设备ip,value:当前设备下面的监测点ID(ip_通道号) diff --git a/detection/src/main/java/com/njcn/gather/dip/mapper/PqDipDataMapper.java b/detection/src/main/java/com/njcn/gather/dip/mapper/PqDipDataMapper.java index 83ac7cf6..b0de97ba 100644 --- a/detection/src/main/java/com/njcn/gather/dip/mapper/PqDipDataMapper.java +++ b/detection/src/main/java/com/njcn/gather/dip/mapper/PqDipDataMapper.java @@ -1,11 +1,11 @@ package com.njcn.gather.dip.mapper; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.github.yulichang.base.MPJBaseMapper; import com.njcn.gather.dip.pojo.po.PqDipData; /** * @author caozehui * @date 2026-04-09 */ -public interface PqDipDataMapper extends BaseMapper { +public interface PqDipDataMapper extends MPJBaseMapper { } diff --git a/detection/src/main/java/com/njcn/gather/dip/pojo/po/PqDipData.java b/detection/src/main/java/com/njcn/gather/dip/pojo/po/PqDipData.java index 9f72dc7f..66cdbaa5 100644 --- a/detection/src/main/java/com/njcn/gather/dip/pojo/po/PqDipData.java +++ b/detection/src/main/java/com/njcn/gather/dip/pojo/po/PqDipData.java @@ -1,11 +1,8 @@ package com.njcn.gather.dip.pojo.po; 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.time.LocalDateTime; /** @@ -15,11 +12,8 @@ import java.time.LocalDateTime; * @date 2026-04-09 */ @Data -@EqualsAndHashCode(callSuper = true) -@TableName("pq_dip_data") -public class PqDipData extends BaseEntity implements Serializable { - - private static final long serialVersionUID = 1L; +@TableName(value = "ad_harmonic_xx") +public class PqDipData { /** * 主键ID @@ -37,7 +31,6 @@ public class PqDipData extends BaseEntity implements Serializable { private Double residualVoltage; /** - * * 持续时间,单位:ms */ private Integer durationMs; diff --git a/detection/src/main/java/com/njcn/gather/dip/service/IPqDipDataService.java b/detection/src/main/java/com/njcn/gather/dip/service/IPqDipDataService.java index d851f0c1..33f5eda8 100644 --- a/detection/src/main/java/com/njcn/gather/dip/service/IPqDipDataService.java +++ b/detection/src/main/java/com/njcn/gather/dip/service/IPqDipDataService.java @@ -3,9 +3,21 @@ package com.njcn.gather.dip.service; import com.baomidou.mybatisplus.extension.service.IService; import com.njcn.gather.dip.pojo.po.PqDipData; +import java.util.List; + /** * @author caozehui * @date 2026-04-09 */ public interface IPqDipDataService extends IService { + + /** + * 查询指定变频器所对应的电压暂降数据 + * + * @param suffix 表后缀 + * @return + */ + List listDipData(Integer suffix); + + void clearAllData(Integer suffix); } diff --git a/detection/src/main/java/com/njcn/gather/dip/service/impl/PqDipDataServiceImpl.java b/detection/src/main/java/com/njcn/gather/dip/service/impl/PqDipDataServiceImpl.java index 1111c307..4c755b79 100644 --- a/detection/src/main/java/com/njcn/gather/dip/service/impl/PqDipDataServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/dip/service/impl/PqDipDataServiceImpl.java @@ -1,15 +1,34 @@ package com.njcn.gather.dip.service.impl; +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler; import com.njcn.gather.dip.mapper.PqDipDataMapper; import com.njcn.gather.dip.pojo.po.PqDipData; import com.njcn.gather.dip.service.IPqDipDataService; import org.springframework.stereotype.Service; +import java.util.List; + /** * @author caozehui * @date 2026-04-09 */ @Service public class PqDipDataServiceImpl extends ServiceImpl implements IPqDipDataService { + @Override + public List listDipData(Integer suffix) { + DynamicTableNameHandler.setTableName("pq_dip_data_" + suffix); + LambdaQueryChainWrapper wrapper = this.lambdaQuery().orderByAsc(PqDipData::getStartTime); + List result = wrapper.list(); + DynamicTableNameHandler.remove(); + return result; + } + + @Override + public void clearAllData(Integer suffix) { + DynamicTableNameHandler.setTableName("pq_dip_data_" + suffix); + this.remove(null); + DynamicTableNameHandler.remove(); + } } diff --git a/detection/src/main/java/com/njcn/gather/freqConverter/controller/FreqConverterController.java b/detection/src/main/java/com/njcn/gather/freqConverter/controller/FreqConverterController.java index 331fec5a..92e3cff2 100644 --- a/detection/src/main/java/com/njcn/gather/freqConverter/controller/FreqConverterController.java +++ b/detection/src/main/java/com/njcn/gather/freqConverter/controller/FreqConverterController.java @@ -7,9 +7,9 @@ import com.njcn.common.pojo.constant.OperateType; import com.njcn.common.pojo.enums.response.CommonResponseEnum; import com.njcn.common.pojo.response.HttpResult; import com.njcn.common.utils.LogUtil; -import com.njcn.gather.device.pojo.param.PqDevParam; import com.njcn.gather.freqConverter.pojo.param.PqFreqConverterParam; import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterConfig; +import com.njcn.gather.freqConverter.pojo.vo.TolerantPointVO; import com.njcn.gather.freqConverter.service.IFreqConverterService; import com.njcn.gather.freqConverter.service.IPqFreqConverterConfigService; import com.njcn.web.controller.BaseController; @@ -20,10 +20,9 @@ import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import java.util.List; /** * @author caozehui @@ -84,10 +83,10 @@ public class FreqConverterController extends BaseController { @PostMapping("/delete") @ApiOperation("删除变频器") @ApiImplicitParam(name = "param", value = "删除参数", required = true) - public HttpResult delete(@RequestBody @Validated PqDevParam.DeleteParam param) { + public HttpResult delete(@RequestBody @Validated List ids) { String methodDescribe = getMethodDescribe("delete"); - LogUtil.njcnDebug(log, "{},删除ID数据为:{}", methodDescribe, String.join(StrUtil.COMMA, param.getIds())); - boolean result = pqFreqConverterConfigService.deletePqFreqConverterConfig(param); + LogUtil.njcnDebug(log, "{},删除ID数据为:{}", methodDescribe, String.join(StrUtil.COMMA, ids)); + boolean result = pqFreqConverterConfigService.deletePqFreqConverterConfig(ids); if (result) { return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe); } else { @@ -95,4 +94,13 @@ public class FreqConverterController extends BaseController { } } + @GetMapping("/result") + @ApiOperation("查询耐受实验结果") + @ApiImplicitParam(name = "param", value = "查询参数", required = true) + public HttpResult> result(@RequestParam("converterId") String converterId) { + String methodDescribe = getMethodDescribe("result"); + LogUtil.njcnDebug(log, "{},查询ID数据为:{}", methodDescribe, converterId); + List tolerantPoints = freqConverterService.getTolerantPoints(converterId); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, tolerantPoints, methodDescribe); + } } diff --git a/detection/src/main/java/com/njcn/gather/freqConverter/pojo/param/PqFreqConverterParam.java b/detection/src/main/java/com/njcn/gather/freqConverter/pojo/param/PqFreqConverterParam.java index 90dd0551..0cb6e66c 100644 --- a/detection/src/main/java/com/njcn/gather/freqConverter/pojo/param/PqFreqConverterParam.java +++ b/detection/src/main/java/com/njcn/gather/freqConverter/pojo/param/PqFreqConverterParam.java @@ -56,7 +56,7 @@ public class PqFreqConverterParam { */ @Data @EqualsAndHashCode(callSuper = true) - public static class UpdateParam extends PqDevParam { + public static class UpdateParam extends PqFreqConverterParam { @ApiModelProperty(value = "id", required = true) @NotBlank(message = DetectionValidMessage.ID_NOT_BLANK) diff --git a/detection/src/main/java/com/njcn/gather/freqConverter/pojo/po/FreqConverterStatus.java b/detection/src/main/java/com/njcn/gather/freqConverter/pojo/po/FreqConverterStatus.java index eb4e73f0..22d4116f 100644 --- a/detection/src/main/java/com/njcn/gather/freqConverter/pojo/po/FreqConverterStatus.java +++ b/detection/src/main/java/com/njcn/gather/freqConverter/pojo/po/FreqConverterStatus.java @@ -1,11 +1,8 @@ package com.njcn.gather.freqConverter.pojo.po; 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.time.LocalDateTime; /** @@ -13,11 +10,8 @@ import java.time.LocalDateTime; * @data 2026-04-07 */ @Data -@EqualsAndHashCode(callSuper = true) -@TableName("pq_freq_converter_status") -public class FreqConverterStatus extends BaseEntity implements Serializable { - - private static final long serialVersionUID = 1L; +@TableName(value = "ad_harmonic_xx") +public class FreqConverterStatus { /** * 主键ID diff --git a/detection/src/main/java/com/njcn/gather/freqConverter/service/IFreqConverterService.java b/detection/src/main/java/com/njcn/gather/freqConverter/service/IFreqConverterService.java index 68c26eaa..75d6ea55 100644 --- a/detection/src/main/java/com/njcn/gather/freqConverter/service/IFreqConverterService.java +++ b/detection/src/main/java/com/njcn/gather/freqConverter/service/IFreqConverterService.java @@ -1,7 +1,6 @@ package com.njcn.gather.freqConverter.service; import com.baomidou.mybatisplus.extension.service.IService; -import com.njcn.gather.dip.pojo.po.PqDipData; import com.njcn.gather.freqConverter.pojo.po.FreqConverterStatus; import com.njcn.gather.freqConverter.pojo.vo.TolerantPointVO; @@ -17,10 +16,11 @@ public interface IFreqConverterService extends IService { /** * 保存变频器状态数据 * + * @param suffix 表后缀 * @param status 变频器状态数据 * @return 是否保存成功 */ - boolean saveFreqConverterStatus(FreqConverterStatus status); + boolean saveFreqConverterStatus(Integer suffix, FreqConverterStatus status); /** @@ -29,23 +29,21 @@ public interface IFreqConverterService extends IService { * @param converterId 变频器ID * @return 状态数据列表 */ - List listStatusHistory(String converterId); + List listStatusData(String converterId); /** * 清空所有数据 * + * @param converterId 变频器ID * @return */ - boolean clearAllData(); + void clearAllData(Integer converterId); /** * 根据设备暂降数据判断变频器是否耐受 * - * @param freqConverterDataList 变频器数据集合 - * @param dipDataList 设备暂降数据集合 + * @param converterId 变频器Id * @return 是否耐受 */ - List getTolerantPoints(List freqConverterDataList, List dipDataList); - - + List getTolerantPoints(String converterId); } diff --git a/detection/src/main/java/com/njcn/gather/freqConverter/service/IPqFreqConverterConfigService.java b/detection/src/main/java/com/njcn/gather/freqConverter/service/IPqFreqConverterConfigService.java index 8ddd0be9..eeebf38c 100644 --- a/detection/src/main/java/com/njcn/gather/freqConverter/service/IPqFreqConverterConfigService.java +++ b/detection/src/main/java/com/njcn/gather/freqConverter/service/IPqFreqConverterConfigService.java @@ -6,6 +6,8 @@ import com.njcn.gather.device.pojo.param.PqDevParam; import com.njcn.gather.freqConverter.pojo.param.PqFreqConverterParam; import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterConfig; +import java.util.List; + /** * @author caozehui * @data 2026-04-08 @@ -13,9 +15,12 @@ import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterConfig; public interface IPqFreqConverterConfigService extends IService { Page listPqFreqConverterConfigs(PqFreqConverterParam.QueryParam queryParam); + Integer getSuffix(String converterId); + boolean addPqFreqConverterConfig(PqFreqConverterParam param); boolean updatePqFreqConverterConfig(PqFreqConverterParam.UpdateParam param); - boolean deletePqFreqConverterConfig(PqDevParam.DeleteParam param); + boolean deletePqFreqConverterConfig(List ids); + } diff --git a/detection/src/main/java/com/njcn/gather/freqConverter/service/impl/FreqConverterServiceImpl.java b/detection/src/main/java/com/njcn/gather/freqConverter/service/impl/FreqConverterServiceImpl.java index a24e44f8..6ff8beed 100644 --- a/detection/src/main/java/com/njcn/gather/freqConverter/service/impl/FreqConverterServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/freqConverter/service/impl/FreqConverterServiceImpl.java @@ -1,11 +1,16 @@ package com.njcn.gather.freqConverter.service.impl; +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler; import com.njcn.gather.dip.pojo.po.PqDipData; +import com.njcn.gather.dip.service.IPqDipDataService; import com.njcn.gather.freqConverter.mapper.FreqConverterStatusMapper; import com.njcn.gather.freqConverter.pojo.po.FreqConverterStatus; import com.njcn.gather.freqConverter.pojo.vo.TolerantPointVO; import com.njcn.gather.freqConverter.service.IFreqConverterService; +import com.njcn.gather.freqConverter.service.IPqFreqConverterConfigService; +import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -26,26 +31,45 @@ import java.util.List; * @since 2026 */ @Service +@AllArgsConstructor public class FreqConverterServiceImpl extends ServiceImpl implements IFreqConverterService { + private final IPqFreqConverterConfigService pqFreqConverterConfigService; + private final IPqDipDataService dipDataService; @Override @Transactional(rollbackFor = Exception.class) - public boolean saveFreqConverterStatus(FreqConverterStatus status) { - return this.save(status); + public boolean saveFreqConverterStatus(Integer suffix, FreqConverterStatus status) { + DynamicTableNameHandler.setTableName("pq_freq_converter_status_" + suffix); + boolean result = this.save(status); + DynamicTableNameHandler.remove(); + return result; } @Override - public List listStatusHistory(String converterId) { - return this.lambdaQuery().list(); + public List listStatusData(String converterId) { + Integer suffix = pqFreqConverterConfigService.getSuffix(converterId); + + DynamicTableNameHandler.setTableName("pq_freq_converter_status_" + suffix); + LambdaQueryChainWrapper wrapper = this.lambdaQuery().orderByAsc(FreqConverterStatus::getTimestamp); + List result = wrapper.list(); + DynamicTableNameHandler.remove(); + + return result; } @Override - public boolean clearAllData() { - return this.remove(null); + @Transactional(rollbackFor = Exception.class) + public void clearAllData(Integer suffix) { + DynamicTableNameHandler.setTableName("pq_freq_converter_status_" + suffix); + this.remove(null); + DynamicTableNameHandler.remove(); } @Override - public List getTolerantPoints(List freqConverterDataList, List dipDataList) { + public List getTolerantPoints(String converterId) { + Integer suffix = pqFreqConverterConfigService.getSuffix(converterId); + List freqConverterDataList = this.listStatusData(converterId); + List dipDataList = dipDataService.listDipData(suffix); dipDataList.sort(Comparator.comparing(PqDipData::getDurationMs)); List res = new ArrayList<>(); diff --git a/detection/src/main/java/com/njcn/gather/freqConverter/service/impl/PqFreqConverterConfigServiceImpl.java b/detection/src/main/java/com/njcn/gather/freqConverter/service/impl/PqFreqConverterConfigServiceImpl.java index 056ca49f..eab9ee2e 100644 --- a/detection/src/main/java/com/njcn/gather/freqConverter/service/impl/PqFreqConverterConfigServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/freqConverter/service/impl/PqFreqConverterConfigServiceImpl.java @@ -1,43 +1,107 @@ package com.njcn.gather.freqConverter.service.impl; import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.njcn.gather.device.pojo.param.PqDevParam; +import com.njcn.common.pojo.enums.common.DataStateEnum; import com.njcn.gather.freqConverter.mapper.PqFreqConverterConfigMapper; import com.njcn.gather.freqConverter.pojo.param.PqFreqConverterParam; import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterConfig; import com.njcn.gather.freqConverter.service.IPqFreqConverterConfigService; +import com.njcn.gather.storage.mapper.TableGenMapper; +import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; /** * @author caozehui * @data 2026-04-08 */ @Service +@AllArgsConstructor public class PqFreqConverterConfigServiceImpl extends ServiceImpl implements IPqFreqConverterConfigService { + private final TableGenMapper tableGenMapper; + @Override public Page listPqFreqConverterConfigs(PqFreqConverterParam.QueryParam queryParam) { - QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.like("name", queryParam.getName()); - return this.page(new Page<>(queryParam.getPageNum(), queryParam.getPageSize()), queryWrapper); + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.like(StrUtil.isNotBlank(queryParam.getName()), "name", queryParam.getName()); + wrapper.eq("state", 1); + return this.page(new Page<>(queryParam.getPageNum(), queryParam.getPageSize()), wrapper); } @Override + public Integer getSuffix(String converterId) { + PqFreqConverterConfig freqConverterConfig = this.lambdaQuery().eq(PqFreqConverterConfig::getId, converterId).one(); + return freqConverterConfig.getSuffix(); + } + + @Override + @Transactional(rollbackFor = Exception.class) public boolean addPqFreqConverterConfig(PqFreqConverterParam param) { + // 建表 + PqFreqConverterConfig freqConverterConfig = this.lambdaQuery().orderByDesc(PqFreqConverterConfig::getSuffix) + .last("limit 1").one(); + Integer maxSuffix = 1; + if (ObjectUtil.isNotNull(freqConverterConfig)) { + maxSuffix = freqConverterConfig.getSuffix() + 1; + } + + String tableSql = "CREATE TABLE `pq_freq_converter_status_" + maxSuffix + "` (" + + " `id` char(32) NOT NULL COMMENT '主键ID'," + + " `slave_address` int(11) DEFAULT NULL COMMENT '从机地址'," + + " `status_word1` int(11) DEFAULT NULL COMMENT '状态字1'," + + " `status_word1_hex` varchar(20) DEFAULT NULL COMMENT '状态字1十六进制'," + + " `timestamp` datetime(3) NOT NULL COMMENT '状态记录时刻(时间戳)'," + + " PRIMARY KEY (`id`) USING BTREE" + + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='变频器状态表';"; + tableGenMapper.genTable(tableSql); + + tableSql = "CREATE TABLE `pq_dip_data_" + maxSuffix + "` (" + + " `id` char(32) NOT NULL COMMENT '主键ID'," + + " `start_time` datetime(3) NOT NULL COMMENT '起始时间戳'," + + " `residual_voltage` decimal(6,2) NOT NULL COMMENT '残余电压(%Ur)'," + + " `duration_ms` int(11) NOT NULL COMMENT '持续时间(ms)'," + + " PRIMARY KEY (`id`)" + + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电压暂降数据表';"; + tableGenMapper.genTable(tableSql); + PqFreqConverterConfig pqFreqConverterConfig = BeanUtil.copyProperties(param, PqFreqConverterConfig.class); + pqFreqConverterConfig.setSuffix(maxSuffix); + pqFreqConverterConfig.setState(DataStateEnum.ENABLE.getCode()); return this.save(pqFreqConverterConfig); } @Override + @Transactional(rollbackFor = Exception.class) public boolean updatePqFreqConverterConfig(PqFreqConverterParam.UpdateParam param) { PqFreqConverterConfig pqFreqConverterConfig = BeanUtil.copyProperties(param, PqFreqConverterConfig.class); return this.updateById(pqFreqConverterConfig); } @Override - public boolean deletePqFreqConverterConfig(PqDevParam.DeleteParam param) { - return this.lambdaUpdate().set(PqFreqConverterConfig::getState, 0).update(); + @Transactional(rollbackFor = Exception.class) + public boolean deletePqFreqConverterConfig(List ids) { + StringBuffer sql = new StringBuffer(); + sql.append("drop table if exists "); + + List pqFreqConverterConfigs = this.listByIds(ids); + for (PqFreqConverterConfig pqFreqConverterConfig : pqFreqConverterConfigs) { + Integer suffix = pqFreqConverterConfig.getSuffix(); + sql.append("pq_freq_converter_status_" + suffix + ",").append("pq_dip_data_" + suffix + ","); + } + + sql.deleteCharAt(sql.length() - 1); + // 删除表 + tableGenMapper.genTable(sql.toString()); + return this.lambdaUpdate() + .in(CollectionUtil.isNotEmpty(ids), PqFreqConverterConfig::getId, ids) + .set(PqFreqConverterConfig::getState, 0).update(); } } diff --git a/entrance/src/main/resources/application.yml b/entrance/src/main/resources/application.yml index 013c1438..78e870f3 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://127.0.0.1:3306/pqs9100?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true + url: jdbc:mysql://192.168.1.24:13306/pqs9100?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true username: root password: njcnpqs #初始化建立物理连接的个数、最小、最大连接数 @@ -46,12 +46,15 @@ mybatis-plus: socket: - source: - ip: 127.0.0.1 - port: 62000 device: ip: 127.0.0.1 port: 61000 + source: + ip: 127.0.0.1 + port: 63000 + freqConverter: + ip: 127.0.0.1 + port: 63000 # source: # ip: 192.168.1.121 # port: 10086 diff --git a/storage/src/main/java/com/njcn/gather/storage/mapper/TableGenMapper.java b/storage/src/main/java/com/njcn/gather/storage/mapper/TableGenMapper.java index 36b79e76..f57cb703 100644 --- a/storage/src/main/java/com/njcn/gather/storage/mapper/TableGenMapper.java +++ b/storage/src/main/java/com/njcn/gather/storage/mapper/TableGenMapper.java @@ -12,4 +12,6 @@ public interface TableGenMapper { void genNonHarmonicResultTable(@Param("code") String code, @Param("isContrast") boolean isContrast); + + void genTable(@Param("tableSql") String tableSql); } diff --git a/storage/src/main/java/com/njcn/gather/storage/mapper/mapping/TableGenMapper.xml b/storage/src/main/java/com/njcn/gather/storage/mapper/mapping/TableGenMapper.xml index ec32b3ca..5f140934 100644 --- a/storage/src/main/java/com/njcn/gather/storage/mapper/mapping/TableGenMapper.xml +++ b/storage/src/main/java/com/njcn/gather/storage/mapper/mapping/TableGenMapper.xml @@ -72,6 +72,10 @@ ) COMMENT='非谐波类检测结果表'; + + ${tableSql} + +