Browse Source

Merge pull request #5277 from Chenzhexian/master

网关路由配置Bug问题!!!
pull/4938/merge
JEECG 1 year ago committed by GitHub
parent
commit
6d34164a16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      jeecg-server-cloud/jeecg-cloud-gateway/src/main/java/org/jeecg/loader/DynamicRouteLoader.java
  2. 16
      jeecg-server-cloud/jeecg-cloud-gateway/src/main/java/org/jeecg/loader/vo/PredicatesVo.java

26
jeecg-server-cloud/jeecg-cloud-gateway/src/main/java/org/jeecg/loader/DynamicRouteLoader.java

@ -21,6 +21,7 @@ import org.jeecg.config.RouterDataType;
import org.jeecg.loader.repository.DynamicRouteService; import org.jeecg.loader.repository.DynamicRouteService;
import org.jeecg.loader.repository.MyInMemoryRouteDefinitionRepository; import org.jeecg.loader.repository.MyInMemoryRouteDefinitionRepository;
import org.jeecg.loader.vo.MyRouteDefinition; import org.jeecg.loader.vo.MyRouteDefinition;
import org.jeecg.loader.vo.PredicatesVo;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.gateway.event.RefreshRoutesEvent; import org.springframework.cloud.gateway.event.RefreshRoutesEvent;
@ -35,10 +36,7 @@ import reactor.core.publisher.Mono;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
/** /**
@ -207,10 +205,26 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
} }
Object predicates = obj.get("predicates"); Object predicates = obj.get("predicates");
if (predicates != null) { if (predicates != null) {
JSONArray list = JSON.parseArray(predicates.toString());
List<PredicatesVo> list = JSON.parseArray(predicates.toString(), PredicatesVo.class);
Map<String, List<String>> groupedPredicates = new HashMap<>();
for (PredicatesVo predicatesVo : list) {
String name = predicatesVo.getName();
List<String> args = predicatesVo.getArgs();
groupedPredicates.computeIfAbsent(name, k -> new ArrayList<>()).addAll(args);
}
list = new ArrayList<>();
for (Map.Entry<String, List<String>> entry : groupedPredicates.entrySet()) {
String name = entry.getKey();
List<String> args = entry.getValue();
list.add(new PredicatesVo(name, args));
}
List<PredicateDefinition> predicateDefinitionList = new ArrayList<>(); List<PredicateDefinition> predicateDefinitionList = new ArrayList<>();
for (Object map : list) { for (Object map : list) {
JSONObject json = (JSONObject) map; JSONObject json = JSON.parseObject(JSON.toJSONString(map));
PredicateDefinition predicateDefinition = new PredicateDefinition(); PredicateDefinition predicateDefinition = new PredicateDefinition();
//update-begin-author:zyf date:20220419 for:【VUEN-762】路由条件添加异常问题,原因是部分路由条件参数需要设置固定key //update-begin-author:zyf date:20220419 for:【VUEN-762】路由条件添加异常问题,原因是部分路由条件参数需要设置固定key
String name=json.getString("name"); String name=json.getString("name");

16
jeecg-server-cloud/jeecg-cloud-gateway/src/main/java/org/jeecg/loader/vo/PredicatesVo.java

@ -0,0 +1,16 @@
package org.jeecg.loader.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PredicatesVo {
private String name;
private List<String> args;
}
Loading…
Cancel
Save