In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to integrate SpringBoot2.0.1 and flowable workflow engine, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
1. To prepare the dependency, the pom.xml file is as follows
4.0.0
Activiti.demo
Activiti-demo
1.0-SNAPSHOT
War
Activiti-demo
Spring-activiti-demo
Org.springframework.boot
Spring-boot-starter-parent
2.0.1.RELEASE
UTF-8
UTF-8
1.8
Org.springframework.boot
Spring-boot-starter-web
Org.flowable
Flowable-spring-boot-starter
6.3.0
Mysql
Mysql-connector-java
5.1.35
Org.springframework.boot
Spring-boot-maven-plugin
-
two。 Prepare the process file, the ExpenseProcess.bpmn20.xml file is as follows
Reimbursement process
500}]] >
-
3. Prepare the SpringBoot properties file, and the application.properties content is as follows
Spring.datasource.driver-class-name=com.mysql.jdbc.Driver
Spring.datasource.url=jdbc:mysql://127.0.0.1:3306/xh_activiti?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false&autoReconnect=true&failOverReadOnly=false&useUnicode=true&characterEncoding=UTF-8
Spring.datasource.username=root
Spring.datasource.password=123456
Spring.jpa.properties.hibernate.hbm2ddl.auto=update
Spring.jpa.show-sql=true
Server.port=8082
Server.tomcat.uri-encoding=UTF-8
Flowable.async-executor-activate=false
-
4. Write the processing classes used in the process
Package name: com.springboot.demo.handler
Class name: ManagerTaskHandler
The class content is as follows
Package com.springboot.demo.handler
Import org.flowable.engine.delegate.TaskListener
Import org.flowable.task.service.delegate.DelegateTask
/ * *
* @ ClassName ManagerTaskHandler
* @ Description TODO
* @ Author yunshuodeng
* @ Date 2019-05-05 09:53
* @ Version 1.0
* * /
Public class ManagerTaskHandler implements TaskListener {
@ Override
Public void notify (DelegateTask delegateTask) {
DelegateTask.setAssignee ("Manager")
}
}
Package name: com.springboot.demo.handler
Class name: BossTaskHandler
The class content is as follows
Package com.springboot.demo.handler
Import org.flowable.engine.delegate.TaskListener
Import org.flowable.task.service.delegate.DelegateTask
/ * *
* @ ClassName BossTaskHandler
* @ Description TODO
* @ Author yunshuodeng
* @ Date 2019-05-05 09:54
* @ Version 1.0
* * /
Public class BossTaskHandler implements TaskListener {
@ Override
Public void notify (DelegateTask delegateTask) {
DelegateTask.setAssignee ("boss")
}
}
-
5. Write a controller
Package name: com.springboot.demo.controller
Class name: ExpenseController
The class content is as follows:
Package com.springboot.demo.controller
Import org.flowable.bpmn.model.BpmnModel
Import org.flowable.engine.*
Import org.flowable.engine.runtime.Execution
Import org.flowable.engine.runtime.ProcessInstance
Import org.flowable.image.ProcessDiagramGenerator
Import org.flowable.task.api.Task
Import org.springframework.beans.factory.annotation.Autowired
Import org.springframework.stereotype.Controller
Import org.springframework.util.StringUtils
Import org.springframework.web.bind.annotation.RequestMapping
Import org.springframework.web.bind.annotation.ResponseBody
Import javax.servlet.http.HttpServletResponse
Import java.io.InputStream
Import java.io.OutputStream
Import java.util.ArrayList
Import java.util.HashMap
Import java.util.List
/ * *
* @ ClassName ExpenseController
* @ Description TODO
* @ Author yunshuodeng
* @ Date 2019-05-05 09:57
* @ Version 1.0
* * /
@ Controller
@ RequestMapping (value = "expense")
Public class ExpenseController {
@ Autowired
Private RuntimeService runtimeService
@ Autowired
Private TaskService taskService
@ Autowired
Private RepositoryService repositoryService
@ Autowired
Private ProcessEngine processEngine
/ * *
* generate the current flowchart
* @ param httpServletResponse
* @ param processId
, /
@ RequestMapping (value = "processDiagram")
Public void genProcessDiagram (HttpServletResponse httpServletResponse,String processId) {
Try {
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery () .processInstanceId (processId) .singleResult ()
If (StringUtils.isEmpty (processInstance)) {
Return
}
Task task = taskService.createTaskQuery () .processInstanceId (processInstance.getId ()) .singleResult ()
String instanceId = task.getProcessInstanceId ()
List executionList = runtimeService.createExecutionQuery () .processInstanceId (instanceId) .list ()
List activityIdList = new ArrayList ()
List flowList = new ArrayList ()
For (Execution execution: executionList) {
List idList = runtimeService.getActiveActivityIds (execution.getId ())
ActivityIdList.addAll (idList)
}
BpmnModel bpmnModel = repositoryService.getBpmnModel (processInstance.getProcessDefinitionId ())
ProcessEngineConfiguration processEngineConfiguration = processEngine.getProcessEngineConfiguration ()
ProcessDiagramGenerator processDiagramGenerator = processEngineConfiguration.getProcessDiagramGenerator ()
InputStream inputStream = processDiagramGenerator.generateDiagram (bpmnModel, "png", activityIdList,flowList
ProcessEngineConfiguration.getActivityFontName ()
ProcessEngineConfiguration.getLabelFontName ()
ProcessEngineConfiguration.getAnnotationFontName ()
ProcessEngineConfiguration.getClassLoader ()
1.0)
OutputStream out = null
Byte [] buf = new byte [1024]
Int legth = 0
Try {
Out = httpServletResponse.getOutputStream ()
While ((legth = inputStream.read (buf))! =-1) {
Out.write (buf, 0, legth)
}
} finally {
If (inputStream! = null) {
InputStream.close ()
}
If (out! = null) {
Out.close ()
}
}
} catch (Exception e) {
System.out.println (e.getMessage ())
}
}
/ * *
* Review-reject
* @ param taskId
* @ return
, /
@ RequestMapping (value = "reject")
@ ResponseBody
Public String reject (String taskId) {
HashMap map = new HashMap ()
Map.put ("outcome", "rejected")
TaskService.complete (taskId,map)
Return "reject"
}
/ * *
* Audit-approved
* @ param taskId
* @ return
, /
@ RequestMapping (value = "apply")
@ ResponseBody
Public String apply (String taskId) {
Task task = taskService.createTaskQuery () .taskId (taskId) .singleResult ()
If (StringUtils.isEmpty (task)) {
Throw new RuntimeException ("process does not exist")
}
HashMap map = new HashMap ()
Map.put ("outcome", "pass")
TaskService.complete (taskId,map)
Return "processed ok"
}
/ * *
* get approval list
* @ param userId
* @ return
, /
@ RequestMapping (value = "list")
@ ResponseBody
Public Object list (String userId) {
String temp = ""
List taskList = taskService.createTaskQuery (). TaskAssignee (userId). OrderByTaskCreateTime (). Desc (). List ()
For (Task task: taskList) {
Temp + = task.toString ()
System.out.println (task.toString ())
}
Return temp
}
/ * *
* start the reimbursement process
* @ param userId user ID
* @ param money reimbursement amount
* @ param description description
* @ return
, /
@ RequestMapping (value = "add")
@ ResponseBody
Public String addExpense (String userId,Integer money,String description) {
HashMap map = new HashMap ()
Map.put ("taskUser", userId)
Map.put ("money", money)
Map.put ("description", description)
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey ("Expense", map)
Return "submitted successfully, process ID is" + processInstance.getId ()
}
}
-
6. Start the service without reporting an error
7. Visit the following address to execute the process
1) submit an reimbursement application
Request address: http://localhost:8082/expense/add?userId=4&money=2000
Returned result: submitted successfully. The process ID is 5043.
Description:
Http://localhost local service
8082 indicates that local services provide access ports to the outside world
Expense represents the controller name
Add represents the method in the controller, which is used to start the reimbursement process, that is, to submit a claim
UserId=4 indicates that the user ID is 4
Money=2000 indicates that the reimbursement amount is 2000.
2) View to-do list
Request address: http://localhost:8082/expense/list?userId=4
Returned result: Task [id=5050, name= travel reimbursement]
Description:
Http://localhost local service
8082 indicates that local services provide access ports to the outside world
Expense represents the controller name
List indicates the name of the method to get the to-do list
UserId=4 indicates that the user's ID is 4 and the to-do list of the user's ID is 4.
3) Review the reimbursement application, and the result is approved
Request address: http://localhost:8082/expense/apply?taskId=5050
Returned result: processed ok
Description:
Http://localhost local service
8082 indicates that local services provide access ports to the outside world
Expense represents the controller name
Apply indicates the approval method
TaskId stands for task ID, and some task ID is to view a task ID in the to-do list
4) generate the current task status diagram
Request address: http://localhost:8082/expense/processDiagram?processId=5043
Return result: a picture in the browser
Description:
Http://localhost local service
8082 indicates that local services provide access ports to the outside world
Expense represents the controller name
ProcessDiagram represents the method of generating pictures.
ProcessId=5043 represents the process ID, which ID is the process ID returned when the claim is submitted in step 1.
Thank you for reading this article carefully. I hope the article "how to integrate SpringBoot2.0.1 and flowable Workflow engine" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.