【代码评审】Bpm:触发器的实现
This commit is contained in:
parent
0723e4571d
commit
f8d6f1e2c4
|
@ -158,6 +158,7 @@ public class BpmSimpleModelNodeVO {
|
|||
@Schema(description = "值", example = "xxx")
|
||||
@NotEmpty(message = "值不能为空")
|
||||
private String value;
|
||||
|
||||
}
|
||||
|
||||
@Schema(description = "审批节点拒绝处理策略")
|
||||
|
@ -362,12 +363,14 @@ public class BpmSimpleModelNodeVO {
|
|||
private List<HttpRequestParam> body;
|
||||
|
||||
/**
|
||||
* 请求返回处理设置。 用于修改流程表单值
|
||||
* key: 表示要修改的流程表单字段 Id.
|
||||
* value: 接口返回的字段名
|
||||
* 请求返回处理设置,用于修改流程表单值
|
||||
*
|
||||
* key:表示要修改的流程表单字段名(name)
|
||||
* value:接口返回的字段名
|
||||
*/
|
||||
@Schema(description = "请求返回处理设置", example = "[]")
|
||||
private List<KeyValue<String,String>> response;
|
||||
private List<KeyValue<String, String>> response;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -160,9 +160,9 @@ public interface BpmProcessInstanceService {
|
|||
/**
|
||||
* 更新 ProcessInstance 的变量
|
||||
*
|
||||
* @param processInstanceId 流程编号
|
||||
* @param id 流程编号
|
||||
* @param variables 流程变量
|
||||
*/
|
||||
void updateProcessInstanceVariables(String processInstanceId, Map<String, Object> variables);
|
||||
void updateProcessInstanceVariables(String id, Map<String, Object> variables);
|
||||
|
||||
}
|
||||
|
|
|
@ -758,7 +758,8 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
|
|||
}
|
||||
|
||||
@Override
|
||||
public void updateProcessInstanceVariables(String processInstanceId, Map<String, Object> variables) {
|
||||
runtimeService.setVariables(processInstanceId, variables);
|
||||
public void updateProcessInstanceVariables(String id, Map<String, Object> variables) {
|
||||
runtimeService.setVariables(id, variables);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -76,7 +76,10 @@ public class BpmHttpRequestTrigger implements BpmTrigger {
|
|||
ResponseEntity<String> responseEntity = restTemplate.exchange(setting.getUrl(), HttpMethod.POST,
|
||||
requestEntity, String.class);
|
||||
log.info("[execute][HTTP 触发器,请求头:{},请求体:{},响应结果:{}]", headers, body, responseEntity);
|
||||
|
||||
// TODO @jason:建议把请求和失败,放在两个 try catch 里处理。
|
||||
// 4. 处理请求返回
|
||||
// TODO @jason:返回结果,要不统一用 CommonResult,符合这个规范。这样,就可以验证 code 为 0 了。必须符合这个规范~~
|
||||
if (CollUtil.isNotEmpty(setting.getResponse()) && responseEntity.getStatusCode().is2xxSuccessful()
|
||||
&& StrUtil.isNotEmpty(responseEntity.getBody())) {
|
||||
// 4.1 获取需要更新的流程变量
|
||||
|
@ -86,15 +89,15 @@ public class BpmHttpRequestTrigger implements BpmTrigger {
|
|||
processInstanceService.updateProcessInstanceVariables(processInstanceId, updateVariables);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (RestClientException e) {
|
||||
log.error("[execute][HTTP 触发器,请求头:{},请求体:{},请求出错:{}]", headers, body, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 从请求返回值获取需要更新的流程变量。优先从 data 字段获取,如果 data 字段不存在,从根节点获取。
|
||||
* 从请求返回值获取需要更新的流程变量
|
||||
*
|
||||
* 优先从 data 字段获取,如果 data 字段不存在,从根节点获取
|
||||
*
|
||||
* @param responseBody 请求返回报文体
|
||||
* @param responseSettings 返回设置
|
||||
|
@ -103,18 +106,21 @@ public class BpmHttpRequestTrigger implements BpmTrigger {
|
|||
private Map<String, Object> getNeedUpdatedVariablesFromResponse(String responseBody,
|
||||
List<KeyValue<String, String>> responseSettings) {
|
||||
Map<String, Object> updateVariables = new HashMap<>();
|
||||
// TODO @jason:这里 if return 更简洁一点;
|
||||
// TODO @jason:JSONUtil => JsonUtils,尽量包一层
|
||||
if (JSONUtil.isTypeJSONObject(responseBody)) {
|
||||
JSONObject dataObj = null;
|
||||
if (JSONUtil.parseObj(responseBody).getObj(PARSE_RESPONSE_FIELD) instanceof JSONObject) {
|
||||
dataObj = (JSONObject) JSONUtil.parseObj(responseBody).getObj(PARSE_RESPONSE_FIELD);
|
||||
}
|
||||
JSONObject updateObj = dataObj == null ? JSONUtil.parseObj(responseBody) : dataObj;
|
||||
responseSettings.forEach(respSetting -> {
|
||||
if (StrUtil.isNotEmpty(respSetting.getKey()) && updateObj.containsKey(respSetting.getValue())) {
|
||||
updateVariables.put(respSetting.getKey(), updateObj.get(respSetting.getValue()));
|
||||
responseSettings.forEach(responseSetting -> {
|
||||
if (StrUtil.isNotEmpty(responseSetting.getKey()) && updateObj.containsKey(responseSetting.getValue())) {
|
||||
updateVariables.put(responseSetting.getKey(), updateObj.get(responseSetting.getValue()));
|
||||
}
|
||||
});
|
||||
}
|
||||
return updateVariables;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue