Merge branch 'feature/RDMP-3845' into test

# Conflicts:
#	workflow-engine-core/src/main/java/cn/axzo/workflow/core/listener/AbstractBpmnEventListener.java
This commit is contained in:
wangli 2025-12-03 14:19:55 +08:00
commit 2bd392b424

View File

@ -1,14 +1,16 @@
package cn.axzo.workflow.core.listener; package cn.axzo.workflow.core.listener;
import cn.axzo.workflow.common.constant.BpmnConstants; import cn.axzo.workflow.common.constant.BpmnConstants;
import cn.axzo.workflow.core.common.context.OperationContext; import cn.axzo.workflow.core.common.context.OperationContext;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import org.slf4j.MDC; import org.slf4j.MDC;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import static cn.azxo.framework.common.constatns.Constants.CTX_LOG_ID_MDC; import static cn.azxo.framework.common.constatns.Constants.CTX_LOG_ID_MDC;
/** /**
@ -48,30 +50,29 @@ public abstract class AbstractBpmnEventListener<T extends OperationContext> impl
return processDefinitionId.split(":")[0]; return processDefinitionId.split(":")[0];
} }
/**
* 移除一些业务不需要关心的变量
*
* @param originVariables
* @return
*/
public static Map<String, Object> removeBpmnConstantsVariables(Map<String, Object> originVariables) { public static Map<String, Object> removeBpmnConstantsVariables(Map<String, Object> originVariables) {
// 定义多个正则表达式规则 if (originVariables == null) return new HashMap<>();
List<String> regexPatterns = Arrays.asList(
"^" + BpmnConstants.INTERNAL_TASK_RELATION_ASSIGNEE_INFO, // "" 开头 // 定义需要移除的前缀列表
"^" + BpmnConstants.INTERNAL_ACTIVITY_RELATION_ASSIGNEE_LIST_INFO_SNAPSHOT, List<String> prefixesToRemove = Arrays.asList(
"^" + BpmnConstants.TASK_COMPLETE_OPERATION_TYPE, BpmnConstants.INTERNAL_TASK_RELATION_ASSIGNEE_INFO,
"^" + BpmnConstants.INTERNAL_TASK_RELATION_ASSIGNEE_LIST_INFO, BpmnConstants.INTERNAL_ACTIVITY_RELATION_ASSIGNEE_LIST_INFO_SNAPSHOT,
"_old$", // "_old" 结尾 BpmnConstants.TASK_COMPLETE_OPERATION_TYPE,
"deprecated|obsolete" // 包含 "deprecated" "obsolete" BpmnConstants.INTERNAL_TASK_RELATION_ASSIGNEE_LIST_INFO
); );
// 预编译正则表达式提升性能 return originVariables.entrySet().stream()
List<Pattern> patterns = regexPatterns.stream() .filter(entry -> entry.getKey() != null)
.map(Pattern::compile) // 核心修改检查 key 是否以任一前缀开头
.collect(Collectors.toList()); .filter(entry -> prefixesToRemove.stream()
.noneMatch(prefix -> entry.getKey().startsWith(prefix)))
.collect(HashMap::new, (m, e) -> m.put(e.getKey(), e.getValue()), HashMap::putAll);
}
// 使用 Stream API 和正则进行过滤
Map<String, Object> filteredMap = originVariables.entrySet().stream()
.filter(entry -> patterns.stream()
.noneMatch(pattern -> pattern.matcher(entry.getKey()).find()))
.collect(Collectors.toMap(
Map.Entry::getKey,
Map.Entry::getValue
));
return filteredMap;
}
} }