复检测试项bug、设备连接异常提示信息、心跳空指针异常
This commit is contained in:
@@ -60,6 +60,7 @@ public enum SourceOperateCodeEnum {
|
||||
SOCKET_TIMEOUT("socket_timeout","与源或者装置通讯等待超时"),
|
||||
STOP_TIMEOUT("stop_timeout","暂停时间超过十分钟"),
|
||||
SERVER_ERROR("server_error","服务端主动关闭连接,请稍后再试"),
|
||||
DEVICE_ERROR("device_error","设备主动关闭连接,请稍后再试"),
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -8,14 +8,11 @@ import com.njcn.gather.detection.pojo.vo.SocketMsg;
|
||||
import com.njcn.gather.detection.util.socket.CnSocketUtil;
|
||||
import com.njcn.gather.detection.util.socket.MsgUtil;
|
||||
import com.njcn.gather.detection.util.socket.SocketManager;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelDuplexHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -42,7 +39,7 @@ public class HeartbeatHandler extends SimpleChannelInboundHandler<String> {
|
||||
private int consecutiveHeartbeatMisses = 0;
|
||||
|
||||
|
||||
public HeartbeatHandler(PreDetectionParam param,String type){
|
||||
public HeartbeatHandler(PreDetectionParam param, String type) {
|
||||
this.param = param;
|
||||
this.handlerType = type;
|
||||
}
|
||||
@@ -70,13 +67,13 @@ public class HeartbeatHandler extends SimpleChannelInboundHandler<String> {
|
||||
msg.setRequestId("yxt");
|
||||
msg.setOperateCode(SourceOperateCodeEnum.HEARTBEAT.getValue());
|
||||
msg.setData("");
|
||||
ctx.channel().writeAndFlush(JSON.toJSONString(msg)+"\n");
|
||||
ctx.channel().writeAndFlush(JSON.toJSONString(msg) + "\n");
|
||||
|
||||
System.out.println(handlerType+"♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥send"+LocalDateTime.now());
|
||||
System.out.println(handlerType + "♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥send" + LocalDateTime.now());
|
||||
consecutiveHeartbeatMisses++;
|
||||
if (consecutiveHeartbeatMisses >= MAX_HEARTBEAT_MISSES) {
|
||||
// 连续三次未收到心跳响应,断开连接
|
||||
System.out.println(handlerType+"连续三次未收到心跳响应,断开连接");
|
||||
System.out.println(handlerType + "连续三次未收到心跳响应,断开连接");
|
||||
if (dev.equals(handlerType)) {
|
||||
//CnSocketUtil.sendToWebSocket(param.getUserPageId(),);
|
||||
CnSocketUtil.quitSend(param);
|
||||
@@ -98,12 +95,11 @@ public class HeartbeatHandler extends SimpleChannelInboundHandler<String> {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
|
||||
// 过滤心跳包,避免进入业务逻辑
|
||||
if (isHeartbeatPacket(msg)) {
|
||||
System.out.println(handlerType+"♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥response"+LocalDateTime.now());
|
||||
System.out.println(handlerType + "♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥response" + LocalDateTime.now());
|
||||
consecutiveHeartbeatMisses = 0;
|
||||
return;
|
||||
}
|
||||
@@ -115,6 +111,6 @@ public class HeartbeatHandler extends SimpleChannelInboundHandler<String> {
|
||||
private boolean isHeartbeatPacket(String msg) {
|
||||
// 判断是否为心跳包
|
||||
SocketDataMsg socketDataMsg = MsgUtil.socketDataMsg(msg);
|
||||
return socketDataMsg.getOperateCode().equals(SourceOperateCodeEnum.HEARTBEAT.getValue());
|
||||
return !Objects.isNull(socketDataMsg.getOperateCode()) && socketDataMsg.getOperateCode().equals(SourceOperateCodeEnum.HEARTBEAT.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
|
||||
} else if (cause instanceof IOException) {
|
||||
// 处理I/O异常,例如读写错误
|
||||
System.out.println("IOException caught: There was an I/O error.");
|
||||
CnSocketUtil.sendToWebSocket(param.getUserPageId(), SourceOperateCodeEnum.SERVER_ERROR.getValue(), SourceOperateCodeEnum.SERVER_ERROR.getValue(), SourceOperateCodeEnum.SERVER_ERROR.getMsg(), null);
|
||||
CnSocketUtil.sendToWebSocket(param.getUserPageId(), SourceOperateCodeEnum.DEVICE_ERROR.getValue(), SourceOperateCodeEnum.DEVICE_ERROR.getValue(), SourceOperateCodeEnum.DEVICE_ERROR.getMsg(), null);
|
||||
|
||||
// 例如,可以记录更详细的I/O错误信息
|
||||
} else if (cause instanceof TimeoutException) {
|
||||
@@ -200,9 +200,11 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
|
||||
} else {
|
||||
// 处理其他类型的异常
|
||||
System.out.println("Unknown exception caught: " + cause.getMessage());
|
||||
CnSocketUtil.sendToWebSocket(param.getUserPageId(), SourceOperateCodeEnum.DEVICE_ERROR.getValue(), SourceOperateCodeEnum.DEVICE_ERROR.getValue(), SourceOperateCodeEnum.DEVICE_ERROR.getMsg(), null);
|
||||
// 可以记录未知异常信息
|
||||
}
|
||||
CnSocketUtil.quitSend(param);
|
||||
CnSocketUtil.quitSendSource(param);
|
||||
socketResponseService.backCheckState(param);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@@ -108,6 +108,8 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean addPqDev(PqDevParam pqDevParam) {
|
||||
pqDevParam.setName(pqDevParam.getName().trim());
|
||||
pqDevParam.setCreateId(pqDevParam.getCreateId().trim());
|
||||
this.checkRepeat(pqDevParam, false);
|
||||
|
||||
PqDev pqDev = new PqDev();
|
||||
@@ -174,6 +176,8 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean updatePqDev(PqDevParam.UpdateParam updateParam) {
|
||||
updateParam.setName(updateParam.getName().trim());
|
||||
updateParam.setCreateId(updateParam.getCreateId().trim());
|
||||
this.checkRepeat(updateParam, true);
|
||||
|
||||
PqDev pqDev = new PqDev();
|
||||
|
||||
@@ -67,6 +67,7 @@ public class PqErrSysServiceImpl extends ServiceImpl<PqErrSysMapper, PqErrSys> i
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean addPqErrSys(PqErrSysParam param) {
|
||||
param.setStandardName(param.getStandardName().trim());
|
||||
this.checkRepeat(param, false);
|
||||
PqErrSys pqErrSys = new PqErrSys();
|
||||
BeanUtils.copyProperties(param, pqErrSys);
|
||||
@@ -84,6 +85,7 @@ public class PqErrSysServiceImpl extends ServiceImpl<PqErrSysMapper, PqErrSys> i
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean updatePqErrSys(PqErrSysParam.UpdateParam param) {
|
||||
param.setStandardName(param.getStandardName().trim());
|
||||
this.checkRepeat(param, true);
|
||||
PqErrSys pqErrSys = new PqErrSys();
|
||||
BeanUtils.copyProperties(param, pqErrSys);
|
||||
|
||||
@@ -47,6 +47,7 @@ public class PqIcdPathServiceImpl extends ServiceImpl<PqIcdPathMapper, PqIcdPath
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean addIcd(PqIcdPathParam param) {
|
||||
param.setName(param.getName().trim());
|
||||
this.checkRepeat(param, false);
|
||||
PqIcdPath pqIcdPath = new PqIcdPath();
|
||||
BeanUtils.copyProperties(param, pqIcdPath);
|
||||
@@ -57,6 +58,7 @@ public class PqIcdPathServiceImpl extends ServiceImpl<PqIcdPathMapper, PqIcdPath
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean updateIcd(PqIcdPathParam.UpdateParam param) {
|
||||
param.setName(param.getName().trim());
|
||||
this.checkRepeat(param, true);
|
||||
PqIcdPath pqIcdPath = new PqIcdPath();
|
||||
BeanUtils.copyProperties(param, pqIcdPath);
|
||||
|
||||
@@ -144,6 +144,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
||||
this.checkRepeat(param, false);
|
||||
AdPlan adPlan = new AdPlan();
|
||||
BeanUtil.copyProperties(param, adPlan);
|
||||
adPlan.setName(param.getName().trim());
|
||||
|
||||
String planId = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
adPlan.setId(planId);
|
||||
@@ -186,6 +187,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean updateAdPlan(AdPlanParam.UpdateParam param) {
|
||||
param.setName(param.getName().trim());
|
||||
this.checkRepeat(param, true);
|
||||
AdPlan plan1 = this.getById(param.getId());
|
||||
AdPlan plan2 = new AdPlan();
|
||||
|
||||
@@ -61,6 +61,7 @@ public class PqScriptServiceImpl extends ServiceImpl<PqScriptMapper, PqScript> i
|
||||
@Override
|
||||
@Transactional
|
||||
public String addPqScript(PqScriptParam param) {
|
||||
param.setName(param.getName().trim());
|
||||
this.checkRepeat(param, false);
|
||||
PqScript pqScript = new PqScript();
|
||||
BeanUtils.copyProperties(param, pqScript);
|
||||
@@ -73,6 +74,7 @@ public class PqScriptServiceImpl extends ServiceImpl<PqScriptMapper, PqScript> i
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean updatePqScript(PqScriptParam.UpdateParam param) {
|
||||
param.setName(param.getName().trim());
|
||||
this.checkRepeat(param, true);
|
||||
PqScript pqScript = new PqScript();
|
||||
BeanUtils.copyProperties(param, pqScript);
|
||||
|
||||
@@ -73,6 +73,7 @@ public class DevTypeServiceImpl extends ServiceImpl<DevTypeMapper, DevType> impl
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean addDevType(DevTypeParam addParam) {
|
||||
addParam.setName(addParam.getName().trim());
|
||||
this.checkRepeat(addParam, false);
|
||||
DevType devType = new DevType();
|
||||
BeanUtil.copyProperties(addParam, devType);
|
||||
@@ -83,6 +84,7 @@ public class DevTypeServiceImpl extends ServiceImpl<DevTypeMapper, DevType> impl
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean updateDevType(DevTypeParam.UpdateParam updateParam) {
|
||||
updateParam.setName(updateParam.getName().trim());
|
||||
this.checkRepeat(updateParam, true);
|
||||
DevType devType = new DevType();
|
||||
BeanUtil.copyProperties(updateParam, devType);
|
||||
|
||||
Reference in New Issue
Block a user