From 72ca05fd2740d4bb44c74c4c5ec82356680e7572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=A2=A6=E6=8A=80=E6=9C=AF?= <596392912@qq.com> Date: Mon, 29 Apr 2024 17:01:27 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E6=B7=BB=E5=8A=A0=20TenantIdUtil?= =?UTF-8?q?=20=E6=96=B9=E4=BE=BF=E5=9C=A8=E9=9D=9E=20web=20=E5=9C=BA?= =?UTF-8?q?=E6=99=AF=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/boot/tenant/TenantIdUtil.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/blade-core-boot/src/main/java/org/springblade/core/boot/tenant/TenantIdUtil.java b/blade-core-boot/src/main/java/org/springblade/core/boot/tenant/TenantIdUtil.java index 8400627..c52f148 100644 --- a/blade-core-boot/src/main/java/org/springblade/core/boot/tenant/TenantIdUtil.java +++ b/blade-core-boot/src/main/java/org/springblade/core/boot/tenant/TenantIdUtil.java @@ -61,4 +61,20 @@ public class TenantIdUtil { } } + /** + * 使用租户 id 执行函数 + * + * @param tenantId tenantId + * @param runnable Runnable + */ + public static void use(String tenantId, Runnable runnable) { + Assert.hasText(tenantId, "参数 tenantId 为空"); + tl.set(tenantId); + try { + runnable.run(); + } finally { + tl.remove(); + } + } + }