package com.qianwen.core.tenant.dynamic; import com.baomidou.dynamic.datasource.aop.DynamicDataSourceAnnotationInterceptor; import com.baomidou.dynamic.datasource.processor.DsProcessor; import org.aopalliance.intercept.MethodInvocation; import com.qianwen.core.secure.utils.AuthUtil; import com.qianwen.core.tenant.exception.TenantDataSourceException; public class TenantDataSourceAnnotationInterceptor extends DynamicDataSourceAnnotationInterceptor { private TenantDataSourceHolder holder; public void setHolder(final TenantDataSourceHolder holder) { this.holder = holder; } public TenantDataSourceAnnotationInterceptor(Boolean allowedPublicOnly, DsProcessor dsProcessor) { super(allowedPublicOnly, dsProcessor); } public Object invoke(MethodInvocation invocation) throws Throwable { try { this.holder.handleDataSource(AuthUtil.getTenantId()); return super.invoke(invocation); } catch (Exception exception) { throw new TenantDataSourceException(exception.getMessage()); } } }