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))