Commit 4364ef09c533e8f5c336fc48bf5653a88ff18189
1 parent
6f2e5389
【代码评审】BPM:流程前后置通知
Showing
7 changed files
with
36 additions
and
40 deletions
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/vo/model/BpmModelMetaInfoVO.java
| ... | ... | @@ -82,9 +82,11 @@ public class BpmModelMetaInfoVO { |
| 82 | 82 | @Schema(description = "摘要设置", example = "{}") |
| 83 | 83 | private SummarySetting summarySetting; |
| 84 | 84 | |
| 85 | + // TODO @lesan:processBeforeTriggerSetting;要不叫这个?主要考虑,notify 留给后续的站内信、短信、邮件这种 notify 通知哈。 | |
| 85 | 86 | @Schema(description = "流程前置通知设置", example = "{}") |
| 86 | 87 | private HttpRequestSetting PreProcessNotifySetting; |
| 87 | 88 | |
| 89 | + // TODO @lesan:processAfterTriggerSetting | |
| 88 | 90 | @Schema(description = "流程后置通知设置", example = "{}") |
| 89 | 91 | private HttpRequestSetting PostProcessNotifySetting; |
| 90 | 92 | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/dataobject/definition/BpmProcessDefinitionInfoDO.java
| ... | ... | @@ -182,23 +182,22 @@ public class BpmProcessDefinitionInfoDO extends BaseDO { |
| 182 | 182 | */ |
| 183 | 183 | @TableField(typeHandler = JacksonTypeHandler.class) |
| 184 | 184 | private BpmModelMetaInfoVO.TitleSetting titleSetting; |
| 185 | - | |
| 186 | 185 | /** |
| 187 | 186 | * 摘要设置 |
| 188 | 187 | */ |
| 189 | 188 | @TableField(typeHandler = JacksonTypeHandler.class) |
| 190 | 189 | private BpmModelMetaInfoVO.SummarySetting summarySetting; |
| 191 | 190 | |
| 191 | + // TODO @lesan:processBeforeTriggerSetting;要不叫这个?主要考虑,notify 留给后续的站内信、短信、邮件这种 notify 通知哈。 | |
| 192 | 192 | /** |
| 193 | 193 | * 流程前置通知设置 |
| 194 | 194 | */ |
| 195 | - @TableField(typeHandler = JacksonTypeHandler.class) | |
| 195 | + @TableField(typeHandler = JacksonTypeHandler.class, exist = false) // TODO @芋艿:临时注释 exist,因为要合并 master-jdk17 | |
| 196 | 196 | private BpmModelMetaInfoVO.HttpRequestSetting PreProcessNotifySetting; |
| 197 | - | |
| 198 | 197 | /** |
| 199 | 198 | * 流程后置通知设置 |
| 200 | 199 | */ |
| 201 | - @TableField(typeHandler = JacksonTypeHandler.class) | |
| 200 | + @TableField(typeHandler = JacksonTypeHandler.class, exist = false) // TODO @芋艿:临时注释 exist,因为要合并 master-jdk17 | |
| 202 | 201 | private BpmModelMetaInfoVO.HttpRequestSetting PostProcessNotifySetting; |
| 203 | 202 | |
| 204 | 203 | } | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/BpmHttpRequestUtils.java
| ... | ... | @@ -37,51 +37,52 @@ public class BpmHttpRequestUtils { |
| 37 | 37 | |
| 38 | 38 | public static void executeBpmHttpRequest(ProcessInstance processInstance, |
| 39 | 39 | String url, |
| 40 | - List<BpmSimpleModelNodeVO.HttpRequestParam> headerParam, | |
| 41 | - List<BpmSimpleModelNodeVO.HttpRequestParam> bodyParam, | |
| 40 | + List<BpmSimpleModelNodeVO.HttpRequestParam> headerParams, | |
| 41 | + List<BpmSimpleModelNodeVO.HttpRequestParam> bodyParams, | |
| 42 | 42 | Boolean handleResponse, |
| 43 | 43 | List<KeyValue<String, String>> response, |
| 44 | + // TODO @lesan:RestTemplate 直接通过 springUtil 获取好咧; | |
| 44 | 45 | RestTemplate restTemplate, |
| 46 | + // TODO @lesan:processInstanceService 直接通过 springUtil 获取好咧; | |
| 45 | 47 | BpmProcessInstanceService processInstanceService) { |
| 46 | 48 | |
| 47 | 49 | // 1.1 设置请求头 |
| 48 | - MultiValueMap<String, String> headers = BpmHttpRequestUtils.buildHttpHeaders(processInstance, headerParam); | |
| 50 | + MultiValueMap<String, String> headers = buildHttpHeaders(processInstance, headerParams); | |
| 49 | 51 | // 1.2 设置请求体 |
| 50 | - MultiValueMap<String, String> body = BpmHttpRequestUtils.buildHttpBody(processInstance, bodyParam); | |
| 52 | + MultiValueMap<String, String> body = buildHttpBody(processInstance, bodyParams); | |
| 51 | 53 | |
| 52 | 54 | // 2. 发起请求 |
| 53 | - ResponseEntity<String> responseEntity = BpmHttpRequestUtils.sendHttpRequest(url, headers, body, restTemplate); | |
| 55 | + ResponseEntity<String> responseEntity = sendHttpRequest(url, headers, body, restTemplate); | |
| 54 | 56 | |
| 55 | 57 | // 3. 处理返回 |
| 58 | + // TODO @lesan:可以用 if return,让括号小点 | |
| 56 | 59 | if (Boolean.TRUE.equals(handleResponse)) { |
| 57 | 60 | // 3.1 判断是否需要解析返回值 |
| 58 | - if (responseEntity == null || StrUtil.isEmpty(responseEntity.getBody()) | |
| 61 | + if (responseEntity == null | |
| 62 | + || StrUtil.isEmpty(responseEntity.getBody()) | |
| 59 | 63 | || !responseEntity.getStatusCode().is2xxSuccessful() |
| 60 | 64 | || CollUtil.isEmpty(response)) { |
| 61 | 65 | return; |
| 62 | 66 | } |
| 63 | 67 | // 3.2 解析返回值, 返回值必须符合 CommonResult 规范。 |
| 64 | - CommonResult<Map<String, Object>> respResult = JsonUtils.parseObjectQuietly( | |
| 65 | - responseEntity.getBody(), new TypeReference<>() { | |
| 66 | - }); | |
| 68 | + CommonResult<Map<String, Object>> respResult = JsonUtils.parseObjectQuietly(responseEntity.getBody(), | |
| 69 | + new TypeReference<>() {}); | |
| 67 | 70 | if (respResult == null || !respResult.isSuccess()) { |
| 68 | 71 | return; |
| 69 | 72 | } |
| 70 | 73 | // 3.3 获取需要更新的流程变量 |
| 71 | - Map<String, Object> updateVariables = BpmHttpRequestUtils.getNeedUpdatedVariablesFromResponse(respResult.getData(), response); | |
| 74 | + Map<String, Object> updateVariables = getNeedUpdatedVariablesFromResponse(respResult.getData(), response); | |
| 72 | 75 | // 3.4 更新流程变量 |
| 73 | 76 | if (CollUtil.isNotEmpty(updateVariables)) { |
| 74 | 77 | processInstanceService.updateProcessInstanceVariables(processInstance.getId(), updateVariables); |
| 75 | 78 | } |
| 76 | 79 | } |
| 77 | - | |
| 78 | 80 | } |
| 79 | 81 | |
| 80 | 82 | public static ResponseEntity<String> sendHttpRequest(String url, |
| 81 | 83 | MultiValueMap<String, String> headers, |
| 82 | 84 | MultiValueMap<String, String> body, |
| 83 | 85 | RestTemplate restTemplate) { |
| 84 | - // 3. 发起请求 | |
| 85 | 86 | HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(body, headers); |
| 86 | 87 | ResponseEntity<String> responseEntity; |
| 87 | 88 | try { |
| ... | ... | @@ -95,7 +96,7 @@ public class BpmHttpRequestUtils { |
| 95 | 96 | } |
| 96 | 97 | |
| 97 | 98 | public static MultiValueMap<String, String> buildHttpHeaders(ProcessInstance processInstance, |
| 98 | - List<BpmSimpleModelNodeVO.HttpRequestParam> headerSettings) { | |
| 99 | + List<BpmSimpleModelNodeVO.HttpRequestParam> headerSettings) { | |
| 99 | 100 | Map<String, Object> processVariables = processInstance.getProcessVariables(); |
| 100 | 101 | MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); |
| 101 | 102 | headers.add(HEADER_TENANT_ID, processInstance.getTenantId()); |
| ... | ... | @@ -104,7 +105,7 @@ public class BpmHttpRequestUtils { |
| 104 | 105 | } |
| 105 | 106 | |
| 106 | 107 | public static MultiValueMap<String, String> buildHttpBody(ProcessInstance processInstance, |
| 107 | - List<BpmSimpleModelNodeVO.HttpRequestParam> bodySettings) { | |
| 108 | + List<BpmSimpleModelNodeVO.HttpRequestParam> bodySettings) { | |
| 108 | 109 | Map<String, Object> processVariables = processInstance.getProcessVariables(); |
| 109 | 110 | MultiValueMap<String, String> body = new LinkedMultiValueMap<>(); |
| 110 | 111 | addHttpRequestParam(body, bodySettings, processVariables); |
| ... | ... | @@ -120,7 +121,7 @@ public class BpmHttpRequestUtils { |
| 120 | 121 | * @return 需要更新的流程变量 |
| 121 | 122 | */ |
| 122 | 123 | public static Map<String, Object> getNeedUpdatedVariablesFromResponse(Map<String, Object> result, |
| 123 | - List<KeyValue<String, String>> responseSettings) { | |
| 124 | + List<KeyValue<String, String>> responseSettings) { | |
| 124 | 125 | Map<String, Object> updateVariables = new HashMap<>(); |
| 125 | 126 | if (CollUtil.isEmpty(result)) { |
| 126 | 127 | return updateVariables; | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java
| ... | ... | @@ -935,10 +935,10 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService |
| 935 | 935 | // 流程前置通知 |
| 936 | 936 | BpmProcessDefinitionInfoDO processDefinitionInfo = processDefinitionService. |
| 937 | 937 | getProcessDefinitionInfo(instance.getProcessDefinitionId()); |
| 938 | + // TODO @lesan:if return 哈。减少括号。 | |
| 938 | 939 | if (ObjUtil.isNotNull(processDefinitionInfo) && |
| 939 | 940 | ObjUtil.isNotNull(processDefinitionInfo.getPreProcessNotifySetting())) { |
| 940 | 941 | BpmModelMetaInfoVO.HttpRequestSetting setting = processDefinitionInfo.getPreProcessNotifySetting(); |
| 941 | - | |
| 942 | 942 | BpmHttpRequestUtils.executeBpmHttpRequest(instance, |
| 943 | 943 | setting.getUrl(), |
| 944 | 944 | setting.getHeader(), |
| ... | ... | @@ -949,4 +949,5 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService |
| 949 | 949 | } |
| 950 | 950 | }); |
| 951 | 951 | } |
| 952 | + | |
| 952 | 953 | } | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/listener/BpmUserTaskListener.java
| ... | ... | @@ -46,22 +46,14 @@ public class BpmUserTaskListener implements TaskListener { |
| 46 | 46 | |
| 47 | 47 | // 2. 发起请求 |
| 48 | 48 | // TODO @芋艿:哪些默认参数,后续再调研下;感觉可以搞个 task 字段,把整个 delegateTask 放进去; |
| 49 | - listenerHandler.getBody() | |
| 50 | - .add(new BpmSimpleModelNodeVO.HttpRequestParam().setKey("processInstanceId") | |
| 51 | - .setType(BpmHttpRequestParamTypeEnum.FIXED_VALUE.getType()) | |
| 52 | - .setValue(delegateTask.getProcessInstanceId())); | |
| 53 | - listenerHandler.getBody() | |
| 54 | - .add(new BpmSimpleModelNodeVO.HttpRequestParam().setKey("assignee") | |
| 55 | - .setType(BpmHttpRequestParamTypeEnum.FIXED_VALUE.getType()) | |
| 56 | - .setValue(delegateTask.getAssignee())); | |
| 57 | - listenerHandler.getBody() | |
| 58 | - .add(new BpmSimpleModelNodeVO.HttpRequestParam().setKey("taskDefinitionKey") | |
| 59 | - .setType(BpmHttpRequestParamTypeEnum.FIXED_VALUE.getType()) | |
| 60 | - .setValue(delegateTask.getTaskDefinitionKey())); | |
| 61 | - listenerHandler.getBody() | |
| 62 | - .add(new BpmSimpleModelNodeVO.HttpRequestParam().setKey("taskId") | |
| 63 | - .setType(BpmHttpRequestParamTypeEnum.FIXED_VALUE.getType()) | |
| 64 | - .setValue(delegateTask.getId())); | |
| 49 | + listenerHandler.getBody().add(new BpmSimpleModelNodeVO.HttpRequestParam().setKey("processInstanceId") | |
| 50 | + .setType(BpmHttpRequestParamTypeEnum.FIXED_VALUE.getType()).setValue(delegateTask.getProcessInstanceId())); | |
| 51 | + listenerHandler.getBody().add(new BpmSimpleModelNodeVO.HttpRequestParam().setKey("assignee") | |
| 52 | + .setType(BpmHttpRequestParamTypeEnum.FIXED_VALUE.getType()).setValue(delegateTask.getAssignee())); | |
| 53 | + listenerHandler.getBody().add(new BpmSimpleModelNodeVO.HttpRequestParam().setKey("taskDefinitionKey") | |
| 54 | + .setType(BpmHttpRequestParamTypeEnum.FIXED_VALUE.getType()).setValue(delegateTask.getTaskDefinitionKey())); | |
| 55 | + listenerHandler.getBody().add(new BpmSimpleModelNodeVO.HttpRequestParam().setKey("taskId") | |
| 56 | + .setType(BpmHttpRequestParamTypeEnum.FIXED_VALUE.getType()).setValue(delegateTask.getId())); | |
| 65 | 57 | BpmHttpRequestUtils.executeBpmHttpRequest(processInstance, |
| 66 | 58 | listenerHandler.getPath(), |
| 67 | 59 | listenerHandler.getHeader(), | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/trigger/http/BpmHttpCallbackTrigger.java
| ... | ... | @@ -41,13 +41,12 @@ public class BpmHttpCallbackTrigger extends BpmAbstractHttpRequestTrigger { |
| 41 | 41 | log.error("[execute][流程({}) HTTP 回调触发器配置为空]", processInstanceId); |
| 42 | 42 | return; |
| 43 | 43 | } |
| 44 | + | |
| 44 | 45 | // 2. 发起请求 |
| 45 | 46 | ProcessInstance processInstance = processInstanceService.getProcessInstance(processInstanceId); |
| 46 | - // 重要:回调请求 taskDefineKey 需要传给被调用方,用于回调执行 | |
| 47 | 47 | setting.getBody().add(new BpmSimpleModelNodeVO.HttpRequestParam() |
| 48 | - .setKey("taskDefineKey") | |
| 49 | - .setType(BpmHttpRequestParamTypeEnum.FIXED_VALUE.getType()) | |
| 50 | - .setValue(setting.getCallbackTaskDefineKey())); | |
| 48 | + .setKey("taskDefineKey") // 重要:回调请求 taskDefineKey 需要传给被调用方,用于回调执行 | |
| 49 | + .setType(BpmHttpRequestParamTypeEnum.FIXED_VALUE.getType()).setValue(setting.getCallbackTaskDefineKey())); | |
| 51 | 50 | BpmHttpRequestUtils.executeBpmHttpRequest(processInstance, |
| 52 | 51 | setting.getUrl(), |
| 53 | 52 | setting.getHeader(), |
| ... | ... | @@ -56,4 +55,5 @@ public class BpmHttpCallbackTrigger extends BpmAbstractHttpRequestTrigger { |
| 56 | 55 | restTemplate, |
| 57 | 56 | processInstanceService); |
| 58 | 57 | } |
| 58 | + | |
| 59 | 59 | } | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/trigger/http/BpmSyncHttpRequestTrigger.java
| ... | ... | @@ -39,6 +39,7 @@ public class BpmSyncHttpRequestTrigger extends BpmAbstractHttpRequestTrigger { |
| 39 | 39 | log.error("[execute][流程({}) HTTP 触发器请求配置为空]", processInstanceId); |
| 40 | 40 | return; |
| 41 | 41 | } |
| 42 | + | |
| 42 | 43 | // 2. 发起请求 |
| 43 | 44 | ProcessInstance processInstance = processInstanceService.getProcessInstance(processInstanceId); |
| 44 | 45 | BpmHttpRequestUtils.executeBpmHttpRequest(processInstance, | ... | ... |