add 添加设备属性设置
parent
27fc96d567
commit
0744d84292
|
@ -155,6 +155,10 @@ public interface Constants {
|
||||||
* 设备-服务调用
|
* 设备-服务调用
|
||||||
*/
|
*/
|
||||||
String INVOKE_SERVICE = "/{deviceId}/service/{service}/invoke";
|
String INVOKE_SERVICE = "/{deviceId}/service/{service}/invoke";
|
||||||
|
/**
|
||||||
|
* 设备-属性获取
|
||||||
|
*/
|
||||||
|
String INVOKE_SERVICE_PROPERTY_GET = "/{deviceId}/service/property/get";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,8 @@ public class DeviceActionService {
|
||||||
|
|
||||||
public String getType() {
|
public String getType() {
|
||||||
//identifier为set固定为属性设置,其它为服务调用
|
//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_PROPERTY;
|
||||||
}
|
}
|
||||||
return ThingModelMessage.TYPE_SERVICE;
|
return ThingModelMessage.TYPE_SERVICE;
|
||||||
|
|
|
@ -88,6 +88,14 @@ public class DeviceController {
|
||||||
return new InvokeResult(deviceService.invokeService(deviceId, service, args));
|
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)
|
@PostMapping(Constants.API_DEVICE.SET_PROPERTIES)
|
||||||
public InvokeResult setProperty(@PathVariable("deviceId") String deviceId,
|
public InvokeResult setProperty(@PathVariable("deviceId") String deviceId,
|
||||||
@RequestBody Map<String, Object> args) {
|
@RequestBody Map<String, Object> args) {
|
||||||
|
|
|
@ -27,6 +27,7 @@ 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.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@ -68,6 +69,17 @@ public class DeviceService {
|
||||||
args, ThingModelMessage.TYPE_SERVICE, service);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设备属性设置
|
* 设备属性设置
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -11,6 +11,7 @@ package cc.iotkit.manager.service;
|
||||||
|
|
||||||
import cc.iotkit.common.thing.ThingService;
|
import cc.iotkit.common.thing.ThingService;
|
||||||
import cc.iotkit.data.IThingModelData;
|
import cc.iotkit.data.IThingModelData;
|
||||||
|
import cc.iotkit.model.device.message.ThingModelMessage;
|
||||||
import cc.iotkit.model.product.ThingModel;
|
import cc.iotkit.model.product.ThingModel;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
@ -37,7 +38,12 @@ public class ThingModelService {
|
||||||
if (properties == null) {
|
if (properties == null) {
|
||||||
return;
|
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)) {
|
} else if (ThingService.TYPE_SERVICE.equals(type)) {
|
||||||
//服务调用
|
//服务调用
|
||||||
Map<String, ThingModel.Service> services = model.serviceMap();
|
Map<String, ThingModel.Service> services = model.serviceMap();
|
||||||
|
|
Loading…
Reference in New Issue