fix:获取下一个节点审批人为空时,返回new HashMap<>(),避免下级使用空指针
review: 优化审批时,校验选择的下一个节点的审批人,是否合法
This commit is contained in:
parent
b6a9b5dda9
commit
26dd8b6670
|
@ -194,7 +194,7 @@ public class FlowableUtils {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static Map<String, List<Long>> getStartUserSelectAssignees(Map<String, Object> processVariables) {
|
public static Map<String, List<Long>> getStartUserSelectAssignees(Map<String, Object> processVariables) {
|
||||||
if (processVariables == null) {
|
if (processVariables == null) {
|
||||||
return null;
|
return new HashMap<>();
|
||||||
}
|
}
|
||||||
return (Map<String, List<Long>>) processVariables.get(
|
return (Map<String, List<Long>>) processVariables.get(
|
||||||
BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES);
|
BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES);
|
||||||
|
@ -214,12 +214,12 @@ public class FlowableUtils {
|
||||||
* 获得流程实例的审批用户选择的下一个节点的审批人 Map
|
* 获得流程实例的审批用户选择的下一个节点的审批人 Map
|
||||||
*
|
*
|
||||||
* @param processVariables 流程变量
|
* @param processVariables 流程变量
|
||||||
* @return 审批用户选择的下一个节点的审批人Map Map
|
* @return 审批用户选择的下一个节点的审批人Map
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static Map<String, List<Long>> getApproveUserSelectAssignees(Map<String, Object> processVariables) {
|
public static Map<String, List<Long>> getApproveUserSelectAssignees(Map<String, Object> processVariables) {
|
||||||
if (processVariables == null) {
|
if (processVariables == null) {
|
||||||
return null;
|
return new HashMap<>();
|
||||||
}
|
}
|
||||||
return (Map<String, List<Long>>) processVariables.get(
|
return (Map<String, List<Long>>) processVariables.get(
|
||||||
BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_APPROVE_USER_SELECT_ASSIGNEES);
|
BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_APPROVE_USER_SELECT_ASSIGNEES);
|
||||||
|
|
|
@ -558,18 +558,12 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
||||||
taskService.addComment(task.getId(), task.getProcessInstanceId(), BpmCommentTypeEnum.APPROVE.getType(),
|
taskService.addComment(task.getId(), task.getProcessInstanceId(), BpmCommentTypeEnum.APPROVE.getType(),
|
||||||
BpmCommentTypeEnum.APPROVE.formatComment(reqVO.getReason()));
|
BpmCommentTypeEnum.APPROVE.formatComment(reqVO.getReason()));
|
||||||
// 2.3 调用 BPM complete 去完成任务
|
// 2.3 调用 BPM complete 去完成任务
|
||||||
// 其中,variables 是存储动态表单到 local 任务级别。过滤一下,避免 ProcessInstance 系统级的变量被占用
|
// 校验并处理 APPROVE_USER_SELECT 当前审批人,选择下一节点审批人的逻辑
|
||||||
if (CollUtil.isNotEmpty(reqVO.getVariables())) {
|
Map<String, Object> variables = validateAndSetNextAssignees(task.getTaskDefinitionKey(), reqVO.getVariables(),
|
||||||
// 校验并处理 APPROVE_USER_SELECT 当前审批人,选择下一节点审批人的逻辑
|
bpmnModel, reqVO.getNextAssignees(), instance);
|
||||||
Map<String, Object> variables = validateAndSetNextAssignees(task.getTaskDefinitionKey(), reqVO.getVariables(),
|
// 完成任务
|
||||||
bpmnModel, reqVO.getNextAssignees(), instance);
|
runtimeService.setVariables(task.getProcessInstanceId(), variables);
|
||||||
// 完成任务
|
taskService.complete(task.getId(), variables, true);
|
||||||
runtimeService.setVariables(task.getProcessInstanceId(), variables);
|
|
||||||
taskService.complete(task.getId(), variables, true);
|
|
||||||
} else {
|
|
||||||
// 完成任务
|
|
||||||
taskService.complete(task.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
// 【加签专属】处理加签任务
|
// 【加签专属】处理加签任务
|
||||||
handleParentTaskIfSign(task.getParentTaskId());
|
handleParentTaskIfSign(task.getParentTaskId());
|
||||||
|
@ -590,51 +584,50 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
||||||
*/
|
*/
|
||||||
private Map<String, Object> validateAndSetNextAssignees(String taskDefinitionKey, Map<String, Object> variables, BpmnModel bpmnModel,
|
private Map<String, Object> validateAndSetNextAssignees(String taskDefinitionKey, Map<String, Object> variables, BpmnModel bpmnModel,
|
||||||
Map<String, List<Long>> nextAssignees, ProcessInstance processInstance) {
|
Map<String, List<Long>> nextAssignees, ProcessInstance processInstance) {
|
||||||
// 下一个节点参数为空,不做处理,表示流程正常流转,无需选择下一个节点的审判人
|
|
||||||
// TODO @小北:会出现漏选,其实需要的情况哇?
|
|
||||||
if (CollUtil.isEmpty(nextAssignees)) {
|
|
||||||
return variables;
|
|
||||||
}
|
|
||||||
// 1. 获取下一个将要执行的节点集合
|
// 1. 获取下一个将要执行的节点集合
|
||||||
FlowElement flowElement = bpmnModel.getFlowElement(taskDefinitionKey);
|
FlowElement flowElement = bpmnModel.getFlowElement(taskDefinitionKey);
|
||||||
List<FlowNode> nextFlowNodes = getNextFlowNodes(flowElement, bpmnModel, variables);
|
List<FlowNode> nextFlowNodes = getNextFlowNodes(flowElement, bpmnModel, variables);
|
||||||
|
|
||||||
// 2. 循环下一个将要执行的节点集合
|
// 2. 循环下一个将要执行的节点集合
|
||||||
Map<String, List<Long>> processVariables = new HashMap<>();
|
Map<String, List<Long>> processVariables;
|
||||||
for (FlowNode nextFlowNode : nextFlowNodes) {
|
for (FlowNode nextFlowNode : nextFlowNodes) {
|
||||||
if (!nextAssignees.containsKey(nextFlowNode.getId())) {
|
// 获取任务节点中的审批人策略
|
||||||
throw exception(TASK_TARGET_NODE_NOT_EXISTS, nextFlowNode.getName());
|
|
||||||
}
|
|
||||||
List<Long> assignees = nextAssignees.get(nextFlowNode.getId());
|
|
||||||
// 2.1 情况一:如果节点中的审批人策略为 发起人自选
|
|
||||||
Integer candidateStrategy = parseCandidateStrategy(nextFlowNode);
|
Integer candidateStrategy = parseCandidateStrategy(nextFlowNode);
|
||||||
|
// 2.1 情况一:如果节点中的审批人策略为 发起人自选
|
||||||
if (ObjUtil.equals(candidateStrategy, BpmTaskCandidateStrategyEnum.START_USER_SELECT.getStrategy())) {
|
if (ObjUtil.equals(candidateStrategy, BpmTaskCandidateStrategyEnum.START_USER_SELECT.getStrategy())) {
|
||||||
processVariables = FlowableUtils.getStartUserSelectAssignees(processInstance.getProcessVariables());
|
|
||||||
if (processVariables == null) {
|
|
||||||
processVariables = new HashMap<>();
|
|
||||||
}
|
|
||||||
List<Long> startUserSelectAssignee = processVariables.get(nextFlowNode.getId());
|
|
||||||
// 特殊:如果当前节点已经存在审批人,则不允许覆盖
|
|
||||||
if (CollUtil.isNotEmpty(startUserSelectAssignee)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// 如果节点存在,但未配置审批人
|
// 如果节点存在,但未配置审批人
|
||||||
|
List<Long> assignees = nextAssignees != null ? nextAssignees.get(nextFlowNode.getId()) : null;
|
||||||
if (CollUtil.isEmpty(assignees)) {
|
if (CollUtil.isEmpty(assignees)) {
|
||||||
throw exception(PROCESS_INSTANCE_START_USER_SELECT_ASSIGNEES_NOT_CONFIG, nextFlowNode.getName());
|
throw exception(PROCESS_INSTANCE_START_USER_SELECT_ASSIGNEES_NOT_CONFIG, nextFlowNode.getName());
|
||||||
}
|
}
|
||||||
|
processVariables = FlowableUtils.getStartUserSelectAssignees(processInstance.getProcessVariables());
|
||||||
|
if (CollUtil.isNotEmpty(processVariables)) {
|
||||||
|
List<Long> startUserSelectAssignee = processVariables.get(nextFlowNode.getId());
|
||||||
|
// 特殊:如果当前节点已经存在审批人,则不允许覆盖
|
||||||
|
if (CollUtil.isNotEmpty(startUserSelectAssignee)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
// 校验通过的全部节点和审批人
|
// 校验通过的全部节点和审批人
|
||||||
processVariables.put(nextFlowNode.getId(), assignees);
|
processVariables.put(nextFlowNode.getId(), nextAssignees.get(nextFlowNode.getId()));
|
||||||
variables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES, processVariables);
|
variables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES, processVariables);
|
||||||
}
|
}
|
||||||
// 2.2 情况二:如果节点中的审批人策略为 审批人,在审批时选择下一个节点的审批人,并且该节点的审批人为空
|
// 2.2 情况二:如果节点中的审批人策略为 审批人,在审批时选择下一个节点的审批人,并且该节点的审批人为空
|
||||||
if (ObjUtil.equals(candidateStrategy, BpmTaskCandidateStrategyEnum.APPROVE_USER_SELECT.getStrategy())) {
|
if (ObjUtil.equals(candidateStrategy, BpmTaskCandidateStrategyEnum.APPROVE_USER_SELECT.getStrategy())) {
|
||||||
// 如果节点存在,但未配置审批人
|
// 如果节点存在,但未配置审批人
|
||||||
|
List<Long> assignees = nextAssignees != null ? nextAssignees.get(nextFlowNode.getId()) : null;
|
||||||
if (CollUtil.isEmpty(assignees)) {
|
if (CollUtil.isEmpty(assignees)) {
|
||||||
throw exception(PROCESS_INSTANCE_APPROVE_USER_SELECT_ASSIGNEES_NOT_CONFIG, nextFlowNode.getName());
|
throw exception(PROCESS_INSTANCE_APPROVE_USER_SELECT_ASSIGNEES_NOT_CONFIG, nextFlowNode.getName());
|
||||||
}
|
}
|
||||||
|
processVariables = FlowableUtils.getApproveUserSelectAssignees(processInstance.getProcessVariables());
|
||||||
|
if (CollUtil.isNotEmpty(processVariables)) {
|
||||||
|
List<Long> approveUserSelectAssignee = processVariables.get(nextFlowNode.getId());
|
||||||
|
// 特殊:如果当前节点已经存在审批人,则不允许覆盖
|
||||||
|
if (CollUtil.isNotEmpty(approveUserSelectAssignee)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
// 校验通过的全部节点和审批人
|
// 校验通过的全部节点和审批人
|
||||||
processVariables.put(nextFlowNode.getId(), assignees);
|
processVariables.put(nextFlowNode.getId(), nextAssignees.get(nextFlowNode.getId()));
|
||||||
// TODO @小北:是不是要类似情况一的做法,通过 PROCESS_INSTANCE_VARIABLE_APPROVE_USER_SELECT_ASSIGNEES 拿一下?因为如果 task1 是审批人自选,task2 是审批人自选,看着会覆盖?
|
|
||||||
variables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_APPROVE_USER_SELECT_ASSIGNEES, processVariables);
|
variables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_APPROVE_USER_SELECT_ASSIGNEES, processVariables);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue