Commit a42ad08bc949337dadb6c3f60508bb4ace214be1
1 parent
8c681a77
【功能优化】 异步 http 请求触发器外部回调 controller 接口
Showing
3 changed files
with
23 additions
and
1 deletions
yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/ErrorCodeConstants.java
| @@ -39,6 +39,7 @@ public interface ErrorCodeConstants { | @@ -39,6 +39,7 @@ public interface ErrorCodeConstants { | ||
| 39 | ErrorCode PROCESS_INSTANCE_START_USER_SELECT_ASSIGNEES_NOT_EXISTS = new ErrorCode(1_009_004_004, "任务({})的候选人({})不存在"); | 39 | ErrorCode PROCESS_INSTANCE_START_USER_SELECT_ASSIGNEES_NOT_EXISTS = new ErrorCode(1_009_004_004, "任务({})的候选人({})不存在"); |
| 40 | ErrorCode PROCESS_INSTANCE_START_USER_CAN_START = new ErrorCode(1_009_004_005, "发起流程失败,你没有权限发起该流程"); | 40 | ErrorCode PROCESS_INSTANCE_START_USER_CAN_START = new ErrorCode(1_009_004_005, "发起流程失败,你没有权限发起该流程"); |
| 41 | ErrorCode PROCESS_INSTANCE_CANCEL_FAIL_NOT_ALLOW = new ErrorCode(1_009_004_005, "流程取消失败,该流程不允许取消"); | 41 | ErrorCode PROCESS_INSTANCE_CANCEL_FAIL_NOT_ALLOW = new ErrorCode(1_009_004_005, "流程取消失败,该流程不允许取消"); |
| 42 | + ErrorCode PROCESS_INSTANCE_HTTP_TRIGGER_CALL_ERROR = new ErrorCode(1_009_004_006, "流程 Http 触发器请求调用失败"); | ||
| 42 | 43 | ||
| 43 | // ========== 流程任务 1-009-005-000 ========== | 44 | // ========== 流程任务 1-009-005-000 ========== |
| 44 | ErrorCode TASK_OPERATE_FAIL_ASSIGN_NOT_SELF = new ErrorCode(1_009_005_001, "操作失败,原因:该任务的审批人不是你"); | 45 | ErrorCode TASK_OPERATE_FAIL_ASSIGN_NOT_SELF = new ErrorCode(1_009_005_001, "操作失败,原因:该任务的审批人不是你"); |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/instance/BpmHttpTriggerCallbackReqVO.java
0 → 100644
| 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 | +@Schema(description = "管理后台 - Bpm 异步 Http 触发器请求回调 Request VO") | ||
| 8 | +@Data | ||
| 9 | +public class BpmHttpTriggerCallbackReqVO { | ||
| 10 | + | ||
| 11 | + @Schema(description = "流程实例的编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "dca1cdcc-b8fe-11ef-99b5-00ff4722db8b") | ||
| 12 | + @NotEmpty(message = "流程实例的编号不能为空") | ||
| 13 | + private String id; | ||
| 14 | + | ||
| 15 | + @Schema(description = "回调编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "dca1cdcc-b8fe-11ef-99b5-01ff4722db8b") | ||
| 16 | + @NotEmpty(message = "回调编号不能为空") | ||
| 17 | + private String callbackId; | ||
| 18 | +} |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/trigger/BpmAbstractHttpRequestTrigger.java
| @@ -16,7 +16,9 @@ import org.springframework.web.client.RestTemplate; | @@ -16,7 +16,9 @@ import org.springframework.web.client.RestTemplate; | ||
| 16 | import java.util.List; | 16 | import java.util.List; |
| 17 | import java.util.Map; | 17 | import java.util.Map; |
| 18 | 18 | ||
| 19 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 19 | import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.HEADER_TENANT_ID; | 20 | import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.HEADER_TENANT_ID; |
| 21 | +import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.PROCESS_INSTANCE_HTTP_TRIGGER_CALL_ERROR; | ||
| 20 | 22 | ||
| 21 | /** | 23 | /** |
| 22 | * BPM 发送 HTTP 请求触发器抽象类 | 24 | * BPM 发送 HTTP 请求触发器抽象类 |
| @@ -35,13 +37,14 @@ public abstract class BpmAbstractHttpRequestTrigger implements BpmTrigger { | @@ -35,13 +37,14 @@ public abstract class BpmAbstractHttpRequestTrigger implements BpmTrigger { | ||
| 35 | // TODO @芋艿:要不要抽象一个 Http 请求的工具类,方便复用呢? | 37 | // TODO @芋艿:要不要抽象一个 Http 请求的工具类,方便复用呢? |
| 36 | // 3. 发起请求 | 38 | // 3. 发起请求 |
| 37 | HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(body, headers); | 39 | HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(body, headers); |
| 38 | - ResponseEntity<String> responseEntity = null; | 40 | + ResponseEntity<String> responseEntity; |
| 39 | try { | 41 | try { |
| 40 | responseEntity = restTemplate.exchange(url, HttpMethod.POST, | 42 | responseEntity = restTemplate.exchange(url, HttpMethod.POST, |
| 41 | requestEntity, String.class); | 43 | requestEntity, String.class); |
| 42 | log.info("[sendHttpRequest][HTTP 触发器,请求头:{},请求体:{},响应结果:{}]", headers, body, responseEntity); | 44 | log.info("[sendHttpRequest][HTTP 触发器,请求头:{},请求体:{},响应结果:{}]", headers, body, responseEntity); |
| 43 | } catch (RestClientException e) { | 45 | } catch (RestClientException e) { |
| 44 | log.error("[sendHttpRequest][HTTP 触发器,请求头:{},请求体:{},请求出错:{}]", headers, body, e.getMessage()); | 46 | log.error("[sendHttpRequest][HTTP 触发器,请求头:{},请求体:{},请求出错:{}]", headers, body, e.getMessage()); |
| 47 | + throw exception(PROCESS_INSTANCE_HTTP_TRIGGER_CALL_ERROR); | ||
| 45 | } | 48 | } |
| 46 | return responseEntity; | 49 | return responseEntity; |
| 47 | } | 50 | } |