From 0b07c719a3e634a750d421f8cff50a566e57fd7f Mon Sep 17 00:00:00 2001 From: dzq Date: Thu, 18 Sep 2025 17:24:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=80=BB=E8=BE=91=E5=B9=B6=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?MQTT=E5=AE=9A=E6=97=B6=E8=BF=9E=E6=8E=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复用户添加时未检查身份证号是否已存在的问题,改为根据身份证号判断是新增还是更新用户 为MQTT服务添加定时连接功能,每5分钟尝试连接一次,并避免重复连接相同配置 --- .../ab98/user/Ab98UserApplicationService.java | 23 ++++++++++++++----- .../agileboot/domain/mqtt/MqttService.java | 21 +++++++++++++++++ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/ab98/user/Ab98UserApplicationService.java b/agileboot-domain/src/main/java/com/agileboot/domain/ab98/user/Ab98UserApplicationService.java index 9377018..c5544dd 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/ab98/user/Ab98UserApplicationService.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/ab98/user/Ab98UserApplicationService.java @@ -198,12 +198,23 @@ public class Ab98UserApplicationService { throw new ApiException(ErrorCode.Internal.INTERNAL_ERROR, "姓名不匹配"); } AddAb98UserCommand addAb98UserCommand = getAddAb98UserCommand(ab98UserDto); - Ab98UserModel model = userModelFactory.create(); - model.loadAddCommand(addAb98UserCommand); - model.insert(); - ab98UserEntity = model.selectById(); - saveQyUserInfoByAb98(qyUser, ab98UserEntity); - return ab98UserEntity; + + ab98UserEntity = userService.getByIdnum(addAb98UserCommand.getIdnum()); + if (ab98UserEntity != null) { + Ab98UserModel model = userModelFactory.loadById(ab98UserEntity.getAb98UserId()); + addAb98UserCommand.setAb98UserId(ab98UserEntity.getAb98UserId()); + model.loadUpdateCommand(addAb98UserCommand); + model.updateById(); + saveQyUserInfoByAb98(qyUser, ab98UserEntity); + return ab98UserEntity; + } else { + Ab98UserModel model = userModelFactory.create(); + model.loadAddCommand(addAb98UserCommand); + model.insert(); + ab98UserEntity = model.selectById(); + saveQyUserInfoByAb98(qyUser, ab98UserEntity); + return ab98UserEntity; + } } @NotNull diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/mqtt/MqttService.java b/agileboot-domain/src/main/java/com/agileboot/domain/mqtt/MqttService.java index ae24a9d..d027ab3 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/mqtt/MqttService.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/mqtt/MqttService.java @@ -8,6 +8,7 @@ import lombok.RequiredArgsConstructor; import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.eclipse.paho.client.mqttv3.*; @@ -31,6 +32,13 @@ public class MqttService implements MqttCallback { && config.getUsername().equals(other.getUsername()) && config.getPassword().equals(other.getPassword()); } + + public boolean isSameConfig(MqttServerEntity other) { + if (other == null) { + return false; + } + return config.getMqttServerId().equals(other.getMqttServerId()); + } } @@ -55,8 +63,21 @@ public class MqttService implements MqttCallback { }); } + @Scheduled(fixedRate = 5 * 60 * 1000) // 每5分钟执行一次 (300000毫秒) + public void scheduledConnect() { + try { + connect(); + } catch (MqttException e) { + log.error("定时MQTT连接失败", e); + } + } + public void connect() throws MqttException { for (MqttServerEntity config : mqttServerService.selectAll()) { + if (clientConfigs.stream().anyMatch(cc -> cc.isSameConfig(config))) { + continue; + } + // 检查是否已有相同连接的client实例 ClientConfig existingConfig = clientConfigs.stream() .filter(cc -> cc.isSameConnection(config))