Эх сурвалжийг харах

更新! 取消GateWay信息

TRX 1 жил өмнө
parent
commit
977afd50ff

+ 30 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/device/DeviceInfoService.java

@@ -380,6 +380,36 @@ public class DeviceInfoService {
         return ResultContent.buildSuccess(model);
     }
 
+    /**
+     * 判断设备是否可用(本身)
+     *
+     * @param deviceId
+     * @return
+     */
+    public ResultContent deviceCanUse(String deviceId) {
+        DeviceInfo deviceInfo = null;
+        if (StringUtils.isNotEmpty(deviceId)) {
+            deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
+        }
+        return deviceCanUse(deviceInfo);
+    }
+
+    /**
+     * 判断设备是否可用(本身)
+     *
+     * @param deviceInfo
+     * @return
+     */
+    public ResultContent deviceCanUse(DeviceInfo deviceInfo) {
+        if (ObjectUtils.isEmpty(deviceInfo)) {
+            return ResultContent.buildFail("设备未找到");
+        }
+        if (deviceInfo.getState() != DeviceState.Enable) {
+            return ResultContent.buildFail(String.format("设备状态不可用:%s", deviceInfo.getState().getRemark()));
+        }
+        return ResultContent.buildSuccess();
+    }
+
     public DeviceInfoModel toModel(String deviceId) {
         DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
         return toModel(deviceInfo);

+ 13 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iotPlatform/impl/OnLineTopic.java

@@ -6,11 +6,13 @@ import com.github.microservice.models.onLine.DeviceOnLineResult;
 import com.github.microservice.net.ResultContent;
 import com.zhongshu.iot.server.core.domain.ExecuteAnnotationService;
 import com.zhongshu.iot.server.core.domain.ExecuteAnnotationServiceMethod;
+import com.zhongshu.iot.server.core.service.device.DeviceInfoService;
 import com.zhongshu.iot.server.core.service.iotPlatform.PlatformTopic;
 import com.zhongshu.iot.server.core.util.DateUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 /**
@@ -22,6 +24,9 @@ import org.springframework.stereotype.Component;
 @Slf4j
 public class OnLineTopic implements PlatformTopic {
 
+    @Autowired
+    private DeviceInfoService deviceInfoService;
+
     @Override
     public String topic() {
         return "/platform/%s/online";
@@ -41,6 +46,14 @@ public class OnLineTopic implements PlatformTopic {
             result.setSuccess();
             result.setDeviceId(param.getDeviceId());
             result.setGateWayId(param.getGateWayId());
+
+            // 验证设备是否可用
+            ResultContent resultContent = deviceInfoService.deviceCanUse(param.getDeviceId());
+            if (resultContent.isFailed()) {
+                result.setFailed(resultContent.getMsg());
+                return ResultContent.buildSuccess(result);
+            }
+            result.setSuccess();
             result.setTime(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
             result.setInfo(param.getInfo());
         }