Commit b2d81e076395290924018af7ce82e241ecf42cb9
1 parent
71b86e62
fix: 通过FixedValue属性方式获取监听器扩展字段
Showing
2 changed files
with
18 additions
and
32 deletions
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/BpmnModelUtils.java
| ... | ... | @@ -23,6 +23,7 @@ import org.flowable.bpmn.model.Process; |
| 23 | 23 | import org.flowable.bpmn.model.*; |
| 24 | 24 | import org.flowable.common.engine.api.FlowableException; |
| 25 | 25 | import org.flowable.common.engine.impl.util.io.BytesStreamSource; |
| 26 | +import org.flowable.engine.impl.el.FixedValue; | |
| 26 | 27 | |
| 27 | 28 | import java.util.*; |
| 28 | 29 | |
| ... | ... | @@ -370,12 +371,10 @@ public class BpmnModelUtils { |
| 370 | 371 | flowableListener.getFieldExtensions().add(fieldExtension); |
| 371 | 372 | } |
| 372 | 373 | |
| 373 | - public static BpmSimpleModelNodeVO.ListenerHandler parseListenerConfig(FlowableListener flowableListener) { | |
| 374 | - FieldExtension fieldExtension = flowableListener.getFieldExtensions().stream() | |
| 375 | - .filter(item -> item.getFieldName().equals("listenerConfig")) | |
| 376 | - .findFirst().orElse(null); | |
| 377 | - Assert.notNull(fieldExtension, "监听器扩展字段({})不能为空", fieldExtension); | |
| 378 | - return JsonUtils.parseObject(fieldExtension.getStringValue(), BpmSimpleModelNodeVO.ListenerHandler.class); | |
| 374 | + public static BpmSimpleModelNodeVO.ListenerHandler parseListenerConfig(FixedValue fixedValue) { | |
| 375 | + String expressionText = fixedValue.getExpressionText(); | |
| 376 | + Assert.notNull(expressionText, "监听器扩展字段({})不能为空", expressionText); | |
| 377 | + return JsonUtils.parseObject(expressionText, BpmSimpleModelNodeVO.ListenerHandler.class); | |
| 379 | 378 | } |
| 380 | 379 | |
| 381 | 380 | // ========== BPM 简单查找相关的方法 ========== | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/listener/BpmUserTaskListener.java
| 1 | 1 | package cn.iocoder.yudao.module.bpm.service.task.listener; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | -import cn.hutool.core.lang.Assert; | |
| 5 | 4 | import cn.hutool.core.util.StrUtil; |
| 6 | 5 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO; |
| 7 | 6 | import cn.iocoder.yudao.module.bpm.enums.definition.BpmListenerParamTypeEnum; |
| 8 | -import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils; | |
| 9 | -import cn.iocoder.yudao.module.bpm.service.definition.BpmModelService; | |
| 10 | 7 | import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService; |
| 11 | 8 | import jakarta.annotation.Resource; |
| 9 | +import lombok.Setter; | |
| 12 | 10 | import lombok.extern.slf4j.Slf4j; |
| 13 | -import org.flowable.bpmn.model.BpmnModel; | |
| 14 | -import org.flowable.bpmn.model.FlowableListener; | |
| 15 | -import org.flowable.bpmn.model.UserTask; | |
| 16 | 11 | import org.flowable.engine.delegate.TaskListener; |
| 17 | 12 | import org.flowable.engine.history.HistoricProcessInstance; |
| 13 | +import org.flowable.engine.impl.el.FixedValue; | |
| 18 | 14 | import org.flowable.task.service.delegate.DelegateTask; |
| 15 | +import org.springframework.context.annotation.Scope; | |
| 19 | 16 | import org.springframework.http.HttpEntity; |
| 20 | 17 | import org.springframework.http.HttpMethod; |
| 21 | 18 | import org.springframework.http.ResponseEntity; |
| ... | ... | @@ -38,34 +35,32 @@ import static cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModel |
| 38 | 35 | */ |
| 39 | 36 | @Component |
| 40 | 37 | @Slf4j |
| 38 | +@Scope("prototype") | |
| 41 | 39 | public class BpmUserTaskListener implements TaskListener { |
| 42 | 40 | |
| 43 | 41 | public static final String DELEGATE_EXPRESSION = "${bpmUserTaskListener}"; |
| 44 | 42 | |
| 45 | 43 | @Resource |
| 46 | - private BpmModelService modelService; | |
| 47 | - | |
| 48 | - @Resource | |
| 49 | 44 | private BpmProcessInstanceService processInstanceService; |
| 50 | 45 | |
| 51 | 46 | @Resource |
| 52 | 47 | private RestTemplate restTemplate; |
| 53 | 48 | |
| 49 | + @Setter | |
| 50 | + private FixedValue listenerConfig; | |
| 51 | + | |
| 54 | 52 | @Override |
| 55 | 53 | public void notify(DelegateTask delegateTask) { |
| 56 | 54 | // 1. 获取所需基础信息 |
| 57 | 55 | HistoricProcessInstance processInstance = processInstanceService.getHistoricProcessInstance(delegateTask.getProcessInstanceId()); |
| 58 | - BpmnModel bpmnModel = modelService.getBpmnModelByDefinitionId(delegateTask.getProcessDefinitionId()); | |
| 59 | - UserTask userTask = (UserTask) BpmnModelUtils.getFlowElementById(bpmnModel, delegateTask.getTaskDefinitionKey()); | |
| 60 | - BpmSimpleModelNodeVO.ListenerHandler listenerHandler = getListenerHandlerByEvent(delegateTask.getEventName(), | |
| 61 | - userTask.getTaskListeners()); | |
| 56 | + BpmSimpleModelNodeVO.ListenerHandler listenerHandler = parseListenerConfig(listenerConfig); | |
| 62 | 57 | |
| 63 | 58 | // 2. 获取请求头和请求体 |
| 64 | 59 | Map<String, Object> processVariables = processInstance.getProcessVariables(); |
| 65 | 60 | MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); |
| 66 | 61 | MultiValueMap<String, String> body = new LinkedMultiValueMap<>(); |
| 67 | - parseListenerMap(listenerHandler.getHeader(), processVariables, headers); | |
| 68 | - parseListenerMap(listenerHandler.getBody(), processVariables, body); | |
| 62 | + parseListenerParam(listenerHandler.getHeader(), processVariables, headers); | |
| 63 | + parseListenerParam(listenerHandler.getBody(), processVariables, body); | |
| 69 | 64 | // 2.1 请求头默认参数 |
| 70 | 65 | if (StrUtil.isNotEmpty(delegateTask.getTenantId())) { |
| 71 | 66 | headers.add(HEADER_TENANT_ID, delegateTask.getTenantId()); |
| ... | ... | @@ -100,9 +95,9 @@ public class BpmUserTaskListener implements TaskListener { |
| 100 | 95 | // 4. 是否需要后续操作?TODO 芋艿:待定! |
| 101 | 96 | } |
| 102 | 97 | |
| 103 | - private void parseListenerMap(List<BpmSimpleModelNodeVO.ListenerHandler.ListenerParam> list, | |
| 104 | - Map<String, Object> processVariables, | |
| 105 | - MultiValueMap<String, String> to) { | |
| 98 | + private void parseListenerParam(List<BpmSimpleModelNodeVO.ListenerHandler.ListenerParam> list, | |
| 99 | + Map<String, Object> processVariables, | |
| 100 | + MultiValueMap<String, String> to) { | |
| 106 | 101 | if (CollUtil.isEmpty(list)) { |
| 107 | 102 | return; |
| 108 | 103 | } |
| ... | ... | @@ -115,12 +110,4 @@ public class BpmUserTaskListener implements TaskListener { |
| 115 | 110 | }); |
| 116 | 111 | } |
| 117 | 112 | |
| 118 | - private BpmSimpleModelNodeVO.ListenerHandler getListenerHandlerByEvent(String eventName, List<FlowableListener> node) { | |
| 119 | - FlowableListener flowableListener = node.stream() | |
| 120 | - .filter(item -> item.getEvent().equals(eventName)) | |
| 121 | - .findFirst().orElse(null); | |
| 122 | - Assert.notNull(flowableListener, "监听器({})不能为空", flowableListener); | |
| 123 | - return parseListenerConfig(flowableListener); | |
| 124 | - } | |
| 125 | - | |
| 126 | 113 | } |
| 127 | 114 | \ No newline at end of file | ... | ... |