From 84c6e48f0ee83f448ec5ff1ba5d40f20af35e8b8 Mon Sep 17 00:00:00 2001 From: ayan Date: Tue, 18 Oct 2022 17:24:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E4=BC=A0=E8=BE=93=E5=8D=8F=E8=AE=AE=E7=9A=84=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E5=8D=8F=E8=AE=AE=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../device/web/ProtocolSupportController.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/jetlinks-manager/device-manager/src/main/java/org/jetlinks/community/device/web/ProtocolSupportController.java b/jetlinks-manager/device-manager/src/main/java/org/jetlinks/community/device/web/ProtocolSupportController.java index fd17e40e..ae36548f 100644 --- a/jetlinks-manager/device-manager/src/main/java/org/jetlinks/community/device/web/ProtocolSupportController.java +++ b/jetlinks-manager/device-manager/src/main/java/org/jetlinks/community/device/web/ProtocolSupportController.java @@ -7,6 +7,7 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.Getter; import org.hswebframework.utils.StringUtils; +import org.hswebframework.web.api.crud.entity.QueryParamEntity; import org.hswebframework.web.authorization.annotation.Authorize; import org.hswebframework.web.authorization.annotation.QueryAction; import org.hswebframework.web.authorization.annotation.Resource; @@ -32,7 +33,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +import reactor.util.function.Tuple2; +import reactor.util.function.Tuples; +import java.util.Comparator; import java.util.List; @RestController @@ -174,4 +178,29 @@ public class ProtocolSupportController public Flux allUnits() { return Flux.fromIterable(ValueUnits.getAllUnit()); } + + + @GetMapping("/supports/{transport}") + @Authorize(merge = false) + @Operation(summary = "获取支持指定传输协议的消息协议") + public Flux getSupportTransportProtocols(@PathVariable String transport, + @Parameter(hidden = true) QueryParamEntity query) { + return protocolSupports + .getProtocols() + .collectMap(ProtocolSupport::getId) + .flatMapMany(protocols -> service.createQuery() + .setParam(query) + .fetch() + .index() + .flatMap(tp2 -> Mono + .justOrEmpty(protocols.get(tp2.getT2().getId())) + .filterWhen(support -> support + .getSupportedTransport() + .filter(t -> t.isSame(transport)) + .hasElements()) + .map(ProtocolInfo::of) + .map(protocolInfo -> Tuples.of(tp2.getT1(), protocolInfo)))) + .sort(Comparator.comparingLong(Tuple2::getT1)) + .map(Tuple2::getT2); + } }