From 127a0e59cd21d89bf24f804f4b162dfebc2c710b Mon Sep 17 00:00:00 2001 From: kailin <449073709@qq.com> Date: Sun, 16 Mar 2025 19:48:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=93=E5=90=8E=E7=AB=AF=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E5=A4=9A=E7=A7=9F=E6=88=B7=E5=8A=9F=E8=83=BD=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E7=A7=AF=E6=9C=A8=E6=8A=A5=E8=A1=A8=E6=A8=A1=E5=9D=97=E4=BB=8D?= =?UTF-8?q?=E4=BC=9A=E8=B0=83=E7=94=A8=20TenantContextHolder.setTenantId()?= =?UTF-8?q?=20=E6=96=B9=E6=B3=95=E8=AE=BE=E7=BD=AE=E7=A7=9F=E6=88=B7?= =?UTF-8?q?=E6=A0=87=E8=AF=86=E3=80=82=E8=BF=99=E5=AF=BC=E8=87=B4=20Flowab?= =?UTF-8?q?le=20=E6=A8=A1=E5=9D=97=E5=9C=A8=E8=B0=83=E7=94=A8=20FlowableUt?= =?UTF-8?q?ils.getTenantId()=20=E6=97=B6=E4=BB=8D=E8=83=BD=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=88=B0=E9=9D=9E=E7=A9=BA=E7=9A=84=E7=A7=9F=E6=88=B7?= =?UTF-8?q?=E6=A0=87=E8=AF=86=EF=BC=8C=E4=BB=8E=E8=80=8C=E5=BC=95=E5=8F=91?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E6=B5=81=E4=BF=A1=E6=81=AF=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=EF=BC=88=E5=A6=82=E6=B5=81=E7=A8=8B=E5=AE=9E?= =?UTF-8?q?=E4=BE=8B=E3=80=81=E4=BB=BB=E5=8A=A1=E7=AD=89=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=9C=AA=E6=8C=89=E9=A2=84=E6=9C=9F=E8=BF=87=E6=BB=A4=E6=88=96?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=A4=B1=E8=B4=A5=EF=BC=89=E3=80=82=E6=9C=AC?= =?UTF-8?q?=E6=AC=A1=E6=8F=90=E4=BA=A4=E5=9C=A8=20FlowableUtils.getTenantI?= =?UTF-8?q?d()=20=E6=96=B9=E6=B3=95=E4=B8=AD=E5=A2=9E=E5=8A=A0=E5=A4=9A?= =?UTF-8?q?=E7=A7=9F=E6=88=B7=E5=8A=9F=E8=83=BD=E5=BC=80=E5=85=B3=E7=9A=84?= =?UTF-8?q?=E5=89=8D=E7=BD=AE=E5=88=A4=E6=96=AD=EF=BC=8C=E5=BD=BB=E5=BA=95?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E4=BA=86=E9=9D=9E=E5=BF=85=E8=A6=81=E7=A7=9F?= =?UTF-8?q?=E6=88=B7=E6=A0=87=E8=AF=86=E7=9A=84=E4=BC=A0=E9=80=92=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../flowable/core/util/FlowableUtils.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/FlowableUtils.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/FlowableUtils.java index 67c24bb9f4..2962484a6b 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/FlowableUtils.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/FlowableUtils.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.bpm.framework.flowable.core.util; -import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.core.KeyValue; @@ -24,6 +23,10 @@ import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl; import org.flowable.engine.impl.util.CommandContextUtil; import org.flowable.engine.runtime.ProcessInstance; import org.flowable.task.api.TaskInfo; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; import java.util.HashMap; import java.util.List; @@ -39,7 +42,10 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. * * @author 芋道源码 */ -public class FlowableUtils { +@Component +public class FlowableUtils implements ApplicationContextAware { + + private static Boolean tenantEnabled; // ========== User 相关的工具方法 ========== @@ -63,8 +69,14 @@ public class FlowableUtils { } public static String getTenantId() { - Long tenantId = TenantContextHolder.getTenantId(); - return tenantId != null ? String.valueOf(tenantId) : ProcessEngineConfiguration.NO_TENANT_ID; + if (tenantEnabled == null) { + throw new RuntimeException("tenantEnabled 参数未加载完成"); + } else if (tenantEnabled) { + Long tenantId = TenantContextHolder.getTenantId(); + return tenantId != null ? String.valueOf(tenantId) : ProcessEngineConfiguration.NO_TENANT_ID; + } else { + return ProcessEngineConfiguration.NO_TENANT_ID; + } } public static void execute(String tenantIdStr, Runnable runnable) { @@ -359,4 +371,9 @@ public class FlowableUtils { return getExpressionValue(variableContainer, expressionString); } + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + // yudao.tenant.enable = false时,tenantFrameworkService Bean 不会注入 + tenantEnabled = applicationContext.containsBean("tenantFrameworkService"); + } }