parent
67ab77a4ee
commit
444de0a35a
|
@ -104,6 +104,12 @@
|
||||||
<artifactId>mapstruct-plus-spring-boot-starter</artifactId>
|
<artifactId>mapstruct-plus-spring-boot-starter</artifactId>
|
||||||
<version>${mapstruct-plus.version}</version>
|
<version>${mapstruct-plus.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>fastjson</artifactId>
|
||||||
|
<version>1.2.83</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|
|
@ -29,5 +29,5 @@ public class OpenapiSetDeviceServicePropertyBo {
|
||||||
private String productKey;
|
private String productKey;
|
||||||
|
|
||||||
@ApiModelProperty(value="参数")
|
@ApiModelProperty(value="参数")
|
||||||
private Map<String, Object> args;
|
private String args;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
package cc.iotkit.openapi.dto.vo;
|
package cc.iotkit.openapi.dto.vo;
|
||||||
|
|
||||||
import cc.iotkit.model.product.ProductModel;
|
|
||||||
import cc.iotkit.model.product.ThingModel;
|
import cc.iotkit.model.product.ThingModel;
|
||||||
import io.github.linpeilie.annotations.AutoMapper;
|
import io.github.linpeilie.annotations.AutoMapper;
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@ApiModel(value = "OpenDevicePropertyVo")
|
@ApiModel(value = "OpenDevicePropertyVo")
|
||||||
@Data
|
@Data
|
||||||
|
@ -16,7 +15,7 @@ import java.util.Map;
|
||||||
public class OpenDevicePropertyVo {
|
public class OpenDevicePropertyVo {
|
||||||
|
|
||||||
@ApiModelProperty(value="设备属性")
|
@ApiModelProperty(value="设备属性")
|
||||||
private Map<String, Object> property = new HashMap<>();
|
private List<OpenPropertyVo> property;
|
||||||
|
|
||||||
@ApiModelProperty(value = "主键")
|
@ApiModelProperty(value = "主键")
|
||||||
private String id;
|
private String id;
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
OpenDevicePropertyVo getDevicePropertyStatus(OpenapiDeviceBo data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,16 +15,19 @@ import cc.iotkit.model.product.Product;
|
||||||
import cc.iotkit.model.product.ThingModel;
|
import cc.iotkit.model.product.ThingModel;
|
||||||
import cc.iotkit.openapi.dto.bo.device.OpenapiDeviceBo;
|
import cc.iotkit.openapi.dto.bo.device.OpenapiDeviceBo;
|
||||||
import cc.iotkit.openapi.dto.vo.OpenDevicePropertyVo;
|
import cc.iotkit.openapi.dto.vo.OpenDevicePropertyVo;
|
||||||
|
import cc.iotkit.openapi.dto.vo.OpenPropertyVo;
|
||||||
import cc.iotkit.openapi.service.OpenDeviceService;
|
import cc.iotkit.openapi.service.OpenDeviceService;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static cc.iotkit.common.enums.ErrCode.DEVICE_NOT_FOUND;
|
|
||||||
import static cc.iotkit.common.enums.ErrCode.DEVICE_OFFLINE;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class OpenDeviceServiceImpl implements OpenDeviceService {
|
public class OpenDeviceServiceImpl implements OpenDeviceService {
|
||||||
|
@ -102,9 +105,9 @@ public class OpenDeviceServiceImpl implements OpenDeviceService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
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
|
@Override
|
||||||
|
@ -112,11 +115,21 @@ public class OpenDeviceServiceImpl implements OpenDeviceService {
|
||||||
ThingModel thingModel = thingModelData.findByProductKey(bo.getProductKey());
|
ThingModel thingModel = thingModelData.findByProductKey(bo.getProductKey());
|
||||||
OpenDevicePropertyVo propertyVo = MapstructUtils.convert(thingModel, OpenDevicePropertyVo.class);
|
OpenDevicePropertyVo propertyVo = MapstructUtils.convert(thingModel, OpenDevicePropertyVo.class);
|
||||||
DeviceInfo deviceInfo = deviceInfoData.findByProductKeyAndDeviceName(bo.getProductKey(), bo.getDeviceName());
|
DeviceInfo deviceInfo = deviceInfoData.findByProductKeyAndDeviceName(bo.getProductKey(), bo.getDeviceName());
|
||||||
|
List<OpenPropertyVo> openPropertyVos = new ArrayList<>();
|
||||||
if (propertyVo != null){
|
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;
|
return propertyVo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue