activiti
一:绘制流程图
二.将流程图后缀名更改为xml 生成uml图并保存为png
生成此图片
三:创建流程
public static void main(String[] args) { ProcessEngineConfiguration processEngineConfigurationFromResource = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml"); ProcessEngine processEngine = processEngineConfigurationFromResource.buildProcessEngine(); RepositoryService repositoryService = processEngine.getRepositoryService(); repositoryService.createDeployment() .addClasspathResource("bpmn/holiday.bpmn") .addClasspathResource("bpmn/holiday.png") .name("创建流程") .deploy(); }
数据库中变化
import org.activiti.engine.*; import org.activiti.engine.repository.Deployment; import org.activiti.engine.runtime.ProcessInstance; import org.activiti.engine.task.Task; import org.junit.Before; import org.junit.Test; import java.util.Iterator; import java.util.List; public class test { ProcessEngine processEngine; @Before public void connection() { ProcessEngineConfiguration processEngineConfigurationFromResource = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml"); processEngine = processEngineConfigurationFromResource.buildProcessEngine(); } @Test public void createDeployment() { System.out.println(processEngine); RepositoryService repositoryService = processEngine.getRepositoryService(); Deployment deployment = repositoryService.createDeployment() .addClasspathResource("bpmn/holiday.bpmn") .addClasspathResource("bpmn/holiday.png") .name("创建流程") .deploy(); System.out.println(deployment.getName()); System.out.println(deployment.getKey()); System.out.println(deployment.getId()); } @Test //启动流程实例 public void startProcessInstance() { RuntimeService runtimeService = processEngine.getRuntimeService(); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProcess_1"); System.out.println(processInstance.getName()); System.out.println(processInstance.getDeploymentId()); System.out.println(processInstance.getActivityId()); } //任务查询 @Test public void findPersonalTaskList(){ TaskService taskService = processEngine.getTaskService(); List<Task> list = taskService.createTaskQuery() .processDefinitionKey("myProcess_1") .taskAssignee("ty").list(); Iterator<Task> iterator = list.iterator(); while (iterator.hasNext()){ System.out.println(iterator.next().toString()); } } @Test //任务处理 public void completTask(){ processEngine.getTaskService().complete("2505"); System.out.println("完成任务"); } }