package com.zy.iot.config;
|
|
import com.zy.iot.entity.IotTopicConfig;
|
import lombok.Data;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.stereotype.Component;
|
|
import java.util.LinkedHashMap;
|
import java.util.Map;
|
|
@Data
|
@Component
|
@ConfigurationProperties(prefix = "iot")
|
public class IotProperties {
|
|
private boolean enabled;
|
|
private String endpoint;
|
|
private Integer port = 8883;
|
|
private String thingName;
|
|
private String clientId;
|
|
private boolean cleanSession;
|
|
private boolean automaticReconnect = true;
|
|
private Integer keepAliveSeconds = 60;
|
|
private Integer connectionTimeoutSeconds = 10;
|
|
private String persistenceDir;
|
|
private String caCertPath;
|
|
private String clientCertPath;
|
|
private String privateKeyPath;
|
|
private IotTopicConfig topics = new IotTopicConfig();
|
|
private Map<String, Integer> pickStationMappings = new LinkedHashMap<>();
|
|
public String getResolvedClientId() {
|
if (clientId != null && clientId.trim().length() > 0) {
|
return clientId.trim();
|
}
|
return thingName;
|
}
|
|
public boolean isTlsEnabled() {
|
String serverUri = getServerUri();
|
return serverUri != null && serverUri.startsWith("ssl://");
|
}
|
|
public String getServerUri() {
|
if (endpoint == null || endpoint.trim().length() == 0) {
|
return null;
|
}
|
String trimmed = endpoint.trim();
|
if (trimmed.startsWith("ssl://") || trimmed.startsWith("tcp://")) {
|
return trimmed;
|
}
|
int resolvedPort = port == null ? 8883 : port;
|
return "ssl://" + trimmed + ":" + resolvedPort;
|
}
|
}
|