Compare commits

...

2 Commits

Author SHA1 Message Date
ca47160c92 Merge remote-tracking branch 'origin/main' into dyf-device 2025-07-08 14:46:35 +08:00
f41bb097fd 添加设备编号 2025-07-08 14:43:28 +08:00
5 changed files with 17 additions and 7 deletions

View File

@ -302,7 +302,7 @@ mqtt:
username: admin username: admin
password: #YtvpSfCNG password: #YtvpSfCNG
url: tcp://47.120.79.150:2883 url: tcp://47.120.79.150:2883
subClientId: fys_subClient_01 subClientId: fys_subClient
subTopic: worker/alert/#,worker/location/# subTopic: worker/alert/#,worker/location/#
pubTopic: 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 = "原始设备") @Schema(name = "原始设备")
private Long originalDeviceId; private Long originalDeviceId;
/*@Schema( name = "设备编号") @Schema( name = "设备编号")
private String deviceNo;*/ private String deviceNo;
@Schema(name = "设备名称") @Schema(name = "设备名称")
private String deviceName; private String deviceName;

View File

@ -1,6 +1,7 @@
package com.fuyuanshen.equipment.service.impl; package com.fuyuanshen.equipment.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.UUID;
import cn.hutool.core.lang.generator.SnowflakeGenerator; import cn.hutool.core.lang.generator.SnowflakeGenerator;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -192,6 +193,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
device.setDeviceType(deviceTypes.getId()); device.setDeviceType(deviceTypes.getId());
BeanUtil.copyProperties(deviceForm, device, true); BeanUtil.copyProperties(deviceForm, device, true);
device.setDeviceNo(createDeviceNo());
deviceMapper.insert(device); deviceMapper.insert(device);
// 新增设备类型记录 // 新增设备类型记录
@ -209,7 +211,10 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
deviceAssignmentsService.save(assignments); deviceAssignmentsService.save(assignments);
} }
private String createDeviceNo() {
String uuidStr = UUID.fastUUID().toString(); // 获取带 - 的标准格式字符串
return uuidStr.replaceAll("-", "");
}
/** /**
* 更新设备信息 * 更新设备信息

View File

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

View File

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