浏览代码

add
mqtt信息发送

lifang 4 周之前
父节点
当前提交
4bf38e6600

+ 36 - 0
nb-common/config-common/src/main/java/com/nb/common/config/aspect/TenantIgnoreAspect.java

@@ -0,0 +1,36 @@
+package com.nb.common.config.aspect;
+
+import com.nb.common.config.annotation.TenantIgnore;
+import com.nb.common.config.context.TenantContextHolder;
+import lombok.extern.slf4j.Slf4j;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.springframework.stereotype.Component;
+
+/**
+ * 忽略多租户的 Aspect,基于 {@link TenantIgnore} 注解实现,用于一些全局的逻辑。
+ * 例如说,一个定时任务,读取所有数据,进行处理。
+ * 又例如说,读取所有数据,进行缓存。
+ *
+ *
+ * @author tr
+ */
+@Aspect
+@Slf4j
+@Component
+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(Boolean.TRUE.equals(oldIgnore));
+        }
+    }
+
+}