Commit 0565db2f2d5b09edc4dcf935db7ec384a5d363c4
1 parent
3c0b9262
【代码评审修改】 异步 http 触发器修改为 Http 回调触发器
Showing
5 changed files
with
21 additions
and
20 deletions
yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/definition/BpmTriggerTypeEnum.java
| @@ -17,9 +17,10 @@ import java.util.Arrays; | @@ -17,9 +17,10 @@ import java.util.Arrays; | ||
| 17 | public enum BpmTriggerTypeEnum implements ArrayValuable<Integer> { | 17 | public enum BpmTriggerTypeEnum implements ArrayValuable<Integer> { |
| 18 | 18 | ||
| 19 | HTTP_REQUEST(1, "发起 HTTP 请求"), | 19 | HTTP_REQUEST(1, "发起 HTTP 请求"), |
| 20 | - FORM_UPDATE(2, "更新流程表单数据"), | ||
| 21 | - FORM_DELETE(3, "删除流程表单数据"), | ||
| 22 | - HTTP_REQUEST_ASYNC(4, "发起异步 HTTP 请求"); // TODO @jason:发起 HTTP 回调 | 20 | + HTTP_CALLBACK(2, "发起 HTTP 回调"), |
| 21 | + FORM_UPDATE(10, "更新流程表单数据"), | ||
| 22 | + FORM_DELETE(11, "删除流程表单数据"), | ||
| 23 | + ; | ||
| 23 | 24 | ||
| 24 | /** | 25 | /** |
| 25 | * 触发器执行动作类型 | 26 | * 触发器执行动作类型 |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/vo/model/simple/BpmSimpleModelNodeVO.java
| @@ -128,7 +128,7 @@ public class BpmSimpleModelNodeVO { | @@ -128,7 +128,7 @@ public class BpmSimpleModelNodeVO { | ||
| 128 | 128 | ||
| 129 | @Schema(description = "附加节点 Id", example = "UserTask_xxx", hidden = true) // 由后端生成(不从前端传递),所以 hidden = true | 129 | @Schema(description = "附加节点 Id", example = "UserTask_xxx", hidden = true) // 由后端生成(不从前端传递),所以 hidden = true |
| 130 | @JsonIgnore | 130 | @JsonIgnore |
| 131 | - private String attachNodeId; // 目前用于触发器节点(异步)。需要 UserTask 和 ReceiveTask(附加节点) 来完成 | 131 | + private String attachNodeId; // 目前用于触发器节点(HTTP 回调)。需要 UserTask 和 ReceiveTask(附加节点) 来完成 |
| 132 | 132 | ||
| 133 | /** | 133 | /** |
| 134 | * 子流程设置 | 134 | * 子流程设置 |
| @@ -390,7 +390,7 @@ public class BpmSimpleModelNodeVO { | @@ -390,7 +390,7 @@ public class BpmSimpleModelNodeVO { | ||
| 390 | private List<KeyValue<String, String>> response; | 390 | private List<KeyValue<String, String>> response; |
| 391 | 391 | ||
| 392 | /** | 392 | /** |
| 393 | - * 异步 Http 请求,需要指定回调任务 Key,用于回调执行 | 393 | + * Http 回调请求,需要指定回调任务 Key,用于回调执行 |
| 394 | */ | 394 | */ |
| 395 | @Schema(description = "回调任务 Key", example = "xxx", hidden = true) | 395 | @Schema(description = "回调任务 Key", example = "xxx", hidden = true) |
| 396 | private String callbackTaskDefineKey; | 396 | private String callbackTaskDefineKey; |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/SimpleModelUtils.java
| @@ -25,7 +25,7 @@ import org.springframework.util.MultiValueMap; | @@ -25,7 +25,7 @@ import org.springframework.util.MultiValueMap; | ||
| 25 | 25 | ||
| 26 | import java.util.*; | 26 | import java.util.*; |
| 27 | 27 | ||
| 28 | -import static cn.iocoder.yudao.module.bpm.enums.definition.BpmTriggerTypeEnum.HTTP_REQUEST_ASYNC; | 28 | +import static cn.iocoder.yudao.module.bpm.enums.definition.BpmTriggerTypeEnum.HTTP_CALLBACK; |
| 29 | import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants.*; | 29 | import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants.*; |
| 30 | import static cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils.*; | 30 | import static cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils.*; |
| 31 | import static java.util.Arrays.asList; | 31 | import static java.util.Arrays.asList; |
| @@ -175,7 +175,7 @@ public class SimpleModelUtils { | @@ -175,7 +175,7 @@ public class SimpleModelUtils { | ||
| 175 | SequenceFlow sequenceFlow = buildBpmnSequenceFlow(node.getId(), finalTargetNodeId); | 175 | SequenceFlow sequenceFlow = buildBpmnSequenceFlow(node.getId(), finalTargetNodeId); |
| 176 | process.addFlowElement(sequenceFlow); | 176 | process.addFlowElement(sequenceFlow); |
| 177 | } else { | 177 | } else { |
| 178 | - // 如果有附加节点:需要先建立和附加节点的连线,再建立附加节点和目标节点的连线。例如说,触发器节点(异步) | 178 | + // 如果有附加节点:需要先建立和附加节点的连线,再建立附加节点和目标节点的连线。例如说,触发器节点(HTTP 回调) |
| 179 | List<SequenceFlow> sequenceFlows = buildAttachNodeSequenceFlow(node.getId(), node.getAttachNodeId(), finalTargetNodeId); | 179 | List<SequenceFlow> sequenceFlows = buildAttachNodeSequenceFlow(node.getId(), node.getAttachNodeId(), finalTargetNodeId); |
| 180 | sequenceFlows.forEach(process::addFlowElement); | 180 | sequenceFlows.forEach(process::addFlowElement); |
| 181 | } | 181 | } |
| @@ -735,17 +735,17 @@ public class SimpleModelUtils { | @@ -735,17 +735,17 @@ public class SimpleModelUtils { | ||
| 735 | 735 | ||
| 736 | public static class TriggerNodeConvert implements NodeConvert { | 736 | public static class TriggerNodeConvert implements NodeConvert { |
| 737 | 737 | ||
| 738 | - // TODO @芋艿:【异步】在看看 | 738 | + // TODO @芋艿:【回调】在看看 |
| 739 | @Override | 739 | @Override |
| 740 | public List<? extends FlowElement> convertList(BpmSimpleModelNodeVO node) { | 740 | public List<? extends FlowElement> convertList(BpmSimpleModelNodeVO node) { |
| 741 | Assert.notNull(node.getTriggerSetting(), "触发器节点设置不能为空"); | 741 | Assert.notNull(node.getTriggerSetting(), "触发器节点设置不能为空"); |
| 742 | List<FlowElement> flowElements = new ArrayList<>(2); | 742 | List<FlowElement> flowElements = new ArrayList<>(2); |
| 743 | - // 异步 HTTP 请求。需要附加一个 ReceiveTask、发起请求后、等待回调执行 | ||
| 744 | - if (HTTP_REQUEST_ASYNC.getType().equals(node.getTriggerSetting().getType())) { | ||
| 745 | - Assert.notNull(node.getTriggerSetting().getHttpRequestSetting(), "触发器 HTTP 请求设置不能为空"); | 743 | + // HTTP 回调请求。需要附加一个 ReceiveTask、发起请求后、等待回调执行 |
| 744 | + if (HTTP_CALLBACK.getType().equals(node.getTriggerSetting().getType())) { | ||
| 745 | + Assert.notNull(node.getTriggerSetting().getHttpRequestSetting(), "触发器 HTTP 回调请求设置不能为空"); | ||
| 746 | ReceiveTask receiveTask = new ReceiveTask(); | 746 | ReceiveTask receiveTask = new ReceiveTask(); |
| 747 | receiveTask.setId("Activity_" + IdUtil.fastUUID()); | 747 | receiveTask.setId("Activity_" + IdUtil.fastUUID()); |
| 748 | - receiveTask.setName("异步 HTTP 请求"); | 748 | + receiveTask.setName("HTTP 回调"); |
| 749 | node.setAttachNodeId(receiveTask.getId()); | 749 | node.setAttachNodeId(receiveTask.getId()); |
| 750 | flowElements.add(receiveTask); | 750 | flowElements.add(receiveTask); |
| 751 | // 重要:设置 callbackTaskDefineKey,用于 HTTP 回调 | 751 | // 重要:设置 callbackTaskDefineKey,用于 HTTP 回调 |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskService.java
| @@ -287,11 +287,12 @@ public interface BpmTaskService { | @@ -287,11 +287,12 @@ public interface BpmTaskService { | ||
| 287 | /** | 287 | /** |
| 288 | * 触发流程任务 (ReceiveTask) 的执行 | 288 | * 触发流程任务 (ReceiveTask) 的执行 |
| 289 | * <p> | 289 | * <p> |
| 290 | - * 1. Simple 模型异步 HTTP 请求触发器节点的回调,触发流程继续执行 | 290 | + * 1. Simple 模型 HTTP 回调请求触发器节点的回调,触发流程继续执行 |
| 291 | * 2. Simple 模型延迟器节点,到时触发流程继续执行 | 291 | * 2. Simple 模型延迟器节点,到时触发流程继续执行 |
| 292 | * | 292 | * |
| 293 | * @param processInstanceId 流程示例编号 | 293 | * @param processInstanceId 流程示例编号 |
| 294 | * @param taskDefineKey 任务 Key | 294 | * @param taskDefineKey 任务 Key |
| 295 | */ | 295 | */ |
| 296 | void triggerTask(String processInstanceId, String taskDefineKey); | 296 | void triggerTask(String processInstanceId, String taskDefineKey); |
| 297 | + | ||
| 297 | } | 298 | } |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/trigger/http/BpmAsyncHttpRequestTrigger.java renamed to yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/trigger/http/BpmHttpCallbackTrigger.java
| @@ -10,22 +10,21 @@ import org.flowable.engine.runtime.ProcessInstance; | @@ -10,22 +10,21 @@ import org.flowable.engine.runtime.ProcessInstance; | ||
| 10 | import org.springframework.stereotype.Component; | 10 | import org.springframework.stereotype.Component; |
| 11 | import org.springframework.util.MultiValueMap; | 11 | import org.springframework.util.MultiValueMap; |
| 12 | 12 | ||
| 13 | -// TODO @jason:BpmHttpCallbackTrigger | ||
| 14 | /** | 13 | /** |
| 15 | - * BPM 发送异步 HTTP 请求触发器 | 14 | + * BPM HTTP 回调触发器 |
| 16 | * | 15 | * |
| 17 | * @author jason | 16 | * @author jason |
| 18 | */ | 17 | */ |
| 19 | @Component | 18 | @Component |
| 20 | @Slf4j | 19 | @Slf4j |
| 21 | -public class BpmAsyncHttpRequestTrigger extends BpmAbstractHttpRequestTrigger { | 20 | +public class BpmHttpCallbackTrigger extends BpmAbstractHttpRequestTrigger { |
| 22 | 21 | ||
| 23 | @Resource | 22 | @Resource |
| 24 | private BpmProcessInstanceService processInstanceService; | 23 | private BpmProcessInstanceService processInstanceService; |
| 25 | 24 | ||
| 26 | @Override | 25 | @Override |
| 27 | public BpmTriggerTypeEnum getType() { | 26 | public BpmTriggerTypeEnum getType() { |
| 28 | - return BpmTriggerTypeEnum.HTTP_REQUEST_ASYNC; | 27 | + return BpmTriggerTypeEnum.HTTP_CALLBACK; |
| 29 | } | 28 | } |
| 30 | 29 | ||
| 31 | @Override | 30 | @Override |
| @@ -34,7 +33,7 @@ public class BpmAsyncHttpRequestTrigger extends BpmAbstractHttpRequestTrigger { | @@ -34,7 +33,7 @@ public class BpmAsyncHttpRequestTrigger extends BpmAbstractHttpRequestTrigger { | ||
| 34 | BpmSimpleModelNodeVO.TriggerSetting.HttpRequestTriggerSetting setting = JsonUtils.parseObject(param, | 33 | BpmSimpleModelNodeVO.TriggerSetting.HttpRequestTriggerSetting setting = JsonUtils.parseObject(param, |
| 35 | BpmSimpleModelNodeVO.TriggerSetting.HttpRequestTriggerSetting.class); | 34 | BpmSimpleModelNodeVO.TriggerSetting.HttpRequestTriggerSetting.class); |
| 36 | if (setting == null) { | 35 | if (setting == null) { |
| 37 | - log.error("[execute][流程({}) HTTP 异步触发器请求配置为空]", processInstanceId); | 36 | + log.error("[execute][流程({}) HTTP 回调触发器配置为空]", processInstanceId); |
| 38 | return; | 37 | return; |
| 39 | } | 38 | } |
| 40 | 39 | ||
| @@ -43,8 +42,8 @@ public class BpmAsyncHttpRequestTrigger extends BpmAbstractHttpRequestTrigger { | @@ -43,8 +42,8 @@ public class BpmAsyncHttpRequestTrigger extends BpmAbstractHttpRequestTrigger { | ||
| 43 | MultiValueMap<String, String> headers = buildHttpHeaders(processInstance, setting.getHeader()); | 42 | MultiValueMap<String, String> headers = buildHttpHeaders(processInstance, setting.getHeader()); |
| 44 | // 2.2 设置请求体 | 43 | // 2.2 设置请求体 |
| 45 | MultiValueMap<String, String> body = buildHttpBody(processInstance, setting.getBody()); | 44 | MultiValueMap<String, String> body = buildHttpBody(processInstance, setting.getBody()); |
| 46 | - // TODO @芋艿:【异步】在看看 | ||
| 47 | - body.add("callbackId", setting.getCallbackTaskDefineKey()); // 异步请求 callbackId 需要传给被调用方,用于回调执行 | 45 | + // TODO @芋艿:【回调】在看看 |
| 46 | + body.add("callbackId", setting.getCallbackTaskDefineKey()); // 回调请求 callbackId 需要传给被调用方,用于回调执行 | ||
| 48 | 47 | ||
| 49 | // 3. 发起请求 | 48 | // 3. 发起请求 |
| 50 | sendHttpRequest(setting.getUrl(), headers, body); | 49 | sendHttpRequest(setting.getUrl(), headers, body); |