对比新文件 |
| | |
| | | package com.iailab.framework.tenant.core.aop; |
| | | |
| | | import com.iailab.framework.tenant.core.context.TenantContextHolder; |
| | | import com.iailab.framework.tenant.core.util.TenantUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.aspectj.lang.ProceedingJoinPoint; |
| | | import org.aspectj.lang.annotation.Around; |
| | | import org.aspectj.lang.annotation.Aspect; |
| | | |
| | | /** |
| | | * 忽略多租户的 Aspect,基于 {@link TenantIgnore} 注解实现,用于一些全局的逻辑。 |
| | | * 例如说,一个定时任务,读取所有数据,进行处理。 |
| | | * 又例如说,读取所有数据,进行缓存。 |
| | | * |
| | | * 整体逻辑的实现,和 {@link TenantUtils#executeIgnore(Runnable)} 需要保持一致 |
| | | * |
| | | * @author iailab |
| | | */ |
| | | @Aspect |
| | | @Slf4j |
| | | public class TenantIgnoreAspect { |
| | | |
| | | @Around("@annotation(tenantIgnore)") |
| | | public Object around(ProceedingJoinPoint joinPoint, TenantIgnore tenantIgnore) throws Throwable { |
| | | Boolean oldIgnore = TenantContextHolder.isIgnore(); |
| | | try { |
| | | TenantContextHolder.setIgnore(true); |
| | | // 执行逻辑 |
| | | return joinPoint.proceed(); |
| | | } finally { |
| | | TenantContextHolder.setIgnore(oldIgnore); |
| | | } |
| | | } |
| | | |
| | | } |