activiti常用函数分类

1、查询流程定义

   @Test
   public void findProcessDefinition(){
         ProcessDefinitionQuery processDefinitionQuery = processEngine.getRepositoryService().createProcessDefinitionQuery();
         /*指定查询条件,where条件,任选一 */
         processDefinitionQuery.deploymentId("1");//使用部署对象ID查询
         processDefinitionQuery.processDefinitionId("helloWorld:1:4");//使用流程定义ID查询
         processDefinitionQuery.processDefinitionKey("helloWorld");//使用流程定义key查询
         processDefinitionQuery.processDefinitionName("helloWorldProcess");//使用流程定义名称查询
         processDefinitionQuery.processDefinitionNameLike("hello");//使用流程定义名称模糊查询
     
        /*排序,可组合*/
         processDefinitionQuery.orderByDeploymentId().desc();//根据部署ID降序
         processDefinitionQuery.orderByProcessDefinitionVersion().desc();//根据定义版本降序,最新版在前
         processDefinitionQuery.orderByProcessDefinitionName().asc();//更具定义名升序,符合习惯
      
         /*返回结果集,任取一*/
         List<ProcessDefinition> list = processDefinitionQuery.list();//多个结果集
         ProcessDefinition processDefinition = processDefinitionQuery.singleResult();//唯一结果集
         long num = processDefinitionQuery.count();//结果集数量
         int firstResult = 0;//首个记录下标
         int maxResults = 15;//每页记录数量
         List<ProcessDefinition> pageList = processDefinitionQuery.listPage(firstResult,maxResults );//分页结果集
      }

2、删除流程定义

	@Test
	public void deleteProcessDefinition(){
		String deploymentId = "17501";
		RepositoryService repositoryService = processEngine.getRepositoryService();
		/* 非级联删除,若有对应的流程启动,则报错*/
		repositoryService.deleteDeployment(deploymentId);
		/*级联删除,同时删除相关流程实例等信息*/
		repositoryService.deleteDeployment(deploymentId, true);
	}

3、查看流程图

     

// 查看流程图
	@Test
	public void getPng() {
		String deploymentId = "1";
		RepositoryService repositoryService = processEngine.getRepositoryService();
		List<String> list = repositoryService.getDeploymentResourceNames(deploymentId);
		String resourceName = null;// 保存资源文件名
		for (String name : list) {
			if (name.indexOf(".png") > 0) {
				resourceName = name;
				break;
			}
		}
		if (null != resourceName) {
			InputStream inputStream = repositoryService.getResourceAsStream(deploymentId, resourceName);
			try {
				String fileName = resourceName.substring(resourceName.lastIndexOf('/') + 1);
				String path = "D:/";
				File file = new File(path + fileName);
				if (file.exists()) {
					file.delete();// 若存在同名文件,先删除后创建
				}
				file.createNewFile();
				FileOutputStream fileOutputStream = new FileOutputStream(file);
				byte[] b = new byte[2 * 1024];
				int len = 0;
				while ((len = inputStream.read(b)) > 0) {
					fileOutputStream.write(b, 0, len);
				}
				fileOutputStream.flush();
				fileOutputStream.close();
				inputStream.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

4、判断流程状态

     

@Test
	public void isInstanceEnd() {
		String processInstanceId = "2501";
		RuntimeService runtimeService = processEngine.getRuntimeService();
		ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
		if(null!=processInstance){
			System.out.println("流程未结束");
		}else{
			System.out.println("流程结束");
		}
		fail("Not yet implemented");
	}

5、查询历史任务

	@Test
	public void getHistoryTaskByUserId(){
		String userId = "A";
		HistoricTaskInstanceQuery historicTaskInstanceQuery = processEngine.getHistoryService().createHistoricTaskInstanceQuery();//创建历史任务实例查询
		List<HistoricTaskInstance> list = historicTaskInstanceQuery.taskAssignee(userId).list();//根据流程指派人查询
		if(null!=list && list.size()>0){
			for(HistoricTaskInstance historicTaskInstance:list){
				System.out.println("任务ID:"+historicTaskInstance.getId());
				System.out.println("任务名称:"+historicTaskInstance.getName());
				System.out.println("任务创建时间:"+historicTaskInstance.getCreateTime());//创建时间为前一任务结束后
				System.out.println("任务开始时间:"+historicTaskInstance.getStartTime());//开始时间为任务接收后
				System.out.println("任务结束时间:"+historicTaskInstance.getEndTime());
				System.out.println("任务持续时间:"+historicTaskInstance.getDurationInMillis());
				System.out.println("任务办理人:"+historicTaskInstance.getAssignee());
			}
		}
	}

你可能感兴趣的:(activiti常用函数分类)