TRX 1 год назад
Родитель
Сommit
23c9374fa7

+ 9 - 4
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/device/DevicePingInfoService.java

@@ -112,9 +112,6 @@ public class DevicePingInfoService extends SuperService {
             devicePingInfo.setTimeStr(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
             devicePingInfoDao.save(devicePingInfo);
 
-            // 通知设备
-            deviceSyncFullCardService.noticeSyncDeviceOnlineTimeChange(deviceId);
-
             // 设备在线状态 检查
             updateDeviceOnLineCheck(deviceInfo.getDeviceId(), deviceInfo.getDeviceName());
         } else {
@@ -154,6 +151,11 @@ public class DevicePingInfoService extends SuperService {
         redisService.setValueSECONDS(expiredKey, deviceName, expirePeriod);
     }
 
+    /**
+     * redis key 过期
+     *
+     * @param expiredKey
+     */
     public void redisExpire(String expiredKey) {
         if (StringUtils.isNotEmpty(expiredKey) && expiredKey.startsWith(CommonTTLTimeConfig.OnLineExpiredKey)) {
             // 设备在线状态
@@ -176,7 +178,9 @@ public class DevicePingInfoService extends SuperService {
         long expirePeriod = CommonTTLTimeConfig.maxDeviceRedisOnLineTime;
         if (ObjectUtils.isNotEmpty(entity)) {
             DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(entity.getDeviceId());
+            // 检查设备在线状态
             deviceCheckOnLineState(deviceInfo);
+
             if (ObjectUtils.isNotEmpty(deviceInfo) && deviceInfo.getHbInterval() != null) {
                 expirePeriod = deviceInfo.getHbInterval();
             }
@@ -208,7 +212,7 @@ public class DevicePingInfoService extends SuperService {
         if (_list != null) {
             long defaultTime = CommonTTLTimeConfig.maxUnPingOnLineTime;
             if (deviceInfo.getHbInterval() != null) {
-                defaultTime = deviceInfo.getHbInterval() * 1000L + 1000;
+                defaultTime = deviceInfo.getHbInterval() * 1000L + 3000;
             }
             Long firstTime = null;
             long avgTime = 0;
@@ -274,6 +278,7 @@ public class DevicePingInfoService extends SuperService {
 
         // 通知业务平台
         deviceSyncFullCardService.noticeSyncDeviceOnlineStateChange(deviceId);
+
         deviceOnLineRecordService.addOnLineRecord(deviceInfo, onLineState);
     }
 

+ 1 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/device/GateWayManagerService.java

@@ -192,7 +192,7 @@ public class GateWayManagerService extends SuperService {
 
         RegistType registType = RegistType.Gateway;
         DeviceInfo gateWayInfo;
-        if (StringUtils.isNotEmpty(param.getGateWayId())) {
+        if (iotTemplate.getDeviceCategory() != DeviceCategory.GW && StringUtils.isNotEmpty(param.getGateWayId())) {
             gateWayInfo = deviceInfoDao.findTopByDeviceId(param.getGateWayId());
             ResultContent resultContent = deviceInfoService.deviceCanUse(gateWayInfo, param.getGateWayId());
             if (resultContent.isFailed()) {

+ 2 - 28
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/sync/DeviceSyncFullCardService.java

@@ -9,12 +9,12 @@ import com.zhongshu.iot.server.core.dao.mqtt.DeviceInfoDao;
 import com.zhongshu.iot.server.core.dao.mqtt.GateWay2DeviceDao;
 import com.zhongshu.iot.server.core.domain.iot.device.DeviceInfo;
 import com.zhongshu.iot.server.core.domain.iot.device.GateWay2Device;
-import com.zhongshu.iot.server.core.event.DeviceOnLineTimeChangeEvent;
 import com.zhongshu.iot.server.core.event.DeviceStateChangeEvent;
 import com.zhongshu.iot.server.core.event.DeviceSyncEvent;
 import com.zhongshu.iot.server.core.httpRequest.ApiRequestService;
 import com.zhongshu.iot.server.core.httpRequest.conf.FullCardAPIConfig;
 import com.zhongshu.iot.server.core.service.base.SuperService;
+import com.zhongshu.iot.server.core.util.CommonUtil;
 import com.zhongshu.iot.server.core.util.bean.BeanUtils;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
@@ -174,37 +174,11 @@ public class DeviceSyncFullCardService extends SuperService {
             param.setOnLineState(deviceInfo.getOnLineState().name());
             param.setProjectInfoCode(deviceInfo.getProjectInfoCode());
             param.setLastOfflineTime(deviceInfo.getLastOfflineTime());
-
             param.setState(deviceInfo.getState());
+            param.setRandomId(CommonUtil.UUID());
             APIResponseModel api = apiRequestService.sendFullCardAPI(FullCardAPIConfig.syncDeviceOnLineState, param);
             log.info("同步设备在线情况:{} {}", api.isSuccess(), api.getMsg());
         }
     }
 
-    public ResultContent noticeSyncDeviceOnlineTimeChange(String deviceId) {
-        if (ObjectUtils.isNotEmpty(deviceId)) {
-            DeviceOnLineTimeChangeEvent event = new DeviceOnLineTimeChangeEvent(this, deviceId);
-            applicationContext.publishEvent(event);
-        }
-        return ResultContent.buildSuccess();
-    }
-
-    @EventListener(classes = DeviceOnLineTimeChangeEvent.class)
-    @Async
-    @SneakyThrows
-    public void syncDeviceOnlineTimeChange(DeviceOnLineTimeChangeEvent event) {
-        String deviceId = event.getDeviceId();
-        log.info("event syncDeviceOnlineTimeChange: {}", deviceId);
-        DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
-        if (ObjectUtils.isNotEmpty(deviceInfo)) {
-            DevicePingInfoParam param = new DevicePingInfoParam();
-            param.setDeviceId(deviceInfo.getDeviceId());
-            param.setLastOnlineTime(deviceInfo.getLastOnlineTime());
-            param.setOnLineState(deviceInfo.getOnLineState().name());
-            param.setProjectInfoCode(deviceInfo.getProjectInfoCode());
-            APIResponseModel api = apiRequestService.sendFullCardAPI(FullCardAPIConfig.syncDeviceOnLineState, param);
-            log.info("同步设备在线时间: {} {}", api.isSuccess(), api.getMsg());
-        }
-    }
-
 }