Learning activiti 5: Turn on the process and the flow advances

Learning activiti 5: Turn on the process and the flow advances

On a blog post describes how to deploy activiti process definition files at this time to learn how to open the process and make the process forward.

First, the relationship between processes and tasks

The following is a simple flow chart of leave, which has a start event, two user tasks, one end event.

After starting the process, activiti will automatically create the first user task flow node, and then we complete the first user task flow will advance to the next process node, create a second node of the process and remove the first task assignment process .

Second, the open process

activiti provides a RuntimeServiceservice component to manage and control the flow of process instances running. Open process in which you need to use api

2.1 open process based on process definition key

The blog post says the process after a successful deployment, the deployment will insert records in act_re_procdef information table act_re_deployment and process definition tables. The flow definition is act_re_procdef key table KEY_value of the field.


When the same record KEY_ fields exist in the table, activiti will choose the latest version VERSION_ record to open a process definition process

    /**
     * 开启流程,根据流程定义key开启流程,
     * 如果流程定义表中有多个相同的流程定义key,activiti会根据版本号字段VERSION_选择最新的版本来开启流程
     */
    @Test
    public void test1() {
        String processDefinitionKey="process";
        //开启流程,得到流程实例对象
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey);
        System.out.println(processInstance);
    }

activiti this interface will be described with ProcessInstance process instance flow obtained after opening.

Third, the user query task

Speaking at the beginning of the first tasks will be to create a user process node after opening process, it is possible to use another service component activiti provided TaskServiceto query the user tasks, TaskServiceprovides task processing and related api

3.1 TaskQuery

activiti provides this interface to query the package task-related api, it can TaskServicebe obtained on its implementation class objects

TaskQuery taskQuery = taskService.createTaskQuery();

TaskQuery then use this query object and other objects activiti similar queries, specify the query, and then execute the query. Here I queried agents according to the task, a task can have only one representative

    /**
     * 查询开启流程后自动创建的任务
     */
    @Test
    public void test2() {
        //根据任务的代理人进行查询,一个任务的代理人是唯一的
        Task task = taskService.createTaskQuery().taskAssignee("tom").singleResult();
        System.out.println(task);
    }

activiti用Task来封装任务对象,对应的是act_ru_task这张表的记录。创建任务后会在这张表中插入一条记录。

四、完成任务

可以使用taskService中的方法来完成当前任务,使流程向下一个节点移动。完成任务时需要给定任务id即act_ru_task表的主键Id,所以完成任务时可以先通过查询方法给定条件查询出一个任务对象,再完成这个任务。

    /**
     * 完成任务,使流程前进到下一个流程节点,并创建下一个节点的任务对象
     */
    @Test
    public void test3() {
        String taskId="4502";
        taskService.complete(taskId);
    }

Guess you like

Origin www.cnblogs.com/chengxuxiaoyuan/p/12013920.html