From f62f129f5761bc01fbc1f8ca5e5e0c675594e04f Mon Sep 17 00:00:00 2001 From: "pref_mail@163.com" Date: Wed, 8 May 2024 01:32:57 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=E5=A2=9E=E5=8A=A0=E5=B7=A5=E5=8E=82?= =?UTF-8?q?=E6=8B=A6=E6=88=AA=E5=99=A8=20=E9=BB=98=E8=AE=A4=E7=99=BB?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/annotations/LocalServerUser.java | 22 ++++ .../springblade/common/cache/CacheNames.java | 5 + .../common/constant/LauncherConstant.java | 25 +++++ .../common/constant/ModuleNameConstant.java | 2 +- .../common/launch/LauncherServiceImpl.java | 8 +- .../LocalServerTenantIdAnnotationAspect.java | 59 +++++++++++ .../controller/FactoryAuthController.java | 2 + .../controller/FactoryCommonController.java | 1 + .../config/InterceptorAdapterConfig.java | 12 ++- .../factory/filer/HttpServletFilter.java | 6 ++ .../LocalServerLoginAccountsInterceptor.java | 100 ++++++++++++++++++ .../CustomHttpServletRequestWrapper.java | 36 +++++++ .../src/main/resources/application-dev.yml | 8 +- 13 files changed, 276 insertions(+), 10 deletions(-) create mode 100644 blade-biz-common/src/main/java/org/springblade/common/annotations/LocalServerUser.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/aspect/LocalServerTenantIdAnnotationAspect.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/interceptor/LocalServerLoginAccountsInterceptor.java create mode 100644 blade-service/logpm-factory/src/main/java/com/logpm/factory/wrapper/CustomHttpServletRequestWrapper.java diff --git a/blade-biz-common/src/main/java/org/springblade/common/annotations/LocalServerUser.java b/blade-biz-common/src/main/java/org/springblade/common/annotations/LocalServerUser.java new file mode 100644 index 000000000..00f2276be --- /dev/null +++ b/blade-biz-common/src/main/java/org/springblade/common/annotations/LocalServerUser.java @@ -0,0 +1,22 @@ +package org.springblade.common.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 特俗标记 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.METHOD}) +public @interface LocalServerUser { + /**‘ + * 匹配值 + * factory:工厂系统 + * 6278683: 租户 + * factory-data: 租户 + * @return + */ + String ds() default ""; +} diff --git a/blade-biz-common/src/main/java/org/springblade/common/cache/CacheNames.java b/blade-biz-common/src/main/java/org/springblade/common/cache/CacheNames.java index 8fd2da967..b2f1599ab 100644 --- a/blade-biz-common/src/main/java/org/springblade/common/cache/CacheNames.java +++ b/blade-biz-common/src/main/java/org/springblade/common/cache/CacheNames.java @@ -78,4 +78,9 @@ public interface CacheNames { * 用户能操作的仓库 */ String USER_WAREHOUSE_OWN = "logpm:user:warehouse:own:"; + + /** + * 模拟登录缓存对象 + */ + String LOCAL_SERVER_USER = "logpm:user:local:user:"; } 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 fa94f125b..95ab83869 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 @@ -90,6 +90,20 @@ public interface LauncherConstant { */ String SEATA_TEST_ADDR = "192.168.2.110:8091"; + /** + * 本地登录 dev地址 + */ + String APPLICATION_DEV_LOGIN_ADDR = "192.168.5.6:13000"; + /** + * 本地登录 test地址 + */ + String APPLICATION_TEST_LOGIN_ADDR = "192.168.5.6:13000"; + + /** + * 本地登录 pord地址 + */ + String APPLICATION_PROD_LOGIN_ADDR = "192.168.5.6:13000"; + /** * dbuuo提供者 @@ -221,4 +235,15 @@ public interface LauncherConstant { } } + static String loginAddr(String profile) { + switch (profile) { + case (AppConstant.PROD_CODE): + return APPLICATION_DEV_LOGIN_ADDR; + case (AppConstant.TEST_CODE): + return APPLICATION_TEST_LOGIN_ADDR; + default: + return APPLICATION_PROD_LOGIN_ADDR; + } + } + } diff --git a/blade-biz-common/src/main/java/org/springblade/common/constant/ModuleNameConstant.java b/blade-biz-common/src/main/java/org/springblade/common/constant/ModuleNameConstant.java index f3c9d0a48..025046feb 100644 --- a/blade-biz-common/src/main/java/org/springblade/common/constant/ModuleNameConstant.java +++ b/blade-biz-common/src/main/java/org/springblade/common/constant/ModuleNameConstant.java @@ -9,7 +9,7 @@ public interface ModuleNameConstant { /** * 如果不需要 "" */ - public static final String DEVAUTH =""; + public static final String DEVAUTH ="-pref"; /** * 工厂对接服务名称 diff --git a/blade-biz-common/src/main/java/org/springblade/common/launch/LauncherServiceImpl.java b/blade-biz-common/src/main/java/org/springblade/common/launch/LauncherServiceImpl.java index eb7a75c87..23a0734e0 100644 --- a/blade-biz-common/src/main/java/org/springblade/common/launch/LauncherServiceImpl.java +++ b/blade-biz-common/src/main/java/org/springblade/common/launch/LauncherServiceImpl.java @@ -44,10 +44,10 @@ public class LauncherServiceImpl implements LauncherService { PropsUtil.setProperty(props, "spring.cloud.sentinel.transport.dashboard", LauncherConstant.sentinelAddr(profile)); - PropsUtil.setProperty(props, "spring.cloud.nacos.discovery.username","nacos"); - PropsUtil.setProperty(props, "spring.cloud.nacos.discovery.password","Nacos123123"); - PropsUtil.setProperty(props, "spring.cloud.nacos.config.username","nacos"); - PropsUtil.setProperty(props, "spring.cloud.nacos.config.password","Nacos123123"); +// PropsUtil.setProperty(props, "spring.cloud.nacos.discovery.username","nacos"); +// PropsUtil.setProperty(props, "spring.cloud.nacos.discovery.password","Nacos123123"); +// PropsUtil.setProperty(props, "spring.cloud.nacos.config.username","nacos"); +// PropsUtil.setProperty(props, "spring.cloud.nacos.config.password","Nacos123123"); // dubbo注册 PropsUtil.setProperty(props, "dubbo.application.name", appName); PropsUtil.setProperty(props, "dubbo.application.qos.enable", "false"); diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/aspect/LocalServerTenantIdAnnotationAspect.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/aspect/LocalServerTenantIdAnnotationAspect.java new file mode 100644 index 000000000..6e41c6cbb --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/aspect/LocalServerTenantIdAnnotationAspect.java @@ -0,0 +1,59 @@ +//package com.logpm.factory.aspect; +// +//import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; +//import org.aspectj.lang.ProceedingJoinPoint; +//import org.aspectj.lang.annotation.Around; +//import org.aspectj.lang.annotation.Aspect; +//import org.aspectj.lang.reflect.MethodSignature; +//import org.springblade.common.annotations.LocalServerUser; +//import org.springblade.core.secure.BladeUser; +//import org.springblade.core.secure.utils.AuthUtil; +//import org.springblade.core.tool.utils.StringUtil; +//import org.springblade.core.tool.utils.WebUtil; +//import org.springblade.system.cache.UserCache; +//import org.springblade.system.entity.User; +//import org.springframework.core.annotation.Order; +//import org.springframework.scheduling.annotation.Async; +//import org.springframework.stereotype.Component; +// +//import javax.servlet.http.HttpServletRequest; +//import java.lang.reflect.Method; +// +//@Aspect +//@Component +//public class LocalServerTenantIdAnnotationAspect { +// +// +// /** +// * 定义一个切点,匹配所有带有@Async("asyncExecutor")注解的方法。 +// * 注意:实际上Spring Framework自带对@Async("asyncExecutor")的处理,直接这样配置可能会导致预期之外的行为。 +// */ +// +// // 定义一个 +// @Around("@annotation(org.springblade.common.annotations.LocalServerUser)") +// public Object logAroundAsyncMethods(ProceedingJoinPoint joinPoint) throws Throwable { +// +// MethodSignature signature = (MethodSignature) joinPoint.getSignature(); +// Method method = signature.getMethod(); +// +// LocalServerUser myAsync = method.getAnnotation(LocalServerUser.class); +// String annotationValue = myAsync.ds(); +// +// if(StringUtil.isNotBlank(annotationValue) ){ +// // 在方法执行前的操作 +// DynamicDataSourceContextHolder.push(annotationValue); +// +// // 执行原方法 +// Object result = joinPoint.proceed(); +// +// // 在方法执行后的操作 +// DynamicDataSourceContextHolder.poll(); +// +// return result; +// }else{ +// return joinPoint.proceed(); +// } +// +// } +// +//} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/comfac/controller/FactoryAuthController.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/comfac/controller/FactoryAuthController.java index b2a90050a..fd821a727 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/comfac/controller/FactoryAuthController.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/comfac/controller/FactoryAuthController.java @@ -26,6 +26,7 @@ import lombok.AllArgsConstructor; import lombok.extern.log4j.Log4j2; import org.springblade.common.exception.CustomerException; import org.springblade.core.boot.ctrl.BladeController; +import org.springblade.core.tenant.annotation.NonDS; import org.springblade.core.tool.api.R; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -39,6 +40,7 @@ import javax.servlet.http.HttpServletResponse; * @since 2023-06-06 */ @Log4j2 +@NonDS @RestController @AllArgsConstructor @RequestMapping("/factory/auth") diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/comfac/controller/FactoryCommonController.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/comfac/controller/FactoryCommonController.java index 43927134f..ae871ff8c 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/comfac/controller/FactoryCommonController.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/comfac/controller/FactoryCommonController.java @@ -10,6 +10,7 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; import lombok.extern.log4j.Log4j2; +import org.springblade.common.annotations.LocalServerUser; import org.springblade.common.constant.RabbitConstant; import org.springblade.common.exception.CustomerException; import org.springblade.common.utils.CommonUtil; 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 c775cf98a..2dbc0319d 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 @@ -2,8 +2,10 @@ package com.logpm.factory.config; import com.logpm.factory.comfac.service.IFactoryTokenService; 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 org.springblade.core.redis.cache.BladeRedis; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.InterceptorRegistration; @@ -15,8 +17,10 @@ public class InterceptorAdapterConfig implements WebMvcConfigurer { @Autowired IFactoryTokenService factoryTokenService; + @Autowired - ZbFactoryProperties zbFactoryProperties; + private BladeRedis redis; + @Override public void addInterceptors(InterceptorRegistry interceptorRegistry) { @@ -26,6 +30,12 @@ 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/**"); } diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/filer/HttpServletFilter.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/filer/HttpServletFilter.java index e0efd0d83..de486416c 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/filer/HttpServletFilter.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/filer/HttpServletFilter.java @@ -11,8 +11,14 @@ import java.io.IOException; public class HttpServletFilter implements Filter { public void init(FilterConfig filterConfig) throws ServletException { + System.out.println("****************************1"); } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { + + + System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 执行这里"); + + ServletRequest requestWrapper = null; if(request instanceof HttpServletRequest) { requestWrapper = new RequestWrapper((HttpServletRequest) request); 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 new file mode 100644 index 000000000..56863f10d --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/interceptor/LocalServerLoginAccountsInterceptor.java @@ -0,0 +1,100 @@ +package com.logpm.factory.interceptor; + +import cn.hutool.core.map.MapUtil; +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import cn.hutool.http.HttpUtil; +import com.alibaba.fastjson.JSONObject; +import com.logpm.factory.comfac.service.IFactoryTokenService; +import com.logpm.factory.config.RequestWrapper; +import com.logpm.factory.wrapper.CustomHttpServletRequestWrapper; +import lombok.AllArgsConstructor; +import lombok.extern.log4j.Log4j2; +import org.springblade.common.cache.CacheNames; +import org.springblade.common.constant.LauncherConstant; +import org.springblade.common.exception.CustomerException; +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.api.R; +import org.springblade.core.tool.utils.StringUtil; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; +import org.springframework.web.servlet.HandlerInterceptor; +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +@Log4j2 +@AllArgsConstructor +public class LocalServerLoginAccountsInterceptor extends HandlerInterceptorAdapter { + + private final BladeRedis bladeRedis; + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws CustomerException { + + + try { + JSONObject data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER); + CustomHttpServletRequestWrapper wrappedRequest = new CustomHttpServletRequestWrapper(request); + if(Objects.isNull(data)){ + String url = "http://"+ LauncherConstant.loginAddr(AppConstant.DEV_CODE)+"/blade-auth/oauth/token"; + cn.hutool.http.HttpRequest urlRequest = HttpRequest.post(url); + urlRequest.header("Authorization", "Basic c2FiZXI6c2FiZXJfc2VjcmV0"); + urlRequest.header("Tenant-Id", "627683"); + + Map params = new HashMap<>(); + params.put("grant_type", "local_server"); + params.put("scope", "all"); + params.put("username", "admin"); + params.put("tenantId", "627683"); + HttpResponse execute = urlRequest.form(params).execute(); + String body = execute.body(); + data = JSONObject.parseObject(body); + bladeRedis.setEx(CacheNames.LOCAL_SERVER_USER,data,3200L); + } + + // 修改或添加header + + // 发送登录请求 + log.info("##########preHandle: request={}", request); + + wrappedRequest.addHeader("Blade-Auth", "bearer "+data.getString("access_token")); + + // 用包装后的request替换原始request + request = wrappedRequest; + RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request)); + return true; + } catch (Exception e) { + returnJson(response, JSONObject.toJSONString(R.fail(500, "服务异常,请联系管理员"))); + return false; + } + } + + private void returnJson(HttpServletResponse response, String json) { + PrintWriter writer = null; + response.setCharacterEncoding("UTF-8"); + response.setContentType("application/json"); + try { + writer = response.getWriter(); + writer.print(json); + + } catch (IOException e) { + System.out.println(e.getMessage()); + } finally { + if (writer != null) { + writer.close(); + } + } + } + + +} diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/wrapper/CustomHttpServletRequestWrapper.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/wrapper/CustomHttpServletRequestWrapper.java new file mode 100644 index 000000000..82b344eab --- /dev/null +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/wrapper/CustomHttpServletRequestWrapper.java @@ -0,0 +1,36 @@ +package com.logpm.factory.wrapper; + +import org.springframework.http.HttpHeaders; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; +import java.util.*; + +public class CustomHttpServletRequestWrapper extends HttpServletRequestWrapper { + + private final HttpHeaders headers; + + public CustomHttpServletRequestWrapper(HttpServletRequest request) { + super(request); + headers = new HttpHeaders(); + } + + @Override + public String getHeader(String name) { + String headerValue = headers.getFirst(name); + return headerValue != null ? headerValue : super.getHeader(name); + } + + @Override + public Enumeration getHeaderNames() { + List names = Collections.list(super.getHeaderNames()); + headers.forEach((key, value) -> names.add(key)); + return Collections.enumeration(names); + } + + // 其他需要覆盖的方法... + + public void addHeader(String name, String value) { + headers.add(name, value); + } +} diff --git a/blade-service/logpm-old-project/src/main/resources/application-dev.yml b/blade-service/logpm-old-project/src/main/resources/application-dev.yml index 68d1f4215..2b684605a 100644 --- a/blade-service/logpm-old-project/src/main/resources/application-dev.yml +++ b/blade-service/logpm-old-project/src/main/resources/application-dev.yml @@ -34,12 +34,12 @@ spring: url: ${blade.datasource.oldproject.master.url} username: ${blade.datasource.oldproject.master.username} password: ${blade.datasource.oldproject.master.password} - slave: + 627683: druid: #独立校验配置 validation-query: select 1 #oracle校验 #validation-query: select 1 from dual - url: ${blade.datasource.oldproject.slave.url} - username: ${blade.datasource.oldproject.slave.username} - password: ${blade.datasource.oldproject.slave.password} + url: ${blade.datasource.oldproject.627683.url} + username: ${blade.datasource.oldproject.627683.username} + password: ${blade.datasource.oldproject.627683.password} From ef6862d575ee1d24010e350680bcdecbbb55ea8c Mon Sep 17 00:00:00 2001 From: "pref_mail@163.com" Date: Wed, 8 May 2024 15:24:15 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=E5=AE=8C=E5=96=84=E6=A8=A1=E6=8B=9F?= =?UTF-8?q?=E7=99=BB=E9=99=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/constant/LauncherConstant.java | 6 +++--- .../comfac/controller/FactoryCommonController.java | 12 +++++++++++- .../LocalServerLoginAccountsInterceptor.java | 4 ++-- .../factory/mt/mapper/MtFactoryOrderMainMapper.java | 1 + 4 files changed, 17 insertions(+), 6 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 95ab83869..8687a94c6 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 @@ -93,16 +93,16 @@ public interface LauncherConstant { /** * 本地登录 dev地址 */ - String APPLICATION_DEV_LOGIN_ADDR = "192.168.5.6:13000"; + String APPLICATION_DEV_LOGIN_ADDR = "192.168.5.14:13000"; /** * 本地登录 test地址 */ - String APPLICATION_TEST_LOGIN_ADDR = "192.168.5.6:13000"; + String APPLICATION_TEST_LOGIN_ADDR = "192.168.5.14:13000"; /** * 本地登录 pord地址 */ - String APPLICATION_PROD_LOGIN_ADDR = "192.168.5.6:13000"; + String APPLICATION_PROD_LOGIN_ADDR = "192.168.5.14:13000"; /** diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/comfac/controller/FactoryCommonController.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/comfac/controller/FactoryCommonController.java index ae871ff8c..2d8f74865 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/comfac/controller/FactoryCommonController.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/comfac/controller/FactoryCommonController.java @@ -14,14 +14,19 @@ import org.springblade.common.annotations.LocalServerUser; import org.springblade.common.constant.RabbitConstant; import org.springblade.common.exception.CustomerException; import org.springblade.common.utils.CommonUtil; +import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.StringUtil; +import org.springblade.core.tool.utils.WebUtil; import org.springframework.amqp.rabbit.connection.CorrelationData; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; +import javax.servlet.http.HttpServletRequest; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -178,8 +183,13 @@ public class FactoryCommonController { map.put("messageData", receiveInfoDTO); map.put("createTime", new Date().getTime()); map.put("flagType", "OrderStatusLog"); + //将消息携带绑定键值 - rabbitTemplate.convertAndSend(RabbitConstant.UNLOAD_CAR_COM_INFO_EXCHANGE, RabbitConstant.UNLOAD_CAR_COM_INFO_ROUTING, map); + rabbitTemplate.convertAndSend(RabbitConstant.UNLOAD_CAR_COM_INFO_EXCHANGE, RabbitConstant.UNLOAD_CAR_COM_INFO_ROUTING, map,message -> { + HttpServletRequest request = WebUtil.getRequest(); + message.getMessageProperties().setHeader("Blade-Auth",request.getHeader("Blade-Auth")); + return message; + }); return R.success("调用成功"); } catch (CustomerException e) { 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 56863f10d..d602b0a44 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 @@ -43,7 +43,7 @@ public class LocalServerLoginAccountsInterceptor extends HandlerInterceptorAdapt try { - JSONObject data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER); + JSONObject data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER+"admin"); CustomHttpServletRequestWrapper wrappedRequest = new CustomHttpServletRequestWrapper(request); if(Objects.isNull(data)){ String url = "http://"+ LauncherConstant.loginAddr(AppConstant.DEV_CODE)+"/blade-auth/oauth/token"; @@ -59,7 +59,7 @@ public class LocalServerLoginAccountsInterceptor extends HandlerInterceptorAdapt HttpResponse execute = urlRequest.form(params).execute(); String body = execute.body(); data = JSONObject.parseObject(body); - bladeRedis.setEx(CacheNames.LOCAL_SERVER_USER,data,3200L); + bladeRedis.setEx(CacheNames.LOCAL_SERVER_USER+"admin",data,3200L); } // 修改或添加header diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/mt/mapper/MtFactoryOrderMainMapper.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/mt/mapper/MtFactoryOrderMainMapper.java index 4d0573c5c..f115e5530 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/mt/mapper/MtFactoryOrderMainMapper.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/mt/mapper/MtFactoryOrderMainMapper.java @@ -1,5 +1,6 @@ package com.logpm.factory.mt.mapper; +import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.logpm.factory.mt.entity.MtFactoryOrderMain;