第一个方法getTaskDefinitionList用于包装下面两个方法:
/** * * @author: Longjun * @Description: 根据实例编号获取下一个任务节点实例集合 * @date:2016年3月18日 下午4:33:36 * @param sessionId是线程的sessionId;isNeedTransaction表示是否需要事务;procInstId流程实例ID */ public List<TaskDefinition> getTaskDefinitionList(String procInstId,String sessionId,boolean isNeedTransaction){ ProcessEngine processEngine = WorkFlowService.getProcessEngine(sessionId, isNeedTransaction); HistoryService historyService = processEngine.getHistoryService(); RepositoryService repositoryService = processEngine.getRepositoryService(); RuntimeService runtimeService = processEngine.getRuntimeService(); List<TaskDefinition> taskDefinitionList = new ArrayList<TaskDefinition>(); //流程标示 String processDefinitionId = historyService.createHistoricProcessInstanceQuery().processInstanceId(procInstId).singleResult().getProcessDefinitionId(); ProcessDefinitionEntity pde = (ProcessDefinitionEntity) repositoryService.getProcessDefinition(processDefinitionId); //ProcessDefinitionEntity def = (ProcessDefinitionEntity) ((RepositoryServiceImpl)repositoryService).getDeployedProcessDefinition(processDefinitionId); //执行实例 ExecutionEntity execution = (ExecutionEntity) runtimeService.createProcessInstanceQuery().processInstanceId(procInstId).singleResult(); //当前实例的执行到哪个节点 String activitiId = execution.getActivityId(); //获得当前任务的所有节点 List<ActivityImpl> activitiList = pde.getActivities(); String id = null; for(ActivityImpl activityImpl:activitiList){ id = activityImpl.getId(); if(activitiId.equals(id)){ logger.debug("当前任务:"+activityImpl.getProperty("name")); taskDefinitionList = nextTaskDefinition(activityImpl, activityImpl.getId()); } } return taskDefinitionList; }
第二个方法nextTaskDefinition获取所有下一节点集合:
/** * * @author: Longjun * @Description: 获取所有下一节点 * @date:2016年3月18日 下午4:33:24 */ private List<TaskDefinition> nextTaskDefinition(ActivityImpl activityImpl, String activityId){ List<TaskDefinition> taskDefinitionList = new ArrayList<TaskDefinition>();//所有的任务实例 List<TaskDefinition> nextTaskDefinition = new ArrayList<TaskDefinition>();//逐个获取的任务实例 TaskDefinition taskDefinition = null; if("userTask".equals(activityImpl.getProperty("type")) && !activityId.equals(activityImpl.getId())){ taskDefinition = ((UserTaskActivityBehavior)activityImpl.getActivityBehavior()).getTaskDefinition(); taskDefinitionList.add(taskDefinition); }else{ List<PvmTransition> outTransitions = activityImpl.getOutgoingTransitions(); List<PvmTransition> outTransitionsTemp = null; for(PvmTransition tr:outTransitions){ PvmActivity ac = tr.getDestination(); //获取线路的终点节点 //如果是互斥网关或者是并行网关 if("exclusiveGateway".equals(ac.getProperty("type"))||"parallelGateway".equals(ac.getProperty("type"))){ outTransitionsTemp = ac.getOutgoingTransitions(); if(outTransitionsTemp.size() == 1){ nextTaskDefinition = nextTaskDefinition((ActivityImpl)outTransitionsTemp.get(0).getDestination(), activityId); taskDefinitionList.addAll(nextTaskDefinition); }else if(outTransitionsTemp.size() > 1){ for(PvmTransition tr1 : outTransitionsTemp){ nextTaskDefinition = nextTaskDefinition((ActivityImpl)tr1.getDestination(), activityId); taskDefinitionList.addAll(nextTaskDefinition); } } }else if("userTask".equals(ac.getProperty("type"))){ taskDefinition = ((UserTaskActivityBehavior)((ActivityImpl)ac).getActivityBehavior()).getTaskDefinition(); taskDefinitionList.add(taskDefinition); }else{ logger.debug((String) ac.getProperty("type")); } } } return taskDefinitionList; }
/** * * @author: Longjun * @Description: 根据连线条件conditionText(类似${iscorrect==1})获取下一个节点,此方法以后会用 * @date:2016年3月18日 下午4:33:24 * @param elString是类似${iscorrect==1}的连线条件 */ @SuppressWarnings("unused") private List<TaskDefinition> nextTaskDefinition(ActivityImpl activityImpl, String activityId, String elString){ List<TaskDefinition> taskDefinitionList = new ArrayList<TaskDefinition>();//所有的任务实例 List<TaskDefinition> nextTaskDefinition = new ArrayList<TaskDefinition>();//逐个获取的任务实例 TaskDefinition taskDefinition = null; if("userTask".equals(activityImpl.getProperty("type")) && !activityId.equals(activityImpl.getId())){ taskDefinition = ((UserTaskActivityBehavior)activityImpl.getActivityBehavior()).getTaskDefinition(); taskDefinitionList.add(taskDefinition); }else{ List<PvmTransition> outTransitions = activityImpl.getOutgoingTransitions(); List<PvmTransition> outTransitionsTemp = null; for(PvmTransition tr:outTransitions){ PvmActivity ac = tr.getDestination(); //获取线路的终点节点 //如果是互斥网关或者是并行网关 if("exclusiveGateway".equals(ac.getProperty("type"))||"parallelGateway".equals(ac.getProperty("type"))){ outTransitionsTemp = ac.getOutgoingTransitions(); if(outTransitionsTemp.size() == 1){ nextTaskDefinition = nextTaskDefinition((ActivityImpl)outTransitionsTemp.get(0).getDestination(), activityId,elString); taskDefinitionList.addAll(nextTaskDefinition); }else if(outTransitionsTemp.size() > 1){ for(PvmTransition tr1 : outTransitionsTemp){ Object s = tr1.getProperty("conditionText"); if(elString.equals(StringUtils.trim(s.toString()))){ nextTaskDefinition = nextTaskDefinition((ActivityImpl)tr1.getDestination(), activityId,elString); taskDefinitionList.addAll(nextTaskDefinition); } } } }else if("userTask".equals(ac.getProperty("type"))){ taskDefinition = ((UserTaskActivityBehavior)((ActivityImpl)ac).getActivityBehavior()).getTaskDefinition(); taskDefinitionList.add(taskDefinition); }else{ logger.debug((String) ac.getProperty("type")); } } } return taskDefinitionList; }