diff --git a/detection/src/main/java/com/njcn/gather/detection/handler/SocketDevResponseService.java b/detection/src/main/java/com/njcn/gather/detection/handler/SocketDevResponseService.java index 3ce30382..75811fdb 100644 --- a/detection/src/main/java/com/njcn/gather/detection/handler/SocketDevResponseService.java +++ b/detection/src/main/java/com/njcn/gather/detection/handler/SocketDevResponseService.java @@ -235,7 +235,7 @@ public class SocketDevResponseService { System.out.println("开始相序校验++++++++++"); PqScriptIssueParam issueParam=new PqScriptIssueParam(); issueParam.setPlanId(param.getPlanId()); - issueParam.setSourceId(param.getScriptId()); + issueParam.setSourceId(param.getSourceId()); issueParam.setIsPhaseSequence(true); issueParam.setDevIds(param.getDevIds()); List sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam); @@ -300,6 +300,7 @@ public class SocketDevResponseService { sourceParam.setPlanId(param.getPlanId()); sourceParam.setDevIds(param.getDevIds()); sourceParam.setIsPhaseSequence(true); + sourceParam.setSourceId(param.getSourceId()); List sourceIssues = scriptDtlsService.listSourceIssue(sourceParam); List info = new ArrayList<>(); if (CollUtil.isNotEmpty(sourceIssues)) { @@ -308,6 +309,15 @@ public class SocketDevResponseService { } } xuClear(); + String s = param.getUserPageId() + "_Source"; + SocketMsg msg= new SocketMsg(); + msg.setRequestId(SourceOperateCodeEnum.YJC_YTXJY.getValue()); + msg.setOperateCode(SourceOperateCodeEnum.CLOSE_GATHER.getValue()); + Map map=new HashMap<>(1); + map.put("sourceId",sourceIssues.get(0).getSourceId()); + msg.setData(JSON.toJSONString(map)); + SocketManager.sendMsg(s, JSON.toJSONString(msg)); + socketMsg.setRequestId(SourceOperateCodeEnum.YJC_XUJY.getValue()); socketMsg.setOperateCode(socketDataMsg.getOperateCode()); socketMsg.setData(JSON.toJSONString(info)); 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 f6072039..9b355acf 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 @@ -133,7 +133,7 @@ public class SocketSourceResponseService { phaseSequenceParam.setMoniterIdList(moniterIdList); phaseSequenceParam.setDataType(Arrays.asList("实时数据/电压有效值","实时数据/电流有效值")); phaseSequenceParam.setReadCount(1); - phaseSequenceParam.setIgnoreCount(1); + phaseSequenceParam.setIgnoreCount(10); socketMsg.setData(JSON.toJSONString(phaseSequenceParam)); SocketManager.sendMsg(s,JSON.toJSONString(socketMsg)); break; diff --git a/detection/src/main/java/com/njcn/gather/detection/pojo/param/PreDetectionParam.java b/detection/src/main/java/com/njcn/gather/detection/pojo/param/PreDetectionParam.java index f972d412..7a0552f5 100644 --- a/detection/src/main/java/com/njcn/gather/detection/pojo/param/PreDetectionParam.java +++ b/detection/src/main/java/com/njcn/gather/detection/pojo/param/PreDetectionParam.java @@ -32,4 +32,8 @@ public class PreDetectionParam { */ private String scriptId; + /** + * 检测脚本Id + */ + private String sourceId; } 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 ca631f79..4799371d 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 @@ -103,20 +103,6 @@ public class PreDetectionServiceImpl implements PreDetectionService { socketDevResponseService.initList(param); if(channel==null || !channel.isActive()){ NettyClient.socketClient(ip, port, param.getUserPageId(), new NettySourceClientHandler(param, sourceResponseService)); - }else{ - //关闭源 - msg= new SocketMsg(); - msg.setRequestId(SourceOperateCodeEnum.YJC_YTXJY.getValue()); - msg.setOperateCode(SourceOperateCodeEnum.CLOSE_GATHER.getValue()); - Map map=new HashMap<>(1); - map.put("sourceId",sourceParam.getSourceId()); - msg.setData(JSON.toJSONString(map)); - SocketManager.sendMsg(s, JSON.toJSONString(msg)); - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } } msg= new SocketMsg(); msg.setRequestId(SourceOperateCodeEnum.YJC_YTXJY.getValue()); diff --git a/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettyClient.java b/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettyClient.java index ce340608..6d4d45d2 100644 --- a/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettyClient.java +++ b/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettyClient.java @@ -39,7 +39,7 @@ import java.util.concurrent.TimeUnit; @Getter public class NettyClient { - public static void socketClient(String ip, Integer port,String userPageId,SimpleChannelInboundHandler handler) { + public static void socketClient(String ip, Integer port, String userPageId, SimpleChannelInboundHandler handler) { NioEventLoopGroup group = new NioEventLoopGroup(); Bootstrap bootstrap = new Bootstrap(); try { @@ -48,16 +48,16 @@ public class NettyClient { .handler(new ChannelInitializer() { @Override protected void initChannel(NioSocketChannel ch) { - if(handler instanceof NettySourceClientHandler){ + if (handler instanceof NettySourceClientHandler) { ch.pipeline() - //空闲状态的handler - // 添加LineBasedFrameDecoder来按行分割数据 + //空闲状态的handler + // 添加LineBasedFrameDecoder来按行分割数据 // .addLast(new LineBasedFrameDecoder(10240)) - .addLast(new IdleStateHandler(0, 5, 0, TimeUnit.SECONDS)) - .addLast(new StringDecoder(CharsetUtil.UTF_8)) - .addLast(new StringEncoder(CharsetUtil.UTF_8)) - .addLast(handler); - }else{ + .addLast(new IdleStateHandler(20, 0, 0, TimeUnit.SECONDS)) + .addLast(new StringDecoder(CharsetUtil.UTF_8)) + .addLast(new StringEncoder(CharsetUtil.UTF_8)) + .addLast(handler); + } else { ch.pipeline() //空闲状态的handler // 添加LineBasedFrameDecoder来按行分割数据 @@ -78,15 +78,15 @@ public class NettyClient { } }); } catch (Exception e) { - System.out.println("连接socker服务端发送异常............"+e.getMessage()); + System.out.println("连接socker服务端发送异常............" + e.getMessage()); group.shutdownGracefully(); //TODO 通知页面 WebSocketVO webSocketVO = new WebSocketVO(); webSocketVO.setCode(SourceResponseCodeEnum.SOCKET_ERROR.getCode()); webSocketVO.setMessage(SourceResponseCodeEnum.SOCKET_ERROR.getMessage()); WebServiceManager.sendMsg(userPageId, JSON.toJSONString(webSocketVO)); - }finally { - // System.out.println("进入clientSocket最后步骤---------------------"); + } finally { + // System.out.println("进入clientSocket最后步骤---------------------"); } } 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 ed7a936c..be39395f 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 @@ -76,7 +76,7 @@ public class NettySourceClientHandler extends SimpleChannelInboundHandler