Browse Source

Merge branch 'pref_0934' into dev

dist.1.3.0
pref_mail@163.com 9 months ago
parent
commit
6e7b1d696d
  1. 22
      blade-biz-common/src/main/java/org/springblade/common/annotations/LocalServerUser.java
  2. 5
      blade-biz-common/src/main/java/org/springblade/common/cache/CacheNames.java
  3. 25
      blade-biz-common/src/main/java/org/springblade/common/constant/LauncherConstant.java
  4. 2
      blade-biz-common/src/main/java/org/springblade/common/constant/ModuleNameConstant.java
  5. 8
      blade-biz-common/src/main/java/org/springblade/common/launch/LauncherServiceImpl.java
  6. 59
      blade-service/logpm-factory/src/main/java/com/logpm/factory/aspect/LocalServerTenantIdAnnotationAspect.java
  7. 2
      blade-service/logpm-factory/src/main/java/com/logpm/factory/comfac/controller/FactoryAuthController.java
  8. 13
      blade-service/logpm-factory/src/main/java/com/logpm/factory/comfac/controller/FactoryCommonController.java
  9. 12
      blade-service/logpm-factory/src/main/java/com/logpm/factory/config/InterceptorAdapterConfig.java
  10. 6
      blade-service/logpm-factory/src/main/java/com/logpm/factory/filer/HttpServletFilter.java
  11. 100
      blade-service/logpm-factory/src/main/java/com/logpm/factory/interceptor/LocalServerLoginAccountsInterceptor.java
  12. 1
      blade-service/logpm-factory/src/main/java/com/logpm/factory/mt/mapper/MtFactoryOrderMainMapper.java
  13. 36
      blade-service/logpm-factory/src/main/java/com/logpm/factory/wrapper/CustomHttpServletRequestWrapper.java
  14. 8
      blade-service/logpm-old-project/src/main/resources/application-dev.yml

22
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 "";
}

5
blade-biz-common/src/main/java/org/springblade/common/cache/CacheNames.java vendored

@ -78,4 +78,9 @@ public interface CacheNames {
* 用户能操作的仓库
*/
String USER_WAREHOUSE_OWN = "logpm:user:warehouse:own:";
/**
* 模拟登录缓存对象
*/
String LOCAL_SERVER_USER = "logpm:user:local:user:";
}

25
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.14:13000";
/**
* 本地登录 test地址
*/
String APPLICATION_TEST_LOGIN_ADDR = "192.168.5.14:13000";
/**
* 本地登录 pord地址
*/
String APPLICATION_PROD_LOGIN_ADDR = "192.168.5.14: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;
}
}
}

2
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";
/**
* 工厂对接服务名称

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

59
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();
// }
//
// }
//
//}

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

13
blade-service/logpm-factory/src/main/java/com/logpm/factory/comfac/controller/FactoryCommonController.java

@ -10,17 +10,23 @@ 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;
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;
@ -177,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) {

12
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/**");
}

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

100
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+"admin");
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<String, Object> 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+"admin",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();
}
}
}
}

1
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;

36
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<String> getHeaderNames() {
List<String> 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);
}
}

8
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}

Loading…
Cancel
Save