TRX 1 ano atrás
pai
commit
25f9de1905

+ 1 - 1
src/main/java/com/zswl/dataservice/service/artemis/OperationMessageService.java

@@ -228,7 +228,7 @@ public class OperationMessageService {
                 jsonObject.put("event", event);
             }
             // 是否是测试
-            boolean isTest = true;
+            boolean isTest = false;
             // ping不执行
             if (isTest && event.equals("ping")) {
                 return;

+ 6 - 4
src/main/java/com/zswl/dataservice/service/mqtt/DevicePingInfoService.java

@@ -134,13 +134,15 @@ public class DevicePingInfoService extends SuperService {
      * 检查设备的状态
      */
     public void checkDeviceState() {
-//        log.info("checkDeviceState: {}", DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
+        log.info("checkDeviceState: {}", DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
         List<DeviceInfo> list = deviceInfoDao.findAll();
         if (ObjectUtils.isNotEmpty(list)) {
             long time = System.currentTimeMillis();
             list.parallelStream().forEach(deviceInfo -> {
-                OnLineState onLineState = OnLineState.OnLine;
-                List<DevicePingInfo> _list = devicePingInfoDao.findTop5ByDeviceIdOrderByCreateTimeDesc(deviceInfo.getDeviceId());
+                // 默认离线
+                OnLineState onLineState = OnLineState.OffLine;
+                List<DevicePingInfo> _list = devicePingInfoDao.findTop5ByDeviceIdOrderByCreateTimeDesc(
+                        deviceInfo.getDeviceId());
                 if (_list != null && _list.size() > 2) {
                     Long firstTime = _list.get(0).getCreateTime();
                     Long lastTime = _list.get(_list.size() - 1).getCreateTime();
@@ -154,7 +156,7 @@ public class DevicePingInfoService extends SuperService {
                         onLineState = OnLineState.OffLine;
                     }
                 }
-
+                log.info("{} {}", deviceInfo.getDeviceId(), onLineState);
                 if (onLineState != deviceInfo.getOnLineState()) {
                     log.info("设备在线状态改变:{} {}", deviceInfo.getDeviceName(), onLineState);
                     Map<String, Object> standardData = new HashMap<String, Object>();

+ 2 - 3
src/main/java/com/zswl/dataservice/work/CheckDeviceStateWork.java → src/main/java/com/zswl/dataservice/timers/CheckDeviceStateWork.java

@@ -1,7 +1,6 @@
-package com.zswl.dataservice.work;
+package com.zswl.dataservice.timers;
 
 import com.zswl.dataservice.service.mqtt.DevicePingInfoService;
-import com.zswl.dataservice.service.mqtt.GateWayInfoService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.EnableScheduling;
@@ -22,7 +21,7 @@ public class CheckDeviceStateWork {
     @Autowired
     private DevicePingInfoService devicePingInfoService;
 
-    @Scheduled(fixedRate = 1000 * 10)
+    @Scheduled(fixedRate = 1000 * 15)
     public void checkDeviceState() {
         devicePingInfoService.checkDeviceState();
         devicePingInfoService.checkGateWayState();