1.获得一个流程引擎配置对象
//获得一个流程引擎配置对象
ProcessEngine pe = ProcessEngines.getDefaultProcessEngine();
调用ProcessEngines的getDefaultProceeEngine方法时会自动加载classpath下名为activiti.cfg.xml文件。
2.管理流程定义
RepositoryService repositoryService = processEngine.getRepositoryService();
DeploymentBuilder deployment = repositoryService.createDeployment();
deployment.addClasspathResource("test1.bpmn");
deployment.addClasspathResource("test1.png");
Deployment deploy = deployment.deploy();
System.out.println(deploy.getId() + " " + deploy.getName() + " " + deploy.getDeploymentTime());
往act_re_deployment表中插入一条数据:
![844709-20170418135212290-522831297.png](https://i-blog.csdnimg.cn/blog_migrate/c4a82a87e0062f8f2967d01ad0c2ebf3.png)
往act_re_procdef表中插入一条数据:
![844709-20170418135213102-1215996902.png](https://i-blog.csdnimg.cn/blog_migrate/f61d8837f9a9284000fba2fa9943ec9e.png)
往act_ge_bytearray表中插入两条数据:
![844709-20170418135214102-1921456720.png](https://i-blog.csdnimg.cn/blog_migrate/6fd5b2c57481471bc5ab75f075432033.png)
3.開啟流程返回流程實例
RuntimeService runtimeService =
processEngine
.getRuntimeService();
String processDefinitionId="test1:1:4";
//
開啟流程
返回流程實例
ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinitionId);
System.out.println(processInstance.getId() + " " + processInstance.getActivityId());
往act_ru_execution(流程实例)表中插入一条数据:
![844709-20170418135215602-2045156139.png](https://i-blog.csdnimg.cn/blog_migrate/2a14b1f7e4ce9e5aaee110d3c5a05ff8.png)
往act_ru_task (任务)表中插入一条数据:
![844709-20170418135217290-257498690.png](https://i-blog.csdnimg.cn/blog_migrate/f3fa8f3abda8f50943db236934cab07c.png)
往act_hi_taskinst (历史任务) 表中插入一条数据:
![844709-20170418135219493-418720391.png](https://i-blog.csdnimg.cn/blog_migrate/281a1355a45cd4b4e9f590710b4c32ea.png)
4.查询任务列表:
TaskService taskService =
processEngine
.getTaskService();
TaskQuery taskQuery = taskService.createTaskQuery();
taskQuery.taskAssignee("张三");
//添加过滤条件,使用办理者查询
taskQuery.orderByTaskId().desc();//添加排序条件
taskQuery.listPage(0, 10);//添加分页条件
List<Task> list = taskQuery.list();//发出sql,查询任务表
for (Task task : list) {
System.out.println(task.getId() + " " + task.getName() + " " + task.getAssignee());
}
5.办理任务:
TaskService taskService =
processEngine
.getTaskService();
String taskId="104";
taskService.complete(taskId);
张三办理完任务后 ,
act_ru_task
表中关于张三的那条任务记录将被删除,走到下个任务节点,到李四审批。
act_ru_task
表中只保存当前在办理的任务,办理完成即被删除。
![844709-20170418135222040-43674796.png](https://i-blog.csdnimg.cn/blog_migrate/9e20c1d0b0a0f685b1144aa789e47d23.png)
李四办理完 ,就走到下个节点,表中也会删除李四那条任务记录。
![844709-20170418135224993-1953766630.png](https://i-blog.csdnimg.cn/blog_migrate/5aeaa7b95362c234de10396755ab900a.png)
act_hi_taskinst
历史任务表 中会保存每个节点,整个流程办理过程都在这里。
![844709-20170418135227352-2067720136.png](https://i-blog.csdnimg.cn/blog_migrate/f212e50105717aaa9ccc68cb5bd0ee4b.png)