|
|
@@ -5,11 +5,13 @@ import com.middle.platform.common.core.exception.BusinessException;
|
|
|
import com.middle.platform.common.core.utils.Result;
|
|
|
import com.middle.platform.data.biz.pojo.IotDeviceUrlVo;
|
|
|
import com.middle.platform.data.biz.pojo.IotHttpUrlVo;
|
|
|
+import com.middle.platform.data.biz.pojo.IotKafkaUrlVo;
|
|
|
import com.middle.platform.data.biz.pojo.constant.UrlProtocol;
|
|
|
import com.middle.platform.manage.api.feign.DeviceApi;
|
|
|
import com.middle.platform.manage.api.pojo.DeviceDetailVo;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.boot.autoconfigure.amqp.RabbitProperties;
|
|
|
+import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
@@ -27,19 +29,12 @@ import java.util.Objects;
|
|
|
@RequestMapping("/device")
|
|
|
@RequiredArgsConstructor
|
|
|
public class UrlController {
|
|
|
- @Value("${spring.rabbitmq.host}")
|
|
|
- private String host;
|
|
|
- @Value("${spring.rabbitmq.username}")
|
|
|
- private String username;
|
|
|
- @Value("${spring.rabbitmq.password}")
|
|
|
- private String password;
|
|
|
- @Value("${spring.rabbitmq.port}")
|
|
|
- private String port;
|
|
|
-
|
|
|
+ private final RabbitProperties rabbitProperties;
|
|
|
+ private final KafkaProperties kafkaProperties;
|
|
|
private final DeviceApi deviceApi;
|
|
|
|
|
|
/**
|
|
|
- * 属性上报
|
|
|
+ * 获取设备连接协议数据配置
|
|
|
*
|
|
|
* @param id 设备id
|
|
|
*/
|
|
|
@@ -51,13 +46,19 @@ public class UrlController {
|
|
|
}
|
|
|
if (StrUtil.equals(String.valueOf(deviceDetailVo.getReportProtocol()), UrlProtocol.MQTT)) {
|
|
|
IotDeviceUrlVo iotDeviceUrlVo = new IotDeviceUrlVo();
|
|
|
- iotDeviceUrlVo.setUsername(username);
|
|
|
- iotDeviceUrlVo.setPassword(password);
|
|
|
- iotDeviceUrlVo.setHost(host);
|
|
|
- iotDeviceUrlVo.setPort(port);
|
|
|
+ iotDeviceUrlVo.setUsername(rabbitProperties.getUsername());
|
|
|
+ iotDeviceUrlVo.setPassword(rabbitProperties.getPassword());
|
|
|
+ iotDeviceUrlVo.setHost(rabbitProperties.getHost());
|
|
|
+ iotDeviceUrlVo.setPort(rabbitProperties.getPort());
|
|
|
iotDeviceUrlVo.setUrl("mqtt://" + iotDeviceUrlVo.getHost());
|
|
|
return Result.ok(iotDeviceUrlVo);
|
|
|
}
|
|
|
+ if (StrUtil.equals(String.valueOf(deviceDetailVo.getReportProtocol()), UrlProtocol.KAFKA)) {
|
|
|
+ IotKafkaUrlVo iotKafkaUrlVo = new IotKafkaUrlVo();
|
|
|
+ iotKafkaUrlVo.setBootstrapServers(kafkaProperties.getBootstrapServers());
|
|
|
+ return Result.ok(iotKafkaUrlVo);
|
|
|
+ }
|
|
|
+
|
|
|
InetAddress inetAddress = InetAddress.getLocalHost();
|
|
|
IotHttpUrlVo iotHttpUrlVo = new IotHttpUrlVo();
|
|
|
iotHttpUrlVo.setHost(inetAddress.getHostAddress());
|