1212import org .jetlinks .core .Values ;
1313import org .jetlinks .core .device .DeviceOperator ;
1414import org .jetlinks .core .metadata .ConfigPropertyMetadata ;
15+ import org .jetlinks .core .metadata .DeviceMetadata ;
16+ import org .jetlinks .supports .official .JetLinksDeviceMetadataCodec ;
1517import org .springframework .util .CollectionUtils ;
1618import org .springframework .util .StringUtils ;
1719import reactor .core .publisher .Mono ;
@@ -127,9 +129,29 @@ public class DeviceDetail {
127129 public DeviceDetail notActive () {
128130
129131 state = DeviceState .notActive ;
132+ initTags ();
130133 return this ;
131134 }
132135
136+ private DeviceMetadata decodeMetadata () {
137+ if (StringUtils .isEmpty (metadata )) {
138+ return null ;
139+ }
140+ return JetLinksDeviceMetadataCodec .getInstance ().doDecode (metadata );
141+ }
142+
143+ private void initTags () {
144+ DeviceMetadata metadata = decodeMetadata ();
145+ if (null != metadata ) {
146+ with (metadata
147+ .getTags ()
148+ .stream ()
149+ .map (DeviceTagEntity ::of )
150+ .collect (Collectors .toList ()));
151+ }
152+ }
153+
154+
133155 public Mono <DeviceDetail > with (DeviceOperator operator , List <ConfigPropertyMetadata > configs ) {
134156 return Mono
135157 .zip (
@@ -140,7 +162,7 @@ public Mono<DeviceDetail> with(DeviceOperator operator, List<ConfigPropertyMetad
140162 //T3: 离线时间
141163 operator .getOfflineTime ().defaultIfEmpty (0L ),
142164 //T4: 物模型
143- operator .getMetadata (),
165+ operator .getMetadata (). switchIfEmpty ( Mono . fromSupplier ( this :: decodeMetadata )) ,
144166 //T5: 真实的配置信息
145167 operator .getSelfConfigs (configs
146168 .stream ()
0 commit comments