2020import io .swagger .v3 .oas .annotations .tags .Tag ;
2121import lombok .AllArgsConstructor ;
2222import lombok .Generated ;
23- import org .hswebframework .ezorm .rdb .operator .dml .query .SortOrder ;
2423import org .hswebframework .web .api .crud .entity .QueryOperation ;
2524import org .hswebframework .web .api .crud .entity .QueryParamEntity ;
2625import org .hswebframework .web .authorization .annotation .Authorize ;
2726import org .hswebframework .web .authorization .annotation .QueryAction ;
2827import org .hswebframework .web .authorization .annotation .Resource ;
2928import org .hswebframework .web .authorization .annotation .SaveAction ;
3029import org .hswebframework .web .crud .web .reactive .ReactiveServiceCrudController ;
31- import org .hswebframework .web .exception .I18nSupportException ;
3230import org .jetlinks .community .network .*;
3331import org .jetlinks .community .network .channel .ChannelInfo ;
3432import org .jetlinks .community .network .manager .entity .NetworkConfigEntity ;
35- import org .jetlinks .community .network .manager .enums . NetworkConfigState ;
36- import org .jetlinks .community .network .manager .service .NetworkChannelProvider ;
33+ import org .jetlinks .community .network .manager .info . NetworkConfigAliveInfo ;
34+ import org .jetlinks .community .network .manager .service .NetworkChannelHandler ;
3735import org .jetlinks .community .network .manager .service .NetworkConfigService ;
3836import org .jetlinks .community .network .manager .web .response .NetworkTypeInfo ;
39- import org .jetlinks .community .reference .DataReferenceManager ;
4037import org .springframework .web .bind .annotation .*;
41- import reactor .bool .BooleanUtils ;
4238import reactor .core .publisher .Flux ;
4339import reactor .core .publisher .Mono ;
4440
45- import java .util .Objects ;
46-
4741/**
4842 * @author zhouhao
4943 * @since 1.0
@@ -60,9 +54,7 @@ public class NetworkConfigController implements ReactiveServiceCrudController<Ne
6054
6155 private final NetworkManager networkManager ;
6256
63- private final DataReferenceManager referenceManager ;
64-
65- private final NetworkChannelProvider channelProvider ;
57+ private final NetworkChannelHandler networkChannelHandler ;
6658
6759 @ Generated
6860 @ Override
@@ -76,16 +68,7 @@ public NetworkConfigService getService() {
7668 @ Operation (summary = "获取指定类型下全部的网络组件信息" )
7769 public Flux <ChannelInfo > getNetworkInfo (@ PathVariable
7870 @ Parameter (description = "网络组件类型" ) String networkType ) {
79- NetworkProvider <?> provider = networkManager
80- .getProvider (networkType )
81- .orElseThrow (() -> new I18nSupportException ("error.unsupported_network_type" , networkType ));
82-
83- return configService
84- .createQuery ()
85- .where (NetworkConfigEntity ::getType , networkType )
86- .orderBy (SortOrder .desc (NetworkConfigEntity ::getId ))
87- .fetch ()
88- .flatMap (entity -> toConfigInfo (entity , provider ));
71+ return networkChannelHandler .getNetworkInfo (QueryParamEntity .of ().noPaging (), networkType );
8972 }
9073
9174 /**
@@ -102,31 +85,21 @@ public Flux<ChannelInfo> getAliveNetworkInfo(@PathVariable
10285 @ Parameter (description = "包含指定的网络组件ID" )
10386 @ RequestParam (required = false ) String include ,
10487 @ Parameter (hidden = true ) QueryParamEntity query ) {
105- NetworkProvider <?> provider = networkManager
106- .getProvider (networkType )
107- .orElseThrow (() -> new I18nSupportException ("error.unsupported_network_type" , networkType ));
108-
109- return configService
110- .createQuery ()
111- .setParam (query )
112- .where (NetworkConfigEntity ::getType , networkType )
113- .and (NetworkConfigEntity ::getState , NetworkConfigState .enabled )
114- .orderBy (SortOrder .desc (NetworkConfigEntity ::getId ))
115- .fetch ()
116- .filterWhen (config -> {
117- if (provider .isReusable () || Objects .equals (config .getId (), include )) {
118- return Mono .just (true );
119- }
120- //判断是否已经被使用
121- return referenceManager
122- .isReferenced (DataReferenceManager .TYPE_NETWORK , config .getId ())
123- .as (BooleanUtils ::not );
124- })
125- .flatMap (entity -> toConfigInfo (entity , provider ));
88+ return networkChannelHandler .getAliveNetworkInfo (networkType , include , query );
12689 }
12790
128- private Mono <ChannelInfo > toConfigInfo (NetworkConfigEntity entity , NetworkProvider <?> provider ) {
129- return channelProvider .toChannelInfo (entity );
91+ @ PostMapping ("/_alive" )
92+ @ QueryAction
93+ @ Operation (summary = "获取多个类型下可用的网络组件信息" )
94+ public Flux <ChannelInfo > getAliveNetworkInfoForMoreType (@ RequestParam (required = false ) @ Parameter (description = "包含指定的网络组件ID" ) String include ,
95+ @ RequestBody @ Parameter (hidden = true ) Mono <NetworkConfigAliveInfo > aliveInfoMono ) {
96+ return aliveInfoMono
97+ .flatMapMany (info -> {
98+ QueryParamEntity query = info .getQuery ();
99+ return networkChannelHandler
100+ .getAliveNetworkInfoForMoreType (info .getNetworkTypes (), include , query );
101+ });
102+
130103 }
131104
132105 @ GetMapping ("/supports" )
0 commit comments