Commit 5e31062d6b64ff7c007f332040c4a805a5441410
1 parent
d0fbb767
【代码评审修改】 异步 http 触发器代码评审修改
Showing
13 changed files
with
73 additions
and
81 deletions
yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/api/task/BpmProcessInstanceApi.java
| ... | ... | @@ -19,13 +19,6 @@ public interface BpmProcessInstanceApi { |
| 19 | 19 | */ |
| 20 | 20 | String createProcessInstance(Long userId, @Valid BpmProcessInstanceCreateReqDTO reqDTO); |
| 21 | 21 | |
| 22 | - // TODO @jason:新增 BpmProcessTaskApi 接口,这个要不改成 triggerTask,保持通用性(和 flowable 保持一致) | |
| 23 | - /** | |
| 24 | - * 异步 HTTP 请求触发器回调, 为了唤醒流程继续执行 | |
| 25 | - * | |
| 26 | - * @param processInstanceId 流程实例编号 | |
| 27 | - * @param callbackId 回调编号, 对应 ReceiveTask Id TODO @jason:改成 taskDefineKey | |
| 28 | - */ | |
| 29 | - void asyncHttpTriggerCallback(String processInstanceId, String callbackId); | |
| 22 | + | |
| 30 | 23 | |
| 31 | 24 | } | ... | ... |
yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/api/task/BpmProcessTaskApi.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.bpm.api.task; | |
| 2 | + | |
| 3 | +import jakarta.validation.constraints.NotEmpty; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * 流程任务 Api 接口 | |
| 7 | + * | |
| 8 | + * @author jason | |
| 9 | + */ | |
| 10 | +public interface BpmProcessTaskApi { | |
| 11 | + | |
| 12 | + | |
| 13 | + /** | |
| 14 | + * 触发流程任务的执行 | |
| 15 | + * | |
| 16 | + * @param processInstanceId 流程实例编号 | |
| 17 | + * @param taskDefineKey 任务 Key | |
| 18 | + */ | |
| 19 | + void triggerTask(@NotEmpty(message = "流程实例的编号不能为空") String processInstanceId, | |
| 20 | + @NotEmpty(message = "任务 Key 不能为空") String taskDefineKey); | |
| 21 | +} | ... | ... |
yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/definition/BpmTriggerTypeEnum.java
| ... | ... | @@ -19,7 +19,7 @@ public enum BpmTriggerTypeEnum implements ArrayValuable<Integer> { |
| 19 | 19 | HTTP_REQUEST(1, "发起 HTTP 请求"), |
| 20 | 20 | FORM_UPDATE(2, "更新流程表单数据"), |
| 21 | 21 | FORM_DELETE(3, "删除流程表单数据"), |
| 22 | - ASYNC_HTTP_REQUEST(4, "发起异步 HTTP 请求"); // TODO @jason:HTTP_REQUEST_ASYNC | |
| 22 | + HTTP_REQUEST_ASYNC(4, "发起异步 HTTP 请求"); | |
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * 触发器执行动作类型 | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/api/task/BpmProcessInstanceApiImpl.java
| ... | ... | @@ -2,12 +2,10 @@ package cn.iocoder.yudao.module.bpm.api.task; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO; |
| 4 | 4 | import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService; |
| 5 | -import cn.iocoder.yudao.module.bpm.service.task.BpmTaskService; | |
| 6 | -import org.springframework.stereotype.Service; | |
| 7 | -import org.springframework.validation.annotation.Validated; | |
| 8 | - | |
| 9 | 5 | import jakarta.annotation.Resource; |
| 10 | 6 | import jakarta.validation.Valid; |
| 7 | +import org.springframework.stereotype.Service; | |
| 8 | +import org.springframework.validation.annotation.Validated; | |
| 11 | 9 | |
| 12 | 10 | /** |
| 13 | 11 | * Flowable 流程实例 Api 实现类 |
| ... | ... | @@ -22,17 +20,8 @@ public class BpmProcessInstanceApiImpl implements BpmProcessInstanceApi { |
| 22 | 20 | @Resource |
| 23 | 21 | private BpmProcessInstanceService processInstanceService; |
| 24 | 22 | |
| 25 | - @Resource | |
| 26 | - private BpmTaskService bpmTaskService; | |
| 27 | - | |
| 28 | 23 | @Override |
| 29 | 24 | public String createProcessInstance(Long userId, @Valid BpmProcessInstanceCreateReqDTO reqDTO) { |
| 30 | 25 | return processInstanceService.createProcessInstance(userId, reqDTO); |
| 31 | 26 | } |
| 32 | - | |
| 33 | - @Override | |
| 34 | - public void asyncHttpTriggerCallback(String processInstanceId, String callbackId) { | |
| 35 | - bpmTaskService.triggerReceiveTask(processInstanceId, callbackId); | |
| 36 | - } | |
| 37 | - | |
| 38 | 27 | } | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/api/task/BpmProcessTaskApiImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.bpm.api.task; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.bpm.service.task.BpmTaskService; | |
| 4 | +import jakarta.annotation.Resource; | |
| 5 | +import org.springframework.stereotype.Service; | |
| 6 | +import org.springframework.validation.annotation.Validated; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * 流程任务 Api 实现类 | |
| 10 | + * | |
| 11 | + * @author jason | |
| 12 | + */ | |
| 13 | +@Service | |
| 14 | +@Validated | |
| 15 | +public class BpmProcessTaskApiImpl implements BpmProcessTaskApi { | |
| 16 | + | |
| 17 | + @Resource | |
| 18 | + private BpmTaskService bpmTaskService; | |
| 19 | + | |
| 20 | + @Override | |
| 21 | + public void triggerTask(String processInstanceId, String taskDefineKey) { | |
| 22 | + bpmTaskService.triggerTask(processInstanceId, taskDefineKey); | |
| 23 | + } | |
| 24 | +} | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/vo/model/simple/BpmSimpleModelNodeVO.java
| ... | ... | @@ -389,13 +389,11 @@ public class BpmSimpleModelNodeVO { |
| 389 | 389 | @Schema(description = "请求返回处理设置", example = "[]") |
| 390 | 390 | private List<KeyValue<String, String>> response; |
| 391 | 391 | |
| 392 | - // TODO @jason:改成 callbackTaskDefineKey | |
| 393 | 392 | /** |
| 394 | - * 异步 Http 请求,需要指定回调 ID,用于回调执行 | |
| 393 | + * 异步 Http 请求,需要指定回调任务 Key,用于回调执行 | |
| 395 | 394 | */ |
| 396 | - @Schema(description = "回调 ID", example = "xxx", hidden = true) | |
| 397 | - private String callbackId; | |
| 398 | - | |
| 395 | + @Schema(description = "回调任务 Key", example = "xxx", hidden = true) | |
| 396 | + private String callbackTaskDefineKey; | |
| 399 | 397 | } |
| 400 | 398 | |
| 401 | 399 | @Schema(description = "流程表单触发器设置", example = "{}") | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/BpmProcessInstanceController.java
| ... | ... | @@ -22,7 +22,6 @@ import io.swagger.v3.oas.annotations.Operation; |
| 22 | 22 | import io.swagger.v3.oas.annotations.Parameter; |
| 23 | 23 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 24 | 24 | import jakarta.annotation.Resource; |
| 25 | -import jakarta.annotation.security.PermitAll; | |
| 26 | 25 | import jakarta.validation.Valid; |
| 27 | 26 | import org.flowable.engine.history.HistoricProcessInstance; |
| 28 | 27 | import org.flowable.engine.repository.ProcessDefinition; |
| ... | ... | @@ -179,14 +178,4 @@ public class BpmProcessInstanceController { |
| 179 | 178 | public CommonResult<BpmProcessInstanceBpmnModelViewRespVO> getProcessInstanceBpmnModelView(@RequestParam(value = "id") String id) { |
| 180 | 179 | return success(processInstanceService.getProcessInstanceBpmnModelView(id)); |
| 181 | 180 | } |
| 182 | - | |
| 183 | - // TODO @jason:要不去掉这个接口,单体通过 asyncHttpTriggerCallback? | |
| 184 | - @PostMapping("/http-trigger/callback") | |
| 185 | - @Operation(summary = "异步 HTTP 请求触发器回调") | |
| 186 | - @PermitAll // 允许外部调用,不需要登录。 TODO @芋艿 需要加一下验证签名吗? | |
| 187 | - public CommonResult<Boolean> httpTriggerCallback(@Valid @RequestBody BpmHttpTriggerCallbackReqVO reqVO) { | |
| 188 | - taskService.triggerReceiveTask(reqVO.getId(), reqVO.getCallbackId()); | |
| 189 | - return success(true); | |
| 190 | - } | |
| 191 | - | |
| 192 | 181 | } | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/instance/BpmHttpTriggerCallbackReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import jakarta.validation.constraints.NotEmpty; | |
| 5 | -import lombok.Data; | |
| 6 | - | |
| 7 | -// TODO @jason:要不去掉这个接口,单体通过 asyncHttpTriggerCallback? | |
| 8 | -@Schema(description = "管理后台 - Bpm 异步 Http 触发器请求回调 Request VO") | |
| 9 | -@Data | |
| 10 | -public class BpmHttpTriggerCallbackReqVO { | |
| 11 | - | |
| 12 | - @Schema(description = "流程实例的编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "dca1cdcc-b8fe-11ef-99b5-00ff4722db8b") | |
| 13 | - @NotEmpty(message = "流程实例的编号不能为空") | |
| 14 | - private String id; | |
| 15 | - | |
| 16 | - @Schema(description = "回调编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "dca1cdcc-b8fe-11ef-99b5-01ff4722db8b") | |
| 17 | - @NotEmpty(message = "回调编号不能为空") | |
| 18 | - private String callbackId; | |
| 19 | - | |
| 20 | -} |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/listener/BpmTaskEventListener.java
| ... | ... | @@ -109,7 +109,7 @@ public class BpmTaskEventListener extends AbstractFlowableEngineEventListener { |
| 109 | 109 | // 2.2 延迟器超时处理 |
| 110 | 110 | } else if (ObjectUtil.equal(bpmTimerBoundaryEventType, BpmBoundaryEventTypeEnum.DELAY_TIMER_TIMEOUT)) { |
| 111 | 111 | String taskKey = boundaryEvent.getAttachedToRefId(); |
| 112 | - taskService.triggerReceiveTask(event.getProcessInstanceId(), taskKey); | |
| 112 | + taskService.triggerTask(event.getProcessInstanceId(), taskKey); | |
| 113 | 113 | } |
| 114 | 114 | } |
| 115 | 115 | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/SimpleModelUtils.java
| ... | ... | @@ -26,7 +26,7 @@ import org.springframework.util.MultiValueMap; |
| 26 | 26 | |
| 27 | 27 | import java.util.*; |
| 28 | 28 | |
| 29 | -import static cn.iocoder.yudao.module.bpm.enums.definition.BpmTriggerTypeEnum.ASYNC_HTTP_REQUEST; | |
| 29 | +import static cn.iocoder.yudao.module.bpm.enums.definition.BpmTriggerTypeEnum.HTTP_REQUEST_ASYNC; | |
| 30 | 30 | import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants.*; |
| 31 | 31 | import static cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils.*; |
| 32 | 32 | import static java.util.Arrays.asList; |
| ... | ... | @@ -754,35 +754,31 @@ public class SimpleModelUtils { |
| 754 | 754 | public List<? extends FlowElement> convertList(BpmSimpleModelNodeVO node) { |
| 755 | 755 | Assert.notNull(node.getTriggerSetting(), "触发器节点设置不能为空"); |
| 756 | 756 | List<FlowElement> flowElements = new ArrayList<>(2); |
| 757 | - // 触发器使用 ServiceTask 来实现 | |
| 758 | - ServiceTask serviceTask = new ServiceTask(); | |
| 759 | - serviceTask.setId(node.getId()); | |
| 760 | - serviceTask.setName(node.getName()); | |
| 761 | - serviceTask.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION); | |
| 762 | - serviceTask.setImplementation("${" + BpmTriggerTaskDelegate.BEAN_NAME + "}"); | |
| 763 | - addExtensionElement(serviceTask, TRIGGER_TYPE, node.getTriggerSetting().getType()); | |
| 764 | - flowElements.add(serviceTask); | |
| 765 | - | |
| 766 | 757 | // 异步 HTTP 请求。需要附加一个 ReceiveTask、发起请求后、等待回调执行 |
| 767 | - // TODO @jason:这里能挪到最后处理么?这样,代码的整体性更好; | |
| 768 | - if (ASYNC_HTTP_REQUEST.getType().equals(node.getTriggerSetting().getType())) { | |
| 758 | + if (HTTP_REQUEST_ASYNC.getType().equals(node.getTriggerSetting().getType())) { | |
| 769 | 759 | Assert.notNull(node.getTriggerSetting().getHttpRequestSetting(), "触发器 HTTP 请求设置不能为空"); |
| 770 | 760 | String attachNodeId = "Activity_" + IdUtil.fastUUID(); |
| 771 | 761 | ReceiveTask receiveTask = new ReceiveTask(); |
| 772 | 762 | receiveTask.setId(attachNodeId); |
| 773 | 763 | receiveTask.setName("异步 HTTP 请求"); |
| 774 | 764 | node.setAttachNodeId(attachNodeId); |
| 775 | - node.getTriggerSetting().getHttpRequestSetting().setCallbackId(attachNodeId); // 设置 receiveId | |
| 765 | + node.getTriggerSetting().getHttpRequestSetting().setCallbackTaskDefineKey(attachNodeId); // 设置 callbackTaskDefineKey | |
| 776 | 766 | flowElements.add(receiveTask); |
| 777 | 767 | } |
| 778 | - | |
| 779 | - // TODO @jason:是不是挪到 flowElements.add(serviceTask); 之前哈,因为它在处理 serviceTask | |
| 768 | + // 触发器使用 ServiceTask 来实现 | |
| 769 | + ServiceTask serviceTask = new ServiceTask(); | |
| 770 | + serviceTask.setId(node.getId()); | |
| 771 | + serviceTask.setName(node.getName()); | |
| 772 | + serviceTask.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION); | |
| 773 | + serviceTask.setImplementation("${" + BpmTriggerTaskDelegate.BEAN_NAME + "}"); | |
| 774 | + addExtensionElement(serviceTask, TRIGGER_TYPE, node.getTriggerSetting().getType()); | |
| 780 | 775 | if (node.getTriggerSetting().getHttpRequestSetting() != null) { |
| 781 | 776 | addExtensionElementJson(serviceTask, TRIGGER_PARAM, node.getTriggerSetting().getHttpRequestSetting()); |
| 782 | 777 | } |
| 783 | 778 | if (node.getTriggerSetting().getFormSettings() != null) { |
| 784 | 779 | addExtensionElementJson(serviceTask, TRIGGER_PARAM, node.getTriggerSetting().getFormSettings()); |
| 785 | 780 | } |
| 781 | + flowElements.add(serviceTask); | |
| 786 | 782 | return flowElements; |
| 787 | 783 | } |
| 788 | 784 | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskService.java
| ... | ... | @@ -276,13 +276,15 @@ public interface BpmTaskService { |
| 276 | 276 | */ |
| 277 | 277 | void processTaskTimeout(String processInstanceId, String taskDefineKey, Integer handlerType); |
| 278 | 278 | |
| 279 | - // TODO @jason:改成 triggerTask。然后,“触发 ReceiveTask,让流程继续执行”,改成一些调用场景 | |
| 279 | + | |
| 280 | 280 | /** |
| 281 | - * 触发 ReceiveTask,让流程继续执行 | |
| 281 | + * 触发流程任务 (ReceiveTask) 的执行 | |
| 282 | + * <p> | |
| 283 | + * 1. Simple 模型异步 HTTP 请求触发器节点的回调,触发流程继续执行 | |
| 284 | + * 2. Simple 模型延迟器节点,到时触发流程继续执行 | |
| 282 | 285 | * |
| 283 | 286 | * @param processInstanceId 流程示例编号 |
| 284 | 287 | * @param taskDefineKey 任务 Key |
| 285 | 288 | */ |
| 286 | - void triggerReceiveTask(String processInstanceId, String taskDefineKey); | |
| 287 | - | |
| 289 | + void triggerTask(String processInstanceId, String taskDefineKey); | |
| 288 | 290 | } | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java
| ... | ... | @@ -1323,7 +1323,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 1323 | 1323 | } |
| 1324 | 1324 | |
| 1325 | 1325 | @Override |
| 1326 | - public void triggerReceiveTask(String processInstanceId, String taskDefineKey) { | |
| 1326 | + public void triggerTask(String processInstanceId, String taskDefineKey) { | |
| 1327 | 1327 | Execution execution = runtimeService.createExecutionQuery() |
| 1328 | 1328 | .processInstanceId(processInstanceId) |
| 1329 | 1329 | .activityId(taskDefineKey) | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/trigger/http/BpmAsyncHttpRequestTrigger.java
| ... | ... | @@ -24,7 +24,7 @@ public class BpmAsyncHttpRequestTrigger extends BpmAbstractHttpRequestTrigger { |
| 24 | 24 | |
| 25 | 25 | @Override |
| 26 | 26 | public BpmTriggerTypeEnum getType() { |
| 27 | - return BpmTriggerTypeEnum.ASYNC_HTTP_REQUEST; | |
| 27 | + return BpmTriggerTypeEnum.HTTP_REQUEST_ASYNC; | |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | @Override |
| ... | ... | @@ -43,7 +43,7 @@ public class BpmAsyncHttpRequestTrigger extends BpmAbstractHttpRequestTrigger { |
| 43 | 43 | // 2.2 设置请求体 |
| 44 | 44 | MultiValueMap<String, String> body = buildHttpBody(processInstance, setting.getBody()); |
| 45 | 45 | // TODO @芋艿:【异步】在看看 |
| 46 | - body.add("callbackId", setting.getCallbackId()); // 异步请求 callbackId 需要传给被调用方,用于回调执行 | |
| 46 | + body.add("callbackId", setting.getCallbackTaskDefineKey()); // 异步请求 callbackId 需要传给被调用方,用于回调执行 | |
| 47 | 47 | |
| 48 | 48 | // 3. 发起请求 |
| 49 | 49 | sendHttpRequest(setting.getUrl(), headers, body); | ... | ... |