mqtt通讯修改 增加模板 计算属性

This commit is contained in:
LEED
2025-03-09 12:39:52 +08:00
parent 20c17b772d
commit 6a8cbff440
41 changed files with 2359 additions and 31 deletions

View File

@@ -4,6 +4,8 @@ import com.xinda.common.core.mq.DeviceReportBo;
import com.xinda.common.enums.TopicType;
import com.xinda.common.utils.StringUtils;
import com.xinda.common.utils.gateway.mq.TopicsUtils;
import com.xinda.iot.domain.Device;
import com.xinda.iot.service.IDeviceService;
import com.xinda.mq.model.ReportDataBo;
import com.xinda.mq.service.IDataHandler;
import com.xinda.mq.service.IMqttMessagePublish;
@@ -27,6 +29,8 @@ public class DeviceOtherMsgHandler {
private IDataHandler dataHandler;
@Resource
private IMqttMessagePublish messagePublish;
@Resource
private IDeviceService deviceService;
/**
* true: 使用netty搭建的mqttBroker false: 使用emq
@@ -42,8 +46,13 @@ public class DeviceOtherMsgHandler {
*/
public void messageHandler(DeviceReportBo bo) {
String type = "";
String name = topicsUtils.parseTopicName(bo.getTopicName());
if (StringUtils.isEmpty(name) || name.endsWith(TopicType.FUNCTION_GET.getTopicSuffix())) return;
String name = "";
if (bo.getTopicName().startsWith(TopicType.PROPERTY_XINDA_DEV.getTopicSuffix()) || bo.getTopicName().startsWith(TopicType.FUNCTION_XINDA_DOWN.getTopicSuffix())) {
name = topicsUtils.parseNewTopicName(bo.getTopicName());
}else{
name = topicsUtils.parseTopicName(bo.getTopicName());
}
if (StringUtils.isEmpty(name) || name.endsWith(TopicType.FUNCTION_GET.getTopicSuffix()) || name.startsWith(TopicType.FUNCTION_XINDA_DOWN.getTopicSuffix()) ) return;
ReportDataBo data = this.buildReportData(bo);
TopicType topicType = TopicType.getType(name);
switch (topicType) {
@@ -73,14 +82,20 @@ public class DeviceOtherMsgHandler {
private ReportDataBo buildReportData(DeviceReportBo bo) {
String message = new String(bo.getData());
log.info("收到设备信息[{}]", message);
Long productId = topicsUtils.parseProductId(bo.getTopicName());
String serialNumber = topicsUtils.parseSerialNumber(bo.getTopicName());
String serialNumber = "";
ReportDataBo dataBo = new ReportDataBo();
dataBo.setMessage(message);
Long productId;
if (bo.getTopicName().startsWith(TopicType.PROPERTY_XINDA_DEV.getTopicSuffix()) || bo.getTopicName().startsWith(TopicType.FUNCTION_XINDA_DOWN.getTopicSuffix())) {
serialNumber = topicsUtils.parseNewSerialNumber(bo.getTopicName());
productId = deviceService.selectDeviceBySerialNumber(serialNumber).getProductId();
}else{
serialNumber = topicsUtils.parseSerialNumber(bo.getTopicName());
productId = topicsUtils.parseProductId(bo.getTopicName());
}
dataBo.setProductId(productId);
dataBo.setSerialNumber(serialNumber);
dataBo.setRuleEngine(false);
return dataBo;
}
}