|
|
@@ -184,8 +184,34 @@ public class DevicePingInfoService extends SuperService {
|
|
|
if (ObjectUtils.isNotEmpty(list)) {
|
|
|
long time = System.currentTimeMillis();
|
|
|
list.parallelStream().forEach(gateWayInfo -> {
|
|
|
- OnLineState onLineState = OnLineState.OnLine;
|
|
|
List<DevicePingInfo> _list = devicePingInfoDao.findTop5ByGateWayIdAndPingTypeOrderByCreateTimeDesc(gateWayInfo.getGateWayId(), DeviceType.GateWay.name());
|
|
|
+ // 默认离线
|
|
|
+ OnLineState onLineState = OnLineState.OffLine;
|
|
|
+ if (_list != null) {
|
|
|
+ Long firstTime = null;
|
|
|
+ long avgTime = 0;
|
|
|
+ if (_list.size() == 1) {
|
|
|
+ firstTime = _list.get(0).getCreateTime();
|
|
|
+ avgTime = maxPingTime;
|
|
|
+ } else if (_list.size() > 2) {
|
|
|
+ firstTime = _list.get(0).getCreateTime();
|
|
|
+ Long lastTime = _list.get(_list.size() - 1).getCreateTime();
|
|
|
+ // 2 次心跳间隔时间
|
|
|
+ avgTime = ((firstTime - lastTime) / (_list.size() - 1)) * 2;
|
|
|
+ if (avgTime > maxPingTime) {
|
|
|
+ avgTime = maxPingTime;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (firstTime != null) {
|
|
|
+ // 根据ping数据判断是否在线
|
|
|
+ if ((time - firstTime) > avgTime) {
|
|
|
+ onLineState = OnLineState.OffLine;
|
|
|
+ } else {
|
|
|
+ onLineState = OnLineState.OnLine;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if (_list != null && _list.size() > 2) {
|
|
|
Long firstTime = _list.get(0).getCreateTime();
|
|
|
Long lastTime = _list.get(_list.size() - 1).getCreateTime();
|