Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Process variable value Business_key of activiti

Shulou Source: shulou.com Published: 2022-06-02 19:26:23 09月30日 Update

Take leave as an example, when we do workflow, we must need to associate our business with workflow, and Activiti provides us with a convenience is Business_key, and this field is specifically used to store our business keywords.

For example, we have a leave business, and my leave information has been written into the database table (tb_leaveBill), but how do I associate my leave information with the activiti database table, right, is to use a given Activiti Business_key, and here is a little trick, for example, my javaBean is called LeaveBill, and my leave information ID is 1, then I can let him write as leaveBill.1, the skill is business Bean. Business ID, so we can set up Business_key

Start the process instance (Business_key)

[java] view plain copy

Public void saveStartProcess (WorkflowBean workflowBean) {

/ / obtain the ID of the request for leave, and the LeaveBill of the object using the request for leave ID

Long id = workflowBean.getId ()

LeaveBill leaveBill = leaveBillDao.findLeaveBillById (id)

/ / update the status of the request for leave

LeaveBill.setState (1)

String key = leaveBill.getClass () .getSimpleName ()

/ / get process variables from session

Map variables = new HashMap ()

Variables.put ("inputUser", SessionContext.get (). GetName ()); / / Table design is unique

/ / use process variables to associate workflow and business

String objId = key + "." + id; / / format LeaveBill.id

/ / start the process instance and set the process variable at the same time. / / use a field (Businesskey) in the object table being executed to enable the startup instance to associate business.

RuntimeService.startProcessInstanceByKey (key,objId,variables)

}

The effect picture is as follows:

Query (Business_key)

When querying, we need to query the task object according to the task ID, then obtain the instance ID according to the task object, and then use the process instance query Business_key to obtain the primary key of the corresponding business, so that we can query the

[java] view plain copy

/ / use task ID to query leave request information

@ Override

Public LeaveBill findLeaveByTaskId (String taskId) {

/ / 1, use task ID to query the object task

Task task = taskService.createTaskQuery () .taskId (taskId) .singleResult ()

/ / 2. Use task ID to get the instance ID

String processInstanceId = task.getProcessInstanceId ()

/ / 3. Use process instances to query

ProcessInstance pi = runtimeService.createProcessInstanceQuery () .processInstanceId (processInstanceId) .singleResult ()

/ / 4. Use the process instance object to get BusinessKey

String business_key = pi.getBusinessKey ()

/ / 5. Get the primary key ID corresponding to Business_key

String id = ""

If (StringUtils.isNotBlank (business_key)) {

/ / intercept string

Id = business_key.split ("\\.") [1] .toString ()

}

LeaveBill leaveBill = leaveBillDao.findLeaveBillById (Long.parseLong (id))

Return leaveBill

}

Tags: Business instance process query object task information that is association variable work field workflow skill data database time right key keyword Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Docker MariaDB OPPO Reno Shulou Technology