Query and complete 04 to start the process instance, task

First, the process instance is started: The KEY start (commonly, data flow can be brought at start) process

The process can be specified at NAME KEY and flow diagrams.
First of all to get to RuntimeService, use the object to complete the boot process:
    @Test
    public void startProcess() {
         RuntimeService runtimeService = processEngine.getRuntimeService();
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("LeaveBill");
        System.out.println ( "process started successfully, the process instance ID is:" + processInstance.getId ());
    }
After the process starts, that can be queried task.

The most common are two ways to start the process instance (using the process are key start):

1、runtimeService.startProcessInstanceByKey( key,businesskey,vars);
key: Process key
the businessKey: business table ID, for example, leave the table, including a leave of absence, beginning and ending time.
VARS: process variables
2、runtimeService.startProcessInstanceByKey(key,businesskey);

Second, the task of queries (queries based on people handling the process)

2.1 Tip:

Any queries activiti in all three points: ① ② sort criteria query query result set ③
    // query the task
    @Test
    public void findTask() {
         TaskService taskService = processEngine.getTaskService();
        Task task = taskService.createTaskQuery().taskAssignee("张三").singleResult();
        System.out.println ( "John's mission ID:" + task.getId ());
    }

Third, to complete the task (it can be brought into the process variables to complete the task)

//mission accomplished
    @Test
    public void doTask() {
         TaskService taskService = processEngine.getTaskService();
        taskService.complete("2504");
    }

Fourth, determine whether the process is ended

Scenario: for example, a leave table approval status needs to judge whether to end the process to change state leave approval, the approval may change state is by or failed.
Analyzing method:
1, the known process instance ID, process instance ID and isolated in the process instance table example is not empty, the flow is not ended.
2, the task ID is known, according to the task ID query instance ID, in a query by the first method.

Guess you like

Origin www.cnblogs.com/Guorisy/p/12099234.html