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 7a6a99c4..5a83e40a 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 @@ -6,8 +6,10 @@ import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum; import com.njcn.gather.detection.pojo.enums.SourceResponseCodeEnum; import com.njcn.gather.detection.pojo.param.DevPhaseSequenceParam; import com.njcn.gather.detection.pojo.param.PreDetectionParam; +import com.njcn.gather.detection.pojo.vo.DevLineTestResult; import com.njcn.gather.detection.pojo.vo.SocketDataMsg; import com.njcn.gather.detection.pojo.vo.SocketMsg; +import com.njcn.gather.detection.pojo.vo.WebSocketVO; import com.njcn.gather.detection.util.socket.MsgUtil; import com.njcn.gather.detection.util.socket.SocketManager; import com.njcn.gather.detection.util.socket.cilent.NettyClient; @@ -19,10 +21,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; @Service @@ -46,9 +45,14 @@ public class SocketSourceResponseService { @Value("${socket.device.port}") private Integer port; + private List devList = new ArrayList<>(); + + + public void deal(PreDetectionParam param, String msg) { SocketDataMsg socketDataMsg = MsgUtil.socketDataMsg(msg); - SourceOperateCodeEnum enumByCode = SourceOperateCodeEnum.getDictDataEnumByCode(socketDataMsg.getRequestId()); + String[] tem = socketDataMsg.getRequestId().split("&&"); + SourceOperateCodeEnum enumByCode = SourceOperateCodeEnum.getDictDataEnumByCode(tem[0]); if (ObjectUtil.isNotNull(enumByCode)) { switch (enumByCode) { //源初始化 @@ -64,8 +68,8 @@ public class SocketSourceResponseService { openSource(param, socketDataMsg); break; case QUITE_SOURCE: + quitDeal(socketDataMsg,param); // System.out.println("关闭源回调:"+msg); - SocketManager.removeUser(param.getUserPageId() + source); break; } @@ -92,7 +96,7 @@ public class SocketSourceResponseService { //todo 前端推送收到的消息暂未处理好 webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(socketDataMsg)); - String s = param.getUserPageId() + "_Dev"; + String s = param.getUserPageId() + DEV; //开始设备通讯检测(发送设备初始化) List devList = iPqDevService.getDevInfo(param.getDevIds()); Map> map = new HashMap(1); @@ -180,19 +184,32 @@ public class SocketSourceResponseService { // webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(socketDataMsg)); String s = param.getUserPageId() + DEV; - socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue()); + socketMsg.setRequestId(SourceOperateCodeEnum.Test_VOL.getValue()); socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_DATA_REQUEST_02.getValue()); - List pqDevList = iPqDevService.getDevInfo(param.getDevIds()); - List moniterIdList = pqDevList.stream().flatMap(x -> x.getMonitorList().stream()) + List moniterIdList = devList.stream().flatMap(x -> x.getMonitorList().stream()) .map(PreDetection.MonitorListDTO::getLineId) .collect(Collectors.toList()); DevPhaseSequenceParam phaseSequenceParam = new DevPhaseSequenceParam(); phaseSequenceParam.setMoniterIdList(moniterIdList); - phaseSequenceParam.setDataType(Arrays.asList("实时数据/电压有效值", "实时数据/电流有效值")); + phaseSequenceParam.setDataType(Arrays.asList("real$VRMS")); phaseSequenceParam.setReadCount(20); phaseSequenceParam.setIgnoreCount(10); socketMsg.setData(JSON.toJSONString(phaseSequenceParam)); SocketManager.sendMsg(s, JSON.toJSONString(socketMsg)); + + + WebSocketVO> webSocketVO = new WebSocketVO<>(); + webSocketVO.setRequestId(socketDataMsg.getRequestId().split("&&")[1]+"_Start"); + List devListRes = new ArrayList<>(); + devList.forEach(item->{ + DevLineTestResult devLineTestResult = new DevLineTestResult(); + devLineTestResult.setDeviceId(item.getDevId()); + devLineTestResult.setDeviceName(item.getDevName()); + devListRes.add(devLineTestResult); + }); + webSocketVO.setData(devListRes); + webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(webSocketVO)); + break; case UNPROCESSED_BUSINESS: webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(socketDataMsg)); @@ -207,4 +224,33 @@ public class SocketSourceResponseService { } } + + /** + * 退出检测返回 + */ + private void quitDeal(SocketDataMsg socketDataMsg, PreDetectionParam param) { + SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode()); + SourceOperateCodeEnum operateCodeEnum = SourceOperateCodeEnum.getDictDataEnumByCode(socketDataMsg.getOperateCode()); + SocketMsg socketMsg = new SocketMsg(); + switch (dictDataEnumByCode) { + case SUCCESS: + //通讯校验成功 + SocketManager.removeUser(param.getUserPageId() + source); + break; + case UNPROCESSED_BUSINESS: + break; + + default: + WebSocketVO webSocketVO = new WebSocketVO(); + break; + } + + } + + + public void initList(PreDetectionParam param){ + devList.clear(); + this.devList = iPqDevService.getDevInfo(param.getDevIds()); + } + } diff --git a/detection/src/main/java/com/njcn/gather/detection/pojo/enums/SourceOperateCodeEnum.java b/detection/src/main/java/com/njcn/gather/detection/pojo/enums/SourceOperateCodeEnum.java index ac1bc846..e74f347c 100644 --- a/detection/src/main/java/com/njcn/gather/detection/pojo/enums/SourceOperateCodeEnum.java +++ b/detection/src/main/java/com/njcn/gather/detection/pojo/enums/SourceOperateCodeEnum.java @@ -54,7 +54,16 @@ public enum SourceOperateCodeEnum { PRE_TEST("0","预检测"), FORMAL_TEST("1","正式检测"), - TIME_TEST("2","守时检测") + TIME_TEST("2","守时检测"), + + + /** + * 检测类型 + */ + Test_Freq("formal_real&&Test_Freq","频率检测"), + Test_VOL("formal_real&&Test_VOL","电压检测"), + + ; diff --git a/detection/src/main/java/com/njcn/gather/detection/pojo/vo/DevLineTestResult.java b/detection/src/main/java/com/njcn/gather/detection/pojo/vo/DevLineTestResult.java new file mode 100644 index 00000000..519d6e36 --- /dev/null +++ b/detection/src/main/java/com/njcn/gather/detection/pojo/vo/DevLineTestResult.java @@ -0,0 +1,21 @@ +package com.njcn.gather.detection.pojo.vo; + +import io.swagger.models.auth.In; +import lombok.Data; + +import java.util.List; + +/** + * @Author: cdf + * @CreateTime: 2024-12-26 + * @Description: 装置测点检测结果 + */ +@Data +public class DevLineTestResult { + + private String deviceId; + + private String deviceName; + + private Integer[] chnResult; +} diff --git a/detection/src/main/java/com/njcn/gather/detection/service/impl/DetectionServiceImpl.java b/detection/src/main/java/com/njcn/gather/detection/service/impl/DetectionServiceImpl.java index 4d7d3d6e..50ff8432 100644 --- a/detection/src/main/java/com/njcn/gather/detection/service/impl/DetectionServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/detection/service/impl/DetectionServiceImpl.java @@ -47,7 +47,7 @@ public class DetectionServiceImpl { devDataMap.forEach(((key, value) -> { Integer num; Boolean b = DetectionIndexProcessing(value, dataRule, issue); - if (ObjectUtil.isNull(b)) { + if (ObjectUtil.isNotNull(b)) { if (b) { num = 1; } else { @@ -74,7 +74,7 @@ public class DetectionServiceImpl { public Boolean DetectionIndexProcessing(List dev, DictDataEnum dataRule, SourceIssue sourceIssue) { PqErrSysParam.DetectionParam param = new PqErrSysParam.DetectionParam(); List pqErrSysDtls = pqErrSysDtlsService.listPqErrSysDtlsByPqErrSysIdAndTypes(param); - switch (sourceIssue.getType()) { + switch ("V") { /** * 频率 */ 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 7aca5e00..ff45daab 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 @@ -53,6 +53,7 @@ public class PreDetectionServiceImpl implements PreDetectionService { private final IPqScriptDtlsService pqScriptDtlsService; private final SocketDevResponseService socketDevResponseService; + private final SocketSourceResponseService socketSourceResponseService; @Value("${socket.source.ip:192.168.1.136}") @@ -68,6 +69,7 @@ public class PreDetectionServiceImpl implements PreDetectionService { public void sourceCommunicationCheck(PreDetectionParam param) { + System.out.println("进来了啊啊啊啊啊啊啊啊啊啊啊啊啊"); Channel channel = SocketManager.getChannelByUserId(param.getUserPageId() + source); if (Objects.nonNull(channel) && channel.isActive()) { System.out.println("进入关闭源。。//////"); @@ -133,6 +135,7 @@ public class PreDetectionServiceImpl implements PreDetectionService { if (ObjectUtil.isNotNull(sourceParam)) { //开始组装socket报文请求头 socketDevResponseService.initList(param); + socketSourceResponseService.initList(param); SocketMsg msg = new SocketMsg(); msg.setRequestId(SourceOperateCodeEnum.YJC_YTXJY.getValue()); msg.setOperateCode(SourceOperateCodeEnum.INIT_GATHER.getValue()); diff --git a/detection/src/main/java/com/njcn/gather/detection/util/socket/SocketManager.java b/detection/src/main/java/com/njcn/gather/detection/util/socket/SocketManager.java index 918ca654..ee2d8d43 100644 --- a/detection/src/main/java/com/njcn/gather/detection/util/socket/SocketManager.java +++ b/detection/src/main/java/com/njcn/gather/detection/util/socket/SocketManager.java @@ -1,6 +1,7 @@ package com.njcn.gather.detection.util.socket; import cn.hutool.core.util.ObjectUtil; +import com.njcn.gather.device.script.pojo.po.SourceIssue; import io.netty.channel.Channel; import io.netty.channel.nio.NioEventLoopGroup; @@ -60,5 +61,26 @@ public class SocketManager { } } + + + /** + * 用于存储源操作的脚本信息 + * key: + */ + private static final Map targetMap = new ConcurrentHashMap<>(); + + public static void addSourceTarget(String sourceTag, SourceIssue sourceIssue) { + targetMap.put(sourceTag, sourceIssue); + } + + public static void delSourceTarget(String sourceTag) { + targetMap.remove(sourceTag); + } + + public static SourceIssue getSourceTarget(String sourceTag) { + return targetMap.get(sourceTag); + } + + } \ No newline at end of file diff --git a/device/src/main/java/com/njcn/gather/device/err/service/impl/PqErrSysDtlsServiceImpl.java b/device/src/main/java/com/njcn/gather/device/err/service/impl/PqErrSysDtlsServiceImpl.java index 62daab0e..7c137e36 100644 --- a/device/src/main/java/com/njcn/gather/device/err/service/impl/PqErrSysDtlsServiceImpl.java +++ b/device/src/main/java/com/njcn/gather/device/err/service/impl/PqErrSysDtlsServiceImpl.java @@ -16,6 +16,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -69,6 +70,11 @@ public class PqErrSysDtlsServiceImpl extends ServiceImpl listPqErrSysDtlsByPqErrSysIdAndTypes(PqErrSysParam.DetectionParam param) { + return this.list(new LambdaQueryWrapper() + .in(PqErrSysDtls::getId, Arrays.asList("ae86b657f37151d78b7c34ec64eefa10")) +// .eq(PqErrSysDtls::getErrorSysId, param.getErrorSysId()) +// .in(PqErrSysDtls::getErrorSysId, param.getType()) + ); //根据检测脚本id和检测序号,查询出检测子项目 @@ -76,6 +82,6 @@ public class PqErrSysDtlsServiceImpl extends ServiceImpl(); +// return new ArrayList<>(); } }