Commit f71ec384568d6291fef8216d0a6897c4395a9f70

Authored by YunaiV
1 parent ff70aaa6

【同步】BOOT 和 CLOUD 的功能

yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/enums/ErrorCodeConstants.java
... ... @@ -40,7 +40,7 @@ public interface ErrorCodeConstants {
40 40 ErrorCode PROCESS_INSTANCE_START_USER_SELECT_ASSIGNEES_NOT_EXISTS = new ErrorCode(1_009_004_004, "任务({})的候选人({})不存在");
41 41 ErrorCode PROCESS_INSTANCE_START_USER_CAN_START = new ErrorCode(1_009_004_005, "发起流程失败,你没有权限发起该流程");
42 42 ErrorCode PROCESS_INSTANCE_CANCEL_FAIL_NOT_ALLOW = new ErrorCode(1_009_004_005, "流程取消失败,该流程不允许取消");
43   - ErrorCode PROCESS_INSTANCE_HTTP_TRIGGER_CALL_ERROR = new ErrorCode(1_009_004_006, "流程 Http 触发器请求调用失败");
  43 + ErrorCode PROCESS_INSTANCE_HTTP_CALL_ERROR = new ErrorCode(1_009_004_006, "流程 Http 请求调用失败");
44 44 ErrorCode PROCESS_INSTANCE_APPROVE_USER_SELECT_ASSIGNEES_NOT_CONFIG = new ErrorCode(1_009_004_007, "下一个任务({})的审批人未配置");
45 45 ErrorCode PROCESS_INSTANCE_CANCEL_CHILD_FAIL_NOT_ALLOW = new ErrorCode(1_009_004_008, "子流程取消失败,子流程不允许取消");
46 46  
... ... @@ -58,7 +58,6 @@ public interface ErrorCodeConstants {
58 58 ErrorCode TASK_SIGN_DELETE_NO_PARENT = new ErrorCode(1_009_005_012, "任务减签失败,被减签的任务必须是通过加签生成的任务");
59 59 ErrorCode TASK_TRANSFER_FAIL_USER_REPEAT = new ErrorCode(1_009_005_013, "任务转办失败,转办人和当前审批人为同一人");
60 60 ErrorCode TASK_TRANSFER_FAIL_USER_NOT_EXISTS = new ErrorCode(1_009_005_014, "任务转办失败,转办人不存在");
61   - ErrorCode TASK_CREATE_FAIL_NO_CANDIDATE_USER = new ErrorCode(1_009_006_003, "操作失败,原因:找不到任务的审批人!");
62 61 ErrorCode TASK_SIGNATURE_NOT_EXISTS = new ErrorCode(1_009_005_015, "签名不能为空!");
63 62 ErrorCode TASK_REASON_REQUIRE = new ErrorCode(1_009_005_016, "审批意见不能为空!");
64 63  
... ...
yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/BpmHttpRequestUtils.java
... ... @@ -6,15 +6,15 @@ import cn.iocoder.yudao.framework.common.core.KeyValue;
6 6 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
7 7 import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
8 8 import cn.iocoder.yudao.framework.common.util.spring.SpringUtils;
  9 +import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
  10 +import cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEvent;
9 11 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
10 12 import cn.iocoder.yudao.module.bpm.enums.definition.BpmHttpRequestParamTypeEnum;
11 13 import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService;
12 14 import com.fasterxml.jackson.core.type.TypeReference;
13 15 import lombok.extern.slf4j.Slf4j;
14 16 import org.flowable.engine.runtime.ProcessInstance;
15   -import org.springframework.http.HttpEntity;
16   -import org.springframework.http.HttpMethod;
17   -import org.springframework.http.ResponseEntity;
  17 +import org.springframework.http.*;
18 18 import org.springframework.util.LinkedMultiValueMap;
19 19 import org.springframework.util.MultiValueMap;
20 20 import org.springframework.web.client.RestClientException;
... ... @@ -26,7 +26,7 @@ import java.util.Map;
26 26  
27 27 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
28 28 import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.HEADER_TENANT_ID;
29   -import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.PROCESS_INSTANCE_HTTP_TRIGGER_CALL_ERROR;
  29 +import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.PROCESS_INSTANCE_HTTP_CALL_ERROR;
30 30  
31 31 /**
32 32 * 工作流发起 HTTP 请求工具类
... ... @@ -42,7 +42,6 @@ public class BpmHttpRequestUtils {
42 42 List<BpmSimpleModelNodeVO.HttpRequestParam> bodyParams,
43 43 Boolean handleResponse,
44 44 List<KeyValue<String, String>> response) {
45   - RestTemplate restTemplate = SpringUtils.getBean(RestTemplate.class);
46 45 BpmProcessInstanceService processInstanceService = SpringUtils.getBean(BpmProcessInstanceService.class);
47 46  
48 47 // 1.1 设置请求头
... ... @@ -51,6 +50,7 @@ public class BpmHttpRequestUtils {
51 50 MultiValueMap<String, String> body = buildHttpBody(processInstance, bodyParams);
52 51  
53 52 // 2. 发起请求
  53 + RestTemplate restTemplate = SpringUtils.getBean(RestTemplate.class);
54 54 ResponseEntity<String> responseEntity = sendHttpRequest(url, headers, body, restTemplate);
55 55  
56 56 // 3. 处理返回
... ... @@ -78,27 +78,55 @@ public class BpmHttpRequestUtils {
78 78 }
79 79 }
80 80  
  81 + public static void executeBpmHttpRequest(BpmProcessInstanceStatusEvent event,
  82 + String url) {
  83 + // 1.1 设置请求头
  84 + HttpHeaders headers = new HttpHeaders();
  85 + headers.setContentType(MediaType.APPLICATION_JSON);
  86 + if (TenantContextHolder.getTenantId() != null) {
  87 + headers.add(HEADER_TENANT_ID, String.valueOf(TenantContextHolder.getTenantId()));
  88 + } else {
  89 + BpmProcessInstanceService processInstanceService = SpringUtils.getBean(BpmProcessInstanceService.class);
  90 + ProcessInstance processInstance = processInstanceService.getProcessInstance(event.getId());
  91 + if (processInstance != null) {
  92 + headers.add(HEADER_TENANT_ID, String.valueOf(TenantContextHolder.getTenantId()));
  93 + }
  94 + }
  95 + // 1.2 设置请求体
  96 +// MultiValueMap<String, String> body = new LinkedMultiValueMap<>();
  97 +// body.add("id", event.getId());
  98 +// body.add("processDefinitionKey", event.getProcessDefinitionKey());
  99 +// body.add("status", event.getStatus().toString());
  100 +// if (StrUtil.isNotEmpty(event.getBusinessKey())) {
  101 +// body.add("businessKey", event.getBusinessKey());
  102 +// }
  103 +
  104 + // 2. 发起请求
  105 + RestTemplate restTemplate = SpringUtils.getBean(RestTemplate.class);
  106 + sendHttpRequest(url, headers, event, restTemplate);
  107 + }
  108 +
81 109 public static ResponseEntity<String> sendHttpRequest(String url,
82 110 MultiValueMap<String, String> headers,
83   - MultiValueMap<String, String> body,
  111 + Object body,
84 112 RestTemplate restTemplate) {
85   - HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(body, headers);
  113 + HttpEntity<Object> requestEntity = new HttpEntity<>(body, headers);
86 114 ResponseEntity<String> responseEntity;
87 115 try {
88 116 responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
89   - log.info("[sendHttpRequest][HTTP 触发器,请求头:{},请求体:{},响应结果:{}]", headers, body, responseEntity);
  117 + log.info("[sendHttpRequest][HTTP 请求,请求头:{},请求体:{},响应结果:{}]", headers, body, responseEntity);
90 118 } catch (RestClientException e) {
91   - log.error("[sendHttpRequest][HTTP 触发器,请求头:{},请求体:{},请求出错:{}]", headers, body, e.getMessage());
92   - throw exception(PROCESS_INSTANCE_HTTP_TRIGGER_CALL_ERROR);
  119 + log.error("[sendHttpRequest][HTTP 请求,请求头:{},请求体:{},请求出错:{}]", headers, body, e.getMessage());
  120 + throw exception(PROCESS_INSTANCE_HTTP_CALL_ERROR);
93 121 }
94 122 return responseEntity;
95 123 }
96 124  
97 125 public static MultiValueMap<String, String> buildHttpHeaders(ProcessInstance processInstance,
98 126 List<BpmSimpleModelNodeVO.HttpRequestParam> headerSettings) {
99   - Map<String, Object> processVariables = processInstance.getProcessVariables();
100 127 MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
101 128 headers.add(HEADER_TENANT_ID, processInstance.getTenantId());
  129 + Map<String, Object> processVariables = processInstance.getProcessVariables();
102 130 addHttpRequestParam(headers, headerSettings, processVariables);
103 131 return headers;
104 132 }
... ...
yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/util/CrmPermissionUtils.java
... ... @@ -32,7 +32,7 @@ public class CrmPermissionUtils {
32 32 * @return 是/否
33 33 */
34 34 public static boolean isCrmAdmin() {
35   - PermissionApi permissionApi = SpringUtil.getBean(PermissionApi.class);
  35 + PermissionCommonApi permissionApi = SpringUtil.getBean(PermissionCommonApi.class);
36 36 return permissionApi.hasAnyRoles(getLoginUserId(), RoleCodeEnum.CRM_ADMIN.getCode());
37 37 }
38 38  
... ...