实际上,我想在当前任务中使用先前的任务名称,因此如何在Activiti中获得当前任务中的先前任务名称。
Actually i want to use the previous task name in current task so how to get the previous task name in current task in activiti. If any one knows could you help me?
例如:TASK1 ==> TASK2 ==> TASK3
eg:TASK1==>TASK2==>TASK3
我想在task2中使用task1名称,在task1中使用task2名称。
i want to use the task1 name in task2 and task2 name in task1.
推荐答案您可以从当前的流程实例中获取它:
You can get it from your current Process Instance:
@Service public class SomeWorkflowService { @Autowired HistoryService historyService; @Autowired TaskService taskService; public Map<String, Object> currentTaskService(String currentTaskId) { Map<String, Object> taskMap = new HashMap<>(); Task currentTask = taskService.createTaskQuery().taskId(currentTaskId).singleResult(); HistoricTaskInstance previousTask = findPreviousTask(currentTask.getProcessInstanceId()); taskMap.put("Current task name: ", currentTask.getName()); taskMap.put("Previous task name: ", previousTask.getName()); return taskMap; } // Order tasks by end date and get the latest public HistoricTaskInstance findPreviousTask(String processInstanceId) { return historyService.createHistoricTaskInstanceQuery(). processInstanceId(processInstanceId).orderByHistoricTaskInstanceEndTime().desc().list().get(0); } }可能存在这种问题简单算法。例如,我在应用程序中有多个子流程,或者可能有并行执行的任务,那么我在使用更复杂的算法来查找先前的任务。
There maybe some issues with this kind of simple algorithm. For example, I have multiple subprocesses in application, or there may be parallely executed tasks, then I'm using more complex algorithm to find previous task.
更多推荐
如何在Activiti工作流程中获取先前的任务名称
发布评论