activiti如何驳回任务
时间: 2024-01-27 10:05:32 浏览: 27
在Activiti中,可以使用以下步骤来驳回任务:
1. 获取当前任务的历史记录,找到上一个任务节点的ID。
2. 使用上一个任务节点的ID,查询该任务节点的输出连线,获取所有可以驳回的节点。
3. 根据驳回节点的ID,创建一个新的任务,并将当前任务的所有数据复制到新任务中。
4. 将新任务提交给驳回节点,完成驳回操作。
需要注意的是,驳回操作可能会涉及到流程历史记录、权限、数据一致性等方面,因此在实际应用中需要仔细考虑。
相关问题
Activiti5驳回
在 Activiti 5 中,驳回功能可以通过以下两种方式实现:
1. 使用 `exclusiveGateway` 和 `userTask` 元素:在流程中添加一个 `exclusiveGateway` 元素,将其与要驳回的目标 `userTask` 元素相连。在 `exclusiveGateway` 元素的条件中,判断是否需要驳回,如果需要驳回,则将流程实例的当前任务设置为目标 `userTask` 元素,即可实现驳回功能。
以下是一个示例流程定义文件:
```xml
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:activiti="http://activiti.org/bpmn"
targetNamespace="http://www.activiti.org/processdef">
<process id="process"
name="Process"
isExecutable="true">
<startEvent id="startEvent"
name="Start">
<outgoing>flow1</outgoing>
</startEvent>
<userTask id="userTask1"
name="Task 1">
<incoming>flow1</incoming>
<outgoing>flow2</outgoing>
</userTask>
<exclusiveGateway id="exclusiveGateway"
name="Gateway">
<incoming>flow2</incoming>
<outgoing>flow3</outgoing>
<outgoing>flow4</outgoing>
</exclusiveGateway>
<userTask id="userTask2"
name="Task 2">
<incoming>flow3</incoming>
<outgoing>flow5</outgoing>
</userTask>
<userTask id="userTask3"
name="Task 3">
<incoming>flow4</incoming>
<outgoing>flow6</outgoing>
</userTask>
<sequenceFlow id="flow1"
sourceRef="startEvent"
targetRef="userTask1" />
<sequenceFlow id="flow2"
sourceRef="userTask1"
targetRef="exclusiveGateway" />
<sequenceFlow id="flow3"
sourceRef="exclusiveGateway"
targetRef="userTask2">
<conditionExpression xsi:type="tFormalExpression">${rejected}</conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow4"
sourceRef="exclusiveGateway"
targetRef="userTask3">
<conditionExpression xsi:type="tFormalExpression">${!rejected}</conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow5"
sourceRef="userTask2"
targetRef="endEvent" />
<sequenceFlow id="flow6"
sourceRef="userTask3"
targetRef="endEvent" />
<endEvent id="endEvent"
name="End">
<incoming>flow5</incoming>
<incoming>flow6</incoming>
</endEvent>
</process
activiti7 驳回 代码
您好,Activiti 7 中的驳回操作可以通过以下代码实现:
```java
public void rejectTask(String taskId) {
// 获取当前任务
Task task = taskService.createTaskQuery()
.taskId(taskId)
.singleResult();
if (task == null) {
throw new RuntimeException("任务不存在");
}
// 获取当前任务的流程实例
String processInstanceId = task.getProcessInstanceId();
// 获取当前任务的历史任务实例列表
List<HistoricTaskInstance> historicTaskList = historyService.createHistoricTaskInstanceQuery()
.processInstanceId(processInstanceId)
.orderByHistoricTaskInstanceEndTime()
.asc()
.list();
// 获取需要驳回到的任务
HistoricTaskInstance targetTask = null;
for (int i = 0; i < historicTaskList.size(); i++) {
HistoricTaskInstance historicTask = historicTaskList.get(i);
if (historicTask.getId().equals(taskId)) {
if (i == 0) {
throw new RuntimeException("该任务已经是第一个任务,无法驳回");
}
targetTask = historicTaskList.get(i - 1);
break;
}
}
if (targetTask == null) {
throw new RuntimeException("未找到驳回目标任务");
}
// 驳回操作
BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId());
Process process = bpmnModel.getProcesses().get(0);
FlowNode sourceNode = (FlowNode) process.getFlowElement(task.getTaskDefinitionKey());
FlowNode targetNode = (FlowNode) process.getFlowElement(targetTask.getTaskDefinitionKey());
List<Execution> executionList = runtimeService.createExecutionQuery()
.processInstanceId(processInstanceId)
.list();
for (Execution execution : executionList) {
if (execution instanceof ExecutionEntity) {
ExecutionEntity executionEntity = (ExecutionEntity) execution;
executionEntity.setCurrentFlowElement(sourceNode);
runtimeService.createChangeActivityStateBuilder()
.processInstanceId(processInstanceId)
.moveExecutionToActivityId(executionEntity.getId(), targetNode.getId())
.changeState();
}
}
}
```
该代码实现了将当前任务驳回到上一步任务的操作,具体的实现过程请参考注释。需要注意的是,该代码中使用了 Activiti 7 中的一些 API,如 `BpmnModel`、`FlowNode` 等,如果您之前使用的是 Activiti 6,可能需要进行一些调整。