瀏覽代碼

Merge branch 'feature-devicesimulator' into dev

jay 2 年之前
父節點
當前提交
86b01a6b29

+ 26 - 5
data/converters/6260396d67aced2696184053/converter.js

@@ -109,7 +109,7 @@ this.encode = function (service,device) {
   var method="thing.service.";
   var topic="/sys/"+service.productKey+"/"+service.deviceName+"/c/service/";
   var params={};
-  
+
   //透传下发
   if(device.transparent){
 	var rst=component.transparentEncode(service,device);
@@ -152,12 +152,29 @@ this.encode = function (service,device) {
 	method+=identifier;
 	topic="/sys/"+service.productKey+"/"+service.deviceName+"/c/deregister";
   }
-  
-  for(var p in service.params){
+  if(type=="property" && identifier=="get"  ){
+	var listParams = []
+	for(var p in service.params){
+	listParams.push(service.params[p]);
+  }
+	return {
+	productKey:service.productKey,
+	deviceName:service.deviceName,
+	mid:deviceMid,
+	content:{
+	  topic:topic,
+	  payload:JSON.stringify({
+		id:deviceMid,
+		method:method,
+		params: listParams
+	  })
+	}
+  }
+  }else{
+   for(var p in service.params){
 	params[p]=service.params[p];
   }
-  
-  return {
+	return {
 	productKey:service.productKey,
 	deviceName:service.deviceName,
 	mid:deviceMid,
@@ -170,4 +187,8 @@ this.encode = function (service,device) {
 	  })
 	}
   }
+
+  }
+ 
+  
 };

+ 4 - 0
iot-common/src/main/java/cc/iotkit/common/Constants.java

@@ -155,6 +155,10 @@ public interface Constants {
          * 设备-服务调用
          */
         String INVOKE_SERVICE = "/{deviceId}/service/{service}/invoke";
+        /**
+         * 设备-属性获取
+         */
+        String INVOKE_SERVICE_PROPERTY_GET = "/{deviceId}/service/property/get";
 
     }
 

+ 37 - 16
iot-components/iot-mqtt-component/src/main/resources/convert.js

@@ -152,22 +152,43 @@ this.encode = function (service,device) {
         method+=identifier;
         topic="/sys/"+service.productKey+"/"+service.deviceName+"/c/deregister";
     }
+    if(type=="property" && identifier=="get"  ){
+        var listParams = []
+        for(var p in service.params){
+            listParams.push(service.params[p]);
+        }
+        return {
+            productKey:service.productKey,
+            deviceName:service.deviceName,
+            mid:deviceMid,
+            content:{
+                topic:topic,
+                payload:JSON.stringify({
+                    id:deviceMid,
+                    method:method,
+                    params: listParams
+                })
+            }
+        }
+    }else{
+        for(var p in service.params){
+            params[p]=service.params[p];
+        }
+        return {
+            productKey:service.productKey,
+            deviceName:service.deviceName,
+            mid:deviceMid,
+            content:{
+                topic:topic,
+                payload:JSON.stringify({
+                    id:deviceMid,
+                    method:method,
+                    params:params
+                })
+            }
+        }
 
-    for(var p in service.params){
-        params[p]=service.params[p];
     }
 
-    return {
-        productKey:service.productKey,
-        deviceName:service.deviceName,
-        mid:deviceMid,
-        content:{
-            topic:topic,
-            payload:JSON.stringify({
-                id:deviceMid,
-                method:method,
-                params:params
-            })
-        }
-    }
-};
+
+};

+ 2 - 1
iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/DeviceActionService.java

@@ -51,7 +51,8 @@ public class DeviceActionService {
 
         public String getType() {
             //identifier为set固定为属性设置,其它为服务调用
-            if (ThingModelMessage.ID_PROPERTY_SET.equals(identifier)) {
+            if (ThingModelMessage.ID_PROPERTY_SET.equals(identifier) ||
+                    ThingModelMessage.ID_PROPERTY_GET.equals(identifier)) {
                 return ThingModelMessage.TYPE_PROPERTY;
             }
             return ThingModelMessage.TYPE_SERVICE;

+ 8 - 0
iot-standalone/src/main/java/cc/iotkit/manager/controller/DeviceController.java

@@ -88,6 +88,14 @@ public class DeviceController {
         return new InvokeResult(deviceService.invokeService(deviceId, service, args));
     }
 
+    @PostMapping(Constants.API_DEVICE.INVOKE_SERVICE_PROPERTY_GET)
+    public InvokeResult invokeServicePropertySet(@PathVariable("deviceId") String deviceId,
+                                      @RequestBody List<String> propertyNames) {
+        if (StringUtils.isBlank(deviceId)) {
+            throw new RuntimeException("deviceId/service is blank.");
+        }
+        return new InvokeResult(deviceService.getProperty(deviceId, propertyNames, true));
+    }
     @PostMapping(Constants.API_DEVICE.SET_PROPERTIES)
     public InvokeResult setProperty(@PathVariable("deviceId") String deviceId,
                                     @RequestBody Map<String, Object> args) {

+ 12 - 0
iot-standalone/src/main/java/cc/iotkit/manager/service/DeviceService.java

@@ -27,6 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
 import java.util.Map;
 
 @Slf4j
@@ -68,6 +69,17 @@ public class DeviceService {
                 args, ThingModelMessage.TYPE_SERVICE, service);
     }
 
+    /**
+     * 设备属性获取
+     */
+    public String getProperty(String deviceId, List<String> properties,
+                              boolean checkOwner) {
+        DeviceInfo device = getAndCheckDevice(deviceId, checkOwner);
+
+        return send(deviceId, device.getProductKey(), device.getDeviceName(), properties,
+                ThingModelMessage.TYPE_PROPERTY, ThingModelMessage.ID_PROPERTY_GET);
+    }
+
     /**
      * 设备属性设置
      */

+ 7 - 1
iot-standalone/src/main/java/cc/iotkit/manager/service/ThingModelService.java

@@ -11,6 +11,7 @@ package cc.iotkit.manager.service;
 
 import cc.iotkit.common.thing.ThingService;
 import cc.iotkit.data.IThingModelData;
+import cc.iotkit.model.device.message.ThingModelMessage;
 import cc.iotkit.model.product.ThingModel;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
@@ -37,7 +38,12 @@ public class ThingModelService {
             if (properties == null) {
                 return;
             }
-            params = parseProperties(properties, (Map<?, ?>) service.getParams());
+            if(identifier.equals(ThingModelMessage.ID_PROPERTY_GET)){
+                params = service.getParams();
+            }
+            else {
+                params = parseProperties(properties, (Map<?, ?>) service.getParams());
+            }
         } else if (ThingService.TYPE_SERVICE.equals(type)) {
             //服务调用
             Map<String, ThingModel.Service> services = model.serviceMap();