Преглед на файлове

fix 网关下线后,子设备也下线

jay преди 10 месеца
родител
ревизия
64d0ab73f5
променени са 1 файла, в които са добавени 15 реда и са изтрити 4 реда
  1. 15 4
      iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/ThingServiceImpl.java

+ 15 - 4
iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/ThingServiceImpl.java

@@ -47,10 +47,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.stereotype.Service;
 
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-import java.util.UUID;
+import java.util.*;
 
 /**
  * @author sjg
@@ -108,6 +105,20 @@ public class ThingServiceImpl implements IThingService {
                     break;
                 case STATE_CHANGE:
                     deviceStateChange(device, (DeviceStateChange) action);
+                    //父设备ID不为空说明是子设备
+                    if (Objects.isNull(device.getParentId())) {
+                        //否则为父设备,同步透传子设备状态
+                        List<String> subDeviceIds = deviceInfoData.findSubDeviceIds(device.getDeviceId());
+                        for (String subDeviceId : subDeviceIds) {
+                            DeviceInfo subDevice = deviceInfoData.findByDeviceId(subDeviceId);
+                            Product product = productData.findByProductKey(subDevice.getProductKey());
+                            Boolean transparent = product.getTransparent();
+                            //透传设备父设备上线,子设备也上线。非透传设备父设备离线,子设备才离线
+                            if (transparent != null && transparent || ((DeviceStateChange) action).getState() != DeviceState.ONLINE) {
+                                deviceStateChange(subDevice, (DeviceStateChange)action);
+                            }
+                        }
+                    }
                     break;
                 case EVENT_REPORT:
                     EventReport eventReport = (EventReport) action;