Commit 1fb8c9238a7e2d773855c10ed12a2e34ae6ca799
1 parent
60d1f119
feat: Simple设计器-监听器完善
Showing
3 changed files
with
37 additions
and
37 deletions
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/BpmnModelUtils.java
| @@ -115,25 +115,6 @@ public class BpmnModelUtils { | @@ -115,25 +115,6 @@ public class BpmnModelUtils { | ||
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | /** | 117 | /** |
| 118 | - * 给节点添加Simple设计器配置Json | ||
| 119 | - * | ||
| 120 | - * @param userTask 节点 | ||
| 121 | - * @param node 节点对象 | ||
| 122 | - */ | ||
| 123 | - public static void addSimpleConfigInfo(FlowElement userTask, Object node) { | ||
| 124 | - addExtensionElementJson(userTask, "config", node); | ||
| 125 | - } | ||
| 126 | - | ||
| 127 | - /** | ||
| 128 | - * 解析Simple设计器配置Json | ||
| 129 | - * | ||
| 130 | - * @param userTask 节点 | ||
| 131 | - */ | ||
| 132 | - public static BpmSimpleModelNodeVO parseSimpleConfigInfo(FlowElement userTask) { | ||
| 133 | - return parseExtensionElementJson(userTask, "config", BpmSimpleModelNodeVO.class); | ||
| 134 | - } | ||
| 135 | - | ||
| 136 | - /** | ||
| 137 | * 给节点添加候选人元素 | 118 | * 给节点添加候选人元素 |
| 138 | * | 119 | * |
| 139 | * @param candidateStrategy 候选人策略 | 120 | * @param candidateStrategy 候选人策略 |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/SimpleModelUtils.java
| @@ -5,6 +5,7 @@ import cn.hutool.core.lang.Assert; | @@ -5,6 +5,7 @@ import cn.hutool.core.lang.Assert; | ||
| 5 | import cn.hutool.core.map.MapUtil; | 5 | import cn.hutool.core.map.MapUtil; |
| 6 | import cn.hutool.core.util.*; | 6 | import cn.hutool.core.util.*; |
| 7 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | 7 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 8 | +import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | ||
| 8 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO; | 9 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO; |
| 9 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO.ConditionGroups; | 10 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO.ConditionGroups; |
| 10 | import cn.iocoder.yudao.module.bpm.enums.definition.*; | 11 | import cn.iocoder.yudao.module.bpm.enums.definition.*; |
| @@ -439,9 +440,6 @@ public class SimpleModelUtils { | @@ -439,9 +440,6 @@ public class SimpleModelUtils { | ||
| 439 | } | 440 | } |
| 440 | // 设置监听器 | 441 | // 设置监听器 |
| 441 | addUserTaskListener(node, userTask); | 442 | addUserTaskListener(node, userTask); |
| 442 | - // 设置 Simple 设计器节点配置 | ||
| 443 | - // TODO @lesan:只设置到 flowableListener 里面,整个 node 太大了!因为很多都保存过啦。 | ||
| 444 | - addSimpleConfigInfo(userTask, node); | ||
| 445 | return userTask; | 443 | return userTask; |
| 446 | } | 444 | } |
| 447 | 445 | ||
| @@ -453,6 +451,10 @@ public class SimpleModelUtils { | @@ -453,6 +451,10 @@ public class SimpleModelUtils { | ||
| 453 | flowableListener.setEvent(TaskListener.EVENTNAME_CREATE); | 451 | flowableListener.setEvent(TaskListener.EVENTNAME_CREATE); |
| 454 | flowableListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION); | 452 | flowableListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION); |
| 455 | flowableListener.setImplementation(DELEGATE_EXPRESSION); | 453 | flowableListener.setImplementation(DELEGATE_EXPRESSION); |
| 454 | + FieldExtension fieldExtension = new FieldExtension(); | ||
| 455 | + fieldExtension.setFieldName("listenerConfig"); | ||
| 456 | + fieldExtension.setStringValue(JsonUtils.toJsonString(node.getTaskCreateListener())); | ||
| 457 | + flowableListener.getFieldExtensions().add(fieldExtension); | ||
| 456 | flowableListeners.add(flowableListener); | 458 | flowableListeners.add(flowableListener); |
| 457 | } | 459 | } |
| 458 | if (node.getTaskAssignListener() != null | 460 | if (node.getTaskAssignListener() != null |
| @@ -461,6 +463,10 @@ public class SimpleModelUtils { | @@ -461,6 +463,10 @@ public class SimpleModelUtils { | ||
| 461 | flowableListener.setEvent(TaskListener.EVENTNAME_ASSIGNMENT); | 463 | flowableListener.setEvent(TaskListener.EVENTNAME_ASSIGNMENT); |
| 462 | flowableListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION); | 464 | flowableListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION); |
| 463 | flowableListener.setImplementation(DELEGATE_EXPRESSION); | 465 | flowableListener.setImplementation(DELEGATE_EXPRESSION); |
| 466 | + FieldExtension fieldExtension = new FieldExtension(); | ||
| 467 | + fieldExtension.setFieldName("listenerConfig"); | ||
| 468 | + fieldExtension.setStringValue(JsonUtils.toJsonString(node.getTaskAssignListener())); | ||
| 469 | + flowableListener.getFieldExtensions().add(fieldExtension); | ||
| 464 | flowableListeners.add(flowableListener); | 470 | flowableListeners.add(flowableListener); |
| 465 | } | 471 | } |
| 466 | if (node.getTaskCompleteListener() != null | 472 | if (node.getTaskCompleteListener() != null |
| @@ -469,6 +475,10 @@ public class SimpleModelUtils { | @@ -469,6 +475,10 @@ public class SimpleModelUtils { | ||
| 469 | flowableListener.setEvent(TaskListener.EVENTNAME_COMPLETE); | 475 | flowableListener.setEvent(TaskListener.EVENTNAME_COMPLETE); |
| 470 | flowableListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION); | 476 | flowableListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION); |
| 471 | flowableListener.setImplementation(DELEGATE_EXPRESSION); | 477 | flowableListener.setImplementation(DELEGATE_EXPRESSION); |
| 478 | + FieldExtension fieldExtension = new FieldExtension(); | ||
| 479 | + fieldExtension.setFieldName("listenerConfig"); | ||
| 480 | + fieldExtension.setStringValue(JsonUtils.toJsonString(node.getTaskCompleteListener())); | ||
| 481 | + flowableListener.getFieldExtensions().add(fieldExtension); | ||
| 472 | flowableListeners.add(flowableListener); | 482 | flowableListeners.add(flowableListener); |
| 473 | } | 483 | } |
| 474 | if (CollUtil.isNotEmpty(flowableListeners)) { | 484 | if (CollUtil.isNotEmpty(flowableListeners)) { |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/listener/BpmUserTaskListener.java
| 1 | package cn.iocoder.yudao.module.bpm.service.task.listener; | 1 | package cn.iocoder.yudao.module.bpm.service.task.listener; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | +import cn.hutool.core.lang.Assert; | ||
| 4 | import cn.hutool.core.util.StrUtil; | 5 | import cn.hutool.core.util.StrUtil; |
| 6 | +import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | ||
| 5 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO; | 7 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO; |
| 6 | import cn.iocoder.yudao.module.bpm.enums.definition.BpmListenerParamTypeEnum; | 8 | import cn.iocoder.yudao.module.bpm.enums.definition.BpmListenerParamTypeEnum; |
| 7 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils; | 9 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils; |
| @@ -10,7 +12,9 @@ import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService; | @@ -10,7 +12,9 @@ import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService; | ||
| 10 | import jakarta.annotation.Resource; | 12 | import jakarta.annotation.Resource; |
| 11 | import lombok.extern.slf4j.Slf4j; | 13 | import lombok.extern.slf4j.Slf4j; |
| 12 | import org.flowable.bpmn.model.BpmnModel; | 14 | import org.flowable.bpmn.model.BpmnModel; |
| 13 | -import org.flowable.bpmn.model.FlowElement; | 15 | +import org.flowable.bpmn.model.FieldExtension; |
| 16 | +import org.flowable.bpmn.model.FlowableListener; | ||
| 17 | +import org.flowable.bpmn.model.UserTask; | ||
| 14 | import org.flowable.engine.delegate.TaskListener; | 18 | import org.flowable.engine.delegate.TaskListener; |
| 15 | import org.flowable.engine.history.HistoricProcessInstance; | 19 | import org.flowable.engine.history.HistoricProcessInstance; |
| 16 | import org.flowable.task.service.delegate.DelegateTask; | 20 | import org.flowable.task.service.delegate.DelegateTask; |
| @@ -26,7 +30,6 @@ import java.util.List; | @@ -26,7 +30,6 @@ import java.util.List; | ||
| 26 | import java.util.Map; | 30 | import java.util.Map; |
| 27 | 31 | ||
| 28 | import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.HEADER_TENANT_ID; | 32 | import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.HEADER_TENANT_ID; |
| 29 | -import static cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils.parseSimpleConfigInfo; | ||
| 30 | 33 | ||
| 31 | /** | 34 | /** |
| 32 | * BPM 用户任务通用监听器 | 35 | * BPM 用户任务通用监听器 |
| @@ -53,9 +56,9 @@ public class BpmUserTaskListener implements TaskListener { | @@ -53,9 +56,9 @@ public class BpmUserTaskListener implements TaskListener { | ||
| 53 | // 1. 获取所需基础信息 | 56 | // 1. 获取所需基础信息 |
| 54 | HistoricProcessInstance processInstance = processInstanceService.getHistoricProcessInstance(delegateTask.getProcessInstanceId()); | 57 | HistoricProcessInstance processInstance = processInstanceService.getHistoricProcessInstance(delegateTask.getProcessInstanceId()); |
| 55 | BpmnModel bpmnModel = modelService.getBpmnModelByDefinitionId(delegateTask.getProcessDefinitionId()); | 58 | BpmnModel bpmnModel = modelService.getBpmnModelByDefinitionId(delegateTask.getProcessDefinitionId()); |
| 56 | - FlowElement userTask = BpmnModelUtils.getFlowElementById(bpmnModel, delegateTask.getTaskDefinitionKey()); | ||
| 57 | - BpmSimpleModelNodeVO node = parseSimpleConfigInfo(userTask); | ||
| 58 | - BpmSimpleModelNodeVO.ListenerHandler listenerHandler = getListenerHandlerByEvent(delegateTask.getEventName(), node); | 59 | + UserTask userTask = (UserTask) BpmnModelUtils.getFlowElementById(bpmnModel, delegateTask.getTaskDefinitionKey()); |
| 60 | + BpmSimpleModelNodeVO.ListenerHandler listenerHandler = getListenerHandlerByEvent(delegateTask.getEventName(), | ||
| 61 | + userTask.getTaskListeners()); | ||
| 59 | 62 | ||
| 60 | // 2. 获取请求头和请求体 | 63 | // 2. 获取请求头和请求体 |
| 61 | Map<String, Object> processVariables = processInstance.getProcessVariables(); | 64 | Map<String, Object> processVariables = processInstance.getProcessVariables(); |
| @@ -79,8 +82,12 @@ public class BpmUserTaskListener implements TaskListener { | @@ -79,8 +82,12 @@ public class BpmUserTaskListener implements TaskListener { | ||
| 79 | HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(body, headers); | 82 | HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(body, headers); |
| 80 | ResponseEntity<String> responseEntity = restTemplate.exchange(listenerHandler.getPath(), HttpMethod.POST, | 83 | ResponseEntity<String> responseEntity = restTemplate.exchange(listenerHandler.getPath(), HttpMethod.POST, |
| 81 | requestEntity, String.class); | 84 | requestEntity, String.class); |
| 82 | - // TODO @lesan:日志打印,可以更全哈,例如说,请求参数、对应的 task id,哪个 listener | ||
| 83 | - log.info("[notify][的响应结果({})]", responseEntity); | 85 | + log.info("[notify][监听器:{},事件类型:{},请求头:{},请求体:{},响应结果:{}]", |
| 86 | + DELEGATE_EXPRESSION, | ||
| 87 | + delegateTask.getEventName(), | ||
| 88 | + headers, | ||
| 89 | + body, | ||
| 90 | + responseEntity); | ||
| 84 | // 4. 是否需要后续操作?TODO 芋艿:待定! | 91 | // 4. 是否需要后续操作?TODO 芋艿:待定! |
| 85 | } | 92 | } |
| 86 | 93 | ||
| @@ -99,14 +106,16 @@ public class BpmUserTaskListener implements TaskListener { | @@ -99,14 +106,16 @@ public class BpmUserTaskListener implements TaskListener { | ||
| 99 | }); | 106 | }); |
| 100 | } | 107 | } |
| 101 | 108 | ||
| 102 | - // TODO @lesan:改成 jdk8 写法哈。主要考虑好兼容! | ||
| 103 | - private BpmSimpleModelNodeVO.ListenerHandler getListenerHandlerByEvent(String eventName, BpmSimpleModelNodeVO node) { | ||
| 104 | - return switch (eventName) { | ||
| 105 | - case TaskListener.EVENTNAME_CREATE -> node.getTaskCreateListener(); | ||
| 106 | - case TaskListener.EVENTNAME_ASSIGNMENT -> node.getTaskAssignListener(); | ||
| 107 | - case TaskListener.EVENTNAME_COMPLETE -> node.getTaskCompleteListener(); | ||
| 108 | - default -> null; // TODO @lesan:这个抛出异常,可控一点 | ||
| 109 | - }; | 109 | + private BpmSimpleModelNodeVO.ListenerHandler getListenerHandlerByEvent(String eventName, List<FlowableListener> node) { |
| 110 | + FlowableListener flowableListener = node.stream() | ||
| 111 | + .filter(item -> item.getEvent().equals(eventName)) | ||
| 112 | + .findFirst().orElse(null); | ||
| 113 | + Assert.notNull(flowableListener, "监听器({})不能为空", flowableListener); | ||
| 114 | + FieldExtension fieldExtension = flowableListener.getFieldExtensions().stream() | ||
| 115 | + .filter(item -> item.getFieldName().equals("listenerConfig")) | ||
| 116 | + .findFirst().orElse(null); | ||
| 117 | + Assert.notNull(fieldExtension, "监听器扩展字段({})不能为空", fieldExtension); | ||
| 118 | + return JsonUtils.parseObject(fieldExtension.getStringValue(), BpmSimpleModelNodeVO.ListenerHandler.class); | ||
| 110 | } | 119 | } |
| 111 | 120 | ||
| 112 | } | 121 | } |
| 113 | \ No newline at end of file | 122 | \ No newline at end of file |