activiti工作流API
activiti工作流
1.activiti6 28张表
1、act_ge_ 通用数据表,ge是general的缩写
2、act_hi_ 历史数据表,hi是history的缩写,对应HistoryService接口
3、act_id_ 身份数据表,id是identity的缩写,对应IdentityService接口
4、act_re_ 流程存储表,re是repository的缩写,对应RepositoryService接口,存储流程部署和流程定义等静态数据
5、act_ru_ 运行时数据表,ru是runtime的缩写,对应RuntimeService接口和TaskService接口,存储流程实例和用户任务等动态数据
2.部署工作流
@Autowired
private ProcessEngine processEngine;
@Override
public void afterPropertiesSet() throws Exception {
processEngine.getRepositoryService().createDeployment().name("员工请假申请流程").
addClasspathResource("processes/staff_leave_process.bpmn").
addClasspathResource("processes/staff_leave_process.png").deploy();
}
3.启动流程
Map<String, Object> map= new HashMap<>();
map.put("user_name","张三");
ProcessInstance pi = runtimeService
.startProcessInstanceByKey("staff_leave_process", map);
System.out.println("流程实例"+pi.getId());
4.api
public static void main(String[] args) {
// 创建 Activiti 流程引擎
ProcessEngine processEngine = ProcessEngineConfiguration.
createStandaloneProcessEngineConfiguration().buildProcessEngine();
// 取得 Activiti 服务
RepositoryService repositoryService = processEngine.getRepositoryService();
RuntimeService runtimeService = processEngine.getRuntimeService();
// 部署流程定义
repositoryService.createDeployment().
addClasspathResource("FinancialReportProcess.bpmn20.xml")
.deploy();
// 启动流程实例
String procId = runtimeService.
startProcessInstanceByKey("financialReport").
getId();
// 获得第一个任务
TaskService taskService = processEngine.getTaskService();
List<Task> tasks = taskService.createTaskQuery().taskCandidateGroup("accountancy").list();
for (Task task : tasks) {
System.out.println("Following task is available for accountancy group: " + task.getName());
// 认领任务
taskService.claim(task.getId(), "fozzie");
}
// 查看 Fozzie 现在是否能够获取到该任务
tasks = taskService.createTaskQuery().taskAssignee("fozzie").list();
for (Task task : tasks) {
System.out.println("Task for fozzie: " + task.getName());
// 完成任务
taskService.complete(task.getId());
}
System.out.println("Number of tasks for fozzie: " + taskService.createTaskQuery().
taskAssignee("fozzie").count());
/**
* 添加任务备注
* if (StringUtils.isNotBlank(comment)) {
* taskService.addComment(taskId, processId, comment);
* }
*/
// 获取 并 认领 第二个任务
tasks = taskService.createTaskQuery().taskCandidateGroup("management").list();
for (Task task : tasks) {
System.out.println("Following task is available for accountancy group: " + task.getName());
taskService.claim(task.getId(), "kermit");
}
// 完成第二个任务结束结束流程
for (Task task : tasks) {
taskService.complete(task.getId());
}
// 核实流程是否结束
HistoryService historyService = processEngine.getHistoryService();
HistoricProcessInstance historicProcessInstance = historyService.
createHistoricProcessInstanceQuery().processInstanceId(procId).singleResult();
System.out.println("Process instance end time: " + historicProcessInstance.getEndTime());
}