!34 修复模拟设备下行属性调试报错,修复模拟设备下行属性日志记录报错

Merge pull request !34 from 胖虎/develop
V0.5.x
xiwa 2023-12-27 15:49:09 +00:00 committed by Gitee
commit 58883ecc81
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 13 additions and 6 deletions

View File

@ -104,17 +104,16 @@ public class PluginMainImpl implements IPluginMain, DeviceService {
throw new BizException(ErrCode.PLUGIN_SERVICE_NOT_FOUND);
}
if (!(service.getParams() instanceof Map)) {
throw new BizException(ErrCode.PARAMS_EXCEPTION);
}
Map<String, ?> params = (Map<String, ?>) service.getParams();
IDevice deviceService = deviceServices.get(0);
String type = service.getType();
String identifier = service.getIdentifier();
ActionResult result = null;
if (ThingService.TYPE_SERVICE.equals(type)) {
if (!(service.getParams() instanceof Map)) {
throw new BizException(ErrCode.PARAMS_EXCEPTION);
}
Map<String, ?> params = (Map<String, ?>) service.getParams();
//服务调用
ServiceInvoke action = ServiceInvoke.builder()
.id(service.getMid())
@ -128,6 +127,10 @@ public class PluginMainImpl implements IPluginMain, DeviceService {
publish(service, result.getCode());
} else if (ThingService.TYPE_PROPERTY.equals(type)) {
if ("set".equals(identifier)) {
if (!(service.getParams() instanceof Map)) {
throw new BizException(ErrCode.PARAMS_EXCEPTION);
}
Map<String, ?> params = (Map<String, ?>) service.getParams();
//属性设置
PropertySet action = PropertySet.builder()
.id(service.getMid())
@ -144,7 +147,7 @@ public class PluginMainImpl implements IPluginMain, DeviceService {
.id(service.getMid())
.productKey(linkPk)
.deviceName(linkDn)
.keys(new ArrayList<>(params.keySet()))
.keys((List<String>) service.getParams())
.build();
//调用插件设备服务接口
result = deviceService.propertyGet(action);

View File

@ -23,6 +23,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ScheduledThreadPoolExecutor;
@ -53,6 +54,9 @@ public class RuleDeviceConsumer implements ConsumerHandler<ThingModelMessage>, A
for (DeviceMessageHandler handler : this.handlers) {
messageHandlerPool.submit(() -> {
try {
if (!(msg.getData() instanceof Map)) {
msg.setData(new HashMap<>());
}
handler.handle(msg);
} catch (Throwable e) {
log.error("handler message error", e);