From d8bcca1edec352e17e8263400a3ce2f552f33ff3 Mon Sep 17 00:00:00 2001 From: caozehui <2427765068@qq.com> Date: Wed, 15 Apr 2026 18:52: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 --- .../SocketFreqConverterDevService.java | 44 +++++++++++++-- .../handler/SocketFreqConverterService.java | 55 ++++++++++++++++--- .../service/impl/PreDetectionServiceImpl.java | 3 +- .../util/socket/FormalTestManager.java | 29 ++++++++++ .../NettyFreqConverterDevClientHandler.java | 6 +- .../device/controller/PqDevController.java | 10 ++++ .../gather/device/service/IPqDevService.java | 2 + .../device/service/impl/PqDevServiceImpl.java | 27 +++++++++ .../config/FreqConverterConfig.java | 18 ++++++ .../pojo/param/PqFreqConverterParam.java | 2 +- .../pojo/po/PqFreqConverterConfig.java | 5 ++ .../service/IFreqConverterService.java | 3 + .../IPqFreqConverterConfigService.java | 3 +- .../IPqFreqConverterTestResService.java | 19 +++++++ .../impl/FreqConverterServiceImpl.java | 38 +++++++++---- .../PqFreqConverterConfigServiceImpl.java | 10 ++++ .../PqFreqConverterTestResServiceImpl.java | 19 +++++++ entrance/src/main/resources/application.yml | 11 +++- 18 files changed, 271 insertions(+), 33 deletions(-) create mode 100644 detection/src/main/java/com/njcn/gather/freqConverter/config/FreqConverterConfig.java 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 1f3bb241..0f6a228e 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 @@ -2,6 +2,7 @@ package com.njcn.gather.detection.handler; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.ListUtil; +import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler; @@ -20,10 +21,15 @@ import com.njcn.gather.detection.util.socket.cilent.NettyClient; import com.njcn.gather.detection.util.socket.cilent.NettyFreqConverterDevClientHandler; import com.njcn.gather.detection.util.socket.config.SocketConnectionConfig; import com.njcn.gather.detection.util.socket.websocket.WebServiceManager; +import com.njcn.gather.device.pojo.po.PqDev; 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.config.FreqConverterConfig; +import com.njcn.gather.freqConverter.pojo.po.FreqConverterStatus; +import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterTestRes; +import com.njcn.gather.freqConverter.service.IFreqConverterService; import com.njcn.gather.freqConverter.service.IPqFreqConverterTestResService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -42,7 +48,9 @@ public class SocketFreqConverterDevService { private final SocketConnectionConfig socketConnectionConfig; private final IPqDevService pqDevService; private final IPqDipDataService pqDipDataService; + private final IFreqConverterService freqConverterService; private final IPqFreqConverterTestResService pqFreqConverterTestResService; + private final FreqConverterConfig freqConverterConfig; private String monitorId; private String userId; @@ -68,6 +76,7 @@ public class SocketFreqConverterDevService { FormalTestManager.freqConverterDevStep = null; FormalTestManager.stopFlag = false; FormalTestManager.isRemoveSocket = false; + FormalTestManager.pendingDipTaskMap.clear(); pqDipDataService.clearAllData(FormalTestManager.freqConverterTableSuffix); pqFreqConverterTestResService.clearAllData(FormalTestManager.freqConverterTableSuffix); this.userId = userId; @@ -122,7 +131,7 @@ public class SocketFreqConverterDevService { FormalTestManager.freqConverterDevStep = SourceOperateCodeEnum.FORMAL_REAL; break; default: - log.info("设备响应异常,devTag={}, operateCode={}, code={}, data={}", devTag, socketDataMsg.getOperateCode(), socketDataMsg.getCode(), socketDataMsg.getData()); + log.warn("设备响应异常,devTag={}, operateCode={}, code={}, data={}", devTag, socketDataMsg.getOperateCode(), socketDataMsg.getCode(), socketDataMsg.getData()); break; } } @@ -147,7 +156,7 @@ public class SocketFreqConverterDevService { case DATA_RESOLVE: case NO_INIT_DEV: default: - log.info("设备响应异常,devTag={}, operateCode={}, code={}, data={}", devTag, socketDataMsg.getOperateCode(), socketDataMsg.getCode(), socketDataMsg.getData()); + log.warn("设备响应异常,devTag={}, operateCode={}, code={}, data={}", devTag, socketDataMsg.getOperateCode(), socketDataMsg.getCode(), socketDataMsg.getData()); break; } } @@ -156,6 +165,8 @@ public class SocketFreqConverterDevService { SourceResponseCodeEnum responseCodeEnum = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode()); switch (responseCodeEnum) { + case UNPROCESSED_BUSINESS: + break; case SUCCESS: cleanup(devTag); break; @@ -203,12 +214,15 @@ public class SocketFreqConverterDevService { private void sendGetDipDataMsg(String devTag) { SocketMsg socketMsg = new SocketMsg<>(); - socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue()); + socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue()+"&&VOLTAGE"); socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue()); DevPhaseSequenceParam phaseSequenceParam = new DevPhaseSequenceParam(); + String[] split = this.monitorId.split(String.valueOf(StrUtil.C_UNDERLINE)); + PqDev dev = pqDevService.getById(split[0]); + // 设置监测点ID列表 - phaseSequenceParam.setMoniterIdList(ListUtil.of(this.monitorId)); + phaseSequenceParam.setMoniterIdList(ListUtil.of(dev.getIp()+StrUtil.C_UNDERLINE+split[1])); // 设置数据类型列表 phaseSequenceParam.setDataType(ListUtil.of("avg$MAG", "avg$DUR")); @@ -253,12 +267,34 @@ public class SocketFreqConverterDevService { } PqDipData pqDipData = new PqDipData(); + pqDipData.setId(IdUtil.fastSimpleUUID()); pqDipData.setStartTime(LocalDateTime.parse(devData.getTime())); pqDipData.setResidualVoltage(residualVoltage); pqDipData.setDurationMs(durationMs); DynamicTableNameHandler.setTableName("pq_dip_data_" + FormalTestManager.freqConverterTableSuffix); pqDipDataService.save(pqDipData); DynamicTableNameHandler.remove(); + + this.initDipTestRes(pqDipData); + } + + private void initDipTestRes(PqDipData pqDipData) { + Integer suffix = FormalTestManager.freqConverterTableSuffix; + List statusList = freqConverterService.getDipDurationStatusData(suffix, pqDipData.getStartTime(), LocalDateTime.now()); + List testResList = new ArrayList<>(); + for (FreqConverterStatus status : statusList) { + PqFreqConverterTestRes testRes = new PqFreqConverterTestRes(); + testRes.setDipId(pqDipData.getId()); + testRes.setStatusId(status.getId()); + testRes.setTolerant(status.getStatusWord1() != freqConverterConfig.getNoTolerant()); + testResList.add(testRes); + } + pqFreqConverterTestResService.saveTestRes(suffix, testResList); + + int collectCount = (int) Math.ceil((freqConverterConfig.getDt()) / freqConverterConfig.getSchedulePeriod()); + if (collectCount > 0) { + FormalTestManager.pendingDipTaskMap.put(pqDipData.getId(), new FormalTestManager.PendingDipTask(pqDipData.getId(), collectCount)); + } } 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 8f1afaab..354bc2b9 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 @@ -13,17 +13,18 @@ import com.njcn.gather.detection.util.socket.SocketManager; import com.njcn.gather.detection.util.socket.cilent.NettyClient; import com.njcn.gather.detection.util.socket.cilent.NettyFreqConverterClientHandler; import com.njcn.gather.detection.util.socket.config.SocketConnectionConfig; +import com.njcn.gather.freqConverter.config.FreqConverterConfig; import com.njcn.gather.freqConverter.pojo.po.FreqConverterStatus; import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterConfig; +import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterTestRes; import com.njcn.gather.freqConverter.service.IFreqConverterService; import com.njcn.gather.freqConverter.service.IPqFreqConverterConfigService; +import com.njcn.gather.freqConverter.service.IPqFreqConverterTestResService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; +import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; @@ -41,7 +42,9 @@ public class SocketFreqConverterService { private final SocketConnectionConfig socketConnectionConfig; private final IPqFreqConverterConfigService pqFreqConverterConfigService; + private final IPqFreqConverterTestResService pqFreqConverterTestResService; private String userId; + private final FreqConverterConfig freqConverterConfig; /** * 连接变频器Socket @@ -98,13 +101,16 @@ public class SocketFreqConverterService { } } - private void init(String userId, String converterId, String monitorId) { + public void init(String userId, String converterId, String monitorId) { this.userId = userId; FormalTestManager.freqConverterStep = null; + FormalTestManager.currentFreqConverterId = converterId; Integer suffix = pqFreqConverterConfigService.getSuffix(converterId); freqConverterService.clearAllData(suffix); FormalTestManager.freqConverterTableSuffix = suffix; FormalTestManager.isRemoveSocket = false; + FormalTestManager.pendingDipTaskMap.clear(); + pqFreqConverterConfigService.updateTestStatus(converterId, 0); clearScheduleTask(); } @@ -172,10 +178,10 @@ public class SocketFreqConverterService { FormalTestManager.scheduler = Executors.newScheduledThreadPool(1); FormalTestManager.scheduledFuture = FormalTestManager.scheduler.scheduleAtFixedRate(() -> { this.sendGetDeviceStatusMsg(converterChannelTag); - }, 0l, 200l, TimeUnit.SECONDS); + }, 0l, freqConverterConfig.getSchedulePeriod(), TimeUnit.MILLISECONDS); } } else { - log.error("变频器初始化串口失败,converterChannelTag={}, converterId={}, converterTag={}, msg={}", converterChannelTag, converterChannelTag, converterChannelTag, respDTO.getMessage()); + log.warn("变频器初始化串口失败,converterChannelTag={}, converterId={}, converterTag={}, msg={}", converterChannelTag, converterChannelTag, converterChannelTag, respDTO.getMessage()); } } @@ -187,16 +193,20 @@ public class SocketFreqConverterService { FreqConverterStatus freqConverterStatus = JSON.parseObject(obj.toString(), FreqConverterStatus.class); // 变频器故障中,移除这段时期内的设备数据 - if (freqConverterStatus.getStatusWord1() == 4) { + if (freqConverterStatus.getStatusWord1() == freqConverterConfig.getNoTolerant()) { FormalTestManager.stopFlag = true; } else { FormalTestManager.stopFlag = false; } freqConverterService.saveFreqConverterStatus(FormalTestManager.freqConverterTableSuffix, freqConverterStatus); + this.consumePendingDipTasks(freqConverterStatus); } private void handleCloseSerial(String converterChannelTag, FreqConverterRespDTO respDTO) { if (respDTO.getCode() == 0 && respDTO.getSuccess()) { + if (FormalTestManager.currentFreqConverterId != null) { + pqFreqConverterConfigService.updateTestStatus(FormalTestManager.currentFreqConverterId, 1); + } cleanup(converterChannelTag); } else { this.sendClose(converterChannelTag); @@ -238,6 +248,37 @@ public class SocketFreqConverterService { } } + private void consumePendingDipTasks(FreqConverterStatus freqConverterStatus) { + if (FormalTestManager.pendingDipTaskMap.isEmpty()) { + return; + } + + List resList = new ArrayList<>(); + Integer suffix = FormalTestManager.freqConverterTableSuffix; + List finishedDipIdList = new ArrayList<>(); + for (FormalTestManager.PendingDipTask task : FormalTestManager.pendingDipTaskMap.values()) { + if (task.getRemainingCount() <= 0) { + finishedDipIdList.add(task.getDipId()); + continue; + } + + PqFreqConverterTestRes testRes = new PqFreqConverterTestRes(); + testRes.setDipId(task.getDipId()); + testRes.setStatusId(freqConverterStatus.getId()); + testRes.setTolerant(freqConverterStatus.getStatusWord1() != freqConverterConfig.getNoTolerant()); + resList.add(testRes); + + task.decrementRemainingCount(); + if (task.getRemainingCount() <= 0) { + finishedDipIdList.add(task.getDipId()); + } + } + pqFreqConverterTestResService.saveTestRes(suffix, resList); + + for (String dipId : finishedDipIdList) { + FormalTestManager.pendingDipTaskMap.remove(dipId); + } + } } 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 c39737e5..ee1d31f0 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 @@ -397,6 +397,7 @@ public class PreDetectionServiceImpl implements PreDetectionService { public void startFreqConverter(String userId, String converterId, String monitorId) { String freqConverterTag = userId + CnSocketUtil.FREQ_CONVERTER_TAG; String devTag = userId + CnSocketUtil.DEV_TAG; +// socketFreqConverterService.init(userId, converterId, monitorId); socketFreqConverterService.connectSocket(freqConverterTag); socketFreqConverterDevService.connectSocket(devTag); @@ -404,7 +405,7 @@ public class PreDetectionServiceImpl implements PreDetectionService { long timeout = 3000; // 3秒超时时间 while (true) { if (SocketManager.isChannelActive(freqConverterTag) && SocketManager.isChannelActive(devTag)) { -// if (SocketManager.isChannelActive(freqConverterTag)) { +// if (SocketManager.isChannelActive(devTag)) { socketFreqConverterService.connectionFreqConverter(userId, freqConverterTag, converterId, monitorId); socketFreqConverterDevService.connectionDev(userId, devTag, converterId, monitorId); break; 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 5a3606d9..9b5de64b 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 @@ -38,6 +38,13 @@ public class FormalTestManager { */ public static Integer freqConverterTableSuffix; + public static String currentFreqConverterId; + + /** + * 待采集后续变频器状态的Dip任务 + */ + public static Map pendingDipTaskMap = new ConcurrentHashMap<>(); + /** * key:设备ip,value:当前设备下面的监测点ID(ip_通道号) */ @@ -215,4 +222,26 @@ public class FormalTestManager { * 是否进行相序校验 */ public static boolean isXu; + + public static class PendingDipTask { + private final String dipId; + private int remainingCount; + + public PendingDipTask(String dipId, int remainingCount) { + this.dipId = dipId; + this.remainingCount = remainingCount; + } + + public String getDipId() { + return dipId; + } + + public int getRemainingCount() { + return remainingCount; + } + + public void decrementRemainingCount() { + this.remainingCount--; + } + } } diff --git a/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettyFreqConverterDevClientHandler.java b/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettyFreqConverterDevClientHandler.java index defd39d4..f26d3363 100644 --- a/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettyFreqConverterDevClientHandler.java +++ b/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettyFreqConverterDevClientHandler.java @@ -32,12 +32,8 @@ public class NettyFreqConverterDevClientHandler extends SimpleChannelInboundHand @Override protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception { - if (FormalTestManager.stopFlag) { - log.debug("变频器异常或重连中,丢弃设备数据,devChannelTag={}, msg={}", devChannelTag, msg); - return; - } + log.info("收到设备消息,devChannelTag={}, msg={},FormalTestManager.stopFlag={}", devChannelTag, msg, FormalTestManager.stopFlag); - log.info("收到设备消息,devChannelTag={}, msg={}", devChannelTag, msg); socketFreqConverterDevService.handleRead(devChannelTag, msg); } diff --git a/detection/src/main/java/com/njcn/gather/device/controller/PqDevController.java b/detection/src/main/java/com/njcn/gather/device/controller/PqDevController.java index 5d62b18f..ad36bfb2 100644 --- a/detection/src/main/java/com/njcn/gather/device/controller/PqDevController.java +++ b/detection/src/main/java/com/njcn/gather/device/controller/PqDevController.java @@ -189,4 +189,14 @@ public class PqDevController extends BaseController { } return pqDevService.importDev(file, patternId, planId, response, cover); } + + @OperateInfo + @GetMapping("/listAll") + @ApiOperation("查询所有未删除设备数据") + public HttpResult> listAll() { + String methodDescribe = getMethodDescribe("listAll"); + LogUtil.njcnDebug(log, "{},查询所有设备", methodDescribe); + List result = pqDevService.listAll(); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); + } } diff --git a/detection/src/main/java/com/njcn/gather/device/service/IPqDevService.java b/detection/src/main/java/com/njcn/gather/device/service/IPqDevService.java index 8da6b10a..fef7807a 100644 --- a/detection/src/main/java/com/njcn/gather/device/service/IPqDevService.java +++ b/detection/src/main/java/com/njcn/gather/device/service/IPqDevService.java @@ -288,4 +288,6 @@ public interface IPqDevService extends IService { * @return */ List getExportContrastDevData(List pqDevVOList); + + List listAll(); } diff --git a/detection/src/main/java/com/njcn/gather/device/service/impl/PqDevServiceImpl.java b/detection/src/main/java/com/njcn/gather/device/service/impl/PqDevServiceImpl.java index 61438320..b935a9d5 100644 --- a/detection/src/main/java/com/njcn/gather/device/service/impl/PqDevServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/device/service/impl/PqDevServiceImpl.java @@ -1625,4 +1625,31 @@ public class PqDevServiceImpl extends ServiceImpl implements } return result; } + + @Override + public List listAll() { + return this.lambdaQuery() + .eq(PqDev::getState, DataStateEnum.ENABLE.getCode()) + .orderByDesc(PqDev::getCreateTime) + .list().stream().map(pqDev -> { + PqDevVO pqDevVO = new PqDevVO(); + BeanUtil.copyProperties(pqDev, pqDevVO); + // 解密序列号和密钥 + if (StrUtil.isNotBlank(pqDevVO.getSeries())) { + pqDevVO.setSeries(EncryptionUtil.decoderString(1, pqDevVO.getSeries())); + } + if (StrUtil.isNotBlank(pqDevVO.getDevKey())) { + pqDevVO.setDevKey(EncryptionUtil.decoderString(1, pqDevVO.getDevKey())); + } + // 填充设备类型信息 + DevType devType = devTypeService.getById(pqDevVO.getDevType()); + if (ObjectUtil.isNotNull(devType)) { + pqDevVO.setDevType(devType.getName()); + pqDevVO.setDevChns(devType.getDevChns()); + pqDevVO.setDevVolt(devType.getDevVolt()); + pqDevVO.setDevCurr(devType.getDevCurr()); + } + return pqDevVO; + }).collect(Collectors.toList()); + } } 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 new file mode 100644 index 00000000..07f8b964 --- /dev/null +++ b/detection/src/main/java/com/njcn/gather/freqConverter/config/FreqConverterConfig.java @@ -0,0 +1,18 @@ +package com.njcn.gather.freqConverter.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +/** + * @author caozehui + * @data 2026-04-15 + */ +@Data +@Component +@ConfigurationProperties(prefix = "freq-converter") +public class FreqConverterConfig { + private Long schedulePeriod; + private Integer noTolerant; + private Integer dt; +} 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 0cb6e66c..fb5671b2 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 @@ -1,7 +1,6 @@ package com.njcn.gather.freqConverter.pojo.param; import com.njcn.common.pojo.constant.PatternRegex; -import com.njcn.gather.device.pojo.param.PqDevParam; import com.njcn.gather.pojo.constant.DetectionValidMessage; import com.njcn.web.pojo.param.BaseParam; import io.swagger.annotations.ApiModelProperty; @@ -40,6 +39,7 @@ public class PqFreqConverterParam { @ApiModelProperty(value = "串口读写超时,单位毫秒", required = true) private Integer timeoutMs; + private Integer testStatus; /** * 分页查询实体 diff --git a/detection/src/main/java/com/njcn/gather/freqConverter/pojo/po/PqFreqConverterConfig.java b/detection/src/main/java/com/njcn/gather/freqConverter/pojo/po/PqFreqConverterConfig.java index edce073b..88afd400 100644 --- a/detection/src/main/java/com/njcn/gather/freqConverter/pojo/po/PqFreqConverterConfig.java +++ b/detection/src/main/java/com/njcn/gather/freqConverter/pojo/po/PqFreqConverterConfig.java @@ -61,6 +61,11 @@ public class PqFreqConverterConfig extends BaseEntity { */ private Integer suffix; + /** + * 检测状态,0未检测,1检测完成 + */ + private Integer testStatus; + /** * 状态:0-删除 1-正常 */ 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 75d6ea55..87bc2057 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 @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.njcn.gather.freqConverter.pojo.po.FreqConverterStatus; import com.njcn.gather.freqConverter.pojo.vo.TolerantPointVO; +import java.time.LocalDateTime; import java.util.List; /** @@ -46,4 +47,6 @@ public interface IFreqConverterService extends IService { * @return 是否耐受 */ List getTolerantPoints(String converterId); + + List getDipDurationStatusData(Integer suffix, LocalDateTime startTime, LocalDateTime endTime); } 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 eeebf38c..cde22ff0 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 @@ -2,7 +2,6 @@ package com.njcn.gather.freqConverter.service; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; -import com.njcn.gather.device.pojo.param.PqDevParam; import com.njcn.gather.freqConverter.pojo.param.PqFreqConverterParam; import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterConfig; @@ -23,4 +22,6 @@ public interface IPqFreqConverterConfigService extends IService ids); + boolean updateTestStatus(String converterId, Integer testStatus); + } 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 f704f2bf..289b811d 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 @@ -3,6 +3,8 @@ package com.njcn.gather.freqConverter.service; import com.baomidou.mybatisplus.extension.service.IService; import com.njcn.gather.freqConverter.pojo.po.PqFreqConverterTestRes; +import java.util.List; + /** * @author caozehui * @data 2026-04-14 @@ -15,4 +17,21 @@ public interface IPqFreqConverterTestResService extends IService testResList); + + /** + * 查询结果记录 + * + * @param suffix 表后缀 + * @return 结果列表 + */ + List listTestRes(Integer suffix); } 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 6ff8beed..b40b2747 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,5 +1,6 @@ package com.njcn.gather.freqConverter.service.impl; +import cn.hutool.core.util.IdUtil; import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler; @@ -7,9 +8,11 @@ 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.po.PqFreqConverterTestRes; 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.gather.freqConverter.service.IPqFreqConverterTestResService; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -18,6 +21,7 @@ import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Comparator; import java.util.List; +import java.util.stream.Collectors; /** * 变频器状态数据Service实现类 @@ -35,10 +39,14 @@ import java.util.List; public class FreqConverterServiceImpl extends ServiceImpl implements IFreqConverterService { private final IPqFreqConverterConfigService pqFreqConverterConfigService; private final IPqDipDataService dipDataService; + private final IPqFreqConverterTestResService pqFreqConverterTestResService; @Override @Transactional(rollbackFor = Exception.class) public boolean saveFreqConverterStatus(Integer suffix, FreqConverterStatus status) { + if (status.getId() == null) { + status.setId(IdUtil.fastSimpleUUID()); + } DynamicTableNameHandler.setTableName("pq_freq_converter_status_" + suffix); boolean result = this.save(status); DynamicTableNameHandler.remove(); @@ -68,8 +76,8 @@ public class FreqConverterServiceImpl extends ServiceImpl getTolerantPoints(String converterId) { Integer suffix = pqFreqConverterConfigService.getSuffix(converterId); - List freqConverterDataList = this.listStatusData(converterId); List dipDataList = dipDataService.listDipData(suffix); + List testResList = pqFreqConverterTestResService.listTestRes(suffix); dipDataList.sort(Comparator.comparing(PqDipData::getDurationMs)); List res = new ArrayList<>(); @@ -77,18 +85,26 @@ public class FreqConverterServiceImpl extends ServiceImpl item.getTimestamp() != null && !item.getTimestamp().isBefore(dipEndTime)) - .min(Comparator.comparing(FreqConverterStatus::getTimestamp)) - .orElse(null); - if (nextStatus == null || nextStatus.getStatusWord1() == null || nextStatus.getStatusWord1() != 4) { - tolerantPointVO.setTolerant(true); - } else { - tolerantPointVO.setTolerant(false); - } + List matchedResList = testResList.stream() + .filter(item -> dipData.getId().equals(item.getDipId())) + .collect(Collectors.toList()); + + boolean tolerant = matchedResList.stream().allMatch(PqFreqConverterTestRes::getTolerant); + tolerantPointVO.setTolerant(tolerant); + res.add(tolerantPointVO); } return res; } + + @Override + public List getDipDurationStatusData(Integer suffix, LocalDateTime startTime, LocalDateTime endTime) { + DynamicTableNameHandler.setTableName("pq_freq_converter_status_" + suffix); + List result = this.lambdaQuery() + .between(FreqConverterStatus::getTimestamp, startTime, endTime) + .orderByDesc(FreqConverterStatus::getTimestamp) + .list(); + DynamicTableNameHandler.remove(); + return result; + } } 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 ecb179da..e2a5e108 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 @@ -83,6 +83,7 @@ public class PqFreqConverterConfigServiceImpl extends ServiceImpl testResList) { + DynamicTableNameHandler.setTableName("pq_freq_converter_test_res_" + suffix); + boolean result = this.saveBatch(testResList); + DynamicTableNameHandler.remove(); + return result; + } + + @Override + public List listTestRes(Integer suffix) { + DynamicTableNameHandler.setTableName("pq_freq_converter_test_res_" + suffix); + List result = this.list(); + DynamicTableNameHandler.remove(); + return result; + } } diff --git a/entrance/src/main/resources/application.yml b/entrance/src/main/resources/application.yml index a5e44e07..ec0a3e9c 100644 --- a/entrance/src/main/resources/application.yml +++ b/entrance/src/main/resources/application.yml @@ -6,9 +6,9 @@ spring: datasource: druid: driver-class-name: com.mysql.cj.jdbc.Driver -# 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/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 username: root password: njcnpqs @@ -126,3 +126,8 @@ power-quality: activate: private-key: "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCcUyYhVqczGxblL+o/xZzF/8nf+LjrfUE/dS1aRHM7uMDD0cgCArhjtfneFePrMxt+Z7W8yNBzSarub8qsfhaVNikV7Es7oaeTygfjQXTi2n4AFkir3fM07J08RpWhl5M8f8uWTCuvFUYAw00gq55typqmnbkmJa2VIUy/iQf+cMCP7abz4/jNhUzUR3qA7TV4oMRgTdIEDUp63YF8dOC+JH8XxYrCVeHXV6fLCwmesdMzl0lB2VTEKMfLbXhOmF5g7P9y/16VCcN8UBuZlbyYfn+GAxJOSbeHi5HshOKfoSuD7Jz+3WQZpNavOWjIFExKIU38/CvnJCOP7XBCqpSTAgMBAAECggEAYeWokWRE3TpvwiOZnUpR/aVMdVi75a3ROL5XIpqPV61B+t/bU3cEpl0GF9C5pUeiRi0IoStZb3mI9D1KPW/REKyUWkhabQO1gFYbTnRlkNOn6MILzKX4cwJjDaZeeo4EBPU7N+qHyOOXrU6hdH5FfxhMdV983ajm5eeuupxER1C2kAcIklTeVpTX6EKOgZb5LBp5ssOVm2P42pOauvcRozRcvZmqnErXmukv0H4l3EVNt4rHpTn9riHUC63e8JfiYzVaF6zuNUxv6nHEft0/SRMw11XSTnNfDzcKqgjz6ksFBS/6eQQYKESk+ONC53HUuYHFAknkwsPupDCT2W8FIQKBgQDLHT/xCU3nxGr4vFKBDNaO2D5oK20ECbBO4oDvLWWmQG7f+6TsMy8PgVdMnoL4RfqGlwFAKEpS6KVFHnBVqnNEhcdy9uCI7x7Xx8UnyUtxj1EDTm76uta9Ki9OrlqB6tImDM9+Ya3vGktW37ht4WOx2OsJRhG1dbf6RLwFlH7DWwKBgQDFBxvi5I1BR6hg6Tj7xd2SqOT2Y+BED3xuSYENhWbmMhLJDResaB7mjztbxlYaY2mOE0holWm2uDmVFFhMh4jYXik4hYH8nmDzq9mDpZCZ9pyjYqnAP8THoAa8EbgrUWB8A6BPH4iL3KbMnBfBKY0pIr2xrvnjQjNBAgta7KDRKQKBgCe6oe4wxrdF2TKsC2tIqpMoQxS3Icy/ZGgZr+SYuaBKTCWtoDW/UT40K3JGMxIDBhzbXphBCUCsVt9tM8Xd4EwP6tJW7dZ7B0pnve2pVwNwaAVAiz6p2yUHIle+jN+Koe5lZRSwYIg7WW81tWpwwsJfzqFyvjYDP6hJV4mz4ROvAoGAaRcdnKvjXApomShMqJ4lTPChD3q+SA8qg3jZSOj6tZXHx00gb2kp8jg7pPvpOTIFPy6x1Ha9aCRjMk0ju84fA6lVuzwa1S907wOehUVuF3Eeo1cgy9Y3k3KbpPyeixxgpkUY4JslLdSHc2NemD0dee951qhJyRmqVOZOQDUuoeECgYEAqBw2cAFk3vM97WY06TSldGA8ajVHx3BYRjj+zl62NTQthy8fw3tqxb3c5e8toOmZWKjZvDhg2TRLhsDDQWEYg3LZG87REqVIjgEPcpjNLidjygGX8n3JF2o0O5I/EMvl0s/+LVQONfduOBvhwDqr8QNisbLsyneiAq7umewMolo=" public-key: "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnFMmIVanMxsW5S/qP8Wcxf/J3/i4631BP3UtWkRzO7jAw9HIAgK4Y7X53hXj6zMbfme1vMjQc0mq7m/KrH4WlTYpFexLO6Gnk8oH40F04tp+ABZIq93zNOydPEaVoZeTPH/LlkwrrxVGAMNNIKuebcqapp25JiWtlSFMv4kH/nDAj+2m8+P4zYVM1Ed6gO01eKDEYE3SBA1Ket2BfHTgviR/F8WKwlXh11enywsJnrHTM5dJQdlUxCjHy214TpheYOz/cv9elQnDfFAbmZW8mH5/hgMSTkm3h4uR7ITin6Erg+yc/t1kGaTWrzloyBRMSiFN/Pwr5yQjj+1wQqqUkwIDAQAB" + +freq-converter: + schedule-period: 1000 #定时器运行间隔 + no-tolerant: 4 #不耐受状态 + dt: 200 #延迟时间ms \ No newline at end of file