当后端关闭多租户功能时,积木报表模块仍会调用 TenantContextHolder.setTenantId() 方法设置租户标识。这导致 Flowable 模块在调用 FlowableUtils.getTenantId() 时仍能获取到非空的租户标识,从而引发工作流信息查询异常(如流程实例、任务等数据未按预期过滤或查询失败)。本次提交在 FlowableUtils.getTenantId() 方法中增加多租户功能开关的前置判断,彻底避免了非必要租户标识的传递。

This commit is contained in:
kailin 2025-03-16 19:48:50 +08:00
parent ba1e4f36b6
commit 127a0e59cd
1 changed files with 21 additions and 4 deletions

View File

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