zhou-hao 5 lat temu
rodzic
commit
1fb8fd8763

+ 4 - 0
jetlinks-manager/device-manager/src/main/java/org/jetlinks/community/device/entity/DeviceTagEntity.java

@@ -57,4 +57,8 @@ public class DeviceTagEntity extends GenericEntity<String> {
         entity.setCreateTime(new Date());
         return entity;
     }
+
+    public static String createTagId(String deviceId,String key){
+        return deviceId.concat(":").concat(key);
+    }
 }

+ 10 - 0
jetlinks-manager/device-manager/src/main/java/org/jetlinks/community/device/response/DeviceDetail.java

@@ -106,6 +106,11 @@ public class DeviceDetail {
         this.tags = new ArrayList<>(map.values());
         this.tags.sort(Comparator.comparing(DeviceTagEntity::getCreateTime));
 
+        if (StringUtils.hasText(id)) {
+            for (DeviceTagEntity tag : getTags()) {
+                tag.setId(DeviceTagEntity.createTagId(id, tag.getKey()));
+            }
+        }
         return this;
     }
 
@@ -135,6 +140,7 @@ public class DeviceDetail {
             .ifPresent(this::setRegisterTime);
 
         setCreateTime(device.getCreateTime());
+        setOrgId(device.getOrgId());
 
         if (!CollectionUtils.isEmpty(device.getConfiguration())) {
             setConfiguration(device.getConfiguration());
@@ -143,6 +149,10 @@ public class DeviceDetail {
             setMetadata(device.getDeriveMetadata());
         }
 
+        for (DeviceTagEntity tag : getTags()) {
+            tag.setId(DeviceTagEntity.createTagId(id, tag.getKey()));
+        }
+
         return this;
     }
 

+ 1 - 1
jetlinks-manager/device-manager/src/main/java/org/jetlinks/community/device/web/DeviceInstanceController.java

@@ -282,7 +282,7 @@ public class DeviceInstanceController implements
                                                @RequestBody Flux<DeviceTagEntity> tags) {
         return tags
             .doOnNext(tag -> {
-                tag.setId(deviceId.concat(":").concat(tag.getKey()));
+                tag.setId(DeviceTagEntity.createTagId(deviceId,tag.getKey()));
                 tag.setDeviceId(deviceId);
                 tag.tryValidate();
             })