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接口,存储流程实例和用户任务等动态数据
更多库表的介绍:https://www.devdoc.cn/activiti-table-summary.html
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  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 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());
  }

流程图相关的

Candidate groups (comma separated) 候选组(逗号分隔)
Candidate users (comma separated) 候选用户(逗号分隔)
Documentation 文档
Delegate Expression 委托表达式
Condition 条件
${days>=0 && days<=3}

你可能感兴趣的:(activiti工作流)