feat:支持租户动态切换
parent
0475f00826
commit
b047655808
|
@ -82,49 +82,4 @@ public class SwaggerConfig {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * 解决springboot升级到2.6.x之后,knife4j报错
|
|
||||||
// *
|
|
||||||
// * @param webEndpointsSupplier the web endpoints supplier
|
|
||||||
// * @param servletEndpointsSupplier the servlet endpoints supplier
|
|
||||||
// * @param controllerEndpointsSupplier the controller endpoints supplier
|
|
||||||
// * @param endpointMediaTypes the endpoint media types
|
|
||||||
// * @param corsProperties the cors properties
|
|
||||||
// * @param webEndpointProperties the web endpoint properties
|
|
||||||
// * @param environment the environment
|
|
||||||
// * @return the web mvc endpoint handler mapping
|
|
||||||
// */
|
|
||||||
// @Bean
|
|
||||||
// public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(
|
|
||||||
// WebEndpointsSupplier webEndpointsSupplier, ServletEndpointsSupplier servletEndpointsSupplier,
|
|
||||||
// ControllerEndpointsSupplier controllerEndpointsSupplier, EndpointMediaTypes endpointMediaTypes,
|
|
||||||
// CorsEndpointProperties corsProperties, WebEndpointProperties webEndpointProperties,
|
|
||||||
// Environment environment) {
|
|
||||||
// List<ExposableEndpoint<?>> allEndpoints = new ArrayList<>();
|
|
||||||
// Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints();
|
|
||||||
// allEndpoints.addAll(webEndpoints);
|
|
||||||
// allEndpoints.addAll(servletEndpointsSupplier.getEndpoints());
|
|
||||||
// allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
|
|
||||||
// String basePath = webEndpointProperties.getBasePath();
|
|
||||||
// EndpointMapping endpointMapping = new EndpointMapping(basePath);
|
|
||||||
// boolean shouldRegisterLinksMapping = shouldRegisterLinksMapping(webEndpointProperties,
|
|
||||||
// environment, basePath);
|
|
||||||
// return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes,
|
|
||||||
// corsProperties.toCorsConfiguration(), new EndpointLinksResolver(allEndpoints, basePath),
|
|
||||||
// shouldRegisterLinksMapping, null);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * shouldRegisterLinksMapping
|
|
||||||
// * @param webEndpointProperties webEndpointProperties
|
|
||||||
// * @param environment environment
|
|
||||||
// * @param basePath /
|
|
||||||
// * @return boolean
|
|
||||||
// */
|
|
||||||
// private boolean shouldRegisterLinksMapping(WebEndpointProperties webEndpointProperties,
|
|
||||||
// Environment environment, String basePath) {
|
|
||||||
// return webEndpointProperties.getDiscovery().isEnabled() && (StringUtils.hasText(basePath)
|
|
||||||
// || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT));
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@ package cc.iotkit.common.tenant.aspect;
|
||||||
|
|
||||||
|
|
||||||
import cc.iotkit.common.satoken.utils.LoginHelper;
|
import cc.iotkit.common.satoken.utils.LoginHelper;
|
||||||
|
import cc.iotkit.common.tenant.helper.TenantHelper;
|
||||||
|
import cc.iotkit.common.utils.StringUtils;
|
||||||
import org.aspectj.lang.annotation.AfterReturning;
|
import org.aspectj.lang.annotation.AfterReturning;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.aspectj.lang.annotation.Pointcut;
|
import org.aspectj.lang.annotation.Pointcut;
|
||||||
|
@ -25,6 +27,10 @@ public class TenantFilterAspect {
|
||||||
public void afterOpenSession(Object session) {
|
public void afterOpenSession(Object session) {
|
||||||
if (session instanceof Session) {
|
if (session instanceof Session) {
|
||||||
String tenantId = LoginHelper.getTenantId();
|
String tenantId = LoginHelper.getTenantId();
|
||||||
|
String dynamic = TenantHelper.getDynamic();
|
||||||
|
if (StringUtils.isNotBlank(dynamic)) {
|
||||||
|
tenantId = dynamic;
|
||||||
|
}
|
||||||
if (tenantId != null && !tenantId.equals("000000")) {
|
if (tenantId != null && !tenantId.equals("000000")) {
|
||||||
org.hibernate.Filter filter = ((Session) session).enableFilter("tenantFilter");
|
org.hibernate.Filter filter = ((Session) session).enableFilter("tenantFilter");
|
||||||
filter.setParameter("tenantId", tenantId);
|
filter.setParameter("tenantId", tenantId);
|
||||||
|
|
|
@ -2,5 +2,7 @@ package cc.iotkit.common.tenant.dao;
|
||||||
|
|
||||||
|
|
||||||
public interface TenantAware {
|
public interface TenantAware {
|
||||||
|
|
||||||
void setTenantId(String tenantId);
|
void setTenantId(String tenantId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ package cc.iotkit.common.tenant.listener;
|
||||||
|
|
||||||
import cc.iotkit.common.satoken.utils.LoginHelper;
|
import cc.iotkit.common.satoken.utils.LoginHelper;
|
||||||
import cc.iotkit.common.tenant.dao.TenantAware;
|
import cc.iotkit.common.tenant.dao.TenantAware;
|
||||||
|
import cc.iotkit.common.tenant.helper.TenantHelper;
|
||||||
|
import cc.iotkit.common.utils.StringUtils;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import javax.persistence.PrePersist;
|
import javax.persistence.PrePersist;
|
||||||
|
@ -23,7 +25,11 @@ public class TenantListener {
|
||||||
@PreRemove
|
@PreRemove
|
||||||
@PrePersist
|
@PrePersist
|
||||||
public void setTenant(TenantAware entity) {
|
public void setTenant(TenantAware entity) {
|
||||||
final String tenantId = LoginHelper.getTenantId();
|
String tenantId = LoginHelper.getTenantId();
|
||||||
|
String dynamic = TenantHelper.getDynamic();
|
||||||
|
if (StringUtils.isNotBlank(dynamic)) {
|
||||||
|
tenantId = dynamic;
|
||||||
|
}
|
||||||
if (!"000000".equals(tenantId) && tenantId != null) {
|
if (!"000000".equals(tenantId) && tenantId != null) {
|
||||||
entity.setTenantId(tenantId);
|
entity.setTenantId(tenantId);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue