|
@@ -11,10 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
-import java.util.Collection;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Optional;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
/**
|
|
@@ -78,60 +75,60 @@ public class DeviceRedisManagerServiceImpl implements DeviceManagerService {
|
|
|
installParam.setMountPlain(deviceMap.get("mountPlain").toString());
|
|
|
}
|
|
|
if (deviceMap.get("isCeiling") != null) {
|
|
|
- installParam.setIsCeiling(Integer.parseInt(deviceMap.get("isCeiling").toString()));
|
|
|
+ installParam.setIsCeiling((int) deviceMap.get("isCeiling"));
|
|
|
}
|
|
|
if (deviceMap.get("height") != null) {
|
|
|
- installParam.setHeight(Float.parseFloat(deviceMap.get("height").toString()));
|
|
|
+ installParam.setHeight((float) deviceMap.get("height"));
|
|
|
}
|
|
|
Device.TrackingRegion trackingRegion = new Device.TrackingRegion();
|
|
|
if (deviceMap.get("startX") != null) {
|
|
|
- trackingRegion.setStartX(Integer.parseInt(deviceMap.get("startX").toString()));
|
|
|
+ trackingRegion.setStartX((int) deviceMap.get("startX"));
|
|
|
}
|
|
|
if (deviceMap.get("startY") != null) {
|
|
|
- trackingRegion.setStartY(Integer.parseInt(deviceMap.get("startY").toString()));
|
|
|
+ trackingRegion.setStartY((int) deviceMap.get("startY"));
|
|
|
}
|
|
|
if (deviceMap.get("startZ") != null) {
|
|
|
- trackingRegion.setStartZ(Integer.parseInt(deviceMap.get("startZ").toString()));
|
|
|
+ trackingRegion.setStartZ((int) deviceMap.get("startZ"));
|
|
|
}
|
|
|
if (deviceMap.get("stopX") != null) {
|
|
|
- trackingRegion.setStopX(Integer.parseInt(deviceMap.get("stopX").toString()));
|
|
|
+ trackingRegion.setStopX((int) deviceMap.get("stopX"));
|
|
|
}
|
|
|
if (deviceMap.get("stopY") != null) {
|
|
|
- trackingRegion.setStopY(Integer.parseInt(deviceMap.get("stopY").toString()));
|
|
|
+ trackingRegion.setStopY((int) deviceMap.get("stopY"));
|
|
|
}
|
|
|
if (deviceMap.get("stopZ") != null) {
|
|
|
- trackingRegion.setStopZ(Integer.parseInt(deviceMap.get("stopZ").toString()));
|
|
|
+ trackingRegion.setStopZ((int) deviceMap.get("stopZ"));
|
|
|
}
|
|
|
installParam.setTrackingRegion(trackingRegion);
|
|
|
device.setInstallParam(installParam);
|
|
|
|
|
|
if (deviceMap.get("online") != null) {
|
|
|
- device.setOnline(Integer.parseInt(deviceMap.get("online").toString()));
|
|
|
+ device.setOnline((int) deviceMap.get("online"));
|
|
|
}
|
|
|
if (deviceMap.get("keepAliveTime") != null) {
|
|
|
- device.setKeepaliveTime(Long.parseLong(deviceMap.get("keepAliveTime").toString()));
|
|
|
+ device.setKeepaliveTime((long) deviceMap.get("keepAliveTime"));
|
|
|
}
|
|
|
if (deviceMap.get("expireTime") != null) {
|
|
|
- device.setKeepaliveTime(Long.parseLong(deviceMap.get("expireTime").toString()));
|
|
|
+ device.setKeepaliveTime((long) deviceMap.get("expireTime"));
|
|
|
}
|
|
|
|
|
|
if (deviceMap.get("lastReportFallTime") != null) {
|
|
|
- device.setLastReportFallTime(Long.parseLong(deviceMap.get("lastReportFallTime").toString()));
|
|
|
+ device.setLastReportFallTime((long) deviceMap.get("lastReportFallTime"));
|
|
|
}
|
|
|
if (deviceMap.get("alarmInterval") != null) {
|
|
|
- device.setAlarmInterval(Long.parseLong(deviceMap.get("alarmInterval").toString()));
|
|
|
+ device.setAlarmInterval((long) deviceMap.get("alarmInterval"));
|
|
|
}
|
|
|
if (deviceMap.get("alarmAck") != null) {
|
|
|
- device.setAlarmAck(Boolean.parseBoolean(deviceMap.get("alarmAck").toString()));
|
|
|
+ device.setAlarmAck((boolean) deviceMap.get("alarmAck"));
|
|
|
}
|
|
|
if (deviceMap.get("lastAlarmAckTime") != null) {
|
|
|
- device.setLastAlarmAckTime(Long.parseLong(deviceMap.get("lastAlarmAckTime").toString()));
|
|
|
+ device.setLastAlarmAckTime((long) deviceMap.get("lastAlarmAckTime"));
|
|
|
}
|
|
|
if (deviceMap.get("alarmAckInterval") != null) {
|
|
|
- device.setAlarmAckInterval(Long.parseLong(deviceMap.get("alarmAckInterval").toString()));
|
|
|
+ device.setAlarmAckInterval((long) deviceMap.get("alarmAckInterval"));
|
|
|
}
|
|
|
if (deviceMap.get("falling") != null) {
|
|
|
- device.setFalling(Integer.valueOf(deviceMap.get("falling").toString()));
|
|
|
+ device.setFalling((int) deviceMap.get("falling"));
|
|
|
}
|
|
|
|
|
|
return Optional.ofNullable(device);
|
|
@@ -238,18 +235,32 @@ public class DeviceRedisManagerServiceImpl implements DeviceManagerService {
|
|
|
|
|
|
@Override
|
|
|
public void checkDeviceKeepAlive(long currentTimeMillis, long timeoutMillis) {
|
|
|
- deviceCache.forEach((devId, device) -> {
|
|
|
- // 只检查在线设备
|
|
|
- if (device.getOnline() != null && device.getOnline() == 1) {
|
|
|
- Long lastKeepAliveTime = device.getKeepaliveTime();
|
|
|
-
|
|
|
- // 如果设备无保活时间或超时,则设置为离线
|
|
|
- if (lastKeepAliveTime == null || (currentTimeMillis - lastKeepAliveTime) > timeoutMillis) {
|
|
|
- log.info("Device keepalive timeout: {}, last keepalive: {}", devId, lastKeepAliveTime);
|
|
|
- deviceStatusService.handleDeviceOffline(device);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
+
|
|
|
+ Set<Object> devIdSet = redisService.sMembers(RedisCacheConstant.KEY_DEVICE_ID);
|
|
|
+ if (CollectionUtils.isEmpty(devIdSet)) {
|
|
|
+ log.info("check device keepalive , no devices in cache");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+// for (Object devIdObj : devIdSet) {
|
|
|
+// Object onlineObj = redisService.hGet(RedisCacheConstant.KEY_DEVICE_pre + devIdObj, "online");
|
|
|
+// if (onlineObj != null && Integer.parseInt(onlineObj.toString()) == 1) {
|
|
|
+// Long lastKeepAliveTime = redisService.hGet(RedisCacheConstant.KEY_DEVICE_pre + devIdObj, "keepAliveTime");
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// deviceCache.forEach((devId, device) -> {
|
|
|
+// // 只检查在线设备
|
|
|
+// if (device.getOnline() != null && device.getOnline() == 1) {
|
|
|
+// Long lastKeepAliveTime = device.getKeepaliveTime();
|
|
|
+//
|
|
|
+// // 如果设备无保活时间或超时,则设置为离线
|
|
|
+// if (lastKeepAliveTime == null || (currentTimeMillis - lastKeepAliveTime) > timeoutMillis) {
|
|
|
+// log.info("Device keepalive timeout: {}, last keepalive: {}", devId, lastKeepAliveTime);
|
|
|
+// deviceStatusService.handleDeviceOffline(device);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// });
|
|
|
}
|
|
|
|
|
|
/**
|