优化transport转换
This commit is contained in:
parent
4c51ca55e5
commit
6baf0d61aa
|
|
@ -4,6 +4,8 @@ import lombok.AllArgsConstructor;
|
|||
import org.jetlinks.community.device.entity.DeviceProductEntity;
|
||||
import org.jetlinks.core.ProtocolSupports;
|
||||
import org.jetlinks.core.message.codec.DefaultTransport;
|
||||
import org.jetlinks.core.message.codec.Transport;
|
||||
import org.jetlinks.core.message.codec.Transports;
|
||||
import org.jetlinks.core.metadata.ConfigMetadata;
|
||||
import org.jetlinks.core.metadata.DeviceConfigScope;
|
||||
import org.jetlinks.community.device.entity.DeviceInstanceEntity;
|
||||
|
|
@ -82,7 +84,7 @@ public class DefaultDeviceConfigMetadataSupplier implements DeviceConfigMetadata
|
|||
//消息协议
|
||||
protocolSupports.getProtocol(product.getMessageProtocol()),
|
||||
//传输协议
|
||||
Mono.justOrEmpty(product.getTransportEnum(Arrays.asList(DefaultTransport.values()))),
|
||||
Mono.justOrEmpty(product.getTransportEnum(Transports.get())),
|
||||
(protocol, transport) -> {
|
||||
return protocol.getMetadataExpandsConfig(transport, metadataType, metadataId, typeId);
|
||||
}
|
||||
|
|
@ -96,6 +98,6 @@ public class DefaultDeviceConfigMetadataSupplier implements DeviceConfigMetadata
|
|||
.findById(productId)
|
||||
.flatMapMany(product -> protocolSupports
|
||||
.getProtocol(product.getMessageProtocol())
|
||||
.flatMap(support -> support.getConfigMetadata(DefaultTransport.valueOf(product.getTransportProtocol()))));
|
||||
.flatMap(support -> support.getConfigMetadata(Transport.of(product.getTransportProtocol()))));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,9 +97,9 @@ public class ProtocolSupportController
|
|||
@Authorize(merge = false)
|
||||
@Operation(summary = "获取协议对应使用传输协议的配置元数据")
|
||||
public Mono<ConfigMetadata> getTransportConfiguration(@PathVariable @Parameter(description = "协议ID") String id,
|
||||
@PathVariable @Parameter(description = "传输协议") DefaultTransport transport) {
|
||||
@PathVariable @Parameter(description = "传输协议") String transport) {
|
||||
return protocolSupports.getProtocol(id)
|
||||
.flatMap(support -> support.getConfigMetadata(transport));
|
||||
.flatMap(support -> support.getConfigMetadata(Transport.of(transport)));
|
||||
}
|
||||
|
||||
@GetMapping("/{id}/{transport}/metadata")
|
||||
|
|
@ -107,11 +107,11 @@ public class ProtocolSupportController
|
|||
@Authorize(merge = false)
|
||||
@Operation(summary = "获取协议设置的默认物模型")
|
||||
public Mono<String> getDefaultMetadata(@PathVariable @Parameter(description = "协议ID") String id,
|
||||
@PathVariable @Parameter(description = "传输协议") DefaultTransport transport) {
|
||||
@PathVariable @Parameter(description = "传输协议") String transport) {
|
||||
return protocolSupports
|
||||
.getProtocol(id)
|
||||
.flatMap(support ->support
|
||||
.getDefaultMetadata(transport)
|
||||
.getDefaultMetadata(Transport.of(transport))
|
||||
.flatMap(metadata-> support.getMetadataCodec().encode(metadata))
|
||||
).defaultIfEmpty("{}");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue