瀏覽代碼

心跳检测

liuf 12 小時之前
父節點
當前提交
c0dd3d52a6

+ 1 - 1
src/main/java/com/tmzn/devicelinkykc/message/DeviceMsgHandle.java

@@ -123,7 +123,7 @@ public class DeviceMsgHandle {
             e.printStackTrace();
             return;
         }
-        logger.info("{},msg>>>" + msg, imei);
+        //logger.info("{},msg>>>" + msg, imei);
         //设备状态更新,true:没有type不是设备上送类型不往云快充处理 false:需要根据设备消息类型往下处理是不是需要上报云快充
 
 

+ 13 - 24
src/main/java/com/tmzn/devicelinkykc/taskQueue/runner/MsgHeartRunner.java

@@ -9,9 +9,11 @@ import com.tmzn.devicelinkykc.entity.DeviceStatus;
 import com.tmzn.devicelinkykc.frameMsg.frameType.HeartFrameSend;
 import com.tmzn.devicelinkykc.frameMsg.frameType.LoginFrame;
 import com.tmzn.devicelinkykc.redis.RedisCache;
+import com.tmzn.devicelinkykc.service.DeviceControlerService;
 import com.tmzn.devicelinkykc.service.DeviceService;
 import com.tmzn.devicelinkykc.socket.DeviceConnectionMsg;
 import com.tmzn.devicelinkykc.socket.SocketHandle;
+import com.tmzn.devicelinkykc.transdata.entity.DeviceParam;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
@@ -42,6 +44,8 @@ public class MsgHeartRunner {
     @Autowired
     private SocketHandle socketHandle;
 
+    @Autowired
+    private DeviceControlerService deviceControlerService;
 
 
     // 使用AtomicBoolean替代基本的boolean
@@ -106,6 +110,14 @@ public class MsgHeartRunner {
            // log.info("not found ones:{}",devicePileCode);
             return;
         }
+
+        //检查多久没有心跳时间了
+        if (oneDs.getOnlineStatus() == DeviceOnlineStatus.ONLINE && (System.currentTimeMillis() - heartTime) > 120 * 1000L) {
+            log.info("heart_over..{},{}" ,devicePileCode, (System.currentTimeMillis() - heartTime));
+            socketHandle.removeDeviceConnection(devicePileCode);
+            deviceControlerService.sendImeiDetail(oneDs.getDeviceImei());
+            return;
+        }
         boolean res = heartFrameSend.heartSend(deviceConnectionMsg, oneDs);
         if(res){
            return;
@@ -124,30 +136,7 @@ public class MsgHeartRunner {
 //            }
 //        }
 
-        if (oneDs.getOnlineStatus() == DeviceOnlineStatus.ONLINE && (System.currentTimeMillis() - heartTime) > 50 * 1000L) {
-            log.info("pileCode:" + devicePileCode + " loging... ..." + (System.currentTimeMillis() - heartTime));
-            int a = 0;
-            if (redisCache.hasKey(RedisConstant.DEVICE_LOGIN_YKC + devicePileCode)) {
-                //如果登录次数30秒内登三次就算断开
-                a = redisCache.getCacheObject(RedisConstant.DEVICE_LOGIN_YKC + devicePileCode);
-                if (a > 3) {
-                    log.info("30s no heart {} reset",devicePileCode);
-                    socketHandle.removeDeviceConnection(devicePileCode);
-                } else {
-//                    QueryWrapper<Device> deviceQueryWrapper = new QueryWrapper<>();
-//                    deviceQueryWrapper.eq("pile_code", devicePileCode).eq("disabled", DeviceOnlineStatus.NORMAL);
-//                    Device device = deviceService.getOne(deviceQueryWrapper);
-//                    if(device!=null){
-////                        loginFrame.loginMsgSend(deviceConnectionMsg, device);
-//                        socketHandle.removeDeviceConnection(devicePileCode);
-//                    }
-                }
-                a++;
-                redisCache.setCacheObject(RedisConstant.DEVICE_LOGIN_YKC + devicePileCode, a,32 * 1000, TimeUnit.MILLISECONDS);
-            } else {
-                redisCache.setCacheObject(RedisConstant.DEVICE_LOGIN_YKC + devicePileCode, a, 32 * 1000, TimeUnit.MILLISECONDS);
-            }
-        }
+
 
     }