浏览代码

1.修改queryDevicePropertyStatus接口的数据返回格式
2.修改setDeviceProperty接口的参数格式

dsy 1 年之前
父节点
当前提交
444de0a35a

+ 6 - 0
iot-module/iot-openapi/pom.xml

@@ -104,6 +104,12 @@
             <artifactId>mapstruct-plus-spring-boot-starter</artifactId>
             <version>${mapstruct-plus.version}</version>
         </dependency>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>1.2.83</version>
+            <scope>compile</scope>
+        </dependency>
     </dependencies>
 
     <properties>

+ 1 - 1
iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/bo/device/OpenapiSetDeviceServicePropertyBo.java

@@ -29,5 +29,5 @@ public class OpenapiSetDeviceServicePropertyBo {
     private String productKey;
 
     @ApiModelProperty(value="参数")
-    private Map<String, Object> args;
+    private String args;
 }

+ 3 - 4
iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/vo/OpenDevicePropertyVo.java

@@ -1,14 +1,13 @@
 package cc.iotkit.openapi.dto.vo;
 
-import cc.iotkit.model.product.ProductModel;
 import cc.iotkit.model.product.ThingModel;
 import io.github.linpeilie.annotations.AutoMapper;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
-import java.util.HashMap;
-import java.util.Map;
+import java.util.List;
+
 
 @ApiModel(value = "OpenDevicePropertyVo")
 @Data
@@ -16,7 +15,7 @@ import java.util.Map;
 public class OpenDevicePropertyVo {
 
     @ApiModelProperty(value="设备属性")
-    private Map<String, Object> property = new HashMap<>();
+    private List<OpenPropertyVo> property;
 
     @ApiModelProperty(value = "主键")
     private String id;

+ 37 - 0
iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/vo/OpenPropertyVo.java

@@ -0,0 +1,37 @@
+package cc.iotkit.openapi.dto.vo;
+
+import cc.iotkit.model.product.ThingModel;
+import io.swagger.annotations.ApiModel;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+@ApiModel(value = "OpenPropertyVo")
+@Data
+public class OpenPropertyVo {
+    private String identifier;
+    private ThingModel.DataType dataType;
+    private String name;
+    private String accessMode = "rw";
+
+    // 描述
+    private String description;
+
+    // 单位
+    private String unit;
+
+    private String time;
+
+    private String value;
+
+    public OpenPropertyVo() {
+    }
+
+    public OpenPropertyVo(String identifier, ThingModel.DataType dataType, String name, String accessMode, String description, String unit) {
+        this.identifier = identifier;
+        this.dataType = dataType;
+        this.name = name;
+        this.accessMode = accessMode;
+        this.description = description;
+        this.unit = unit;
+    }
+}

+ 1 - 1
iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/service/OpenDeviceService.java

@@ -22,7 +22,7 @@ public interface OpenDeviceService {
     /**
      * 设备属性设置
      */
-    String setProperty(String productKey, String deviceName, Map<String, Object> properties);
+    String setProperty(String productKey, String deviceName, String properties);
 
     OpenDevicePropertyVo getDevicePropertyStatus(OpenapiDeviceBo data);
 }

+ 19 - 6
iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/service/impl/OpenDeviceServiceImpl.java

@@ -15,16 +15,19 @@ import cc.iotkit.model.product.Product;
 import cc.iotkit.model.product.ThingModel;
 import cc.iotkit.openapi.dto.bo.device.OpenapiDeviceBo;
 import cc.iotkit.openapi.dto.vo.OpenDevicePropertyVo;
+import cc.iotkit.openapi.dto.vo.OpenPropertyVo;
 import cc.iotkit.openapi.service.OpenDeviceService;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 
-import static cc.iotkit.common.enums.ErrCode.DEVICE_NOT_FOUND;
-import static cc.iotkit.common.enums.ErrCode.DEVICE_OFFLINE;
 
 @Service
 public class OpenDeviceServiceImpl implements OpenDeviceService {
@@ -102,9 +105,9 @@ public class OpenDeviceServiceImpl implements OpenDeviceService {
     }
 
     @Override
-    public String setProperty(String productKey, String deviceName, Map<String, Object> args) {
+    public String setProperty(String productKey, String deviceName, String args) {
         DeviceInfo deviceRepetition = deviceInfoData.findByProductKeyAndDeviceName(productKey, deviceName);
-        return deviceService.setProperty(deviceRepetition.getDeviceId(), args, true);
+        return deviceService.setProperty(deviceRepetition.getDeviceId(), JSON.parseObject(args,Map.class), true);
     }
 
     @Override
@@ -112,11 +115,21 @@ public class OpenDeviceServiceImpl implements OpenDeviceService {
         ThingModel thingModel = thingModelData.findByProductKey(bo.getProductKey());
         OpenDevicePropertyVo propertyVo = MapstructUtils.convert(thingModel, OpenDevicePropertyVo.class);
         DeviceInfo deviceInfo = deviceInfoData.findByProductKeyAndDeviceName(bo.getProductKey(), bo.getDeviceName());
+        List<OpenPropertyVo> openPropertyVos = new ArrayList<>();
         if (propertyVo != null){
-            propertyVo.setProperty(deviceInfoData.getProperties(deviceInfo.getDeviceId()));
+            Map<String, Object> properties = deviceInfoData.getProperties(deviceInfo.getDeviceId());
+            for (ThingModel.Property property : propertyVo.getModel().getProperties()) {
+                OpenPropertyVo openPropertyVo = new OpenPropertyVo(property.getIdentifier(), property.getDataType(), property.getName(), property.getAccessMode(), property.getDescription(), property.getUnit());
+                Map<String,Object> map = (Map<String, Object>) properties.get(openPropertyVo.getIdentifier());
+                if (map != null){
+                    openPropertyVo.setTime(String.valueOf(map.get("occurred")));
+                    openPropertyVo.setValue(String.valueOf(map.get("value")));
+                }
+                openPropertyVos.add(openPropertyVo);
+            }
+            propertyVo.setProperty(openPropertyVos);
         }
         return propertyVo;
     }
 
-
 }