添加 TenantIdUtil 方便在非 web 场景使用

This commit is contained in:
卢春梦 2024-04-29 17:01:27 +08:00
parent 78dea9b212
commit 72ca05fd27
1 changed files with 16 additions and 0 deletions

View File

@ -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();
}
}
}