|
|
|
@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil; |
|
|
|
|
import cn.iocoder.yudao.framework.common.core.KeyValue; |
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
|
|
|
|
import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
|
|
|
|
import cn.iocoder.yudao.framework.common.util.spring.SpringUtils; |
|
|
|
|
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO; |
|
|
|
|
import cn.iocoder.yudao.module.bpm.enums.definition.BpmHttpRequestParamTypeEnum; |
|
|
|
|
import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService; |
|
|
|
@ -40,11 +41,9 @@ public class BpmHttpRequestUtils { |
|
|
|
|
List<BpmSimpleModelNodeVO.HttpRequestParam> headerParams, |
|
|
|
|
List<BpmSimpleModelNodeVO.HttpRequestParam> bodyParams, |
|
|
|
|
Boolean handleResponse, |
|
|
|
|
List<KeyValue<String, String>> response, |
|
|
|
|
// TODO @lesan:RestTemplate 直接通过 springUtil 获取好咧;
|
|
|
|
|
RestTemplate restTemplate, |
|
|
|
|
// TODO @lesan:processInstanceService 直接通过 springUtil 获取好咧;
|
|
|
|
|
BpmProcessInstanceService processInstanceService) { |
|
|
|
|
List<KeyValue<String, String>> response) { |
|
|
|
|
RestTemplate restTemplate = SpringUtils.getBean(RestTemplate.class); |
|
|
|
|
BpmProcessInstanceService processInstanceService = SpringUtils.getBean(BpmProcessInstanceService.class); |
|
|
|
|
|
|
|
|
|
// 1.1 设置请求头
|
|
|
|
|
MultiValueMap<String, String> headers = buildHttpHeaders(processInstance, headerParams); |
|
|
|
@ -55,27 +54,27 @@ public class BpmHttpRequestUtils { |
|
|
|
|
ResponseEntity<String> responseEntity = sendHttpRequest(url, headers, body, restTemplate); |
|
|
|
|
|
|
|
|
|
// 3. 处理返回
|
|
|
|
|
// TODO @lesan:可以用 if return,让括号小点
|
|
|
|
|
if (Boolean.TRUE.equals(handleResponse)) { |
|
|
|
|
// 3.1 判断是否需要解析返回值
|
|
|
|
|
if (responseEntity == null |
|
|
|
|
|| StrUtil.isEmpty(responseEntity.getBody()) |
|
|
|
|
|| !responseEntity.getStatusCode().is2xxSuccessful() |
|
|
|
|
|| CollUtil.isEmpty(response)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
// 3.2 解析返回值, 返回值必须符合 CommonResult 规范。
|
|
|
|
|
CommonResult<Map<String, Object>> respResult = JsonUtils.parseObjectQuietly(responseEntity.getBody(), |
|
|
|
|
new TypeReference<>() {}); |
|
|
|
|
if (respResult == null || !respResult.isSuccess()) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
// 3.3 获取需要更新的流程变量
|
|
|
|
|
Map<String, Object> updateVariables = getNeedUpdatedVariablesFromResponse(respResult.getData(), response); |
|
|
|
|
// 3.4 更新流程变量
|
|
|
|
|
if (CollUtil.isNotEmpty(updateVariables)) { |
|
|
|
|
processInstanceService.updateProcessInstanceVariables(processInstance.getId(), updateVariables); |
|
|
|
|
} |
|
|
|
|
if (Boolean.FALSE.equals(handleResponse)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
// 3.1 判断是否需要解析返回值
|
|
|
|
|
if (responseEntity == null |
|
|
|
|
|| StrUtil.isEmpty(responseEntity.getBody()) |
|
|
|
|
|| !responseEntity.getStatusCode().is2xxSuccessful() |
|
|
|
|
|| CollUtil.isEmpty(response)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
// 3.2 解析返回值, 返回值必须符合 CommonResult 规范。
|
|
|
|
|
CommonResult<Map<String, Object>> respResult = JsonUtils.parseObjectQuietly(responseEntity.getBody(), |
|
|
|
|
new TypeReference<>() {}); |
|
|
|
|
if (respResult == null || !respResult.isSuccess()) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
// 3.3 获取需要更新的流程变量
|
|
|
|
|
Map<String, Object> updateVariables = getNeedUpdatedVariablesFromResponse(respResult.getData(), response); |
|
|
|
|
// 3.4 更新流程变量
|
|
|
|
|
if (CollUtil.isNotEmpty(updateVariables)) { |
|
|
|
|
processInstanceService.updateProcessInstanceVariables(processInstance.getId(), updateVariables); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|