我也没想到 Springboot + Flowable 开发工作流会这么简单

{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":">本文收录在个人博客:"},{"type":"link","attrs":{"href":"http://www.chengxy-nds.top","title":""},"content":[{"type":"text","text":"www.chengxy-nds.top"}]},{"type":"text","text":",技术资料共享,同进步"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"程序员是块砖,哪里需要哪里搬"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"公司内部的OA系统最近要升级改造,由于人手不够就把我借调过去了,但说真的我还没做过这方面的功能,第一次接触工作流的开发,还是有点好奇是个怎样的流程。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"项目主要用 "},{"type":"codeinline","content":[{"type":"text","text":"Springboot"}]},{"type":"text","text":" + "},{"type":"codeinline","content":[{"type":"text","text":"Flowable"}]},{"type":"text","text":" 重构原有的工作流程,"},{"type":"codeinline","content":[{"type":"text","text":"Flowable"}]},{"type":"text","text":" 是个用 "},{"type":"codeinline","content":[{"type":"text","text":"Java"}]},{"type":"text","text":"语言写的轻量级工作流引擎,上手比较简单开发效率也挺高的,一起学习下这个框架。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"官方地址:"},{"type":"codeinline","content":[{"type":"text","text":"https://www.flowable.org/docs/userguide/index.html"}]},{"type":"text","text":",分享的只是简单应用,深入研究还得看官方文档。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":" Flowable 核心依赖"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"javascript"},"content":[{"type":"text","text":"\n\n\torg.flowable\n\tflowable-spring-boot-starter\n\t6.3.0\n\n\n\torg.springframework.boot\n\tspring-boot-starter-jdbc\n\n\n\torg.springframework.boot\n\tspring-boot-starter-web\n\n\n\torg.mybatis.spring.boot\n\tmybatis-spring-boot-starter\n\t1.3.2\n\n\n\tmysql\n\tmysql-connector-java\n\truntime\n"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"流程设计"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"工作流开发的核心是任务流程的设计,"},{"type":"codeinline","content":[{"type":"text","text":"Flowable"}]},{"type":"text","text":" 官方建议采用业界标准"},{"type":"codeinline","content":[{"type":"text","text":"BPMN2.0"}]},{"type":"text","text":"的 "},{"type":"codeinline","content":[{"type":"text","text":"XML"}]},{"type":"text","text":"来描述需要定义的工作流。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"我们需要在 "},{"type":"codeinline","content":[{"type":"text","text":"resource"}]},{"type":"text","text":" 目录下创建 "},{"type":"codeinline","content":[{"type":"text","text":"processes"}]},{"type":"text","text":"路径,存放相关的 "},{"type":"codeinline","content":[{"type":"text","text":"XML"}]},{"type":"text","text":"流程配置文件。"},{"type":"codeinline","content":[{"type":"text","text":"Flowable"}]},{"type":"text","text":" 框架会默认加载此目录下的工作流文件并解析 "},{"type":"codeinline","content":[{"type":"text","text":"XML"}]},{"type":"text","text":",并将解析后的流程配置信息持久化到数据库。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/57/57703222a45ef0aeb613658c1b886328.png","alt":null,"title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"Flowable"}]},{"type":"text","text":" 是依赖于数据库的,但它并不需要我们手动的创建表,而是在程序第一次启动时,自动的向"},{"type":"codeinline","content":[{"type":"text","text":"MySQL"}]},{"type":"text","text":" 中创建它所需要的一系列表。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"javascript"},"content":[{"type":"text","text":"spring:\n datasource:\n url: jdbc:mysql://47.93.6.5:3306/order?serverTimezone=UTC\n username: root\n password: 123455"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/d8/d8d26d5eb4d226db5e36c39a50742a29.png","alt":null,"title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"看到项目启动成功一共生成了60个表,数量还是比较多的,建议使用专门的数据库存在这些工作流表。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/52/528d8fb873c39d2ce1f5a0fc972e65c6.png","alt":null,"title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"举个栗子:假如一个请假流程,需要经理审核通过,请假才能生效,如果他驳回流程结束。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/99/99d546e3a31766144994872d7f57d21d.png","alt":null,"title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"接下来我们用 "},{"type":"codeinline","content":[{"type":"text","text":"XML"}]},{"type":"text","text":" 翻译下上边的请假流程图,整体非常简单只要够细心就行了,一起看看每个标签都是什么含义。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"java"},"content":[{"type":"text","text":"\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"其实就是把流程图的各种线条逻辑,用不同的"},{"type":"codeinline","content":[{"type":"text","text":"XML"}]},{"type":"text","text":"标签描绘出来了。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":""}]},{"type":"text","text":" : 表示一个完整的工作流"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":""}]},{"type":"text","text":" : 对工作流的描述"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":""}]},{"type":"text","text":" : 工作流中起点位置(开始)"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":""}]},{"type":"text","text":" : 工作流中结束位置(结束)"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":""}]},{"type":"text","text":" : 代表一个任务审核节点(组长、经理等角色)"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":""}]},{"type":"text","text":" : 逻辑判断节点,相当于流程图中的菱形框"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":""}]},{"type":"text","text":" :链接各个节点的线条,"},{"type":"codeinline","content":[{"type":"text","text":"sourceRef"}]},{"type":"text","text":" 属性表示线的起始节点,"},{"type":"codeinline","content":[{"type":"text","text":"targetRef"}]},{"type":"text","text":" 属性表示线指向的节点。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"上边这一大坨"},{"type":"codeinline","content":[{"type":"text","text":"XML"}]},{"type":"text","text":"是不是看着超级麻烦,要是有自动生成工具就好了,我发现"},{"type":"codeinline","content":[{"type":"text","text":"IDEA"}]},{"type":"text","text":"自带设计工具,但实在是太难用了。"}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/fd/fd0685f53081c6640959ccb8636b57fe.png","alt":null,"title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"作为一个面向百度编程的程序员,别的不行上网找答案的能力还是可以的,既然我都觉得写"},{"type":"codeinline","content":[{"type":"text","text":"XML"}]},{"type":"text","text":"麻烦,那么想来官方肯定也想到了,说不定有现成的工具,逛了一圈官网"},{"type":"codeinline","content":[{"type":"text","text":"https://www.flowable.org/downloads.html"}]},{"type":"text","text":" ,居然真的找到了。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"github"}]},{"type":"text","text":"下载地址:https://github.com/flowable/flowable-engine/releases/download/flowable-6.4.0/flowable-6.4.0.zip,下载速度那是相当感人,而且这个工具需要自己安装......."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/83/830eda2a751d851c428e18936b006764.png","alt":null,"title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"又找了个在线编辑的工具: http://www.learun.cn:8090/home_online.htm,各种折腾~,设计完流程后,直接复制自动生成的代码即可。"}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/c9/c916c8a17daeb81adc78dc659c04e7e3.png","alt":null,"title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"流程审批"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"流程设计完后剩下的就是对工作流的审批和生成流程图。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"首先启动一个请假的流程,以员工ID "},{"type":"codeinline","content":[{"type":"text","text":"staffId"}]},{"type":"text","text":" 作为唯一标识,"},{"type":"codeinline","content":[{"type":"text","text":"XML"}]},{"type":"text","text":"文件中会接收变量 "},{"type":"codeinline","content":[{"type":"text","text":"leaveTask"}]},{"type":"text","text":","},{"type":"codeinline","content":[{"type":"text","text":"Flowable"}]},{"type":"text","text":"内部会进行数据库持久化,并返回一个流程Id "},{"type":"codeinline","content":[{"type":"text","text":"processId"}]},{"type":"text","text":" ,用它可以查询工作流的整体情况,任务Id "},{"type":"codeinline","content":[{"type":"text","text":"task"}]},{"type":"text","text":"为员工具体的请假任务。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"注意"},{"type":"text","text":":一个请假流程 "},{"type":"codeinline","content":[{"type":"text","text":"processId"}]},{"type":"text","text":"中可以包含多个请假任务 "},{"type":"codeinline","content":[{"type":"text","text":"taskId"}]},{"type":"text","text":"。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"javascript"},"content":[{"type":"text","text":"/**\n * @author xiaofu\n * @description 启动流程\n * @date 2020/8/26 17:36\n */\n @RequestMapping(value = \"startLeaveProcess\")\n @ResponseBody\n public String startLeaveProcess(String staffId) {\n HashMap map = new HashMap<>();\n map.put(\"leaveTask\", staffId);\n ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(\"Leave\", map);\n StringBuilder sb = new StringBuilder();\n sb.append(\"创建请假流程 processId:\" + processInstance.getId());\n List tasks = taskService.createTaskQuery().taskAssignee(staffId).orderByTaskCreateTime().desc().list();\n for (Task task : tasks) {\n sb.append(\"任务taskId:\" + task.getId());\n }\n return sb.toString();\n }"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"用启动流程时返回的 "},{"type":"codeinline","content":[{"type":"text","text":"processId"}]},{"type":"text","text":" 看一下一下当前的流程图"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"java"},"content":[{"type":"text","text":"http://localhost:4000/leave/createProcessDiagramPic?processId=37513"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/b9/b904094c4b0095e2fd9aeafc704fa1a6.png","alt":null,"title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"接下来将请假申请进行驳回 ,传入相应的 "},{"type":"codeinline","content":[{"type":"text","text":"taskId"}]},{"type":"text","text":" 后执行驳回,再看看整个工作流的效果。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"javascript"},"content":[{"type":"text","text":"http://localhost:4000/leave/rejectTask?taskId=10086"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"javascript"},"content":[{"type":"text","text":" /**\n * @param taskId\n * @author xinzhifu\n * @description 驳回\n * @date 2020/8/27 14:30\n */\n @ResponseBody\n @RequestMapping(value = \"rejectTask\")\n public String rejectTask(String taskId) {\n HashMap map = new HashMap<>();\n map.put(\"checkResult\", \"驳回\");\n taskService.complete(taskId, map);\n return \"申请审核驳回~\";\n }"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"看到整个请假流程在经理审核这成功阻断了。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"javascript"},"content":[{"type":"text","text":"http://localhost:4000/leave/createProcessDiagramPic?processId=37513"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/7c/7ce7908d4bd8292e7f6b62bf7f0f6580.png","alt":null,"title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"总结"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"开发工作流一般多用在OA系统等传统项目中,我也是第一次尝试做此类功能,收获还是蛮多的,技术栈又压进了一个知识点。今天分享的是个超级简单的"},{"type":"codeinline","content":[{"type":"text","text":"demo"}]},{"type":"text","text":",因为也是刚开始接触,等我用的贼溜的时候,再给小伙伴们做更成熟更深入的分享。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"demo"}]},{"type":"text","text":"的"},{"type":"codeinline","content":[{"type":"text","text":"github"}]},{"type":"text","text":" 地址:"},{"type":"codeinline","content":[{"type":"text","text":"https://github.com/chengxy-nds/Springboot-Notebook/tree/master/springboot-work-flowable"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"horizontalrule"},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"原创不易,燃烧秀发输出内容,如果有一丢丢收获,点个赞鼓励一下吧!"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"整理了几百本各类技术电子书,送给小伙伴们。关注公号回复【"},{"type":"text","marks":[{"type":"strong"}],"text":"666"},{"type":"text","text":"】自行领取。和一些小伙伴们建了一个技术交流群,一起探讨技术、分享技术资料,旨在共同学习进步,如果感兴趣就加入我们吧!"}]}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章