activiti工作流常用方法

	//模型实例
	BpmnModel model = repositoryService.getBpmnModel(task.getProcessDefinitionId());
	
	//节点属性
	UserTask userTask = (UserTask) model.getFlowElement(destId);
	//候选组
	List<String> groups = userTask.getCandidateGroups();
	//获取当前节点候选组角色
	List<IdentityLink> ilList = taskService.getIdentityLinksForTask(currtask.getId());
	//获取评论
	List<Comment> comlist = taskService.getTaskComments(task.getId());
	//获取附件
	List<Attachment> attachments = taskService.getTaskAttachments(taskId);
	//获取历史流程(倒叙)
	List<HistoricTaskInstance> his = historyService
	                    .createHistoricTaskInstanceQuery().finished()
	                    .orderByHistoricTaskInstanceEndTime().desc()
	                    .processInstanceId(c.getProcessInstanceId()).list();
//获取流程图所有信息
public JSONArray findHistoryTask(String processInstanceId){
	JSONArray array = new JSONArray();
	ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
	// 查询流程定义 。
	String processDefinitionId = processInstance.getProcessDefinitionId();
	//模型实例
	BpmnModel model = repositoryService.getBpmnModel(processDefinitionId);
	//由于我们这里仅仅定义了一个Process 所以获取集合中的第一个就可以
	//Process对象封装了全部的节点、连线、以及关口等信息。拿到这个对象就能够为所欲为了。
	Process process = model.getProcesses().get(0);
	//获取全部的FlowElement(流元素)信息
	Collection<FlowElement> flowElements = process.getFlowElements();
	for (FlowElement flowElement : flowElements) {
		//假设是开始节点
		if(flowElement instanceof StartEvent){
			StartEvent startEvent = (StartEvent)flowElement;
			System.out.println(startEvent);
		}
		//假设是任务节点
		if(flowElement instanceof UserTask) {
			UserTask userTask = (UserTask)flowElement;
			List<String> candidateUsers = userTask.getCandidateUsers();
			for (String string : candidateUsers) {
				System.out.println("-------"+string);
			}
			System.out.println(userTask);
		}
		//假设是结束节点
		if(flowElement instanceof EndEvent) {
			EndEvent endEvent = (EndEvent)flowElement;
			System.out.println(endEvent);
		}
		//假设是连接线
		if(flowElement instanceof SequenceFlow) {
			SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
			System.out.println(sequenceFlow);
			String name=sequenceFlow.getName();
			String str =sequenceFlow.getConditionExpression();
			String value = str.substring(str.lastIndexOf("=") + 1, str.lastIndexOf("}"));
		}
	}
}	

你可能感兴趣的:(Java)