Activiti Advanced (5) - Process Execution History

The previous articles briefly introduced the definition of the deployment process, the start of process instances, the viewing and handling of personal tasks, and how to set and obtain process variables. This series of activities constitutes a complete execution process. How do we view the relevant definitions of the process? This blog post will briefly introduce the history query of process execution.

 

    1. Query historical process example

 

 

  1. /**Query historical process instance*/  
  2. @Test  
  3. publicvoid findHisProcessInstance(){      
  4.     List<HistoricProcessInstance> list = processEngine.getHistoryService()  
  5.             .createHistoricProcessInstanceQuery()  
  6.             .processDefinitionId( "testVariables:2:1704" ) //Process Definition ID  
  7.             .list();  
  8.       
  9.     if(list != null && list.size()>0){  
  10.         for(HistoricProcessInstance hi:list){  
  11.             System.out.println(hi.getId()+"   "+hi.getStartTime()+"   "+hi.getEndTime());  
  12.         }  
  13.     }  
  14. }  
	/**Query historical process instance*/
	@Test
	public void findHisProcessInstance(){	
		List<HistoricProcessInstance> list = processEngine.getHistoryService()
				.createHistoricProcessInstanceQuery()
				.processDefinitionId("testVariables:2:1704")//Process Definition ID
				.list();
		
		if(list != null && list.size()>0){
			for(HistoricProcessInstance hi:list){
				System.out.println(hi.getId()+"	  "+hi.getStartTime()+"   "+hi.getEndTime());
			}
		}
	}

 

 

     Querying historical process instances is to find out how many times the process has been executed according to the rules defined by a process, and the corresponding database table: act_hi_procinst

     

     We can see from the table that we can get the historical process instance of the object through the process instance ID and process deployment ID, so as to obtain the start time and end time of the instance and some other attribute definitions.

 

     2. Query historical activities

 

 

  1. /** Query historical activity 
  2.  * Question: Which table corresponds to HistoricActivityInstance 
  3.  * Question: What is the difference between HistoricActivityInstance and HistoricTaskInstance*/  
  4. @Test   
  5. publicvoid findHisActivitiList(){   
  6.     String processInstanceId = "1801";  
  7.     List<HistoricActivityInstance> list = processEngine.getHistoryService()  
  8.             .createHistoricActivityInstanceQuery()  
  9.             .processInstanceId(processInstanceId)  
  10.             .list();  
  11.     if(list != null && list.size()>0){  
  12.         for(HistoricActivityInstance hai : list){  
  13.             System.out.println(hai.getId()+"  "+hai.getActivityName());  
  14.         }  
  15.     }  
  16. }  
	/** Query historical activity
	 * Question: Which table corresponds to HistoricActivityInstance
	 * Question: What is the difference between HistoricActivityInstance and HistoricTaskInstance*/
	@Test
	public void findHisActivitiList(){
		String processInstanceId = "1801";
		List<HistoricActivityInstance> list = processEngine.getHistoryService()
				.createHistoricActivityInstanceQuery()
				.processInstanceId(processInstanceId)
				.list();
		if(list != null && list.size()>0){
			for(HistoricActivityInstance hai : list){
				System.out.println(hai.getId()+"  "+hai.getActivityName());
			}
		}
	}

 

 

      Querying historical activities is to query how many activities have been experienced in the execution of a certain process. Here we use the process definition ID to query, and the corresponding database table is: act_hi_actinst

 



     3. Query historical tasks

 

 

  1. /** Query historical tasks    
  2.  * Question: Which table corresponds to HistoricTaskInstance*/  
  3. @Test  
  4. publicvoid findHisTaskList(){   
  5.     String processInstanceId = "1801";  
  6.     List<HistoricTaskInstance> list = processEngine.getHistoryService()  
  7.             .createHistoricTaskInstanceQuery()  
  8.             .processInstanceId(processInstanceId)  
  9.             .list();  
  10.     if(list!=null && list.size()>0){  
  11.         for(HistoricTaskInstance hti:list){  
  12.             System.out.println(hti.getId()+"    "+hti.getName()+"   "+hti.getClaimTime());  
  13.         }  
  14.     }  
  15. }  
	/** Query historical tasks	
	 * Question: Which table corresponds to HistoricTaskInstance*/
	@Test
	public void findHisTaskList(){
		String processInstanceId = "1801";
		List<HistoricTaskInstance> list = processEngine.getHistoryService()
				.createHistoricTaskInstanceQuery()
				.processInstanceId(processInstanceId)
				.list();
		if(list!=null && list.size()>0){
			for(HistoricTaskInstance hti:list){
				System.out.println(hti.getId()+"    "+hti.getName()+"   "+hti.getClaimTime());
			}
		}
	}


     Querying historical tasks is to query how many tasks have been experienced in the execution of a process. The corresponding table: act_hi_taskinst

 

 



     4. Query historical process variables

 

 

  1. /**Query historical process variables*/  
  2. @Test  
  3. publicvoid findHisVariablesList(){   
  4.     String processInstanceId = "1801";  
  5.     List<HistoricVariableInstance> list = processEngine.getHistoryService()  
  6.             .createHistoricVariableInstanceQuery()  
  7.             .processInstanceId(processInstanceId)  
  8.             .list();  
  9.     if(list != null && list.size()>0){  
  10.         for (HistoricVariableInstance hvi: list) {  
  11.             System.out.println(hvi.getId()+"    "+hvi.getVariableName()+"   "+hvi.getValue());  
  12.         }  
  13.     }  
  14. }  
	/**Query historical process variables*/
	@Test
	public void findHisVariablesList(){
		String processInstanceId = "1801";
		List<HistoricVariableInstance> list = processEngine.getHistoryService()
				.createHistoricVariableInstanceQuery()
				.processInstanceId(processInstanceId)
				.list();
		if(list != null && list.size()>0){
			for (HistoricVariableInstance hvi: list) {
				System.out.println(hvi.getId()+"    "+hvi.getVariableName()+"	"+hvi.getValue());
			}
		}
	}


     Querying historical process variables is to query the process variables set in the execution of a certain process, corresponding to the table: act_hi_varinst

 

 


 

     Summarize:

     Since historical information and running process instance information are stored in the database , the frequency of viewing completed tasks in actual projects is far less than the viewing of tasks to be done and running, so activiti adopts separate management and hands over running tasks to RuntimeService manages, and historical data is handed over to HistoryService to manage.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326677298&siteId=291194637