作为第一次接触工作流小白,总结一下两天学习成果。
- 使用flowable画流程图。
参考文章:https://www.jianshu.com/p/e8f4e9a7bd8a (部署flowable)
https://blog.csdn.net/weixin_44150993/article/details/117750490(flowable流程设计设计器组件用法)
- 我这里就是用的请假流程的例子。这里设置的表单的字段和后面代码中字段是统一的。
- 流程创建好之后,点击下载,将保存bpmn20文件到本地。
- 流程图画好之后,接下来是用springboot整合flowable.
- 导入flowable和数据库连接依赖。
<dependency> <groupId>org.flowable</groupId> <artifactId>flowable-spring-boot-starter</artifactId> <version>6.6.0</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.26</version> </dependency>
- 配置application.yml文件
spring: datasource: url: jdbc:mysql://127.0.0.1:3306/leaveflow?nullCatalogMeansCurrent=true&autoReconnect=true&useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC username: xxxxxx password: xxxxxx flowable: #关闭定时任务JOB async-executor-activate: false server: servlet: context-path: port: 8081
- 在resources目录下创建processes文件夹。将下载下来的bpmn文件放到processes文件夹下。启动项目,springboot会自动启动流程。启动成功后,可以在数据库中看到自动生成的表。
- 最后写一个controller测试一下。
@Controller
public class LeaveTestController { @Autowired private RuntimeService runtimeService; @Autowired private TaskService taskService; @Autowired private RepositoryService repositoryService; @Qualifier("processEngine") @Autowired private ProcessEngine processEngine; /** * 请假申请 * * @param userName 请假申请人姓名 * @param days 请假天数 * @param reason 请假理由 */ @RequestMapping(value = "/requestholiday") @ResponseBody public String addExpense(String userName, Integer days, String reason) { //启动流程 HashMap<String, Object> map = new HashMap<>(); //这里的key和当时画流程图设置的表单字段是统一的 map.put("leave_name",userName); map.put("leave_days",days); map.put("leave_reason",reason); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("leave", map); //这里的leave是流程id return "提交成功.流程Id为:" + processInstance.getId(); }
} -
测试。地址栏输入:http://localhost:8081/requestholiday?userName=小张&days=6&reason=病假