添加设备编号

This commit is contained in:
2025-07-08 14:43:28 +08:00
parent b5ae17c3e3
commit f41bb097fd
5 changed files with 17 additions and 7 deletions

View File

@ -302,7 +302,7 @@ mqtt:
username: admin
password: #YtvpSfCNG
url: tcp://47.120.79.150:2883
subClientId: fys_subClient_01
subClientId: fys_subClient
subTopic: worker/alert/#,worker/location/#
pubTopic: worker/location
pubClientId: fys_pubClient_01
pubClientId: fys_pubClient

View File

@ -59,8 +59,8 @@ public class Device extends TenantEntity {
@Schema(name = "原始设备")
private Long originalDeviceId;
/*@Schema( name = "设备编号")
private String deviceNo;*/
@Schema( name = "设备编号")
private String deviceNo;
@Schema(name = "设备名称")
private String deviceName;

View File

@ -1,6 +1,7 @@
package com.fuyuanshen.equipment.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.UUID;
import cn.hutool.core.lang.generator.SnowflakeGenerator;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -146,10 +147,14 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
device.setTypeName(deviceTypes.get(0).getTypeName());
BeanUtil.copyProperties(deviceForm, device, true);
device.setDeviceNo(createDeviceNo());
deviceMapper.insert(device);
}
private String createDeviceNo() {
String uuidStr = UUID.fastUUID().toString(); // 获取带 - 的标准格式字符串
return uuidStr.replaceAll("-", "");
}
/**
* 更新设备信息

View File

@ -1,6 +1,7 @@
package com.fuyuanshen.system.mqtt.config;
import cn.hutool.core.lang.UUID;
import com.fuyuanshen.system.mqtt.receiver.ReceiverMessageHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
@ -40,9 +41,11 @@ public class MqttInboundConfiguration {
* */
@Bean
public MessageProducer messageProducer(){
// 生成一个不重复的随机数
String clientId = mqttPropertiesConfig.getSubClientId() + "_" + UUID.fastUUID();
MqttPahoMessageDrivenChannelAdapter mqttPahoMessageDrivenChannelAdapter = new MqttPahoMessageDrivenChannelAdapter(
mqttPropertiesConfig.getUrl(),
mqttPropertiesConfig.getSubClientId(),
clientId,
mqttPahoClientFactory,
mqttPropertiesConfig.getSubTopic().split(",")
);

View File

@ -1,5 +1,6 @@
package com.fuyuanshen.system.mqtt.config;
import cn.hutool.core.lang.UUID;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
@ -36,9 +37,10 @@ public class MqttOutboundConfiguration {
@Bean
@ServiceActivator(inputChannel = "mqttOutboundChannel") // 指定处理器针对哪个通道的消息进行处理
public MessageHandler mqttOutboundMessageHandler(){
String clientId = mqttPropertiesConfig.getPubClientId() + "_" + UUID.fastUUID();
MqttPahoMessageHandler mqttPahoMessageHandler = new MqttPahoMessageHandler(
mqttPropertiesConfig.getUrl(),
mqttPropertiesConfig.getPubClientId(),
clientId,
mqttPahoClientFactory
);
mqttPahoMessageHandler.setDefaultQos(1);