审批流程删减人员
package com.newdata.flowable.cmd;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.impl.cmd.NeedsActiveTaskCmd;
import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
import org.flowable.engine.impl.persistence.entity.ExecutionEntityManager;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.task.service.HistoricTaskService;
import org.flowable.task.service.TaskService;
import org.flowable.task.service.TaskServiceConfiguration;
import org.flowable.task.service.impl.persistence.entity.HistoricTaskInstanceEntity;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
public class NewDeleteTaskCmd extends NeedsActiveTaskCmd<Void> {
protected static final String NR_OF_COMPLETED_INSTANCES = "nrOfCompletedInstances";
public NewDeleteTaskCmd(String taskId) {
super(taskId);
}
@Override
protected Void execute(CommandContext commandContext, TaskEntity taskEntity) {
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
TaskServiceConfiguration taskServiceConfiguration = processEngineConfiguration.getTaskServiceConfiguration();
TaskService taskService = taskServiceConfiguration.getTaskService();
taskService.deleteTask(taskEntity, true);
String id = taskEntity.getId();
HistoricTaskService historicTaskService = taskServiceConfiguration.getHistoricTaskService();
HistoricTaskInstanceEntity historicTask = historicTaskService.getHistoricTask(id);
historicTaskService.deleteHistoricTask(historicTask);
String executionId = taskEntity.getExecutionId();
ExecutionEntityManager executionEntityManager = processEngineConfiguration.getExecutionEntityManager();
ExecutionEntity executionEntity = executionEntityManager.findById(executionId);
if (executionEntity != null){
int nrOfCompletedInstances = (int) executionEntity.getVariable(NR_OF_COMPLETED_INSTANCES);
executionEntity.setVariable(NR_OF_COMPLETED_INSTANCES, nrOfCompletedInstances + 1);
}
return null;
}
}