mirror of
https://gitee.com/iteaj/iboot.git
synced 2026-08-31 01:40:54 +08:00
完善mqtt解析path路径功能
This commit is contained in:
@@ -131,7 +131,7 @@ public class PanelsController extends BaseController {
|
||||
// 设置各属性的实时值
|
||||
RealtimeData realtimeData = realtimeDataMap.get(attrValue.getField());
|
||||
if(realtimeData != null && realtimeData.getRealtime() != null
|
||||
&& realtimeData.getRealtime().getStatus() == CollectStatus.Success) {
|
||||
&& realtimeData.getRealtime().getValue() != null) {
|
||||
attrValue.setValue(realtimeData.getRealtime().getValue().toString());
|
||||
if(Boolean.TRUE.equals(attrValue.getCtrlStatus())) {
|
||||
panelsDeviceDto.setCtrlValue(attrValue.getValue());
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.iteaj.iboot.module.iot.mqtt;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.JSONPath;
|
||||
import com.iteaj.framework.spi.iot.*;
|
||||
import com.iteaj.framework.spi.iot.consts.DataType;
|
||||
import com.iteaj.framework.spi.iot.consts.TransportProtocol;
|
||||
@@ -28,6 +30,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -39,10 +42,10 @@ public class DefaultMqttHandle implements ClientProtocolHandle<DefaultMqttSubscr
|
||||
private final static String deviceSn = "deviceSn";
|
||||
private final static String gatewaySn = "gatewaySn";
|
||||
private final static String DEFAULT_MQTT_IMPL = "MQTT_DEFAULT_IMPL";
|
||||
private IotCacheManager cacheManager;
|
||||
private IProductService productService;
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
private Map<String, Map<String, SubscribeConfig>> productSubscribeApis = new ConcurrentHashMap<>();
|
||||
private final IotCacheManager cacheManager;
|
||||
private final IProductService productService;
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
private final Map<String, Map<String, SubscribeConfig>> productSubscribeApis = new ConcurrentHashMap<>();
|
||||
|
||||
public DefaultMqttHandle(IotCacheManager cacheManager, IProductService productService) {
|
||||
this.cacheManager = cacheManager;
|
||||
@@ -148,9 +151,16 @@ public class DefaultMqttHandle implements ClientProtocolHandle<DefaultMqttSubscr
|
||||
, String gatewaySnValue, String deviceSnValue, RealtimeStatus device) {
|
||||
Date date = new Date();
|
||||
byte[] message = protocol.requestMessage().getMessage();
|
||||
JSONObject jsonObject = JSONObject.parseObject(new String(message, Charset.forName("utf-8")));
|
||||
JSONObject jsonObject = JSONObject.parseObject(new String(message, StandardCharsets.UTF_8));
|
||||
List<SignalOrFieldValue> fieldValues = dicts.stream().map(item -> {
|
||||
Object value = DataValueResolverFactory.resolver(item, jsonObject.get(item.getField()));
|
||||
Object fieldValue;
|
||||
if(StrUtil.isBlank(item.getPath())) {
|
||||
fieldValue = jsonObject.get(item.getField());
|
||||
} else {
|
||||
fieldValue = JSONPath.eval(jsonObject, item.getPath());
|
||||
}
|
||||
|
||||
Object value = DataValueResolverFactory.resolver(item, fieldValue);
|
||||
return new SignalOrFieldValue(item.getId(), item.getField(), date, value);
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
@@ -208,11 +218,12 @@ public class DefaultMqttHandle implements ClientProtocolHandle<DefaultMqttSubscr
|
||||
} else {
|
||||
attrs = config.getDicts().stream().map(item -> new UpModelAttr(Long.valueOf(item.getDictValue())
|
||||
, item.getAttrField(), item.getDictName(), DataType.build(item.getDataType())
|
||||
, item.getAccuracy(), item.getGain(), item.getResolver(), item.getScript())).collect(Collectors.toList());
|
||||
, item.getAccuracy(), item.getGain(), item.getResolver(), item.getScript()
|
||||
, item.getPath())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
} else {
|
||||
isWill = Boolean.valueOf(config.getValue());
|
||||
isWill = Boolean.parseBoolean(config.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,16 +257,16 @@ public class DefaultMqttHandle implements ClientProtocolHandle<DefaultMqttSubscr
|
||||
}
|
||||
|
||||
@Getter
|
||||
public class SubscribeConfig {
|
||||
public static class SubscribeConfig {
|
||||
/**
|
||||
* 是否遗嘱
|
||||
*/
|
||||
private boolean isWill;
|
||||
private final boolean isWill;
|
||||
|
||||
/**
|
||||
* 属性配置
|
||||
*/
|
||||
private List<UpModelAttr> attrs;
|
||||
private final List<UpModelAttr> attrs;
|
||||
|
||||
public SubscribeConfig(boolean isWill, List<UpModelAttr> attrs) {
|
||||
this.isWill = isWill;
|
||||
|
||||
@@ -155,11 +155,13 @@ public class ProtocolInvokeUtil {
|
||||
if(DataType.t_json.getValue().equals(item.getDataType())) {
|
||||
item.getDicts().forEach(dict -> {
|
||||
upConfigAttrs.add(new UpModelAttr(dict.getModelAttrId(), dict.getAttrField(), dict.getDictName()
|
||||
, DataType.build(dict.getDataType()), dict.getAccuracy(), dict.getGain(), dict.getResolver(), dict.getScript()));
|
||||
, DataType.build(dict.getDataType()), dict.getAccuracy(), dict.getGain(), dict.getResolver()
|
||||
, dict.getScript(), dict.getPath()));
|
||||
});
|
||||
} else {
|
||||
upConfigAttrs.add(new UpModelAttr(item.getModelAttrId(), item.getAttrField(), item.getAttrName()
|
||||
, DataType.build(item.getDataType()), item.getAccuracy(), item.getGain(), item.getResolver(), item.getScript()));
|
||||
, DataType.build(item.getDataType()), item.getAccuracy(), item.getGain(), item.getResolver()
|
||||
, item.getScript(), null));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
<select id="listUpByApiCode" resultMap="JoinModelAttrDictMap">
|
||||
select a.*, pa.attr_type func_type, pa.accuracy, pa.script, pa.gain, pa.resolver, ad.model_attr_id ad_model_attr_id, ad.dict_name ad_dict_name, ad.dict_value ad_dict_value
|
||||
, jpa.field ad_attr_field, jpa.data_type ad_data_type, jpa.accuracy ad_accuracy, jpa.gain ad_gain, jpa.resolver ad_resolver
|
||||
, jpa.script ad_script from iot_model_api_config a
|
||||
, jpa.script ad_script, ad.path ad_path from iot_model_api_config a
|
||||
left join iot_model_attr_dict ad on a.model_attr_id=ad.model_attr_id
|
||||
left join iot_model_attr pa on a.model_attr_id=pa.id
|
||||
left join iot_model_attr jpa on a.protocol_data_type = 'json' and jpa.id=ad.dict_value
|
||||
@@ -57,7 +57,7 @@
|
||||
<select id="listDownByApiCode" resultMap="JoinModelAttrDictMap">
|
||||
select a.*, pa.attr_type func_type, pa.accuracy, pa.script, pa.gain, pa.resolver, ad.model_attr_id ad_model_attr_id, ad.dict_name ad_dict_name, ad.dict_value ad_dict_value
|
||||
, pa.default_value attr_default_value, jpa.accuracy ad_accuracy, jpa.gain ad_gain, jpa.resolver ad_resolver
|
||||
, jpa.script ad_script from iot_model_api_config a
|
||||
, jpa.script ad_script, ad.path ad_path from iot_model_api_config a
|
||||
left join iot_model_attr_dict ad on a.model_attr_id=ad.model_attr_id
|
||||
left join iot_model_attr pa on a.model_attr_id=pa.id
|
||||
left join iot_model_attr jpa on a.protocol_data_type = 'json' and jpa.id=ad.dict_value
|
||||
|
||||
@@ -48,12 +48,18 @@ public class UpModelAttr {
|
||||
*/
|
||||
private String script;
|
||||
|
||||
/**
|
||||
* json解析路径
|
||||
*/
|
||||
private String path;
|
||||
|
||||
public UpModelAttr(Long id, String field, String name, DataType dataType
|
||||
, Integer accuracy, Integer gain, String resolver, String script) {
|
||||
, Integer accuracy, Integer gain, String resolver, String script, String path) {
|
||||
this.id = id;
|
||||
this.field = field;
|
||||
this.name = name;
|
||||
this.gain = gain;
|
||||
this.path = path;
|
||||
this.script = script;
|
||||
this.resolver = resolver;
|
||||
this.accuracy = accuracy;
|
||||
|
||||
Reference in New Issue
Block a user