|
@@ -4,6 +4,7 @@ import org.hswebframework.ezorm.rdb.mapping.ReactiveRepository;
|
|
import org.jetlinks.core.device.*;
|
|
import org.jetlinks.core.device.*;
|
|
import org.jetlinks.community.device.entity.DeviceInstanceEntity;
|
|
import org.jetlinks.community.device.entity.DeviceInstanceEntity;
|
|
import org.jetlinks.community.device.entity.DeviceProductEntity;
|
|
import org.jetlinks.community.device.entity.DeviceProductEntity;
|
|
|
|
+import org.springframework.util.StringUtils;
|
|
import reactor.core.publisher.Mono;
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
public class AutoDiscoverDeviceRegistry implements DeviceRegistry {
|
|
public class AutoDiscoverDeviceRegistry implements DeviceRegistry {
|
|
@@ -24,15 +25,23 @@ public class AutoDiscoverDeviceRegistry implements DeviceRegistry {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Mono<DeviceOperator> getDevice(String deviceId) {
|
|
public Mono<DeviceOperator> getDevice(String deviceId) {
|
|
- return parent
|
|
|
|
|
|
+ if (StringUtils.isEmpty(deviceId)) {
|
|
|
|
+ return Mono.empty();
|
|
|
|
+ }
|
|
|
|
+ return Mono.defer(() -> parent
|
|
.getDevice(deviceId)
|
|
.getDevice(deviceId)
|
|
.switchIfEmpty(Mono.defer(() -> deviceRepository
|
|
.switchIfEmpty(Mono.defer(() -> deviceRepository
|
|
.findById(deviceId)
|
|
.findById(deviceId)
|
|
- .flatMap(instance -> parent.register(instance.toDeviceInfo()))));
|
|
|
|
|
|
+ .flatMap(instance -> parent.register(instance.toDeviceInfo())))
|
|
|
|
+ )
|
|
|
|
+ );
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Mono<DeviceProductOperator> getProduct(String productId) {
|
|
public Mono<DeviceProductOperator> getProduct(String productId) {
|
|
|
|
+ if (StringUtils.isEmpty(productId)) {
|
|
|
|
+ return Mono.empty();
|
|
|
|
+ }
|
|
return parent
|
|
return parent
|
|
.getProduct(productId)
|
|
.getProduct(productId)
|
|
.switchIfEmpty(Mono.defer(() -> productRepository
|
|
.switchIfEmpty(Mono.defer(() -> productRepository
|