Skip to content

Commit c7a226b

Browse files
committed
feat: 适配新的网络组件查询接口
1 parent d6eb169 commit c7a226b

File tree

3 files changed

+178
-44
lines changed

3 files changed

+178
-44
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2025 JetLinks https://www.jetlinks.cn
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.jetlinks.community.network.manager.info;
17+
18+
import io.swagger.v3.oas.annotations.media.Schema;
19+
import lombok.Getter;
20+
import lombok.Setter;
21+
import org.hswebframework.web.api.crud.entity.QueryParamEntity;
22+
23+
import java.util.Set;
24+
25+
@Setter
26+
@Getter
27+
public class NetworkConfigAliveInfo {
28+
29+
@Schema(description = "动态查询条件")
30+
private QueryParamEntity query = QueryParamEntity.of();
31+
32+
@Schema(description = "多个网络组建类型")
33+
private Set<String> networkTypes;
34+
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* Copyright 2025 JetLinks https://www.jetlinks.cn
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.jetlinks.community.network.manager.service;
17+
18+
import jakarta.annotation.Nullable;
19+
import lombok.AllArgsConstructor;
20+
import org.apache.commons.collections4.CollectionUtils;
21+
import org.hswebframework.ezorm.rdb.operator.dml.query.SortOrder;
22+
import org.hswebframework.web.api.crud.entity.QueryParamEntity;
23+
import org.hswebframework.web.exception.I18nSupportException;
24+
import org.jetlinks.community.network.NetworkManager;
25+
import org.jetlinks.community.network.NetworkProvider;
26+
import org.jetlinks.community.network.channel.ChannelInfo;
27+
import org.jetlinks.community.network.manager.entity.NetworkConfigEntity;
28+
import org.jetlinks.community.reference.DataReferenceManager;
29+
import org.springframework.stereotype.Component;
30+
import reactor.bool.BooleanUtils;
31+
import reactor.core.publisher.Flux;
32+
import reactor.core.publisher.Mono;
33+
34+
import java.util.Objects;
35+
import java.util.Set;
36+
37+
/**
38+
* @author liusq
39+
* @date 2024/3/22
40+
*/
41+
@Component
42+
@AllArgsConstructor
43+
public class NetworkChannelHandler {
44+
private final NetworkConfigService configService;
45+
46+
private final NetworkManager networkManager;
47+
48+
private final DataReferenceManager referenceManager;
49+
50+
private final NetworkChannelProvider channelProvider;
51+
52+
53+
public Flux<ChannelInfo> getAliveNetworkInfo(String networkType, @Nullable String include, QueryParamEntity query) {
54+
NetworkProvider<?> provider = networkManager
55+
.getProvider(networkType)
56+
.orElseThrow(() -> new I18nSupportException("error.unsupported_network_type", networkType));
57+
58+
return configService
59+
.createQuery()
60+
.setParam(query)
61+
.where(NetworkConfigEntity::getType, networkType)
62+
.orderBy(SortOrder.desc(NetworkConfigEntity::getId))
63+
.fetch()
64+
.filterWhen(config -> {
65+
if (provider.isReusable() || Objects.equals(config.getId(), include)) {
66+
return Mono.just(true);
67+
}
68+
//判断是否已经被使用
69+
return referenceManager
70+
.isReferenced(DataReferenceManager.TYPE_NETWORK, config.getId())
71+
.as(BooleanUtils::not);
72+
})
73+
.flatMap(channelProvider::toChannelInfo);
74+
}
75+
76+
/**
77+
* 查询多个指定的网络组建类型的信息
78+
*
79+
* @param networkTypes 多个网络组件类型
80+
* @param include 包含指定的网络组件ID
81+
* @param query 动态查询条件
82+
* @return Flux<ChannelInfo>
83+
*/
84+
public Flux<ChannelInfo> getAliveNetworkInfoForMoreType(Set<String> networkTypes, @Nullable String include, QueryParamEntity query) {
85+
if (CollectionUtils.isEmpty(networkTypes)) {
86+
return Flux.empty();
87+
}
88+
return configService
89+
.createQuery()
90+
.setParam(query)
91+
.in(NetworkConfigEntity::getType, networkTypes)
92+
.orderBy(SortOrder.desc(NetworkConfigEntity::getId))
93+
.fetch()
94+
.filterWhen(config -> {
95+
NetworkProvider<?> provider = networkManager
96+
.getProvider(config.getType())
97+
.orElseThrow(() -> new I18nSupportException("error.unsupported_network_type", config.getType()));
98+
99+
if (provider.isReusable() || Objects.equals(config.getId(), include)) {
100+
return Mono.just(true);
101+
}
102+
//判断是否已经被使用
103+
return referenceManager
104+
.isReferenced(DataReferenceManager.TYPE_NETWORK, config.getId())
105+
.as(BooleanUtils::not);
106+
})
107+
.flatMap(channelProvider::toChannelInfo);
108+
}
109+
110+
111+
/**
112+
* 获取指定类型下全部的网络组件信息
113+
*
114+
* @param param 查询条件
115+
* @param networkType 网络组件类型
116+
*/
117+
public Flux<ChannelInfo> getNetworkInfo(QueryParamEntity param, String networkType) {
118+
return configService
119+
.createQuery()
120+
.setParam(param)
121+
.where(NetworkConfigEntity::getType, networkType)
122+
.orderBy(SortOrder.desc(NetworkConfigEntity::getId))
123+
.fetch()
124+
.flatMap(channelProvider::toChannelInfo);
125+
}
126+
127+
}

jetlinks-manager/network-manager/src/main/java/org/jetlinks/community/network/manager/web/NetworkConfigController.java

Lines changed: 17 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,24 @@
2020
import io.swagger.v3.oas.annotations.tags.Tag;
2121
import lombok.AllArgsConstructor;
2222
import lombok.Generated;
23-
import org.hswebframework.ezorm.rdb.operator.dml.query.SortOrder;
2423
import org.hswebframework.web.api.crud.entity.QueryOperation;
2524
import org.hswebframework.web.api.crud.entity.QueryParamEntity;
2625
import org.hswebframework.web.authorization.annotation.Authorize;
2726
import org.hswebframework.web.authorization.annotation.QueryAction;
2827
import org.hswebframework.web.authorization.annotation.Resource;
2928
import org.hswebframework.web.authorization.annotation.SaveAction;
3029
import org.hswebframework.web.crud.web.reactive.ReactiveServiceCrudController;
31-
import org.hswebframework.web.exception.I18nSupportException;
3230
import org.jetlinks.community.network.*;
3331
import org.jetlinks.community.network.channel.ChannelInfo;
3432
import 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;
3735
import org.jetlinks.community.network.manager.service.NetworkConfigService;
3836
import org.jetlinks.community.network.manager.web.response.NetworkTypeInfo;
39-
import org.jetlinks.community.reference.DataReferenceManager;
4037
import org.springframework.web.bind.annotation.*;
41-
import reactor.bool.BooleanUtils;
4238
import reactor.core.publisher.Flux;
4339
import 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

Comments
 (0)