From 1380af6d5006211fcf3d45153ceef64d71b587bd Mon Sep 17 00:00:00 2001 From: caozehui <2427765068@qq.com> Date: Fri, 23 May 2025 15:34:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=8D=E6=A3=80=E6=B5=8B=E8=AF=95=E9=A1=B9bu?= =?UTF-8?q?g=E3=80=81=E8=AE=BE=E5=A4=87=E8=BF=9E=E6=8E=A5=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E6=8F=90=E7=A4=BA=E4=BF=A1=E6=81=AF=E3=80=81=E5=BF=83?= =?UTF-8?q?=E8=B7=B3=E7=A9=BA=E6=8C=87=E9=92=88=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pojo/enums/SourceOperateCodeEnum.java | 1 + .../util/socket/cilent/HeartbeatHandler.java | 18 +++++++----------- .../socket/cilent/NettyDevClientHandler.java | 4 +++- .../device/service/impl/PqDevServiceImpl.java | 4 ++++ .../err/service/impl/PqErrSysServiceImpl.java | 2 ++ .../icd/service/impl/PqIcdPathServiceImpl.java | 2 ++ .../plan/service/impl/AdPlanServiceImpl.java | 2 ++ .../service/impl/PqScriptServiceImpl.java | 2 ++ .../type/service/impl/DevTypeServiceImpl.java | 2 ++ .../service/impl/AdHarmonicServiceImpl.java | 2 -- .../service/impl/DictDataServiceImpl.java | 2 ++ .../service/impl/DictPqServiceImpl.java | 2 ++ .../service/impl/DictTreeServiceImpl.java | 2 ++ .../service/impl/DictTypeServiceImpl.java | 2 ++ .../service/impl/SysFunctionServiceImpl.java | 2 ++ .../user/service/impl/SysRoleServiceImpl.java | 2 ++ .../user/service/impl/SysUserServiceImpl.java | 3 +++ 17 files changed, 40 insertions(+), 14 deletions(-) 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 2ad1796d..10e560e4 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 @@ -60,6 +60,7 @@ public enum SourceOperateCodeEnum { SOCKET_TIMEOUT("socket_timeout","与源或者装置通讯等待超时"), STOP_TIMEOUT("stop_timeout","暂停时间超过十分钟"), SERVER_ERROR("server_error","服务端主动关闭连接,请稍后再试"), + DEVICE_ERROR("device_error","设备主动关闭连接,请稍后再试"), diff --git a/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/HeartbeatHandler.java b/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/HeartbeatHandler.java index ee3d80aa..98cd3f97 100644 --- a/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/HeartbeatHandler.java +++ b/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/HeartbeatHandler.java @@ -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 { 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 { 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 { } - @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 { 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()); } } 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 c5c90755..b4f1d889 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 @@ -186,7 +186,7 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler { } 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 { } 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(); } diff --git a/detection/src/main/java/com/njcn/gather/device/service/impl/PqDevServiceImpl.java b/detection/src/main/java/com/njcn/gather/device/service/impl/PqDevServiceImpl.java index 40a05fce..a3f3feef 100644 --- a/detection/src/main/java/com/njcn/gather/device/service/impl/PqDevServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/device/service/impl/PqDevServiceImpl.java @@ -108,6 +108,8 @@ public class PqDevServiceImpl extends ServiceImpl 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 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(); diff --git a/detection/src/main/java/com/njcn/gather/err/service/impl/PqErrSysServiceImpl.java b/detection/src/main/java/com/njcn/gather/err/service/impl/PqErrSysServiceImpl.java index 19bfb159..654f319a 100644 --- a/detection/src/main/java/com/njcn/gather/err/service/impl/PqErrSysServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/err/service/impl/PqErrSysServiceImpl.java @@ -67,6 +67,7 @@ public class PqErrSysServiceImpl extends ServiceImpl 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 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); diff --git a/detection/src/main/java/com/njcn/gather/icd/service/impl/PqIcdPathServiceImpl.java b/detection/src/main/java/com/njcn/gather/icd/service/impl/PqIcdPathServiceImpl.java index 9a7d77b9..8a7e72a3 100644 --- a/detection/src/main/java/com/njcn/gather/icd/service/impl/PqIcdPathServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/icd/service/impl/PqIcdPathServiceImpl.java @@ -47,6 +47,7 @@ public class PqIcdPathServiceImpl extends ServiceImpl 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 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(); diff --git a/detection/src/main/java/com/njcn/gather/script/service/impl/PqScriptServiceImpl.java b/detection/src/main/java/com/njcn/gather/script/service/impl/PqScriptServiceImpl.java index efea552a..e0131e49 100644 --- a/detection/src/main/java/com/njcn/gather/script/service/impl/PqScriptServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/script/service/impl/PqScriptServiceImpl.java @@ -61,6 +61,7 @@ public class PqScriptServiceImpl extends ServiceImpl 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 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); diff --git a/detection/src/main/java/com/njcn/gather/type/service/impl/DevTypeServiceImpl.java b/detection/src/main/java/com/njcn/gather/type/service/impl/DevTypeServiceImpl.java index 96d37ed3..b5370121 100644 --- a/detection/src/main/java/com/njcn/gather/type/service/impl/DevTypeServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/type/service/impl/DevTypeServiceImpl.java @@ -73,6 +73,7 @@ public class DevTypeServiceImpl extends ServiceImpl 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 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); diff --git a/storage/src/main/java/com/njcn/gather/storage/service/impl/AdHarmonicServiceImpl.java b/storage/src/main/java/com/njcn/gather/storage/service/impl/AdHarmonicServiceImpl.java index f008bc7d..67d40c0d 100644 --- a/storage/src/main/java/com/njcn/gather/storage/service/impl/AdHarmonicServiceImpl.java +++ b/storage/src/main/java/com/njcn/gather/storage/service/impl/AdHarmonicServiceImpl.java @@ -209,7 +209,6 @@ public class AdHarmonicServiceImpl extends ServiceImpl adHarmonicResultList = this.list(lambdaQueryWrapper); @@ -220,7 +219,6 @@ public class AdHarmonicServiceImpl extends ServiceImpl nonHarmonicResults = adNonHarmonicMapper.selectList(resultLambdaQueryWrapper); diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictDataServiceImpl.java b/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictDataServiceImpl.java index aa2f9ef5..8ed26dc0 100644 --- a/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictDataServiceImpl.java +++ b/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictDataServiceImpl.java @@ -77,6 +77,7 @@ public class DictDataServiceImpl extends ServiceImpl 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 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); diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictPqServiceImpl.java b/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictPqServiceImpl.java index 9b3e4649..77194d4c 100644 --- a/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictPqServiceImpl.java +++ b/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictPqServiceImpl.java @@ -58,6 +58,7 @@ public class DictPqServiceImpl extends ServiceImpl 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 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); diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictTreeServiceImpl.java b/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictTreeServiceImpl.java index d5961683..ab22971c 100644 --- a/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictTreeServiceImpl.java +++ b/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictTreeServiceImpl.java @@ -59,6 +59,7 @@ public class DictTreeServiceImpl extends ServiceImpl 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 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); diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictTypeServiceImpl.java b/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictTypeServiceImpl.java index 166429bc..c184f309 100644 --- a/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictTypeServiceImpl.java +++ b/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictTypeServiceImpl.java @@ -60,6 +60,7 @@ public class DictTypeServiceImpl extends ServiceImpl 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 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); diff --git a/user/src/main/java/com/njcn/gather/user/user/service/impl/SysFunctionServiceImpl.java b/user/src/main/java/com/njcn/gather/user/user/service/impl/SysFunctionServiceImpl.java index bb40a5de..89f37f92 100644 --- a/user/src/main/java/com/njcn/gather/user/user/service/impl/SysFunctionServiceImpl.java +++ b/user/src/main/java/com/njcn/gather/user/user/service/impl/SysFunctionServiceImpl.java @@ -48,6 +48,7 @@ public class SysFunctionServiceImpl extends ServiceImpl 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 impl @Override @Transactional public boolean updateRole(SysRoleParam.UpdateParam updateParam) { + updateParam.setName(updateParam.getName().trim()); checkRepeat(updateParam, true); //不能修改超级管理员角色 Integer count = this.lambdaQuery() diff --git a/user/src/main/java/com/njcn/gather/user/user/service/impl/SysUserServiceImpl.java b/user/src/main/java/com/njcn/gather/user/user/service/impl/SysUserServiceImpl.java index a9f399f1..e7a6da43 100644 --- a/user/src/main/java/com/njcn/gather/user/user/service/impl/SysUserServiceImpl.java +++ b/user/src/main/java/com/njcn/gather/user/user/service/impl/SysUserServiceImpl.java @@ -106,6 +106,8 @@ public class SysUserServiceImpl extends ServiceImpl 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 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);