diff --git a/detection/src/main/java/com/njcn/gather/detection/handler/SocketResponseService.java b/detection/src/main/java/com/njcn/gather/detection/handler/SocketDevResponseService.java similarity index 98% rename from detection/src/main/java/com/njcn/gather/detection/handler/SocketResponseService.java rename to detection/src/main/java/com/njcn/gather/detection/handler/SocketDevResponseService.java index 7eb51699..a8719673 100644 --- a/detection/src/main/java/com/njcn/gather/detection/handler/SocketResponseService.java +++ b/detection/src/main/java/com/njcn/gather/detection/handler/SocketDevResponseService.java @@ -28,7 +28,7 @@ import java.util.*; @Service @RequiredArgsConstructor -public class SocketResponseService { +public class SocketDevResponseService { private final WebSocketHandler webSocketHandler; 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 24b74883..e24b7870 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 @@ -4,6 +4,8 @@ import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSON; 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.SocketDataMsg; import com.njcn.gather.detection.pojo.vo.SocketMsg; import com.njcn.gather.detection.util.socket.MsgUtil; @@ -11,10 +13,17 @@ 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.NettyDevClientHandler; import com.njcn.gather.detection.util.socket.web.WebSocketHandler; +import com.njcn.gather.device.device.pojo.vo.PreDetection; +import com.njcn.gather.device.device.service.IPqDevService; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + @Service @RequiredArgsConstructor public class SocketSourceResponseService { @@ -23,44 +32,111 @@ public class SocketSourceResponseService { * 向webSocket客户端发送消息 */ private final WebSocketHandler webSocketHandler; + private final SocketDevResponseService socketDevResponseService; + private final IPqDevService iPqDevService; - private final SocketResponseService sourceResponseService; @Value("${socket.device.ip}") private String ip; @Value("${socket.device.port}") private Integer port; - public void deal(String userId,String msg){ + public void deal(PreDetectionParam param, String msg){ SocketDataMsg socketDataMsg = MsgUtil.socketDataMsg(msg); - if(SourceOperateCodeEnum.YJC_YTXJY.getValue().equals(socketDataMsg.getRequestId())){ - SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode()); - if(ObjectUtil.isNotNull(dictDataEnumByCode)){ - switch (dictDataEnumByCode){ - case SUCCESS: - webSocketHandler.sendMsgToUser(userId,msg); - String s = userId + "_Dev"; - //todo 创建终端socket连接 - NettyClient.socketClient(ip, port, s, new NettyDevClientHandler(s, sourceResponseService)); - SocketManager.sendMsg(s,"向127服务器发送"); - break; - case UNPROCESSED_BUSINESS: - break; - default: - SocketMsg socketMsg=new SocketMsg(); - socketMsg.setRequestId(socketDataMsg.getRequestId()); - socketMsg.setOperateCode(socketDataMsg.getOperateCode()); - socketMsg.setData(dictDataEnumByCode.getMessage()); - webSocketHandler.sendMsgToUser(userId, JSON.toJSONString(socketMsg)); - break; - } - } + SourceOperateCodeEnum enumByCode = SourceOperateCodeEnum.getDictDataEnumByCode(socketDataMsg.getRequestId()); + switch (enumByCode){ + case YJC_YTXJY: + extracted(param, msg, socketDataMsg); + break; + case YJC_XUJY: + break; } + + + if(SourceOperateCodeEnum.YJC_YTXJY.getValue().equals(socketDataMsg.getRequestId())){ + + } + //装置通讯成功之后,会跟据获取到的源通道,进行发送源参数发送(处理发送成功后的信息) + if(SourceOperateCodeEnum.YJC_XUJY.getValue().equals(socketDataMsg.getRequestId())){ + extracted1(param, msg, socketDataMsg); + } + } + /** + * 源装置检测 + * @param param + * @param msg + * @param socketDataMsg + */ + private void extracted(PreDetectionParam param, String msg, SocketDataMsg socketDataMsg) { + SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode()); + if(ObjectUtil.isNotNull(dictDataEnumByCode)){ + SocketMsg socketMsg=new SocketMsg(); + switch (dictDataEnumByCode){ + case SUCCESS: + webSocketHandler.sendMsgToUser(param.getUserPageId(), msg); + String s = param.getUserPageId() + "_Dev"; + //开始设备通讯检测 + NettyClient.socketClient(ip, port,param.getPlanId(), new NettyDevClientHandler(param.getPlanId(), socketDevResponseService)); + List devList = iPqDevService.getDevInfo(param.getDevIds()); + Map> map = new HashMap(1); + map.put("deviceList", devList); + String jsonString = JSON.toJSONString(map); + socketMsg.setRequestId(SourceOperateCodeEnum.YJC_SBTXJY.getValue()); + socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_01.getValue()); + socketMsg.setData(jsonString); + String json = JSON.toJSONString(socketMsg); + SocketManager.sendMsg(s,json); + break; + case UNPROCESSED_BUSINESS: + break; + default: + socketMsg.setRequestId(socketDataMsg.getRequestId()); + socketMsg.setOperateCode(socketDataMsg.getOperateCode()); + socketMsg.setData(dictDataEnumByCode.getMessage()); + webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(socketMsg)); + break; + } + } + } - + private void extracted1(PreDetectionParam param, String msg, SocketDataMsg socketDataMsg) { + SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode()); + if(ObjectUtil.isNotNull(dictDataEnumByCode)){ + SocketMsg socketMsg=new SocketMsg(); + switch (dictDataEnumByCode){ + case SUCCESS: + webSocketHandler.sendMsgToUser(param.getUserPageId(), msg); + String s = param.getUserPageId() + "_Dev"; + //缺少向终端发送相序校验的参数 + socketMsg.setRequestId(socketDataMsg.getRequestId()); + socketMsg.setOperateCode(socketDataMsg.getOperateCode()); + List pqDevList = iPqDevService.getDevInfo(param.getDevIds()); + List moniterIdList = pqDevList.stream().flatMap(x -> x.getMonitorList().stream()) + .map(PreDetection.MonitorListDTO::getLineId) + .collect(Collectors.toList()); + DevPhaseSequenceParam phaseSequenceParam=new DevPhaseSequenceParam(); + phaseSequenceParam.setMoniterIdList(moniterIdList); +// phaseSequenceParam.setDataType(); +// phaseSequenceParam.setReadCount(); +// phaseSequenceParam.setIgnoreCount(); +// +// socketMsg.setData(); + SocketManager.sendMsg(s,JSON.toJSONString(socketMsg)); + break; + case UNPROCESSED_BUSINESS: + break; + default: + socketMsg.setRequestId(socketDataMsg.getRequestId()); + socketMsg.setOperateCode(socketDataMsg.getOperateCode()); + socketMsg.setData(dictDataEnumByCode.getMessage()); + webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(socketMsg)); + break; + } + } + } } 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 b96b38bf..c21f1da8 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 @@ -1,5 +1,6 @@ package com.njcn.gather.detection.pojo.enums; +import cn.hutool.core.util.ObjectUtil; import lombok.Getter; /** @@ -41,4 +42,13 @@ public enum SourceOperateCodeEnum { this.value = value; this.msg = msg; } + + public static SourceOperateCodeEnum getDictDataEnumByCode(String value) { + for (SourceOperateCodeEnum sourceOperateCodeEnum : SourceOperateCodeEnum.values()) { + if (ObjectUtil.equals(value, sourceOperateCodeEnum.getValue())) { + return sourceOperateCodeEnum; + } + } + return null; + } } diff --git a/detection/src/main/java/com/njcn/gather/detection/pojo/param/DevPhaseSequenceParam.java b/detection/src/main/java/com/njcn/gather/detection/pojo/param/DevPhaseSequenceParam.java new file mode 100644 index 00000000..3e27598c --- /dev/null +++ b/detection/src/main/java/com/njcn/gather/detection/pojo/param/DevPhaseSequenceParam.java @@ -0,0 +1,43 @@ +package com.njcn.gather.detection.pojo.param; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiOperation; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * @author wr + * @description + * @date 2024/12/18 9:17 + */ +@NoArgsConstructor +@Data +public class DevPhaseSequenceParam { + + /** + * 装置下测点集合 + */ + @JSONField(name = "moniterIdList", ordinal = 1) + private List moniterIdList; + + /** + * 设置需要的取值(平均值/电压有效值) + */ + @JSONField(name = "dataType", ordinal = 2) + private List dataType; + + /** + * 获取多少组数据 + */ + @JSONField(name = "readCount", ordinal = 3) + private Integer readCount; + + /** + * 忽略多少组数据 + */ + @JSONField(name = "ignoreCount", ordinal = 4) + private Integer ignoreCount; +} diff --git a/detection/src/main/java/com/njcn/gather/detection/pojo/po/DevData.java b/detection/src/main/java/com/njcn/gather/detection/pojo/po/DevData.java new file mode 100644 index 00000000..6bd36dc7 --- /dev/null +++ b/detection/src/main/java/com/njcn/gather/detection/pojo/po/DevData.java @@ -0,0 +1,82 @@ +package com.njcn.gather.detection.pojo.po; + +import com.alibaba.fastjson.annotation.JSONField; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * @author wr + * @description + * @date 2024/12/18 9:09 + */ +@NoArgsConstructor +@Data +public class DevData { + + @JSONField(name = "Time", ordinal = 1) + private String time; + + @JSONField(name = "ID", ordinal = 2) + private String id; + + @JSONField(name = "result", ordinal = 3) + private Boolean result; + + @JSONField(name = "SqlData", ordinal = 4) + private List sqlData; + + @JSONField(name = "SqlDataHarm", ordinal = 5) + private List sqlDataHarm; + + @NoArgsConstructor + @Data + public static class SqlDataDTO { + //类型 平均值 最大值 最小值 CP95值 实时值 + @JSONField(name = "type", ordinal = 1) + private String type; + //指标 电流有效值 + @JSONField(name = "desc", ordinal = 2) + private String desc; + @JSONField(name = "list", ordinal = 3) + private ListDTO list; + + @NoArgsConstructor + @Data + public static class ListDTO { + @JSONField(name = "A", ordinal = 1) + private Float a; + @JSONField(name = "B", ordinal = 2) + private Float b; + @JSONField(name = "C", ordinal = 3) + private Float c; + @JSONField(name = "T", ordinal = 4) + private Float t; + } + } + + @NoArgsConstructor + @Data + public static class SqlDataHarmDTO { + @JSONField(name = "type", ordinal = 1) + private String type; + @JSONField(name = "desc", ordinal = 2) + private String desc; + @JSONField(name = "num", ordinal = 3) + private Integer num; + @JSONField(name = "list", ordinal = 4) + private ListDTO list; + + @NoArgsConstructor + @Data + public static class ListDTO { + @JSONField(name = "A", ordinal = 1) + private List a; + @JSONField(name = "B", ordinal = 2) + private List b; + @JSONField(name = "C", ordinal = 3) + private List c; + } + } +} 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 91e0aaa0..28fddf1d 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 @@ -12,9 +12,7 @@ import com.njcn.gather.detection.service.PreDetectionService; 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.NettyDevClientHandler; import com.njcn.gather.detection.util.socket.cilent.NettySourceClientHandler; -import com.njcn.gather.device.device.pojo.vo.PreDetection; import com.njcn.gather.device.device.service.IPqDevService; import com.njcn.gather.device.script.pojo.param.PqScriptIssueParam; import com.njcn.gather.device.script.pojo.po.SourceIssue; @@ -27,11 +25,6 @@ import com.njcn.gather.plan.service.IAdPlanService; import com.njcn.gather.plan.service.IAdPlanSourceService; import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum; import com.njcn.gather.system.dictionary.service.IDictDataService; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureListener; -import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; -import io.netty.channel.Channel; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -75,11 +68,11 @@ public class PreDetectionServiceImpl implements PreDetectionService { switch (dictDataEnumByCode) { case DIGITAL: case SIMULATE: - sendYtxSocket(plan.getId(),param.getUserPageId()); + sendYtxSocket(param); break; case CONTRAST: //todo 对比式可以是多个源 - sendYtxSocket(plan.getId(),param.getUserPageId()); + sendYtxSocket(param); break; default: //todo 没有找到对应的模式 @@ -92,9 +85,9 @@ public class PreDetectionServiceImpl implements PreDetectionService { } - private void sendYtxSocket(String planId,String userPageId){ + private void sendYtxSocket(PreDetectionParam param){ AdPlanSource planSource = adPlanSourceService.getOne(new LambdaQueryWrapper() - .eq(AdPlanSource::getPlanId,planId) + .eq(AdPlanSource::getPlanId,param.getPlanId()) ); if(ObjectUtil.isNotNull(planSource)){ SourceInitialize sourceParam = pqSourceService.getSourceInitializeParam(planSource.getSourceId()); @@ -104,16 +97,16 @@ public class PreDetectionServiceImpl implements PreDetectionService { msg.setRequestId(SourceOperateCodeEnum.YJC_YTXJY.getValue()); msg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue()); msg.setData(JSON.toJSONString(sourceParam)); - String s = userPageId + "_Source"; - NettyClient.socketClient(ip, port,userPageId, new NettySourceClientHandler(s, sourceResponseService)); + String s = param.getUserPageId() + "_Source"; + NettyClient.socketClient(ip, port,param.getUserPageId(), new NettySourceClientHandler(param, sourceResponseService)); SocketManager.sendMsg(s,JSON.toJSONString(msg)); - PqScriptIssueParam param=new PqScriptIssueParam(); - param.setScriptId(planSource.getSourceId()); - param.setPlanId(planId); - param.setSourceId(planSource.getSourceId()); - List sourceIssues = pqScriptDtlsService.listSourceIssue(param); + PqScriptIssueParam issueParam=new PqScriptIssueParam(); + issueParam.setScriptId(planSource.getSourceId()); + issueParam.setPlanId(param.getPlanId()); + issueParam.setSourceId(planSource.getSourceId()); + List sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam); for (SourceIssue sourceIssue : sourceIssues) { String jsonString = JSON.toJSONString(sourceIssue); } @@ -130,18 +123,18 @@ public class PreDetectionServiceImpl implements PreDetectionService { @Override public boolean startTest(PreDetectionParam param) { - Runnable runnable = new Runnable() { - @Override - public void run() { - String ddId = param.getUserPageId(); - Channel channel = SocketManager.getChannelByUserId(ddId); - if( channel== null || !channel.isActive()){ - NettyClient.socketClient(ip, port,param.getUserPageId(),new NettySourceClientHandler(ddId, sourceResponseService)); - } - SocketManager.sendMsg(ddId,"start\n"); - } - }; - runnable.run(); +// Runnable runnable = new Runnable() { +// @Override +// public void run() { +// String ddId = param.getUserPageId(); +// Channel channel = SocketManager.getChannelByUserId(ddId); +// if( channel== null || !channel.isActive()){ +// NettyClient.socketClient(ip, port,param.getUserPageId(),new NettySourceClientHandler(ddId, sourceResponseService)); +// } +// SocketManager.sendMsg(ddId,"start\n"); +// } +// }; +// runnable.run(); return true; } } \ No newline at end of file diff --git a/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettyDevClientHandler.java b/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettyDevClientHandler.java index 434315f4..ffa4e5ad 100644 --- a/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettyDevClientHandler.java +++ b/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettyDevClientHandler.java @@ -1,7 +1,6 @@ package com.njcn.gather.detection.util.socket.cilent; -import com.njcn.gather.detection.handler.SocketResponseService; -import com.njcn.gather.detection.handler.SocketSourceResponseService; +import com.njcn.gather.detection.handler.SocketDevResponseService; import com.njcn.gather.detection.util.socket.SocketManager; import com.njcn.gather.detection.util.socket.WebServiceManager; import io.netty.channel.ChannelHandlerContext; @@ -28,7 +27,7 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler { private final String webUser; - private final SocketResponseService socketResponseService; + private final SocketDevResponseService socketResponseService; @Value("${socket.device.ip}") private String devIp; diff --git a/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettySourceClientHandler.java b/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettySourceClientHandler.java index e3ae2153..af50c46d 100644 --- a/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettySourceClientHandler.java +++ b/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettySourceClientHandler.java @@ -1,6 +1,7 @@ package com.njcn.gather.detection.util.socket.cilent; import com.njcn.gather.detection.handler.SocketSourceResponseService; +import com.njcn.gather.detection.pojo.param.PreDetectionParam; import com.njcn.gather.detection.util.socket.SocketManager; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; @@ -17,8 +18,7 @@ import lombok.RequiredArgsConstructor; @RequiredArgsConstructor public class NettySourceClientHandler extends SimpleChannelInboundHandler { - private final String webUser; - + private final PreDetectionParam webUser; private final SocketSourceResponseService sourceResponseService; /** @@ -78,7 +78,7 @@ public class NettySourceClientHandler extends SimpleChannelInboundHandler