feat(RDMP-3845) - 调整 MQ 广播事件中的流程变量输出,过滤一些对业务无关紧要的数据

This commit is contained in:
wangli 2025-11-21 13:34:17 +08:00
parent 4694ed6280
commit c9acc9cad8

View File

@ -7,10 +7,9 @@ import org.slf4j.MDC;
import org.springframework.util.StringUtils;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
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;
@ -52,29 +51,21 @@ public abstract class AbstractBpmnEventListener<T extends OperationContext> impl
}
public static Map<String, Object> removeBpmnConstantsVariables(Map<String, Object> originVariables) {
// 定义多个正则表达式规则
List<String> regexPatterns = Arrays.asList(
"^" + BpmnConstants.INTERNAL_TASK_RELATION_ASSIGNEE_INFO, // "" 开头
"^" + BpmnConstants.INTERNAL_ACTIVITY_RELATION_ASSIGNEE_LIST_INFO_SNAPSHOT,
"^" + BpmnConstants.TASK_COMPLETE_OPERATION_TYPE,
"^" + BpmnConstants.INTERNAL_TASK_RELATION_ASSIGNEE_LIST_INFO,
"_old$", // "_old" 结尾
"deprecated|obsolete" // 包含 "deprecated" "obsolete"
if (originVariables == null) return new HashMap<>();
// 定义需要移除的前缀列表
List<String> prefixesToRemove = Arrays.asList(
BpmnConstants.INTERNAL_TASK_RELATION_ASSIGNEE_INFO,
BpmnConstants.INTERNAL_ACTIVITY_RELATION_ASSIGNEE_LIST_INFO_SNAPSHOT,
BpmnConstants.TASK_COMPLETE_OPERATION_TYPE,
BpmnConstants.INTERNAL_TASK_RELATION_ASSIGNEE_LIST_INFO
);
// 预编译正则表达式提升性能
List<Pattern> patterns = regexPatterns.stream()
.map(Pattern::compile)
.collect(Collectors.toList());
// 使用 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;
return originVariables.entrySet().stream()
.filter(entry -> entry.getKey() != null)
// 核心修改检查 key 是否以任一前缀开头
.filter(entry -> prefixesToRemove.stream()
.noneMatch(prefix -> entry.getKey().startsWith(prefix)))
.collect(HashMap::new, (m, e) -> m.put(e.getKey(), e.getValue()), HashMap::putAll);
}
}