From 3a6e0af815780e39fd98a4c9fdb57ba796816943 Mon Sep 17 00:00:00 2001 From: "xin.cao" Date: Sun, 31 Mar 2019 10:41:02 +0800 Subject: [PATCH] ok --- .gitignore | 8 ++++- .../ui/controller/SwitcherController.java | 35 +++++++++++++++---- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 7267309..f9a609b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ +/*/.classpath +/*/.project +/*/.settings +/.classpath +/.project +/.settings /jswitcher-api/target/ /jswitcher-service/target/ /jswitcher-cli/target/ @@ -11,4 +17,4 @@ /jswitcher-core/bin/target/ /jswitcher-sample/bin/target/ /jswitcher-spring-boot-starter/bin/target/ -/jswitcher-ui/bin/target/ \ No newline at end of file +/jswitcher-ui/bin/target/ diff --git a/jswitcher-ui/src/main/java/com/github/xincao9/jswitcher/ui/controller/SwitcherController.java b/jswitcher-ui/src/main/java/com/github/xincao9/jswitcher/ui/controller/SwitcherController.java index bd4906a..eba4a1e 100644 --- a/jswitcher-ui/src/main/java/com/github/xincao9/jswitcher/ui/controller/SwitcherController.java +++ b/jswitcher-ui/src/main/java/com/github/xincao9/jswitcher/ui/controller/SwitcherController.java @@ -63,7 +63,7 @@ public class SwitcherController { /** * 开关列表 - * + * * @return 开关 */ @GetMapping("keys") @@ -78,10 +78,10 @@ public ResponseEntity>> keys() { /** * 获取开关列表 - * + * * @return 开关列表 */ - private List> getKeys () { + private List> getKeys() { try { List endpoints = discoveryService.query(SwitcherService.class.getTypeName()); if (endpoints == null || endpoints.isEmpty()) { @@ -102,6 +102,29 @@ private List> getKeys () { keys.add(v0); }); } + Collections.sort(keys, (Map o1, Map o2) -> { + String application1 = String.valueOf(o1.get("application")); + String application2 = String.valueOf(o2.get("application")); + if (!application1.equalsIgnoreCase(application2)) { + return application1.compareTo(application2); + } + String key1 = String.valueOf(o1.get("key")); + String key2 = String.valueOf(o2.get("key")); + if (!key1.equalsIgnoreCase(key2)) { + return key1.compareTo(key2); + } + String host1 = String.valueOf(o1.get("host")); + String host2 = String.valueOf(o2.get("host")); + if (!host1.equalsIgnoreCase(host2)) { + return host1.compareTo(host2); + } + String port1 = String.valueOf(o1.get("port")); + String port2 = String.valueOf(o2.get("port")); + if (!port1.equalsIgnoreCase(port2)) { + return port1.compareTo(port2); + } + return 0; + }); return keys; } catch (Throwable e) { LOGGER.error(e.getMessage()); @@ -111,7 +134,7 @@ private List> getKeys () { /** * 开关列表 - * + * * @return 开关 */ @GetMapping("tree") @@ -191,12 +214,12 @@ public ResponseEntity> endpointKeys(@PathVariable String host, @P /** * 开关列表 - * + * * @param host 主机 * @param port 端口 * @return 开关列表 */ - private List getKeysByHostAndPort (String host, Integer port) { + private List getKeysByHostAndPort(String host, Integer port) { StringBuilder method = new StringBuilder(); method.append(SwitcherService.class.getTypeName()) .append('.')