|
@@ -8,6 +8,8 @@ import org.flowable.engine.ManagementService;
|
|
|
import org.flowable.engine.RuntimeService;
|
|
|
import org.flowable.engine.TaskService;
|
|
|
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
|
|
|
+import org.flowable.engine.impl.persistence.entity.ActivityInstanceEntity;
|
|
|
+import org.flowable.engine.impl.persistence.entity.ActivityInstanceEntityManager;
|
|
|
import org.flowable.engine.impl.util.CommandContextUtil;
|
|
|
import org.flowable.engine.runtime.Execution;
|
|
|
import org.flowable.task.api.Task;
|
|
@@ -16,13 +18,11 @@ import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
public class DeleteTaskExecutionCmd implements Command<Void> {
|
|
|
- protected String processInstanceId;
|
|
|
- protected String activityId;
|
|
|
+ protected Task task;
|
|
|
protected String assignee;
|
|
|
|
|
|
- public DeleteTaskExecutionCmd(String processInstanceId, String activityId, String assignee) {
|
|
|
- this.processInstanceId = processInstanceId;
|
|
|
- this.activityId = activityId;
|
|
|
+ public DeleteTaskExecutionCmd(Task task, String assignee) {
|
|
|
+ this.task = task;
|
|
|
this.assignee = assignee;
|
|
|
}
|
|
|
|
|
@@ -30,13 +30,14 @@ public class DeleteTaskExecutionCmd implements Command<Void> {
|
|
|
public Void execute(CommandContext commandContext) {
|
|
|
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration();
|
|
|
ManagementService managementService = processEngineConfiguration.getManagementService();
|
|
|
- MultiInstanceLoopCharacteristics loopCharacteristics = managementService.executeCommand(new GetLoopCharacteristicsCmd(this.processInstanceId, this.activityId));
|
|
|
+ ActivityInstanceEntityManager activityInstanceEntityManager = processEngineConfiguration.getActivityInstanceEntityManager();
|
|
|
+ MultiInstanceLoopCharacteristics loopCharacteristics = managementService.executeCommand(new GetLoopCharacteristicsCmd(this.task.getProcessInstanceId(), this.task.getTaskDefinitionKey()));
|
|
|
if (Objects.nonNull(loopCharacteristics)) {
|
|
|
RuntimeService runtimeService = processEngineConfiguration.getRuntimeService();
|
|
|
String collectionName = loopCharacteristics.getInputDataItem();
|
|
|
collectionName = collectionName.substring(2, collectionName.length() - 1);
|
|
|
List<String> assigneeList = runtimeService.getVariable(
|
|
|
- this.processInstanceId,
|
|
|
+ this.task.getProcessInstanceId(),
|
|
|
collectionName,
|
|
|
List.class
|
|
|
);
|
|
@@ -46,17 +47,17 @@ public class DeleteTaskExecutionCmd implements Command<Void> {
|
|
|
if (assigneeList.size() == 1) {
|
|
|
throw new FlowableException("会签必须保留一个用户");
|
|
|
}
|
|
|
- Execution miExecution = managementService.executeCommand(new GetMultiInstanceRootExecutionCmd(this.processInstanceId, this.activityId));
|
|
|
+ Execution miExecution = managementService.executeCommand(new GetMultiInstanceRootExecutionCmd(this.task.getProcessInstanceId(), this.task.getTaskDefinitionKey()));
|
|
|
if (loopCharacteristics.isSequential()) {
|
|
|
- Integer loopCounter = runtimeService.getVariableLocal(miExecution.getId(), "loopCounter", Integer.class);
|
|
|
+ Integer loopCounter = runtimeService.getVariableLocal(this.task.getExecutionId(), "loopCounter", Integer.class);
|
|
|
if (!assigneeList.subList(loopCounter, assigneeList.size() - 1).contains(this.assignee)) {
|
|
|
throw new FlowableException(String.format("会签后续办理者中没有用户:%s", this.assignee));
|
|
|
}
|
|
|
} else {
|
|
|
TaskService taskService = processEngineConfiguration.getTaskService();
|
|
|
List<Task> tasks = taskService.createTaskQuery()
|
|
|
- .processInstanceId(this.processInstanceId)
|
|
|
- .taskDefinitionKey(this.activityId)
|
|
|
+ .processInstanceId(this.task.getProcessInstanceId())
|
|
|
+ .taskDefinitionKey(this.task.getTaskDefinitionKey())
|
|
|
.active()
|
|
|
.list();
|
|
|
if (tasks.stream().noneMatch(task -> task.getAssignee().equals(this.assignee))) {
|
|
@@ -65,16 +66,18 @@ public class DeleteTaskExecutionCmd implements Command<Void> {
|
|
|
Integer nrOfActiveInstances = runtimeService.getVariableLocal(miExecution.getId(), "nrOfActiveInstances", Integer.class);
|
|
|
runtimeService.setVariableLocal(miExecution.getId(), "nrOfActiveInstances", nrOfActiveInstances - 1);
|
|
|
List<Task> deleteTasks = taskService.createTaskQuery()
|
|
|
- .processInstanceId(this.processInstanceId)
|
|
|
- .taskDefinitionKey(this.activityId)
|
|
|
+ .processInstanceId(this.task.getProcessInstanceId())
|
|
|
+ .taskDefinitionKey(this.task.getTaskDefinitionKey())
|
|
|
.taskAssignee(this.assignee)
|
|
|
.list();
|
|
|
for (Task deleteTask : deleteTasks) {
|
|
|
runtimeService.deleteMultiInstanceExecution(deleteTask.getExecutionId(), false);
|
|
|
+ ActivityInstanceEntity activityInstanceEntity = activityInstanceEntityManager.findActivityInstanceByTaskId(deleteTask.getId());
|
|
|
+ activityInstanceEntityManager.delete(activityInstanceEntity);
|
|
|
}
|
|
|
}
|
|
|
assigneeList.remove(this.assignee);
|
|
|
- runtimeService.setVariable(this.processInstanceId, collectionName, assigneeList);
|
|
|
+ runtimeService.setVariable(this.task.getProcessInstanceId(), collectionName, assigneeList);
|
|
|
} else {
|
|
|
throw new FlowableException("当前节点不支持减签");
|
|
|
}
|