MQTT通信修改 使用服务器数据库
This commit is contained in:
@@ -33,9 +33,9 @@ public class JacksonConfig {
|
||||
public Module registerJavaTimeModule() {
|
||||
// 全局配置序列化返回 JSON 处理
|
||||
JavaTimeModule javaTimeModule = new JavaTimeModule();
|
||||
javaTimeModule.addSerializer(Long.class, BigNumberSerializer.INSTANCE);
|
||||
javaTimeModule.addSerializer(Long.class, ToStringSerializer.instance);
|
||||
javaTimeModule.addSerializer(Long.TYPE, BigNumberSerializer.INSTANCE);
|
||||
javaTimeModule.addSerializer(BigInteger.class, BigNumberSerializer.INSTANCE);
|
||||
javaTimeModule.addSerializer(BigInteger.class, ToStringSerializer.instance);
|
||||
javaTimeModule.addSerializer(BigDecimal.class, ToStringSerializer.instance);
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(formatter));
|
||||
|
||||
@@ -43,5 +43,10 @@
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>water-app</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.dromara.mqtt;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.app.domain.mqtt.DeviceCommand;
|
||||
import org.dromara.app.service.IDeviceCommandPublisher;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.json.utils.JsonUtils;
|
||||
import org.dromara.mqtt.config.properties.MqttProperties;
|
||||
@@ -44,14 +45,18 @@ public class DeviceMqttCommandPublisher implements IDeviceCommandPublisher {
|
||||
}
|
||||
|
||||
private String buildCommandTopic(String deviceNo) {
|
||||
if (StringUtils.isBlank(deviceNo)) {
|
||||
throw new ServiceException("命令下发缺少设备编号,无法拼接主题");
|
||||
}
|
||||
String device = deviceNo.trim().toLowerCase();
|
||||
String prefix = mqttProperties.getTopics().getPublishPrefix();
|
||||
if (StringUtils.isBlank(prefix)) {
|
||||
return "/" + deviceNo + "/subscriber/cmd";
|
||||
return "/" + device + "/subscriber/cmd";
|
||||
}
|
||||
String normalizedPrefix = prefix.startsWith("/") ? prefix : "/" + prefix;
|
||||
if (normalizedPrefix.endsWith("/")) {
|
||||
normalizedPrefix = normalizedPrefix.substring(0, normalizedPrefix.length() - 1);
|
||||
}
|
||||
return normalizedPrefix + "/" + deviceNo + "/subscriber/cmd";
|
||||
return normalizedPrefix + "/" + device + "/subscriber/cmd";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user