【代码评审修改】 异步 http 触发器修改为 Http 回调触发器
This commit is contained in:
parent
3c0b9262d7
commit
0565db2f2d
|
@ -17,9 +17,10 @@ import java.util.Arrays;
|
|||
public enum BpmTriggerTypeEnum implements ArrayValuable<Integer> {
|
||||
|
||||
HTTP_REQUEST(1, "发起 HTTP 请求"),
|
||||
FORM_UPDATE(2, "更新流程表单数据"),
|
||||
FORM_DELETE(3, "删除流程表单数据"),
|
||||
HTTP_REQUEST_ASYNC(4, "发起异步 HTTP 请求"); // TODO @jason:发起 HTTP 回调
|
||||
HTTP_CALLBACK(2, "发起 HTTP 回调"),
|
||||
FORM_UPDATE(10, "更新流程表单数据"),
|
||||
FORM_DELETE(11, "删除流程表单数据"),
|
||||
;
|
||||
|
||||
/**
|
||||
* 触发器执行动作类型
|
||||
|
|
|
@ -128,7 +128,7 @@ public class BpmSimpleModelNodeVO {
|
|||
|
||||
@Schema(description = "附加节点 Id", example = "UserTask_xxx", hidden = true) // 由后端生成(不从前端传递),所以 hidden = true
|
||||
@JsonIgnore
|
||||
private String attachNodeId; // 目前用于触发器节点(异步)。需要 UserTask 和 ReceiveTask(附加节点) 来完成
|
||||
private String attachNodeId; // 目前用于触发器节点(HTTP 回调)。需要 UserTask 和 ReceiveTask(附加节点) 来完成
|
||||
|
||||
/**
|
||||
* 子流程设置
|
||||
|
@ -390,7 +390,7 @@ public class BpmSimpleModelNodeVO {
|
|||
private List<KeyValue<String, String>> response;
|
||||
|
||||
/**
|
||||
* 异步 Http 请求,需要指定回调任务 Key,用于回调执行
|
||||
* Http 回调请求,需要指定回调任务 Key,用于回调执行
|
||||
*/
|
||||
@Schema(description = "回调任务 Key", example = "xxx", hidden = true)
|
||||
private String callbackTaskDefineKey;
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.springframework.util.MultiValueMap;
|
|||
|
||||
import java.util.*;
|
||||
|
||||
import static cn.iocoder.yudao.module.bpm.enums.definition.BpmTriggerTypeEnum.HTTP_REQUEST_ASYNC;
|
||||
import static cn.iocoder.yudao.module.bpm.enums.definition.BpmTriggerTypeEnum.HTTP_CALLBACK;
|
||||
import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants.*;
|
||||
import static cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils.*;
|
||||
import static java.util.Arrays.asList;
|
||||
|
@ -175,7 +175,7 @@ public class SimpleModelUtils {
|
|||
SequenceFlow sequenceFlow = buildBpmnSequenceFlow(node.getId(), finalTargetNodeId);
|
||||
process.addFlowElement(sequenceFlow);
|
||||
} else {
|
||||
// 如果有附加节点:需要先建立和附加节点的连线,再建立附加节点和目标节点的连线。例如说,触发器节点(异步)
|
||||
// 如果有附加节点:需要先建立和附加节点的连线,再建立附加节点和目标节点的连线。例如说,触发器节点(HTTP 回调)
|
||||
List<SequenceFlow> sequenceFlows = buildAttachNodeSequenceFlow(node.getId(), node.getAttachNodeId(), finalTargetNodeId);
|
||||
sequenceFlows.forEach(process::addFlowElement);
|
||||
}
|
||||
|
@ -735,17 +735,17 @@ public class SimpleModelUtils {
|
|||
|
||||
public static class TriggerNodeConvert implements NodeConvert {
|
||||
|
||||
// TODO @芋艿:【异步】在看看
|
||||
// TODO @芋艿:【回调】在看看
|
||||
@Override
|
||||
public List<? extends FlowElement> convertList(BpmSimpleModelNodeVO node) {
|
||||
Assert.notNull(node.getTriggerSetting(), "触发器节点设置不能为空");
|
||||
List<FlowElement> flowElements = new ArrayList<>(2);
|
||||
// 异步 HTTP 请求。需要附加一个 ReceiveTask、发起请求后、等待回调执行
|
||||
if (HTTP_REQUEST_ASYNC.getType().equals(node.getTriggerSetting().getType())) {
|
||||
Assert.notNull(node.getTriggerSetting().getHttpRequestSetting(), "触发器 HTTP 请求设置不能为空");
|
||||
// HTTP 回调请求。需要附加一个 ReceiveTask、发起请求后、等待回调执行
|
||||
if (HTTP_CALLBACK.getType().equals(node.getTriggerSetting().getType())) {
|
||||
Assert.notNull(node.getTriggerSetting().getHttpRequestSetting(), "触发器 HTTP 回调请求设置不能为空");
|
||||
ReceiveTask receiveTask = new ReceiveTask();
|
||||
receiveTask.setId("Activity_" + IdUtil.fastUUID());
|
||||
receiveTask.setName("异步 HTTP 请求");
|
||||
receiveTask.setName("HTTP 回调");
|
||||
node.setAttachNodeId(receiveTask.getId());
|
||||
flowElements.add(receiveTask);
|
||||
// 重要:设置 callbackTaskDefineKey,用于 HTTP 回调
|
||||
|
|
|
@ -287,11 +287,12 @@ public interface BpmTaskService {
|
|||
/**
|
||||
* 触发流程任务 (ReceiveTask) 的执行
|
||||
* <p>
|
||||
* 1. Simple 模型异步 HTTP 请求触发器节点的回调,触发流程继续执行
|
||||
* 1. Simple 模型 HTTP 回调请求触发器节点的回调,触发流程继续执行
|
||||
* 2. Simple 模型延迟器节点,到时触发流程继续执行
|
||||
*
|
||||
* @param processInstanceId 流程示例编号
|
||||
* @param taskDefineKey 任务 Key
|
||||
*/
|
||||
void triggerTask(String processInstanceId, String taskDefineKey);
|
||||
|
||||
}
|
||||
|
|
|
@ -10,22 +10,21 @@ import org.flowable.engine.runtime.ProcessInstance;
|
|||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
// TODO @jason:BpmHttpCallbackTrigger
|
||||
/**
|
||||
* BPM 发送异步 HTTP 请求触发器
|
||||
* BPM HTTP 回调触发器
|
||||
*
|
||||
* @author jason
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class BpmAsyncHttpRequestTrigger extends BpmAbstractHttpRequestTrigger {
|
||||
public class BpmHttpCallbackTrigger extends BpmAbstractHttpRequestTrigger {
|
||||
|
||||
@Resource
|
||||
private BpmProcessInstanceService processInstanceService;
|
||||
|
||||
@Override
|
||||
public BpmTriggerTypeEnum getType() {
|
||||
return BpmTriggerTypeEnum.HTTP_REQUEST_ASYNC;
|
||||
return BpmTriggerTypeEnum.HTTP_CALLBACK;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -34,7 +33,7 @@ public class BpmAsyncHttpRequestTrigger extends BpmAbstractHttpRequestTrigger {
|
|||
BpmSimpleModelNodeVO.TriggerSetting.HttpRequestTriggerSetting setting = JsonUtils.parseObject(param,
|
||||
BpmSimpleModelNodeVO.TriggerSetting.HttpRequestTriggerSetting.class);
|
||||
if (setting == null) {
|
||||
log.error("[execute][流程({}) HTTP 异步触发器请求配置为空]", processInstanceId);
|
||||
log.error("[execute][流程({}) HTTP 回调触发器配置为空]", processInstanceId);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -43,8 +42,8 @@ public class BpmAsyncHttpRequestTrigger extends BpmAbstractHttpRequestTrigger {
|
|||
MultiValueMap<String, String> headers = buildHttpHeaders(processInstance, setting.getHeader());
|
||||
// 2.2 设置请求体
|
||||
MultiValueMap<String, String> body = buildHttpBody(processInstance, setting.getBody());
|
||||
// TODO @芋艿:【异步】在看看
|
||||
body.add("callbackId", setting.getCallbackTaskDefineKey()); // 异步请求 callbackId 需要传给被调用方,用于回调执行
|
||||
// TODO @芋艿:【回调】在看看
|
||||
body.add("callbackId", setting.getCallbackTaskDefineKey()); // 回调请求 callbackId 需要传给被调用方,用于回调执行
|
||||
|
||||
// 3. 发起请求
|
||||
sendHttpRequest(setting.getUrl(), headers, body);
|
Loading…
Reference in New Issue