最开始想法是想做一个,如果当前节点与下一个节点审批人相同情况下,自动审批这个功能,所以想法在这个节点找下个节点的审批人,判断是不是登录人,写一半发现实际我要做的业务好像不用这么麻烦,先记录一下吧。
根据底层代码,可以找到整个的节点流转,一点点获取到下一个节点的activityId,并打算根据activityId,获取到当前节点的审批人列表,if(sequenceFlow.getConditionExpression().equals("KaTeX parse error: Expected '}', got 'EOF' at end of input: …但现在的方法只能实现条件固定为{pass==1}也就是审批通过的情况,其它的还没写
private void getNextActivityElement(Task task){
// 获取与任务关联的执行实例
List<Execution> executions = runtimeService.createExecutionQuery().activityId(task.getTaskDefinitionKey()).list();
// 检查是否有执行实例
if (!executions.isEmpty()) {
Execution execution = executions.get(0); // 通常只有一个执行实例与任务关联
// 获取流程模型
BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId());
List<String> activeActivityIds = runtimeService.getActiveActivityIds(execution.getId());
// 检查是否有活动节点
if (!activeActivityIds.isEmpty()) {
// 遍历活动节点,获取下一个节点
for (String activityId : activeActivityIds) {
// 获取流程模型中的下一个活动节点
FlowElement flowElement = bpmnModel.getFlowElement(activityId);
if (flowElement != null) {
List<SequenceFlow> outgoingFlows = flowElement.getSubProcess().getOutgoingFlows();
if(outgoingFlows.size()>0){
String targetRef = outgoingFlows.get(0).getTargetRef();
if(targetRef.contains("Gateway")){
for (SequenceFlow outgoingFlow : outgoingFlows) {
FlowElement targetFlowElement = outgoingFlow.getTargetFlowElement();
List<SequenceFlow> outgoingFlows1 = targetFlowElement.getSubProcess().getOutgoingFlows();
for (SequenceFlow sequenceFlow : outgoingFlows1) {
if(sequenceFlow.getConditionExpression().equals("${pass==1}")){
mockDelegateExecution(task,sequenceFlow.getTargetRef());
return;
}
}
}
}else{
FlowElement flowElement1 = bpmnModel.getFlowElement(targetRef);
List<SequenceFlow> outgoingFlows1 = flowElement1.getSubProcess().getOutgoingFlows();
String targetRef1 = outgoingFlows1.get(0).getTargetRef();
mockDelegateExecution(task,targetRef1);
}
}
}
}
}
}
}
获取节点审批人,这块是基于芋道的框架开发的,想法类似于模拟test,走框架代码,获取节点审批 人。
private void mockDelegateExecution(Task task,String activiteyId) {
ExecutionEntityImpl execution = new ExecutionEntityImpl();
execution.setProcessInstanceId(task.getProcessInstanceId());
execution.setProcessDefinitionId(task.getProcessDefinitionId());
execution.setActivityId(activiteyId);
Set<Long> candidateUserIds = ruleService.calculateTaskCandidateUsers(execution);
System.out.println(candidateUserIds);
}
最后实现 (跟上面没关系了)
BpmTaskExtDO bpmTaskExtDO = taskExtMapper.selectLastCompleteTaskByInstanceId(delegateTask.getProcessInstanceId());
if(ObjectUtils.isNotEmpty(bpmTaskExtDO) && assignee.equals(bpmTaskExtDO.getAssigneeUserId())){
// 完成任务,审批通过
taskService.complete(delegateTask.getId(), map);
// 更新任务拓展表为通过
BpmTaskExtDO extDO = new BpmTaskExtDO();
extDO.setResult(BpmProcessInstanceResultEnum.APPROVE.getResult());
extDO.setReason("");
taskExtMapper.updateByTaskId(extDO);
}