From 34981c30a78e8bbd7791131059a9210f9928b62c Mon Sep 17 00:00:00 2001
From: 刘光辉 <347230014@qq.com>
Date: 星期四, 17 九月 2026 09:24:09 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master' into master
---
jnpf-gateway/src/main/java/jnpf/config/MyServiceDiscoverHandler.java | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 101 insertions(+), 0 deletions(-)
diff --git a/jnpf-gateway/src/main/java/jnpf/config/MyServiceDiscoverHandler.java b/jnpf-gateway/src/main/java/jnpf/config/MyServiceDiscoverHandler.java
new file mode 100644
index 0000000..1508638
--- /dev/null
+++ b/jnpf-gateway/src/main/java/jnpf/config/MyServiceDiscoverHandler.java
@@ -0,0 +1,101 @@
+//package jnpf.config;
+//
+//import com.github.xiaoymin.knife4j.spring.gateway.Knife4jGatewayProperties;
+//import com.github.xiaoymin.knife4j.spring.gateway.discover.ServiceDiscoverHandler;
+//import com.github.xiaoymin.knife4j.spring.gateway.enums.OpenApiVersion;
+//import com.github.xiaoymin.knife4j.spring.gateway.spec.v2.OpenAPI2Resource;
+//import com.github.xiaoymin.knife4j.spring.gateway.utils.PathUtils;
+//import lombok.Getter;
+//import lombok.extern.slf4j.Slf4j;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.cloud.gateway.config.GatewayProperties;
+//import org.springframework.cloud.gateway.route.RouteDefinition;
+//import org.springframework.cloud.gateway.support.NameUtils;
+//import org.springframework.context.EnvironmentAware;
+//import org.springframework.context.annotation.Configuration;
+//import org.springframework.context.annotation.Primary;
+//import org.springframework.core.env.Environment;
+//import org.springframework.util.StringUtils;
+//
+//import jakarta.annotation.Resource;
+//import java.nio.charset.StandardCharsets;
+//import java.util.*;
+//
+//@Slf4j
+//public class MyServiceDiscoverHandler extends ServiceDiscoverHandler {
+//
+// /**
+// * Knife4j gateway properties
+// */
+// @Autowired
+// private Knife4jGatewayProperties gatewayProperties;
+//
+// /**
+// * 鑱氬悎鍐呭
+// */
+// @Getter
+// private List<OpenAPI2Resource> gatewayResources;
+//
+// @Autowired
+// private GatewayProperties gatewayPropertiess;
+//
+// /**
+// * Spring Environment
+// */
+// private Environment environment;
+//
+// public MyServiceDiscoverHandler(Knife4jGatewayProperties gatewayProperties) {
+// super(gatewayProperties);
+// }
+//
+// /**
+// * 澶勭悊娉ㄥ唽涓績鐨勬湇鍔�
+// * @param service 鏈嶅姟鍒楄〃闆嗗悎
+// */
+// @Override
+// public void discover(List<String> service) {
+//
+// log.debug("service has change.");
+// Set<String> excludeService = getExcludeService();
+// // 鐗堟湰
+// OpenApiVersion apiVersion = this.gatewayProperties.getDiscover().getVersion();
+// // 鍒ゆ柇褰撳墠绫诲瀷
+// String url = this.gatewayProperties.getDiscover().getUrl();
+// // 涓�у寲鏈嶅姟鐨勯厤缃俊鎭�
+// Map<String, Knife4jGatewayProperties.ServiceConfigInfo> configInfoMap = this.gatewayProperties.getDiscover().getServiceConfig();
+// List<OpenAPI2Resource> resources = new ArrayList<>();
+// if (service != null && !service.isEmpty()) {
+// for (String serviceName : service) {
+// if (!serviceName.startsWith("jnpf-") || serviceName.equals("jnpf-datareport") || excludeService.contains(serviceName)) {
+// continue;
+// }
+// int order = 0;
+// String groupName = serviceName;
+// String contextPath = "/";
+//// Knife4jGatewayProperties.ServiceConfigInfo serviceConfigInfo = configInfoMap.get(serviceName);
+//// if (serviceConfigInfo != null) {
+//// order = serviceConfigInfo.getOrder();
+//// groupName = serviceConfigInfo.getGroupName();
+//// contextPath = PathUtils.append(contextPath, serviceConfigInfo.getContextPath());
+//// }
+// OpenAPI2Resource resource = new OpenAPI2Resource(order, true);
+// resource.setName(groupName);
+// RouteDefinition routeDefinition = gatewayPropertiess.getRoutes().stream().filter(t -> t.getId().equals(serviceName)).findFirst().orElse(new RouteDefinition());
+// String replace = routeDefinition.getPredicates().get(0).getArgs().get(NameUtils.GENERATED_NAME_PREFIX + "0").replace("/**", "");
+// resource.setContextPath(replace);
+//// // 鍒ゆ柇鐗堟湰
+//// if (apiVersion == OpenApiVersion.OpenAPI3) {
+//// if (contextPath.equalsIgnoreCase("/")) {
+//// // 鑷姩杩藉姞涓�涓猻erviceName
+//// resource.setContextPath("/" + serviceName);
+//// }
+//// }
+// resource.setUrl(PathUtils.append(PathUtils.append(replace, url), contextPath + serviceName));
+// resource.setId(Base64.getEncoder().encodeToString((resource.getName() + resource.getUrl() + resource.getContextPath()).getBytes(StandardCharsets.UTF_8)));
+// resources.add(resource);
+// }
+// }
+// super.discover(service);
+// }
+//
+//}
--
Gitblit v1.8.0