Commit d36c0dce7cf24514dd7484f7b9e1a05afd5e2ff8

Authored by YunaiV
1 parent 51859afa

fix:【BPM 工作流】BPMN 场景下,多次提醒可能丢失 elementId 的问题

yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/listener/BpmTaskEventListener.java
@@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.bpm.framework.flowable.core.listener; @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.bpm.framework.flowable.core.listener;
3 import cn.hutool.core.collection.CollUtil; 3 import cn.hutool.core.collection.CollUtil;
4 import cn.hutool.core.util.ObjectUtil; 4 import cn.hutool.core.util.ObjectUtil;
5 import cn.hutool.core.util.StrUtil; 5 import cn.hutool.core.util.StrUtil;
  6 +import cn.hutool.json.JSONObject;
6 import cn.iocoder.yudao.framework.common.util.number.NumberUtils; 7 import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
7 import cn.iocoder.yudao.module.bpm.enums.definition.BpmBoundaryEventTypeEnum; 8 import cn.iocoder.yudao.module.bpm.enums.definition.BpmBoundaryEventTypeEnum;
8 import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants; 9 import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants;
@@ -98,6 +99,23 @@ public class BpmTaskEventListener extends AbstractFlowableEngineEventListener { @@ -98,6 +99,23 @@ public class BpmTaskEventListener extends AbstractFlowableEngineEventListener {
98 String processDefinitionId = event.getProcessDefinitionId(); 99 String processDefinitionId = event.getProcessDefinitionId();
99 BpmnModel bpmnModel = modelService.getBpmnModelByDefinitionId(processDefinitionId); 100 BpmnModel bpmnModel = modelService.getBpmnModelByDefinitionId(processDefinitionId);
100 Job entity = (Job) event.getEntity(); 101 Job entity = (Job) event.getEntity();
  102 + // 特殊 from https://t.zsxq.com/h6oWr :当 elementId 为空时,尝试从 JobHandlerConfiguration 中解析 JSON 获取
  103 + String elementId = entity.getElementId();
  104 + if (elementId == null && entity.getJobHandlerConfiguration() != null) {
  105 + try {
  106 + String handlerConfig = entity.getJobHandlerConfiguration();
  107 + if (handlerConfig.startsWith("{") && handlerConfig.contains("activityId")) {
  108 + elementId = new JSONObject(handlerConfig).getStr("activityId");
  109 + }
  110 + } catch (Exception e) {
  111 + log.error("[timerFired][解析 entity({}) 失败]", entity, e);
  112 + return;
  113 + }
  114 + }
  115 + if (elementId == null) {
  116 + log.error("[timerFired][解析 entity({}) elementId 为空,跳过处理]", entity);
  117 + return;
  118 + }
101 FlowElement element = BpmnModelUtils.getFlowElementById(bpmnModel, entity.getElementId()); 119 FlowElement element = BpmnModelUtils.getFlowElementById(bpmnModel, entity.getElementId());
102 if (!(element instanceof BoundaryEvent)) { 120 if (!(element instanceof BoundaryEvent)) {
103 return; 121 return;