|
@@ -7,11 +7,13 @@ import io.swagger.v3.oas.annotations.Parameter;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import lombok.Getter;
|
|
import lombok.Getter;
|
|
import org.hswebframework.utils.StringUtils;
|
|
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.Authorize;
|
|
import org.hswebframework.web.authorization.annotation.QueryAction;
|
|
import org.hswebframework.web.authorization.annotation.QueryAction;
|
|
import org.hswebframework.web.authorization.annotation.Resource;
|
|
import org.hswebframework.web.authorization.annotation.Resource;
|
|
import org.hswebframework.web.authorization.annotation.SaveAction;
|
|
import org.hswebframework.web.authorization.annotation.SaveAction;
|
|
import org.hswebframework.web.crud.web.reactive.ReactiveServiceCrudController;
|
|
import org.hswebframework.web.crud.web.reactive.ReactiveServiceCrudController;
|
|
|
|
+import org.hswebframework.web.exception.BusinessException;
|
|
import org.jetlinks.community.device.entity.ProtocolSupportEntity;
|
|
import org.jetlinks.community.device.entity.ProtocolSupportEntity;
|
|
import org.jetlinks.community.device.service.LocalProtocolSupportService;
|
|
import org.jetlinks.community.device.service.LocalProtocolSupportService;
|
|
import org.jetlinks.community.device.web.protocol.ProtocolDetail;
|
|
import org.jetlinks.community.device.web.protocol.ProtocolDetail;
|
|
@@ -19,6 +21,7 @@ import org.jetlinks.community.device.web.protocol.ProtocolInfo;
|
|
import org.jetlinks.community.device.web.protocol.TransportInfo;
|
|
import org.jetlinks.community.device.web.protocol.TransportInfo;
|
|
import org.jetlinks.community.device.web.request.ProtocolDecodeRequest;
|
|
import org.jetlinks.community.device.web.request.ProtocolDecodeRequest;
|
|
import org.jetlinks.community.device.web.request.ProtocolEncodeRequest;
|
|
import org.jetlinks.community.device.web.request.ProtocolEncodeRequest;
|
|
|
|
+import org.jetlinks.community.protocol.TransportDetail;
|
|
import org.jetlinks.core.ProtocolSupport;
|
|
import org.jetlinks.core.ProtocolSupport;
|
|
import org.jetlinks.core.ProtocolSupports;
|
|
import org.jetlinks.core.ProtocolSupports;
|
|
import org.jetlinks.core.message.codec.Transport;
|
|
import org.jetlinks.core.message.codec.Transport;
|
|
@@ -32,7 +35,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import reactor.core.publisher.Flux;
|
|
import reactor.core.publisher.Flux;
|
|
import reactor.core.publisher.Mono;
|
|
import reactor.core.publisher.Mono;
|
|
|
|
+import reactor.util.function.Tuple2;
|
|
|
|
+import reactor.util.function.Tuples;
|
|
|
|
|
|
|
|
+import java.util.Comparator;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
@@ -174,4 +180,57 @@ public class ProtocolSupportController
|
|
public Flux<ValueUnit> allUnits() {
|
|
public Flux<ValueUnit> allUnits() {
|
|
return Flux.fromIterable(ValueUnits.getAllUnit());
|
|
return Flux.fromIterable(ValueUnits.getAllUnit());
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @GetMapping("/supports/{transport}")
|
|
|
|
+ @Authorize(merge = false)
|
|
|
|
+ @Operation(summary = "获取支持指定传输协议的消息协议")
|
|
|
|
+ public Flux<ProtocolInfo> 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);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @GetMapping("/{id}/transport/{transport}")
|
|
|
|
+ @Authorize(merge = false)
|
|
|
|
+ @Operation(summary = "获取消息协议对应的传输协议信息")
|
|
|
|
+ public Mono<TransportDetail> getTransportDetail(@PathVariable @Parameter(description = "协议ID") String id,
|
|
|
|
+ @PathVariable @Parameter(description = "传输协议") String transport) {
|
|
|
|
+ return protocolSupports
|
|
|
|
+ .getProtocol(id)
|
|
|
|
+ .onErrorMap(e -> new BusinessException("error.unable_to_load_protocol_by_access_id", 404, id))
|
|
|
|
+ .flatMapMany(protocol -> protocol
|
|
|
|
+ .getSupportedTransport()
|
|
|
|
+ .filter(trans -> trans.isSame(transport))
|
|
|
|
+ .distinct()
|
|
|
|
+ .flatMap(_transport -> TransportDetail.of(protocol, _transport)))
|
|
|
|
+ .singleOrEmpty();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @PostMapping("/{id}/detail")
|
|
|
|
+ @QueryAction
|
|
|
|
+ @Operation(summary = "获取协议详情")
|
|
|
|
+ public Mono<ProtocolDetail> protocolDetail(@PathVariable String id) {
|
|
|
|
+ return protocolSupports
|
|
|
|
+ .getProtocol(id)
|
|
|
|
+ .onErrorMap(e -> new BusinessException("error.unable_to_load_protocol_by_access_id", 404, id))
|
|
|
|
+ .flatMap(ProtocolDetail::of);
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|