Skip to content

Commit

Permalink
Merge pull request #5277 from Chenzhexian/master
Browse files Browse the repository at this point in the history
网关路由配置Bug问题!!!
  • Loading branch information
zhangdaiscott authored Oct 16, 2023
2 parents e15335d + 5974a2e commit 6d34164
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.jeecg.loader.repository.DynamicRouteService;
import org.jeecg.loader.repository.MyInMemoryRouteDefinitionRepository;
import org.jeecg.loader.vo.MyRouteDefinition;
import org.jeecg.loader.vo.PredicatesVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.gateway.event.RefreshRoutesEvent;
Expand All @@ -35,10 +36,7 @@

import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.*;
import java.util.concurrent.Executor;

/**
Expand Down Expand Up @@ -207,10 +205,26 @@ public static List<MyRouteDefinition> getRoutesByJson(JSONArray array) throws UR
}
Object predicates = obj.get("predicates");
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<>();
for (Object map : list) {
JSONObject json = (JSONObject) map;
JSONObject json = JSON.parseObject(JSON.toJSONString(map));
PredicateDefinition predicateDefinition = new PredicateDefinition();
//update-begin-author:zyf date:20220419 for:【VUEN-762】路由条件添加异常问题,原因是部分路由条件参数需要设置固定key
String name=json.getString("name");
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 6d34164

Please sign in to comment.