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");