瀏覽代碼

增加重置物模型接口

zhou-hao 4 年之前
父節點
當前提交
72ebae0a9a

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

@@ -744,20 +744,33 @@ public class DeviceInstanceController implements
     @Operation(summary = "更新物模型")
     public Mono<Void> updateMetadata(@PathVariable String id,
                                      @RequestBody Mono<String> metadata) {
-
-        return Mono
-            .zip(
-                registry.getDevice(id),
-                metadata
-            )
-            .flatMap(tp2 -> service
+        return metadata
+            .flatMap(metadata_ -> service
                 .createUpdate()
-                .set(DeviceInstanceEntity::getDeriveMetadata, tp2.getT2())
+                .set(DeviceInstanceEntity::getDeriveMetadata, metadata_)
                 .where(DeviceInstanceEntity::getId, id)
                 .execute()
-                .then(tp2.getT1().updateMetadata(tp2.getT2())))
+                .then(registry.getDevice(id))
+                .flatMap(device -> device.updateMetadata(metadata_)))
             .then();
     }
 
+    //重置设备物模型
+    @DeleteMapping(value = "/{id}/metadata")
+    @SaveAction
+    @Operation(summary = "重置物模型")
+    public Mono<Void> resetMetadata(@PathVariable String id) {
+
+        return registry
+            .getDevice(id)
+            .flatMap(DeviceOperator::resetMetadata)
+            .then(service
+                      .createUpdate()
+                      .setNull(DeviceInstanceEntity::getDeriveMetadata)
+                      .where(DeviceInstanceEntity::getId, id)
+                      .execute()
+                      .then());
+    }
+
 
 }