Camunda 使用restapi

本文介绍了如何使用Camunda BPM的REST API进行流程部署、获取进程定义、启动流程、查询待办任务以及完成任务。通过具体的HTTP请求示例,展示了在不同场景下如何与Camunda BPM引擎交互,包括设置流程变量和业务键。
摘要由CSDN通过智能技术生成

参考:http://camunda-cn.shaochenfeng.com/reference/rest/task/get-query/

这里我就举一个流程的例子:

我的流程图:

以下接口,除了端口和参数,其他无需改动

POM:

rest 就是接口

webapp 是网页

<dependency>
            <groupId>org.camunda.bpm.springboot</groupId>
            <artifactId>camunda-bpm-spring-boot-starter-rest</artifactId>
        </dependency>

        <dependency>
            <groupId>org.camunda.bpm.springboot</groupId>
            <artifactId>camunda-bpm-spring-boot-starter-webapp</artifactId>
        </dependency>

1 发布流程

http://localhost:9020/engine-rest/deployment/create

传递你的bpmn名称,通过file类型选择bpmn文件

2 获取进程定义

http://localhost:9020/engine-rest/process-definition

返回:

[
    {
        "id": "Process_1xebez9:1:7929ac88-64ac-11ed-946f-0892043f3120",
        "key": "Process_1xebez9",
        "category": "http://bpmn.io/schema/bpmn",
        "description": null,
        "name": "customerAudit",
        "version": 1,
        "resource": "customerAudit.bpmn",
        "deploymentId": "7924f196-64ac-11ed-946f-0892043f3120",
        "diagram": null,
        "suspended": false,
        "tenantId": null,
        "versionTag": null,
        "historyTimeToLive": null,
        "startableInTasklist": true
    },
    {
        "id": "audit_process:1:57b07816-63fa-11ed-ae19-0892043f3120",
        "key": "audit_process",
        "category": "http://bpmn.io/schema/bpmn",
        "description": null,
        "name": "Audit Process",
        "version": 1,
        "resource": "audit.bpmn",
        "deploymentId": "579a30f3-63fa-11ed-ae19-0892043f3120",
        "diagram": null,
        "suspended": false,
        "tenantId": null,
        "versionTag": null,
        "historyTimeToLive": null,
        "startableInTasklist": true
    }
]

3 启动流程

http://localhost:9020/engine-rest/process-definition/Process_1xebez9:1:7929ac88-64ac-11ed-946f-0892043f3120/start

上面的Id就是来自步骤2的id

参数:

这里我传递了审批人(流程界面中,设置了${adminList} ${mpmList})

${adminList}设置:

${mpmList}设置:

 

并且设置了businessKey

{
  "variables": {
    "adminList" : {
        "value":"[\"admin\"]",
            "type":"Object",
            "valueInfo":{
                "objectTypeName":"java.util.ArrayList",
                "serializationDataFormat":"application/json"
            }
    },
    "mpmList": {
        "value":"[\"mpm1\"]",
            "type":"Object",
            "valueInfo":{
                "objectTypeName":"java.util.ArrayList",
                "serializationDataFormat":"application/json"
            }
    }
  },
 "businessKey" : 40
}

4 获取进程实例

http://localhost:9020/engine-rest/process-instance/1cef6cfa-64b3-11ed-946f-0892043f3120

上面的id,就是步骤3返回的id

5.1 获取待办任务 (某人&进程ID)

http://localhost:9020/engine-rest/task?assignee=mpm1&processInstanceId=1cef6cfa-64b3-11ed-946f-0892043f3120

5.2 获取待办任务 (某人)

http://localhost:9020/engine-rest/task?assignee=admin

5.3 获取待办任务 (BusinessKey)

http://localhost:9020/engine-rest/task?processInstanceBusinessKey=40

6 审批

http://localhost:9020/engine-rest/task/ae952619-64bd-11ed-946f-0892043f3120/complete

传参:

由于taskid已经在url中传递了,所以审批人是可以确定的。

{"variables":
    {
        "approve": {"value": true},
        "comment": {"value": "hello world112"}
    },
 "withVariablesInReturn": true
}

评论 22
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值