add 添加设备属性设置

V0.5.x
jay 2023-03-24 18:09:19 +08:00
parent 27fc96d567
commit 0744d84292
5 changed files with 33 additions and 2 deletions

View File

@ -155,6 +155,10 @@ public interface Constants {
* -
*/
String INVOKE_SERVICE = "/{deviceId}/service/{service}/invoke";
/**
* -
*/
String INVOKE_SERVICE_PROPERTY_GET = "/{deviceId}/service/property/get";
}

View File

@ -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;

View File

@ -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) {

View File

@ -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);
}
/**
*
*/

View File

@ -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();