From 30151a232466ac6c544945b0be994018d56a265d Mon Sep 17 00:00:00 2001 From: Chenzhexian <92191856+Chenzhexian@users.noreply.github.com> Date: Thu, 17 Aug 2023 16:06:16 +0800 Subject: [PATCH] Update DynamicRouteLoader.java --- .../org/jeecg/loader/DynamicRouteLoader.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/jeecg-server-cloud/jeecg-cloud-gateway/src/main/java/org/jeecg/loader/DynamicRouteLoader.java b/jeecg-server-cloud/jeecg-cloud-gateway/src/main/java/org/jeecg/loader/DynamicRouteLoader.java index 0537ba70..c052b4a2 100644 --- a/jeecg-server-cloud/jeecg-cloud-gateway/src/main/java/org/jeecg/loader/DynamicRouteLoader.java +++ b/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.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; @@ -35,10 +36,7 @@ import reactor.core.publisher.Mono; 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; /** @@ -207,7 +205,23 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware { } Object predicates = obj.get("predicates"); if (predicates != null) { - JSONArray list = JSON.parseArray(predicates.toString()); + + List list = JSON.parseArray(predicates.toString(), PredicatesVo.class); + Map> groupedPredicates = new HashMap<>(); + + for (PredicatesVo predicatesVo : list) { + String name = predicatesVo.getName(); + List args = predicatesVo.getArgs(); + groupedPredicates.computeIfAbsent(name, k -> new ArrayList<>()).addAll(args); + } + + list = new ArrayList<>(); + for (Map.Entry> entry : groupedPredicates.entrySet()) { + String name = entry.getKey(); + List args = entry.getValue(); + list.add(new PredicatesVo(name, args)); + } + List predicateDefinitionList = new ArrayList<>(); for (Object map : list) { JSONObject json = (JSONObject) map;