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"); + } }