/**
* 根据当前任务id获取下一步审批节点
*
* @param taskId
* @return
*/
@Override
public List<Map<String, String>> getNextAuditNodes(String taskId) {
HistoricTaskInstance historicTask = historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult();
if (Objects.isNull(historicTask)) {
return null;
}
ProcessDefinition processDefinition = getByKey(historicTask.getProcessDefinitionKey());
BpmnModelInstance bpmnModelInstance = repositoryService.getBpmnModelInstance(processDefinition.getId());
UserTask userTask = bpmnModelInstance.getModelElementById(historicTask.getTaskDefinitionKey());
Collection<SequenceFlow> outgoing = userTask.getOutgoing();
Iterator<SequenceFlow> iterator = outgoing.stream().iterator();
List<Map<String, String>> nodeList = new ArrayList<>();
while (iterator.hasNext()) {
SequenceFlow flow = iterator.next();
FlowNode target = flow.getTarget();
if ("exclusiveGateway".equals(target.getElementType().getTypeName())) {
Collection<SequenceFlow> targetOutgoing = target.getOutgoing();
Iterator<SequenceFlow> targetIt = targetOutgoing.stream().iterator();
while (targetIt.hasNext()) {
SequenceFlow targetFlow = targetIt.next();
FlowNode gatewayTarget = targetFlow.getTarget();
Map<String, String> map = generateTaskNode(gatewayTarget);
if (!Objects.isNull(map)) {
nodeList.add(map);
}
}
} else if ("userTask".equals(target.getElementType().getTypeName())) {
Map<String, String> map = generateTaskNode(target);
if (!Objects.isNull(map)) {
nodeList.add(map);
}
}
}
return nodeList;
}
/**
* 生成任务节点
*
* @param target
* @return
*/
public Map<String, String> generateTaskNode(FlowNode target) {
if ("userTask".equals(target.getElementType().getTypeName())) {
Map<String, String> map = new HashMap<>();
map.put("value", target.getId());
map.put("label", target.getName());
map.put("assignee", getTaskAssign(target));
return map;
}
return null;
}
/**
* 获取任务办理人
*
* @param target
* @return
*/
public String getTaskAssign(FlowNode target) {
//代理人
String assignee = target.getAttributeValueNs(BpmnModelConstants.CAMUNDA_NS, "assignee");
if (StringUtils.isNotBlank(assignee)) {
return assignee;
} else {
//代理人不存在,获取组任务办理人
String candidateUsers = target.getAttributeValueNs(BpmnModelConstants.CAMUNDA_NS, "candidateUsers");
if (StringUtils.isNotBlank(candidateUsers)) {
return candidateUsers;
} else {
//如果组任务办理人不存在,获取多实例任务办理人
MultiInstanceLoopCharacteristics modelElementInstance = (MultiInstanceLoopCharacteristics) target
.getUniqueChildElementByNameNs(BpmnModelConstants.BPMN20_NS, "multiInstanceLoopCharacteristics");
if (!Objects.isNull(modelElementInstance)) {
return modelElementInstance.getAttributeValueNs(BpmnModelConstants.CAMUNDA_NS, "collection");
}
return null;
}
}
}
camunda根据当前任务id获取下一步审批节点
最新推荐文章于 2023-09-06 09:11:38 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)