|
@@ -69,24 +69,36 @@ public class MsgHeartRunner {
|
|
|
String portStatusCacheKey = portId==1?RedisConstant.ONLINE_DEVICE_ONE:RedisConstant.ONLINE_DEVICE_TWO;
|
|
String portStatusCacheKey = portId==1?RedisConstant.ONLINE_DEVICE_ONE:RedisConstant.ONLINE_DEVICE_TWO;
|
|
|
//1:当上一次的心跳和本次的心跳相差大于30秒证明已经3次没收到心跳回复了,进行重新登录
|
|
//1:当上一次的心跳和本次的心跳相差大于30秒证明已经3次没收到心跳回复了,进行重新登录
|
|
|
//2:设备第一次上线时未触发过登录,设备连接集合中初始话的心跳时间还是0,符合该判断,进行登录
|
|
//2:设备第一次上线时未触发过登录,设备连接集合中初始话的心跳时间还是0,符合该判断,进行登录
|
|
|
- DeviceStatus oneDs = redisCache.getCacheMapValue(portStatusCacheKey, devicePileCode);
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
if (deviceConnectionMsg.getLoginStatus()== Constant.DEVICE_NOT_LOGIN_STATUS) {
|
|
if (deviceConnectionMsg.getLoginStatus()== Constant.DEVICE_NOT_LOGIN_STATUS) {
|
|
|
- if (oneDs != null && oneDs.getOnlineStatus() == DeviceOnlineStatus.ONLINE && (System.currentTimeMillis() - heartTime) > 50 * 1000L) {
|
|
|
|
|
- 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);
|
|
|
|
|
- }
|
|
|
|
|
- log.info("heartTaskAsyncPool-1>not longin and heart normal>>" + devicePileCode);
|
|
|
|
|
|
|
+ //刚登录5秒内不发送心跳 避免重复发送LoginMsg
|
|
|
|
|
+ if ((System.currentTimeMillis() - deviceConnectionMsg.getLoginTime()) < 8 * 1000) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ DeviceStatus oneDs = redisCache.getCacheMapValue(portStatusCacheKey, devicePileCode);
|
|
|
if(oneDs==null){
|
|
if(oneDs==null){
|
|
|
|
|
+ log.info("not found ones:{}",devicePileCode);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
+ boolean res = heartFrameSend.heartSend(deviceConnectionMsg, oneDs);
|
|
|
|
|
+ if(res){
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+// if (deviceConnectionMsg.getLoginStatus()== Constant.DEVICE_NOT_LOGIN_STATUS) {
|
|
|
|
|
+// if (oneDs != null && oneDs.getOnlineStatus() == DeviceOnlineStatus.ONLINE && (System.currentTimeMillis() - heartTime) > 50 * 1000L) {
|
|
|
|
|
+// 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);
|
|
|
|
|
+// }
|
|
|
|
|
+// log.info("heartTaskAsyncPool-1>not longin and heart normal>>" + devicePileCode);
|
|
|
|
|
+// return;
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
if (oneDs.getOnlineStatus() == DeviceOnlineStatus.ONLINE && (System.currentTimeMillis() - heartTime) > 50 * 1000L) {
|
|
if (oneDs.getOnlineStatus() == DeviceOnlineStatus.ONLINE && (System.currentTimeMillis() - heartTime) > 50 * 1000L) {
|
|
|
log.info("pileCode:" + devicePileCode + " loging... ..." + (System.currentTimeMillis() - heartTime));
|
|
log.info("pileCode:" + devicePileCode + " loging... ..." + (System.currentTimeMillis() - heartTime));
|
|
@@ -95,24 +107,22 @@ public class MsgHeartRunner {
|
|
|
//如果登录次数30秒内登三次就算断开
|
|
//如果登录次数30秒内登三次就算断开
|
|
|
a = redisCache.getCacheObject(RedisConstant.DEVICE_LOGIN_YKC + devicePileCode);
|
|
a = redisCache.getCacheObject(RedisConstant.DEVICE_LOGIN_YKC + devicePileCode);
|
|
|
if (a > 3) {
|
|
if (a > 3) {
|
|
|
|
|
+ log.info("30s no heart {} reset",devicePileCode);
|
|
|
socketHandle.removeDeviceConnection(devicePileCode);
|
|
socketHandle.removeDeviceConnection(devicePileCode);
|
|
|
} else {
|
|
} 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);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// 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++;
|
|
a++;
|
|
|
redisCache.setCacheObject(RedisConstant.DEVICE_LOGIN_YKC + devicePileCode, a,32 * 1000, TimeUnit.MILLISECONDS);
|
|
redisCache.setCacheObject(RedisConstant.DEVICE_LOGIN_YKC + devicePileCode, a,32 * 1000, TimeUnit.MILLISECONDS);
|
|
|
} else {
|
|
} else {
|
|
|
redisCache.setCacheObject(RedisConstant.DEVICE_LOGIN_YKC + devicePileCode, a, 32 * 1000, TimeUnit.MILLISECONDS);
|
|
redisCache.setCacheObject(RedisConstant.DEVICE_LOGIN_YKC + devicePileCode, a, 32 * 1000, TimeUnit.MILLISECONDS);
|
|
|
}
|
|
}
|
|
|
- }else {
|
|
|
|
|
- //存在设备在线状态的,上送心跳
|
|
|
|
|
- // log.info("heartSend-1>>>"+devicePileCode);
|
|
|
|
|
- heartFrameSend.heartSend(deviceConnectionMsg, oneDs);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|