diff --git a/iot-module/iot-openapi/pom.xml b/iot-module/iot-openapi/pom.xml index 783b14fa..7ec1bc3a 100644 --- a/iot-module/iot-openapi/pom.xml +++ b/iot-module/iot-openapi/pom.xml @@ -104,6 +104,12 @@ mapstruct-plus-spring-boot-starter ${mapstruct-plus.version} + + com.alibaba + fastjson + 1.2.83 + compile + diff --git a/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/bo/device/OpenapiSetDeviceServicePropertyBo.java b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/bo/device/OpenapiSetDeviceServicePropertyBo.java index f8ddb318..f1120ed3 100644 --- a/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/bo/device/OpenapiSetDeviceServicePropertyBo.java +++ b/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 args; + private String args; } diff --git a/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/vo/OpenDevicePropertyVo.java b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/vo/OpenDevicePropertyVo.java index 6f4f79d1..aab73a63 100644 --- a/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/vo/OpenDevicePropertyVo.java +++ b/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 property = new HashMap<>(); + private List property; @ApiModelProperty(value = "主键") private String id; diff --git a/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/vo/OpenPropertyVo.java b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/vo/OpenPropertyVo.java new file mode 100644 index 00000000..d8bd3050 --- /dev/null +++ b/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; + } +} diff --git a/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/service/OpenDeviceService.java b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/service/OpenDeviceService.java index 567a7fca..dae8239f 100644 --- a/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/service/OpenDeviceService.java +++ b/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 properties); + String setProperty(String productKey, String deviceName, String properties); OpenDevicePropertyVo getDevicePropertyStatus(OpenapiDeviceBo data); } diff --git a/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/service/impl/OpenDeviceServiceImpl.java b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/service/impl/OpenDeviceServiceImpl.java index 0e148d84..858d6243 100644 --- a/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/service/impl/OpenDeviceServiceImpl.java +++ b/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 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 openPropertyVos = new ArrayList<>(); if (propertyVo != null){ - propertyVo.setProperty(deviceInfoData.getProperties(deviceInfo.getDeviceId())); + Map 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 map = (Map) 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; } - }