Activiti工作流介绍

Activiti项目是一项新的基于Apache许可的开源BPM平台,从基础开始构建,旨在提供支持新的BPMN 2.0标准,包括支持对象管理组(OMG),面对新技术的机遇,诸如互操作性和云架构,提供技术实现。

Activiti工作流介绍_第1张图片Activiti工作流介绍_第2张图片
Activiti工作流介绍_第3张图片
Activiti工作流介绍_第4张图片
Activiti工作流介绍_第5张图片
Activiti工作流介绍_第6张图片
Activiti工作流介绍_第7张图片
Activiti工作流介绍_第8张图片
Activiti工作流介绍_第9张图片
Activiti工作流介绍_第10张图片
Activiti工作流介绍_第11张图片
Activiti工作流介绍_第12张图片
Activiti工作流介绍_第13张图片
Activiti工作流介绍_第14张图片

		
		
			org.activiti
			activiti-engine
			5.19.0.2
		
		
		
			org.activiti
			activiti-spring
			5.19.0.2
		
		
			org.activiti
			activiti-bpmn-model
			5.19.0.2
		
        
		
			mysql
			mysql-connector-java
			5.1.41
		

activity.cfg.xml



	
	
		
		
		
		
		
	


Activiti工作流介绍_第15张图片
Activiti工作流介绍_第16张图片
Activiti工作流介绍_第17张图片
Activiti工作流介绍_第18张图片



  
    
    
    
    
    
    
    
    
    
      
    
    
       5}]]>
    
    
    
  
  
    
      
        
      
      
        
      
      
        
      
      
        
      
      
        
      
      
        
      
      
        
        
      
      
        
        
      
      
        
        
        
      
      
        
        
        
      
      
        
        
      
      
        
        
      
    
  

Activiti工作流介绍_第19张图片
Activiti工作流介绍_第20张图片
Activiti工作流介绍_第21张图片
Activiti工作流介绍_第22张图片
Activiti工作流介绍_第23张图片

package com.test;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import com.test.mapper.OrderMapper;

@RunWith(SpringRunner.class)
@SpringBootTest(classes=Starter.class)
public class Tester
{
	private ProcessEngine initFromCode()
	{
		ProcessEngineConfiguration pec = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
		pec.setJdbcUrl("jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC");
		pec.setJdbcDriver("com.mysql.jdbc.Driver");
		pec.setJdbcUsername("root");
		pec.setJdbcPassword("root");
		pec.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
		ProcessEngine processEngine = pec.buildProcessEngine();
		return processEngine;
	}
	
	private ProcessEngine initFromXml()
	{
    	ProcessEngineConfiguration pec = ProcessEngineConfiguration
    			.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
    	ProcessEngine processEngine = pec.buildProcessEngine();
    	return processEngine;
	}
	
	private ProcessEngine initDefault()
	{
		ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
		return processEngine;
	}
	
	private ProcessEngine initProcessEngine()
	{
		return initFromCode();
	}
	
    private Deployment deployProcess()
    {
    	ProcessEngine pec = initProcessEngine();
		//部署的服务对象
		RepositoryService repositoryService = pec.getRepositoryService();
		//部署请假任务:
		Deployment deploy = repositoryService.createDeployment()
				.addClasspathResource("holiday.bpmn")
				.name("请假")
				.deploy();
		return deploy;
    }
    
    private ProcessInstance startProcess(String processName,String userName)
    {
    	//String processName = "activitiReview";
    	//String userName = "chqx";
    	ProcessEngine pec = initProcessEngine();
		RuntimeService runtimeService = pec.getRuntimeService();
		Map variables = new HashMap();
		variables.put("userName",userName);
		//根据key得到流程实例
		ProcessInstance instProcess = runtimeService.startProcessInstanceByKey(processName,variables);
		return instProcess;
    }
    
    private List getWorkItem(String processName,String userName)
    {
    	//String processName = "activitiReview";
    	//String userName = "chqx";
    	ProcessEngine pec = initProcessEngine();
    	
    	TaskService tsrv = pec.getTaskService();
    	List list = tsrv.createTaskQuery()
                .processDefinitionKey(processName)
                .taskAssignee(userName)
                .list();

    	return list;
    }
    
    private void completeTask(String taskId,String userName)
    {
    	ProcessEngine pec = initProcessEngine();
    	TaskService tsrv = pec.getTaskService();
		Map variables = new HashMap();
		variables.put("userName",userName);
		variables.put("days","6");

    	tsrv.complete(taskId, variables);
    }
    
    @Test
    public void testActiviti()
    {
    	//Deployment deployment = deployProcess();
    	//System.out.println("工作流模板发布:"+deployment.getId()+","+deployment.getName());
    	
    	String processName = "myProcess";
    	String userName = "wx";
    	
    	//ProcessInstance instProc = startProcess(processName,userName);
    	//System.out.println("工作流实例:"+instProc.getId()+","+instProc.getName());
    	

    	List tasks = getWorkItem(processName,userName);
    	for(Task task:tasks)
    	{
    		System.out.println("Task.id="+task.getId()+",参与者="+task.getAssignee()+",任务名称:="+task.getName());
    		completeTask(task.getId(),"wx");
    	}

    }
    
}

你可能感兴趣的:(Activiti)