From b0476558081c93bcbbdfca67c74351aef9b20581 Mon Sep 17 00:00:00 2001 From: xiwa Date: Sun, 7 Jan 2024 18:56:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=94=AF=E6=8C=81=E7=A7=9F=E6=88=B7?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iotkit/swagger/config/SwaggerConfig.java | 45 ------------------- .../tenant/aspect/TenantFilterAspect.java | 6 +++ .../iotkit/common/tenant/dao/TenantAware.java | 2 + .../tenant/listener/TenantListener.java | 8 +++- 4 files changed, 15 insertions(+), 46 deletions(-) diff --git a/iot-common-doc/src/main/java/cc/iotkit/swagger/config/SwaggerConfig.java b/iot-common-doc/src/main/java/cc/iotkit/swagger/config/SwaggerConfig.java index ad57d23..8624b71 100755 --- a/iot-common-doc/src/main/java/cc/iotkit/swagger/config/SwaggerConfig.java +++ b/iot-common-doc/src/main/java/cc/iotkit/swagger/config/SwaggerConfig.java @@ -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> allEndpoints = new ArrayList<>(); -// Collection 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)); -// } } diff --git a/iot-common-tenant/src/main/java/cc/iotkit/common/tenant/aspect/TenantFilterAspect.java b/iot-common-tenant/src/main/java/cc/iotkit/common/tenant/aspect/TenantFilterAspect.java index 8bb0339..a911cd8 100755 --- a/iot-common-tenant/src/main/java/cc/iotkit/common/tenant/aspect/TenantFilterAspect.java +++ b/iot-common-tenant/src/main/java/cc/iotkit/common/tenant/aspect/TenantFilterAspect.java @@ -2,6 +2,8 @@ package cc.iotkit.common.tenant.aspect; 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.Aspect; import org.aspectj.lang.annotation.Pointcut; @@ -25,6 +27,10 @@ public class TenantFilterAspect { public void afterOpenSession(Object session) { if (session instanceof Session) { String tenantId = LoginHelper.getTenantId(); + String dynamic = TenantHelper.getDynamic(); + if (StringUtils.isNotBlank(dynamic)) { + tenantId = dynamic; + } if (tenantId != null && !tenantId.equals("000000")) { org.hibernate.Filter filter = ((Session) session).enableFilter("tenantFilter"); filter.setParameter("tenantId", tenantId); diff --git a/iot-common-tenant/src/main/java/cc/iotkit/common/tenant/dao/TenantAware.java b/iot-common-tenant/src/main/java/cc/iotkit/common/tenant/dao/TenantAware.java index 3c5d57c..bde1444 100755 --- a/iot-common-tenant/src/main/java/cc/iotkit/common/tenant/dao/TenantAware.java +++ b/iot-common-tenant/src/main/java/cc/iotkit/common/tenant/dao/TenantAware.java @@ -2,5 +2,7 @@ package cc.iotkit.common.tenant.dao; public interface TenantAware { + void setTenantId(String tenantId); + } diff --git a/iot-common-tenant/src/main/java/cc/iotkit/common/tenant/listener/TenantListener.java b/iot-common-tenant/src/main/java/cc/iotkit/common/tenant/listener/TenantListener.java index eb48098..60fcd34 100755 --- a/iot-common-tenant/src/main/java/cc/iotkit/common/tenant/listener/TenantListener.java +++ b/iot-common-tenant/src/main/java/cc/iotkit/common/tenant/listener/TenantListener.java @@ -3,6 +3,8 @@ package cc.iotkit.common.tenant.listener; import cc.iotkit.common.satoken.utils.LoginHelper; 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 javax.persistence.PrePersist; @@ -23,7 +25,11 @@ public class TenantListener { @PreRemove @PrePersist 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) { entity.setTenantId(tenantId); }