Activiti

基于原生Activiti 6 的Rest API服务

参考

安装

MySQL 5.7

用于存储数据的db

docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -p 3306:3306 -d mysql:5.7

Tomcat 7

运行Activiti的web容器

FROM tomcat:7

# 暴露weapps
VOLUME [ "/usr/local/tomcat/webapps" ]

EXPOSE 8080
CMD ["catalina.sh", "run"]

Activiti 6

使用

新建工作流的步骤

以本地启动的http://localhost:8080/activiti-app/为例:

  1. Kickstart App-ProcessesCreate Process
  2. 定义Process Model的name和key
  3. 画布上拖拽元素(启停事件、Task、Gateway等),建立关联线条
    1. 每个元素填写属性Id和Name等
    2. UserTask设置认领角色Assignment
    3. Task设置绑定的表单Referenced form
  4. 保存
  5. Kickstart App-AppsCreate App
  6. 定义App的name和key
  7. 选择App下属的Models
  8. 保存
  9. 发布App==发布工作流
  10. 点进之前定义的App
  11. 选择Publish

调用工作流实例

Rest API

通用说明

访问认证

常用方法

  1. 工作流
  2. 按流程名检索: GET repository/deployments?name={精确流程名}
  3. 发布新流程:

    ```bash
    curl -X POST \
    http://localhost:8080/activiti-rest/service/repository/deployments \
    -H 'Authorization: Basic YWRtaW46dGVzdA==' \  # 按实际用户密码加密
    -H 'cache-control: no-cache' \
    -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
    -F demo.bpmn20.xml=@/Users/jeff.chen/Downloads/Process_demo.bpmn20-v2.xml
    # demo.bpmn20.xml是流程名,=后跟用户本地bpmn定义
    # 只接收.bpmn20.xml, .bpmn, .bar or .zip后缀
    ```
    
    1. 获取工作流定义一览: GET repository/process-definitions
    2. 激活指定工作流: PUT repository/process-definitions/{processDefinitionId}
  4. 流程运行实例

  5. 当前运行的流程运行实例一览: GET /runtime/process-instances
  6. 通过流程key,(bpmn文件中的process.id),启动新流程实例,start_new_process_by_key:

    ```bash
    curl -X POST \
    http://localhost:8080/activiti-rest/service/runtime/process-instances \
    -H 'Authorization: Basic YWRtaW46dGVzdA==' \
    -H 'Content-Type: application/json' \
    -H 'cache-control: no-cache' \
    -d '{
            "processDefinitionKey":"Process_one_step_demo_id"
        }'
    # 获取返回json,其中有后续Task需要的信息
    {
        "id": "7532",  # 核心参数,当前流程实例id
        "url": "http://localhost:8080/activiti-rest/service/runtime/process-instances/7532",
        "businessKey": null,
        "suspended": false,
        "ended": false,
        "processDefinitionId": "Process_one_step_demo_id:1:5045",
        "processDefinitionUrl": "http://localhost:8080/activiti-rest/service/repository/process-definitions/Process_one_step_demo_id:1:5045",
        "processDefinitionKey": "Process_one_step_demo_id",
        "activityId": null,
        "variables": [],
        "tenantId": "",
        "name": null,
        "completed": false
    }
    ```
    
    1. 获取指定流程id的流转状态图: GET runtime/process-instances/7532/diagramprocess-instance-diagram
    2. 红框代表流程执行到的Task
    3. 任务
    4. 获取指定流程实例下待处理任务列表: GET runtime/tasks?processInstanceId=7532,反馈json如下:

      js { "data": [ { "id": "7539", // 核心参数,待处理的Task.id "url": "http://localhost:8080/activiti-rest/service/runtime/tasks/7539", "owner": null, "assignee": "admin", "delegationState": null, "name": "Write monthly financial report", "description": "Write monthly financial report for publication to shareholders.", "createTime": "2019-08-09T09:01:55.610Z", "dueDate": null, "priority": 50, "suspended": false, "taskDefinitionKey": "writeReportTask", "tenantId": "", "category": null, "formKey": "UserInputMessage", "parentTaskId": null, "parentTaskUrl": null, "executionId": "7536", "executionUrl": "http://localhost:8080/activiti-rest/service/runtime/executions/7536", "processInstanceId": "7532", "processInstanceUrl": "http://localhost:8080/activiti-rest/service/runtime/process-instances/7532", "processDefinitionId": "Process_one_step_demo_id:1:5045", "processDefinitionUrl": "http://localhost:8080/activiti-rest/service/repository/process-definitions/Process_one_step_demo_id:1:5045", "variables": [] } ], "total": 1, "start": 0, "sort": "id", "order": "asc", "size": 1 }

    5. 完成指定任务:

      ```bash curl -X POST \ http://localhost:8080/activiti-rest/service/runtime/tasks/7539 \ -H 'Authorization: Basic YWRtaW46dGVzdA==' \ -H 'Content-Type: application/json' \ -H 'cache-control: no-cache' \ -d '{ "action": "complete", # 执行任务的行为”完成“,可有其他Action类型,详情看官方文档 "variables": [{ # 需要填写的表单参数 "name": "message", # 表单input元素的id,参考下图 "value": "This is a User Input Message" # 在input中的填写 }] }'

      如果反馈HTTP状态码为200,表示更新成功

      ```

      引用的input元素对应task_input_name