In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
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
}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.