复检测试项bug、设备连接异常提示信息、心跳空指针异常

This commit is contained in:
caozehui
2025-05-23 15:34:01 +08:00
parent 21dcd87be2
commit 1380af6d50
17 changed files with 40 additions and 14 deletions

View File

@@ -60,6 +60,7 @@ public enum SourceOperateCodeEnum {
SOCKET_TIMEOUT("socket_timeout","与源或者装置通讯等待超时"),
STOP_TIMEOUT("stop_timeout","暂停时间超过十分钟"),
SERVER_ERROR("server_error","服务端主动关闭连接,请稍后再试"),
DEVICE_ERROR("device_error","设备主动关闭连接,请稍后再试"),

View File

@@ -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());
}
}

View File

@@ -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();
}

View File

@@ -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();

View File

@@ -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);

View File

@@ -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);

View File

@@ -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();

View File

@@ -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);

View File

@@ -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);

View File

@@ -209,7 +209,6 @@ public class AdHarmonicServiceImpl extends ServiceImpl<AdHarmonicMappper, AdHarm
lambdaQueryWrapper.select(AdHarmonicResult::getSort)
.likeRight(StrUtil.isNotBlank(param.getDevId()), AdHarmonicResult::getMonitorId, param.getDevId())
.ne(AdHarmonicResult::getResultFlag, 1)
.ne(AdHarmonicResult::getResultFlag, 4)
.ne(AdHarmonicResult::getResultFlag, 5)
.eq(AdHarmonicResult::getScriptId, param.getScriptId());
List<AdHarmonicResult> adHarmonicResultList = this.list(lambdaQueryWrapper);
@@ -220,7 +219,6 @@ public class AdHarmonicServiceImpl extends ServiceImpl<AdHarmonicMappper, AdHarm
resultLambdaQueryWrapper.select(AdNonHarmonicResult::getSort)
.likeRight(StrUtil.isNotBlank(param.getDevId()), AdNonHarmonicResult::getMonitorId, param.getDevId())
.ne(AdNonHarmonicResult::getResultFlag, 1)
.ne(AdNonHarmonicResult::getResultFlag, 4)
.ne(AdNonHarmonicResult::getResultFlag, 5)
.eq(AdNonHarmonicResult::getScriptId, param.getScriptId());
List<AdNonHarmonicResult> nonHarmonicResults = adNonHarmonicMapper.selectList(resultLambdaQueryWrapper);

View File

@@ -77,6 +77,7 @@ public class DictDataServiceImpl extends ServiceImpl<DictDataMapper, DictData> i
@Override
@Transactional
public boolean addDictData(DictDataParam dictDataParam) {
dictDataParam.setName(dictDataParam.getName().trim());
checkDicDataName(dictDataParam, false);
DictData dictData = new DictData();
BeanUtil.copyProperties(dictDataParam, dictData);
@@ -89,6 +90,7 @@ public class DictDataServiceImpl extends ServiceImpl<DictDataMapper, DictData> i
@Override
@Transactional
public boolean updateDictData(DictDataParam.UpdateParam updateParam) {
updateParam.setName(updateParam.getName().trim());
checkDicDataName(updateParam, true);
DictData dictData = new DictData();
BeanUtil.copyProperties(updateParam, dictData);

View File

@@ -58,6 +58,7 @@ public class DictPqServiceImpl extends ServiceImpl<DictPqMapper, DictPq> impleme
@Override
@Transactional
public boolean addDictPq(DictPqParam dictPqParam) {
dictPqParam.setName(dictPqParam.getName().trim());
checkDicPqName(dictPqParam, false);
DictPq dictPq = new DictPq();
BeanUtil.copyProperties(dictPqParam, dictPq);
@@ -69,6 +70,7 @@ public class DictPqServiceImpl extends ServiceImpl<DictPqMapper, DictPq> impleme
@Override
@Transactional
public boolean updateDictPq(DictPqParam.UpdateParam updateParam) {
updateParam.setName(updateParam.getName().trim());
checkDicPqName(updateParam, true);
DictPq dictPq = new DictPq();
BeanUtil.copyProperties(updateParam, dictPq);

View File

@@ -59,6 +59,7 @@ public class DictTreeServiceImpl extends ServiceImpl<DictTreeMapper, DictTree> i
@Override
@Transactional
public boolean addDictTree(DictTreeParam dictTreeParam) {
dictTreeParam.setName(dictTreeParam.getName().trim());
checkRepeat(dictTreeParam, false);
boolean result;
DictTree dictTree = new DictTree();
@@ -79,6 +80,7 @@ public class DictTreeServiceImpl extends ServiceImpl<DictTreeMapper, DictTree> i
@Override
@Transactional
public boolean updateDictTree(DictTreeParam.UpdateParam param) {
param.setName(param.getName().trim());
DictTree dictTree = this.getById(param.getId());
if("975f63baeb6f653c54fca226a9ae36ca".equals(param.getId()) || dictTree.getPids().contains("975f63baeb6f653c54fca226a9ae36ca")){
throw new BusinessException(SystemResponseEnum.CAN_NOT_UPDATE_USED_DICT);

View File

@@ -60,6 +60,7 @@ public class DictTypeServiceImpl extends ServiceImpl<DictTypeMapper, DictType> i
@Override
@Transactional
public boolean addDictType(DictTypeParam dictTypeParam) {
dictTypeParam.setName(dictTypeParam.getName().trim());
checkDicTypeName(dictTypeParam, false);
DictType dictType = new DictType();
BeanUtil.copyProperties(dictTypeParam, dictType);
@@ -71,6 +72,7 @@ public class DictTypeServiceImpl extends ServiceImpl<DictTypeMapper, DictType> i
@Override
@Transactional
public boolean updateDictType(DictTypeParam.UpdateParam updateParam) {
updateParam.setName(updateParam.getName().trim());
checkDicTypeName(updateParam, true);
DictType dictType = new DictType();
BeanUtil.copyProperties(updateParam, dictType);

View File

@@ -48,6 +48,7 @@ public class SysFunctionServiceImpl extends ServiceImpl<SysFunctionMapper, SysFu
@Override
@Transactional
public boolean addFunction(SysFunctionParam functionParam) {
functionParam.setName(functionParam.getName().trim());
functionParam.setPath(functionParam.getPath().trim());
functionParam.setComponent(functionParam.getComponent().trim());
checkFunctionParam(functionParam, false);
@@ -71,6 +72,7 @@ public class SysFunctionServiceImpl extends ServiceImpl<SysFunctionMapper, SysFu
@Override
@Transactional
public boolean updateFunction(SysFunctionParam.UpdateParam param) {
param.setName(param.getName().trim());
boolean result = false;
param.setPath(param.getPath().trim());
param.setComponent(param.getComponent().trim());

View File

@@ -55,6 +55,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
@Override
@Transactional
public boolean addRole(SysRoleParam sysRoleParam) {
sysRoleParam.setName(sysRoleParam.getName().trim());
checkRepeat(sysRoleParam, false);
SysRole role = new SysRole();
BeanUtil.copyProperties(sysRoleParam, role);
@@ -66,6 +67,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
@Override
@Transactional
public boolean updateRole(SysRoleParam.UpdateParam updateParam) {
updateParam.setName(updateParam.getName().trim());
checkRepeat(updateParam, true);
//不能修改超级管理员角色
Integer count = this.lambdaQuery()

View File

@@ -106,6 +106,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@Override
@Transactional
public boolean addUser(SysUserParam.SysUserAddParam addUserParam) {
addUserParam.setName(addUserParam.getName().trim());
addUserParam.setLoginName(addUserParam.getLoginName().trim());
if (UserConst.SUPER_ADMIN.equals(addUserParam.getLoginName())) {
throw new BusinessException(UserResponseEnum.SUPER_ADMIN_REPEAT);
}
@@ -129,6 +131,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@Override
@Transactional
public boolean updateUser(SysUserParam.SysUserUpdateParam updateUserParam) {
updateUserParam.setName(updateUserParam.getName().trim());
checkRepeat(updateUserParam, true, updateUserParam.getId());
SysUser sysUser = new SysUser();
BeanUtils.copyProperties(updateUserParam, sysUser);