From e35d9540f786e01d4db9214fa1cc6954786fd663 Mon Sep 17 00:00:00 2001 From: "pref_mail@163.com" Date: Thu, 9 May 2024 16:34:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E6=96=B0=E5=A2=9E=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E9=9A=8F=E7=B3=BB=E7=BB=9F=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E4=B8=80=E8=B5=B7=E6=9B=B4=E6=96=B0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/constant/LauncherConstant.java | 2 +- .../aspect/AsyncAnnotationAspect.java | 4 +++- .../aspect/AsyncAnnotationAspect.java | 4 +++- .../jinpai/aspect/AnnotationAspect.java | 4 +++- .../factory/aspect/AsyncAnnotationAspect.java | 4 +++- .../config/InterceptorAdapterConfig.java | 21 ++++++++----------- .../LocalServerLoginAccountsInterceptor.java | 5 +++-- .../patch/aspect/AsyncAnnotationAspect.java | 4 +++- 8 files changed, 28 insertions(+), 20 deletions(-) diff --git a/blade-biz-common/src/main/java/org/springblade/common/constant/LauncherConstant.java b/blade-biz-common/src/main/java/org/springblade/common/constant/LauncherConstant.java index dd664ddb0..5512d0806 100644 --- a/blade-biz-common/src/main/java/org/springblade/common/constant/LauncherConstant.java +++ b/blade-biz-common/src/main/java/org/springblade/common/constant/LauncherConstant.java @@ -237,7 +237,7 @@ public interface LauncherConstant { static String loginAddr(String profile) { switch (profile) { - case (AppConstant.PROD_CODE): + case (AppConstant.DEV_CODE): return APPLICATION_DEV_LOGIN_ADDR; case (AppConstant.TEST_CODE): return APPLICATION_TEST_LOGIN_ADDR; diff --git a/blade-service/logpm-aftersales/src/main/java/com/logpm/aftersales/aspect/AsyncAnnotationAspect.java b/blade-service/logpm-aftersales/src/main/java/com/logpm/aftersales/aspect/AsyncAnnotationAspect.java index 7fe7bc2fa..8c63fd073 100644 --- a/blade-service/logpm-aftersales/src/main/java/com/logpm/aftersales/aspect/AsyncAnnotationAspect.java +++ b/blade-service/logpm-aftersales/src/main/java/com/logpm/aftersales/aspect/AsyncAnnotationAspect.java @@ -16,6 +16,7 @@ import org.springblade.core.redis.cache.BladeRedis; import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.utils.StringUtil; import org.springblade.core.tool.utils.ThreadLocalUtil; +import org.springframework.core.env.Environment; import org.springframework.http.HttpHeaders; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.scheduling.annotation.Async; @@ -33,6 +34,7 @@ import java.util.Objects; @AllArgsConstructor public class AsyncAnnotationAspect { private final BladeRedis bladeRedis; + private final Environment environment; /** * 定义一个切点,匹配所有带有@Async("asyncExecutor")注解的方法。 * 注意:实际上Spring Framework自带对@Async("asyncExecutor")的处理,直接这样配置可能会导致预期之外的行为。 @@ -96,7 +98,7 @@ public class AsyncAnnotationAspect { String account ="shujutongbu"; JSONObject data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER+account); if(Objects.isNull(data)){ - String url = "http://"+ LauncherConstant.loginAddr(AppConstant.DEV_CODE)+"/blade-auth/oauth/token"; + String url = "http://"+ LauncherConstant.loginAddr(Objects.requireNonNull(environment.getActiveProfiles()[0]))+"/blade-auth/oauth/token"; HttpRequest urlRequest = HttpRequest.post(url); urlRequest.header("Authorization", "Basic c2FiZXI6c2FiZXJfc2VjcmV0"); urlRequest.header("Tenant-Id", "627683"); diff --git a/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/aspect/AsyncAnnotationAspect.java b/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/aspect/AsyncAnnotationAspect.java index 8d0102614..d7ad192be 100644 --- a/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/aspect/AsyncAnnotationAspect.java +++ b/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/aspect/AsyncAnnotationAspect.java @@ -16,6 +16,7 @@ import org.springblade.core.redis.cache.BladeRedis; import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.utils.StringUtil; import org.springblade.core.tool.utils.ThreadLocalUtil; +import org.springframework.core.env.Environment; import org.springframework.http.HttpHeaders; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.scheduling.annotation.Async; @@ -33,6 +34,7 @@ import java.util.Objects; @AllArgsConstructor public class AsyncAnnotationAspect { private final BladeRedis bladeRedis; + private final Environment environment; /** * 定义一个切点,匹配所有带有@Async("asyncExecutor")注解的方法。 * 注意:实际上Spring Framework自带对@Async("asyncExecutor")的处理,直接这样配置可能会导致预期之外的行为。 @@ -94,7 +96,7 @@ public class AsyncAnnotationAspect { String account ="shujutongbu"; JSONObject data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER+account); if(Objects.isNull(data)){ - String url = "http://"+ LauncherConstant.loginAddr(AppConstant.DEV_CODE)+"/blade-auth/oauth/token"; + String url = "http://"+ LauncherConstant.loginAddr(Objects.requireNonNull(environment.getActiveProfiles()[0]))+"/blade-auth/oauth/token"; HttpRequest urlRequest = HttpRequest.post(url); urlRequest.header("Authorization", "Basic c2FiZXI6c2FiZXJfc2VjcmV0"); urlRequest.header("Tenant-Id", "627683"); diff --git a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/aspect/AnnotationAspect.java b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/aspect/AnnotationAspect.java index a5d2c47a0..84cb0a40c 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/aspect/AnnotationAspect.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-jinpai/src/main/java/com/logpm/factorydata/jinpai/aspect/AnnotationAspect.java @@ -14,6 +14,7 @@ import org.springblade.core.launch.constant.AppConstant; import org.springblade.core.redis.cache.BladeRedis; import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.utils.ThreadLocalUtil; +import org.springframework.core.env.Environment; import org.springframework.http.HttpHeaders; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.stereotype.Component; @@ -29,6 +30,7 @@ import java.util.Objects; @AllArgsConstructor public class AnnotationAspect { private final BladeRedis bladeRedis; + private final Environment environment; /** * 该方法为一个切面,用于对标记了@RabbitListener注解的方法进行增强,主要增加了日志记录和数据源上下文处理的功能。 * @@ -90,7 +92,7 @@ public class AnnotationAspect { String account ="shujutongbu"; JSONObject data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER+account); if(Objects.isNull(data)){ - String url = "http://"+ LauncherConstant.loginAddr(AppConstant.DEV_CODE)+"/blade-auth/oauth/token"; + String url = "http://"+ LauncherConstant.loginAddr(Objects.requireNonNull(environment.getActiveProfiles()[0]))+"/blade-auth/oauth/token"; HttpRequest urlRequest = HttpRequest.post(url); urlRequest.header("Authorization", "Basic c2FiZXI6c2FiZXJfc2VjcmV0"); urlRequest.header("Tenant-Id", "627683"); diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/aspect/AsyncAnnotationAspect.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/aspect/AsyncAnnotationAspect.java index 5f9a17674..45f0d23e8 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/aspect/AsyncAnnotationAspect.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/aspect/AsyncAnnotationAspect.java @@ -23,6 +23,7 @@ import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.core.tool.utils.StringUtil; import org.springblade.core.tool.utils.ThreadLocalUtil; +import org.springframework.core.env.Environment; import org.springframework.http.HttpHeaders; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.scheduling.annotation.Async; @@ -41,6 +42,7 @@ import java.util.Objects; @AllArgsConstructor public class AsyncAnnotationAspect { private final BladeRedis bladeRedis; + private final Environment environment; /** * 该方法为一个切面,用于对标记了@RabbitListener注解的方法进行增强,主要增加了日志记录和数据源上下文处理的功能。 * @@ -105,7 +107,7 @@ public class AsyncAnnotationAspect { String account ="shujutongbu"; JSONObject data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER+account); if(Objects.isNull(data)){ - String url = "http://"+ LauncherConstant.loginAddr(AppConstant.DEV_CODE)+"/blade-auth/oauth/token"; + String url = "http://"+ LauncherConstant.loginAddr(Objects.requireNonNull(environment.getActiveProfiles()[0]))+"/blade-auth/oauth/token"; cn.hutool.http.HttpRequest urlRequest = HttpRequest.post(url); urlRequest.header("Authorization", "Basic c2FiZXI6c2FiZXJfc2VjcmV0"); urlRequest.header("Tenant-Id", "627683"); diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/config/InterceptorAdapterConfig.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/config/InterceptorAdapterConfig.java index 2dbc0319d..b29922165 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/config/InterceptorAdapterConfig.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/config/InterceptorAdapterConfig.java @@ -5,21 +5,24 @@ import com.logpm.factory.interceptor.FactoryAccountsInterceptor; import com.logpm.factory.interceptor.LocalServerLoginAccountsInterceptor; import com.logpm.factory.interceptor.ZbFactoryAccountsInterceptor; import com.logpm.factory.props.ZbFactoryProperties; +import lombok.AllArgsConstructor; import org.springblade.core.redis.cache.BladeRedis; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; import org.springframework.web.servlet.config.annotation.InterceptorRegistration; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration +@AllArgsConstructor public class InterceptorAdapterConfig implements WebMvcConfigurer { - @Autowired - IFactoryTokenService factoryTokenService; + private final IFactoryTokenService factoryTokenService; - @Autowired - private BladeRedis redis; + private final BladeRedis redis; + + private final Environment environment; @Override @@ -30,13 +33,7 @@ public class InterceptorAdapterConfig implements WebMvcConfigurer { excludePathPatterns("/factory/oupai/**"). excludePathPatterns("/factory/zb/**") .excludePathPatterns("/factory/common/**"); - registry=interceptorRegistry.addInterceptor(new LocalServerLoginAccountsInterceptor(redis)); -// registry.addPathPatterns("/factory/**"). -// excludePathPatterns("/factory/auth/token"). -// excludePathPatterns("/factory/oupai/**"). -// excludePathPatterns("/factory/zb/**") -// .excludePathPatterns("/factory/common/**"); -// InterceptorRegistration registryZbFactory = interceptorRegistry.addInterceptor(new ZbFactoryAccountsInterceptor(zbFactoryProperties)); -// registryZbFactory.addPathPatterns("/factory/zb/**"); + registry=interceptorRegistry.addInterceptor(new LocalServerLoginAccountsInterceptor(redis,environment)); + } } diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/interceptor/LocalServerLoginAccountsInterceptor.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/interceptor/LocalServerLoginAccountsInterceptor.java index e18d9199e..faed9b869 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/interceptor/LocalServerLoginAccountsInterceptor.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/interceptor/LocalServerLoginAccountsInterceptor.java @@ -19,6 +19,7 @@ import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.StringUtil; import org.springblade.core.tool.utils.ThreadLocalUtil; +import org.springframework.core.env.Environment; import org.springframework.http.HttpHeaders; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; @@ -39,7 +40,7 @@ import java.util.Objects; public class LocalServerLoginAccountsInterceptor extends HandlerInterceptorAdapter { private final BladeRedis bladeRedis; - + private final Environment environment; @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws CustomerException { @@ -49,7 +50,7 @@ public class LocalServerLoginAccountsInterceptor extends HandlerInterceptorAdapt String account ="shujutongbu"; JSONObject data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER+account); if(Objects.isNull(data)){ - String url = "http://"+ LauncherConstant.loginAddr(AppConstant.DEV_CODE)+"/blade-auth/oauth/token"; + String url = "http://"+ LauncherConstant.loginAddr(Objects.requireNonNull(environment.getActiveProfiles()[0]))+"/blade-auth/oauth/token"; cn.hutool.http.HttpRequest urlRequest = HttpRequest.post(url); urlRequest.header("Authorization", "Basic c2FiZXI6c2FiZXJfc2VjcmV0"); urlRequest.header("Tenant-Id", "627683"); diff --git a/blade-service/logpm-patch/src/main/java/com/logpm/patch/aspect/AsyncAnnotationAspect.java b/blade-service/logpm-patch/src/main/java/com/logpm/patch/aspect/AsyncAnnotationAspect.java index 7a1842621..a8e258ba0 100644 --- a/blade-service/logpm-patch/src/main/java/com/logpm/patch/aspect/AsyncAnnotationAspect.java +++ b/blade-service/logpm-patch/src/main/java/com/logpm/patch/aspect/AsyncAnnotationAspect.java @@ -14,6 +14,7 @@ import org.springblade.core.launch.constant.AppConstant; import org.springblade.core.redis.cache.BladeRedis; import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.utils.ThreadLocalUtil; +import org.springframework.core.env.Environment; import org.springframework.http.HttpHeaders; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.stereotype.Component; @@ -29,6 +30,7 @@ import java.util.Objects; @AllArgsConstructor public class AsyncAnnotationAspect { private final BladeRedis bladeRedis; + private final Environment environment; /** * 该方法为一个切面,用于对标记了@RabbitListener注解的方法进行增强,主要增加了日志记录和数据源上下文处理的功能。 * @@ -93,7 +95,7 @@ public class AsyncAnnotationAspect { String account ="shujutongbu"; JSONObject data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER+account); if(Objects.isNull(data)){ - String url = "http://"+ LauncherConstant.loginAddr(AppConstant.DEV_CODE)+"/blade-auth/oauth/token"; + String url = "http://"+ LauncherConstant.loginAddr(Objects.requireNonNull(environment.getActiveProfiles()[0]))+"/blade-auth/oauth/token"; HttpRequest urlRequest = HttpRequest.post(url); urlRequest.header("Authorization", "Basic c2FiZXI6c2FiZXJfc2VjcmV0"); urlRequest.header("Tenant-Id", "627683");