/**
* 流程撤回功能
* @param taskId 要撤回的任务id,可为空,为空的情况下根据流程实例去获取当前的任务
* @param processInstanceId 流程实例id
*/
public void revoke(String taskId,String processInstanceId) throws Exception{
List<Task> tasks = processEngine.getTaskService().createTaskQuery().processInstanceId(processInstanceId).list();
if (StringUtil.isEmpty(taskId) && tasks != null && tasks.size() > 0) {
taskId = tasks.get(0).getId();
}
// 取得当前任务
HistoricTaskInstance currTask = processEngine.getHistoryService()
.createHistoricTaskInstanceQuery().taskId(taskId)
.singleResult();
//根据流程id查询代办任务中流程信息
Execution execution = processEngine.getRuntimeService().createExecutionQuery().executionId(currTask.getExecutionId()).singleResult();
String activityId = execution.getActivityId();
//取回流程接点 当前任务id 取回任务id
callBackProcess(currTask.getId(),activityId);
//删除历史流程走向记录
processEngine.getHistoryService().deleteHistoricTaskInstance(currTask.getId());
processEngine.getHistoryService().deleteHistoricTaskInstance(currTask.getId());
}
/**
* 取回流程
* @param taskId 当前任务ID
* @param activityId 取回节点ID
* @throws Exception
*/
public void callBackProcess(String taskId, String activityId)
throws Exception {
if (StringUtil.isEmpty(activityId)) {
throw new Exception("目标节点ID为空!");
}
//注意这里,要对所有的通过人数,不通过人数置空,否则下次审批会有问题
Map<String, Object> variables = new HashMap<String, Object>();
HistoricTaskInstance currTask = processEngine.getHistoryService()
.createHistoricTaskInstanceQuery().taskId(taskId)
.singleResult();
Map<String, Object> map = processEngine.getRuntimeService().getVariables(currTask.getExecutionId());
for (Map.Entry<String, Object> entry : map.entrySet()) {
if (entry.getKey().contains("passCount") ||
entry.getKey().contains("noPassCount") ||
entry.getKey().contains("totalCount")) {
variables.put(entry.getKey(), null);