Skip to content

Commit

Permalink
修复未激活设备无法获取标签信息
Browse files Browse the repository at this point in the history
  • Loading branch information
zhou-hao committed Jan 13, 2022
1 parent 1794e3d commit 888f776
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.jetlinks.core.Values;
import org.jetlinks.core.device.DeviceOperator;
import org.jetlinks.core.metadata.ConfigPropertyMetadata;
import org.jetlinks.core.metadata.DeviceMetadata;
import org.jetlinks.supports.official.JetLinksDeviceMetadataCodec;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import reactor.core.publisher.Mono;
Expand Down Expand Up @@ -127,9 +129,29 @@ public class DeviceDetail {
public DeviceDetail notActive() {

state = DeviceState.notActive;
initTags();
return this;
}

private DeviceMetadata decodeMetadata() {
if (StringUtils.isEmpty(metadata)) {
return null;
}
return JetLinksDeviceMetadataCodec.getInstance().doDecode(metadata);
}

private void initTags() {
DeviceMetadata metadata = decodeMetadata();
if (null != metadata) {
with(metadata
.getTags()
.stream()
.map(DeviceTagEntity::of)
.collect(Collectors.toList()));
}
}


public Mono<DeviceDetail> with(DeviceOperator operator, List<ConfigPropertyMetadata> configs) {
return Mono
.zip(
Expand All @@ -140,7 +162,7 @@ public Mono<DeviceDetail> with(DeviceOperator operator, List<ConfigPropertyMetad
//T3: 离线时间
operator.getOfflineTime().defaultIfEmpty(0L),
//T4: 物模型
operator.getMetadata(),
operator.getMetadata().switchIfEmpty(Mono.fromSupplier(this::decodeMetadata)),
//T5: 真实的配置信息
operator.getSelfConfigs(configs
.stream()
Expand Down

0 comments on commit 888f776

Please sign in to comment.