测试提交
This commit is contained in:
@@ -37,33 +37,19 @@ public class SocketDevResponseService {
|
|||||||
|
|
||||||
public void deal(String userId,String msg){
|
public void deal(String userId,String msg){
|
||||||
SocketDataMsg socketDataMsg = MsgUtil.socketDataMsg(msg);
|
SocketDataMsg socketDataMsg = MsgUtil.socketDataMsg(msg);
|
||||||
if(SourceOperateCodeEnum.YJC_YTXJY.getValue().equals(socketDataMsg.getRequestId())){
|
SourceOperateCodeEnum sourceOperateCodeEnum = SourceOperateCodeEnum.getDictDataEnumByCode(socketDataMsg.getRequestId());
|
||||||
SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
|
switch (sourceOperateCodeEnum) {
|
||||||
if(ObjectUtil.isNotNull(dictDataEnumByCode)){
|
case YJC_SBTXJY:
|
||||||
SocketMsg socketMsg=new SocketMsg();
|
|
||||||
|
|
||||||
switch (dictDataEnumByCode){
|
|
||||||
case SUCCESS:
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case UNPROCESSED_BUSINESS:
|
case YJC_XYJY:
|
||||||
break;
|
break;
|
||||||
case RE_OPERATE:
|
|
||||||
socketMsg.setRequestId(socketDataMsg.getRequestId());
|
|
||||||
socketMsg.setOperateCode("QUIT_FUNEND$01");
|
|
||||||
SocketManager.sendMsg(userId,JSON.toJSONString(socketMsg));
|
|
||||||
|
|
||||||
break;
|
case YJC_XUJY:
|
||||||
default:
|
|
||||||
socketMsg.setRequestId(socketDataMsg.getRequestId());
|
|
||||||
socketMsg.setOperateCode(socketDataMsg.getOperateCode());
|
|
||||||
socketMsg.setData(dictDataEnumByCode.getMessage());
|
|
||||||
webSocketHandler.sendMsgToUser(userId, JSON.toJSONString(socketMsg));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import com.njcn.gather.detection.util.socket.cilent.NettyDevClientHandler;
|
|||||||
import com.njcn.gather.detection.util.socket.web.WebSocketHandler;
|
import com.njcn.gather.detection.util.socket.web.WebSocketHandler;
|
||||||
import com.njcn.gather.device.device.pojo.vo.PreDetection;
|
import com.njcn.gather.device.device.pojo.vo.PreDetection;
|
||||||
import com.njcn.gather.device.device.service.IPqDevService;
|
import com.njcn.gather.device.device.service.IPqDevService;
|
||||||
|
import io.netty.channel.Channel;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -78,9 +79,9 @@ public class SocketSourceResponseService {
|
|||||||
switch (dictDataEnumByCode){
|
switch (dictDataEnumByCode){
|
||||||
case SUCCESS:
|
case SUCCESS:
|
||||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), msg);
|
webSocketHandler.sendMsgToUser(param.getUserPageId(), msg);
|
||||||
String s = param.getUserPageId() + "_Dev";
|
String s = param.getUserPageId() + "_dev";
|
||||||
//开始设备通讯检测
|
//开始设备通讯检测
|
||||||
NettyClient.socketClient(ip, port,param.getPlanId(), new NettyDevClientHandler(param.getPlanId(), socketDevResponseService));
|
NettyClient.socketClient(ip, port, param.getUserPageId(), new NettyDevClientHandler(s, socketDevResponseService));
|
||||||
List<PreDetection> devList = iPqDevService.getDevInfo(param.getDevIds());
|
List<PreDetection> devList = iPqDevService.getDevInfo(param.getDevIds());
|
||||||
Map<String, List<PreDetection>> map = new HashMap(1);
|
Map<String, List<PreDetection>> map = new HashMap(1);
|
||||||
map.put("deviceList", devList);
|
map.put("deviceList", devList);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.njcn.gather.detection.pojo.vo;
|
package com.njcn.gather.detection.pojo.vo;
|
||||||
|
|
||||||
|
import com.njcn.gather.detection.pojo.enums.SourceResponseCodeEnum;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.apache.poi.ss.formula.functions.T;
|
import org.apache.poi.ss.formula.functions.T;
|
||||||
|
|
||||||
@@ -11,4 +12,20 @@ public class WebSocketVO {
|
|||||||
private String message;
|
private String message;
|
||||||
|
|
||||||
private T data;
|
private T data;
|
||||||
|
|
||||||
|
|
||||||
|
public WebSocketVO(SourceResponseCodeEnum sourceResponseCodeEnum){
|
||||||
|
this.code = sourceResponseCodeEnum.getCode();
|
||||||
|
this.message= sourceResponseCodeEnum.getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
public WebSocketVO(Integer code, String message, T data) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WebSocketVO() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import com.njcn.gather.plan.service.IAdPlanService;
|
|||||||
import com.njcn.gather.plan.service.IAdPlanSourceService;
|
import com.njcn.gather.plan.service.IAdPlanSourceService;
|
||||||
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
|
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
|
||||||
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
||||||
|
import io.netty.channel.Channel;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -123,18 +124,18 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
|||||||
@Override
|
@Override
|
||||||
public boolean startTest(PreDetectionParam param) {
|
public boolean startTest(PreDetectionParam param) {
|
||||||
|
|
||||||
// Runnable runnable = new Runnable() {
|
Runnable runnable = new Runnable() {
|
||||||
// @Override
|
@Override
|
||||||
// public void run() {
|
public void run() {
|
||||||
// String ddId = param.getUserPageId();
|
String ddId = param.getUserPageId()+"_Source";
|
||||||
// Channel channel = SocketManager.getChannelByUserId(ddId);
|
Channel channel = SocketManager.getChannelByUserId(ddId);
|
||||||
// if( channel== null || !channel.isActive()){
|
if( channel== null || !channel.isActive()){
|
||||||
// NettyClient.socketClient(ip, port,param.getUserPageId(),new NettySourceClientHandler(ddId, sourceResponseService));
|
NettyClient.socketClient(ip, port,param.getUserPageId(),new NettySourceClientHandler(param, sourceResponseService));
|
||||||
// }
|
}
|
||||||
// SocketManager.sendMsg(ddId,"start\n");
|
SocketManager.sendMsg(ddId,"start\n");
|
||||||
// }
|
}
|
||||||
// };
|
};
|
||||||
// runnable.run();
|
runnable.run();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -30,6 +30,7 @@ public class SocketManager {
|
|||||||
public static void sendMsg(String userId,String msg) {
|
public static void sendMsg(String userId,String msg) {
|
||||||
Channel channel = userSessions.get(userId);
|
Channel channel = userSessions.get(userId);
|
||||||
channel.writeAndFlush(msg);
|
channel.writeAndFlush(msg);
|
||||||
|
System.out.println(userId+"__"+channel.id()+"往"+channel.remoteAddress()+"发送数据:"+msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.njcn.gather.detection.util.socket;
|
package com.njcn.gather.detection.util.socket;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.njcn.gather.detection.pojo.vo.WebSocketVO;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -57,5 +59,16 @@ public class WebServiceManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void sendMessage(String userId, WebSocketVO webSocketVO) {
|
||||||
|
Channel channel = userSessions.get(userId);
|
||||||
|
if(Objects.nonNull(channel) && channel.isActive()){
|
||||||
|
TextWebSocketFrame wd = new TextWebSocketFrame(JSON.toJSONString(webSocketVO));
|
||||||
|
channel.writeAndFlush(wd);
|
||||||
|
}else {
|
||||||
|
log.error("{}-websocket推送消息失败;当前用户-{}-客户端已经断开连接", LocalDateTime.now(),userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,8 +62,8 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void channelInactive(ChannelHandlerContext ctx) {
|
public void channelInactive(ChannelHandlerContext ctx) {
|
||||||
System.out.println("客户端连接成功");
|
System.out.println("客户端重新连接成功");
|
||||||
SocketManager.addUser(webUser,ctx.channel());
|
//SocketManager.addUser(webUser,ctx.channel());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -97,7 +97,7 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handlerAdded(ChannelHandlerContext ctx) {
|
public void handlerAdded(ChannelHandlerContext ctx) {
|
||||||
SocketManager.addUser(webUser,ctx.channel());
|
SocketManager.addUser(webUser+"_dev",ctx.channel());
|
||||||
System.out.println("有通道接入" + ctx.channel());
|
System.out.println("有通道接入" + ctx.channel());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user