位置: IT常识 - 正文

springboot集成Camunda,加前端bpmn页面流程编辑器(springboot集成camunda+bpmn)

编辑:rootadmin
springboot集成Camunda,加前端bpmn页面流程编辑器 1.后端搭建

推荐整理分享springboot集成Camunda,加前端bpmn页面流程编辑器(springboot集成camunda+bpmn),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:springboot集成camunda+bpmn,springboot集成camunda教程,springboot集成camunda教程,springboot集成camel,springboot集成camunda,springboot集成camunda后403,springboot集成camunda 源码,springboot集成camunda,内容如对您有帮助,希望把文章链接给更多的朋友!

搭建流程引擎后端的时候,主要注意springboot版本和Camunda版本之间的兼容性。此次springboot版本2.6.4,Camunda版本7.18.0。pom文件内容如下:

<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.6.4</version></parent><groupId>com.example</groupId><artifactId>camunda-demo2</artifactId><version>0.0.1-SNAPSHOT</version><properties><springboot.version>2.6.4</springboot.version><camunda.springboot.version>7.18.0</camunda.springboot.version><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><!-- <scope>runtime</scope>--></dependency><!-- <dependency>--><!-- <groupId>org.springframework.boot</groupId>--><!-- <artifactId>spring-boot-starter-test</artifactId>--><!-- <scope>test</scope>--><!-- </dependency>--><dependency><groupId>org.camunda.bpm.springboot</groupId><artifactId>camunda-bpm-spring-boot-starter</artifactId><version>${camunda.springboot.version}</version></dependency><dependency><groupId>org.camunda.bpm.springboot</groupId><artifactId>camunda-bpm-spring-boot-starter-rest</artifactId><version>${camunda.springboot.version}</version></dependency><dependency><groupId>org.camunda.bpm.springboot</groupId><artifactId>camunda-bpm-spring-boot-starter-webapp</artifactId><version>${camunda.springboot.version}</version></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

pom文件配置好后,通过一般的注解入口@SpringBootApplication,即可启动Camunda流程引擎。

2.数据库改造

Camunda默认使用的数据库为自带的h2内存数据库,此时一般需要将其改成mysql数据库,在配置文件配置数据库即可,application.yaml如下:

spring:datasource:url: jdbc:mysql://localhost:3306/cmd_dev?characterEncoding=UTF-8&useUnicode=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghaidriver-class-name: com.mysql.cj.jdbc.Driverusername: rootpassword: 123456camunda.bpm:admin-user:id: demopassword: demofirstName: Tomfilter:create: All tasks

一般Camunda会自动初始化mysql生成act_开头的49张表,如需手动初始化sql,可去官网找到对应版本(此例中Camunda版本为7.18.0)的sql脚本文件,https://camunda.com/download/,

下载windows安装压缩包,./configuration/sql目录下即可找到sql文件,engine和identity都执行。

不需要增加java代码或配置,直接启动即成功切换数据库。

3.流程接口文档

流程接口可以直接使用rest-api,参考官方文档https://docs.camunda.org/manual/7.18/reference/rest/。

a.部署流程

文档地址:https://docs.camunda.org/manual/7.18/reference/rest/deployment/post-deployment/

接口路径 POST /deployment/create

全路径:post http://localhost:8080/engine-rest/deployment/create

将流程文件 流程.bpmn 通过此接口即可完成流程部署,返回definitionId;

b.启动流程实例

文档地址https://docs.camunda.org/manual/7.18/reference/rest/process-definition/post-start-process-instance/

接口路径 POST /process-definition/{id}/start

其中id为上一步获取到的definitionId;

c.提交任务

接口路径 post /task/{id}/complete

d.获取待办任务

接口地址 get /task

参数assignee承办人,选用一对一模式(一个任务对应一个参与者)可通过此参数获取本人待办

参数candidateUser候选人,需要用到一对多模式,可用参数candidateUser获取本人待办

e.审批意见

接口地址 post /task/{id}/comment/create

当然,除了官方提供的rest-api,也可以自定义开发api,通过以下代码同样可以实现流程部署:

    @Autowiredprivate RepositoryService repositoryService;InputStream in;try {in= new FileInputStream("D:/ab/a.bpmn");} catch (FileNotFoundException e) {throw new RuntimeException(e);}Deployment deploy = repositoryService.createDeployment().addInputStream("b.bpmn", in) //流程定义文件名称.name("nameA") //流程部署名称.source("sourceA") //流程部署source.deploy();

所有class类官方文档https://docs.camunda.org/javadoc/camunda-bpm-platform/7.18/allclasses.html

其中:

RepositoryService: 对流程定义即bpm文件的相关操作;

RuntimeService: 通过流程定义产生的流程实例,由RuntimeService操作

TaskService: 由用户去执行的任务的相关操作

IdentityService: 管理组和用户

springboot集成Camunda,加前端bpmn页面流程编辑器(springboot集成camunda+bpmn)

FormService: 可选的表单服务

HistoryService: 历史记录服务

4.流程编辑器bpmn

可参考开源项目https://gitcode.net/mirrors/PL-FE/bpmn-camunda?utm_source=csdn_github_accelerator

编辑流程图bpmn文件:

<?xml version="1.0" encoding="UTF-8"?><definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="sid-38422fae-e03e-43a3-bef4-bd33b32041b2" targetNamespace="http://bpmn.io/bpmn" exporter="bpmn-js (https://demo.bpmn.io)" exporterVersion="5.1.2"><process id="Process_7" name="流程7" isExecutable="true"><startEvent id="StartEvent_1y45yut" name="开始"><outgoing>Flow_0yq3fo1</outgoing></startEvent><userTask id="Activity_04i1hw0" name="审批7" camunda:assignee="${deptMajor}"><incoming>Flow_1ona6kc</incoming><outgoing>Flow_0r1n32u</outgoing></userTask><userTask id="Activity_1x3adqc" name="结算7" camunda:assignee="${orgMajor}"><incoming>Flow_0yedygk</incoming><outgoing>Flow_1kw655g</outgoing></userTask><endEvent id="Event_06xx78w"><incoming>Flow_0r1n32u</incoming><incoming>Flow_1kw655g</incoming></endEvent><exclusiveGateway id="Gateway_19qnoe0"><incoming>Flow_0yq3fo1</incoming><outgoing>Flow_1ona6kc</outgoing><outgoing>Flow_0yedygk</outgoing></exclusiveGateway><sequenceFlow id="Flow_0yq3fo1" sourceRef="StartEvent_1y45yut" targetRef="Gateway_19qnoe0" /><sequenceFlow id="Flow_1ona6kc" sourceRef="Gateway_19qnoe0" targetRef="Activity_04i1hw0"><conditionExpression xsi:type="tFormalExpression">${flag==1}</conditionExpression></sequenceFlow><sequenceFlow id="Flow_0yedygk" sourceRef="Gateway_19qnoe0" targetRef="Activity_1x3adqc"><conditionExpression xsi:type="tFormalExpression">${flag==2}</conditionExpression></sequenceFlow><sequenceFlow id="Flow_0r1n32u" sourceRef="Activity_04i1hw0" targetRef="Event_06xx78w" /><sequenceFlow id="Flow_1kw655g" sourceRef="Activity_1x3adqc" targetRef="Event_06xx78w" /></process><bpmndi:BPMNDiagram id="BpmnDiagram_1"><bpmndi:BPMNPlane id="BpmnPlane_1" bpmnElement="Process_7"><bpmndi:BPMNEdge id="Flow_1kw655g_di" bpmnElement="Flow_1kw655g"><omgdi:waypoint x="370" y="200" /><omgdi:waypoint x="500" y="200" /><omgdi:waypoint x="500" y="138" /></bpmndi:BPMNEdge><bpmndi:BPMNEdge id="Flow_0r1n32u_di" bpmnElement="Flow_0r1n32u"><omgdi:waypoint x="370" y="30" /><omgdi:waypoint x="500" y="30" /><omgdi:waypoint x="500" y="102" /></bpmndi:BPMNEdge><bpmndi:BPMNEdge id="Flow_0yedygk_di" bpmnElement="Flow_0yedygk"><omgdi:waypoint x="150" y="145" /><omgdi:waypoint x="150" y="200" /><omgdi:waypoint x="270" y="200" /></bpmndi:BPMNEdge><bpmndi:BPMNEdge id="Flow_1ona6kc_di" bpmnElement="Flow_1ona6kc"><omgdi:waypoint x="150" y="95" /><omgdi:waypoint x="150" y="30" /><omgdi:waypoint x="270" y="30" /></bpmndi:BPMNEdge><bpmndi:BPMNEdge id="Flow_0yq3fo1_di" bpmnElement="Flow_0yq3fo1"><omgdi:waypoint x="38" y="120" /><omgdi:waypoint x="125" y="120" /></bpmndi:BPMNEdge><bpmndi:BPMNShape id="StartEvent_1y45yut_di" bpmnElement="StartEvent_1y45yut"><omgdc:Bounds x="2" y="102" width="36" height="36" /><bpmndi:BPMNLabel><omgdc:Bounds x="10" y="145" width="22" height="14" /></bpmndi:BPMNLabel></bpmndi:BPMNShape><bpmndi:BPMNShape id="Activity_04i1hw0_di" bpmnElement="Activity_04i1hw0"><omgdc:Bounds x="270" y="-10" width="100" height="80" /></bpmndi:BPMNShape><bpmndi:BPMNShape id="Activity_1x3adqc_di" bpmnElement="Activity_1x3adqc"><omgdc:Bounds x="270" y="160" width="100" height="80" /></bpmndi:BPMNShape><bpmndi:BPMNShape id="Event_06xx78w_di" bpmnElement="Event_06xx78w"><omgdc:Bounds x="482" y="102" width="36" height="36" /></bpmndi:BPMNShape><bpmndi:BPMNShape id="Gateway_19qnoe0_di" bpmnElement="Gateway_19qnoe0" isMarkerVisible="true"><omgdc:Bounds x="125" y="95" width="50" height="50" /></bpmndi:BPMNShape></bpmndi:BPMNPlane></bpmndi:BPMNDiagram></definitions>

其中:”可执行文件“,这个选项需要勾选上,不然流程部署后,3.b.启动流程实例步骤获取不到definitionId

创建任务的时候,要选择用户任务

,而不是普通任务

默认的编辑器没有用户任务,需要在前端项目node_modules文件夹下找到

bpmn-js/lib/features/palette/paletteprovider.js

参照create.task添加create.user-task:

    'create.task': createAction('bpmn:Task', 'activity', 'bpmn-icon-task',translate('Create Task')),'create.user-task': createAction('bpmn:UserTask', 'activity', 'bpmn-icon-user-task',translate('Create User Task')),a.设置参与者

assignee承办人对应用户任务的”代理人“属性,也可以选用一对多的candidateUser候选人或候选组

设置参与者的时候,可以直接写死参与者的id,也可以通过使用流程变量来动态设置参与者,格式如下:

${deptMajor}

其中流程变量deptMajor,在启动流程时候,需要定义数据类型(值可以先不定义)

参照接口3.b POST /process-definition/{id}/start

在请求体传入如下json数据,初始化流程变量:

{"variables": {"deptMajor" : {"value" : "123","type": "String"},"orgMajor" : {"value" : null,"type": "String"},"flag" : {"value" : 2,"type": "Integer"}}}b.流程分支控制

设计流程图时,网关各分支增加条件,条件类型为表达式:${flag==1}

然后如上启动流程的时候给流程变量flag初始化和赋值,后续提交任务的时候,也可随时通过修改流程变量的值来控制流程分支的走向。

5.常用表

act_ge_bytearray 记录部署的bpmn流程文件

act_re_deployment 部署发布的流程会在此产生记录

act_re_procdef 已发布的流程定义(BPMN流程模型定义表)

act_hi_procinst 历史流程实例表

act_hi_actinst 历史活动实例表

act_hi_identitylink 历史任务执行人表

act_ru_task 任务表

act_ru_identitylink 任务执行人表

act_ru_execution BPMN流程运行时记录表

6.当前流程图高亮

基本思路为通过接口查出流程定义的xml内容,然后找到当前正在运行的节点,通过方法canvas.addMarker(actId, 'highlight'),修改其样式:

<template><div class="containers"><div id="canvas" ref="canvas"></div></div></template><script>import BpmnViewer from 'bpmn-js'import MoveCanvasModule from 'diagram-js/lib/navigation/movecanvas'let bpmnViewer = nullconst webUrl = "http://localhost:8095/camunda"export default {name: 'bpmnView',data () {return {msg: 'Welcome to yjr Vue.js App',bpmnModeler: null}},mounted() {bpmnViewer = new BpmnViewer({container: '#canvas',width: '100%',height: '100%',additionalModules: [MoveCanvasModule // 移动整个画布]})this.greet()},methods: {createBpmnViewer :async function (bpmnXML) {try {await bpmnViewer.importXML(bpmnXML);} catch (err) {console.error('error loading BPMN 2.0 XML', err);}let canvas = bpmnViewer.get('canvas')canvas.zoom('fit-viewport', 'auto')},greet: function () {const that = thisconst processDefinitionId = this.$route.query.processDefinitionIdthis.$http.get(webUrl + '/engine-rest/process-definition/' + processDefinitionId + '/xml').then((response)=>{if(response.data.bpmn20Xml){that.createBpmnViewer(response.data.bpmn20Xml)that.getAct();}}).catch((response)=>{console.log(response);})},getAct: function () {const that = thisconst processInstanceId = this.$route.query.processInstanceIdlet canvas = bpmnViewer.get('canvas')this.$http.get(webUrl + '/web/processInstance/getAct?processInstanceId=' + processInstanceId).then((response)=>{if(response.data.code == 200){let list = response.data.data;for(var actId in list){canvas.addMarker(list[actId], 'highlight');}}}).catch((response)=>{console.log(response);})}}}</script><style>.highlight .djs-visual > :nth-child(1) {stroke: green !important;fill: rgba(0, 80, 0, 0.4) !important;}.djs-container{height: 80vh !important;}</style>

效果如下:

具体js中初始化及方法可参考bpmn官网:bpmn-js walkthrough | Toolkits | bpmn.io

本文链接地址:https://www.jiuchutong.com/zhishi/277736.html 转载请保留说明!

上一篇:电脑系统出问题时如何减少损失?(电脑系统出问题了怎么办)

下一篇:共享文档无法访问设置教程(共享文档无法访问如何解决)

  • 海信空调体感模式怎么关闭(海信空调体感模式省电吗)

    海信空调体感模式怎么关闭(海信空调体感模式省电吗)

  • 小爱音响怎么重新连接wifi(小爱音响怎么重新配对)

    小爱音响怎么重新连接wifi(小爱音响怎么重新配对)

  • macbookpro大小写转换(macbookpro大小写转换快捷键)

    macbookpro大小写转换(macbookpro大小写转换快捷键)

  • 闪存和硬盘的区别(闪存和硬盘的区别是什么)

    闪存和硬盘的区别(闪存和硬盘的区别是什么)

  • word文档怎么删除一页空白页(word文档怎么删除批注区域)

    word文档怎么删除一页空白页(word文档怎么删除批注区域)

  • qq怎么邀请好友注册(qq怎么邀请好友一起看电影)

    qq怎么邀请好友注册(qq怎么邀请好友一起看电影)

  • 拼多多预售是什么意思(拼多多预售是什么时候发货?一直不发货咋办)

    拼多多预售是什么意思(拼多多预售是什么时候发货?一直不发货咋办)

  • 苹果11全屏壁纸尺寸(苹果13好看的全屏壁纸)

    苹果11全屏壁纸尺寸(苹果13好看的全屏壁纸)

  • 华为手机屏保图片怎么设置(华为手机屏保图片怎么换)

    华为手机屏保图片怎么设置(华为手机屏保图片怎么换)

  • 微信非好友还能发消息(微信非好友还能转账吗)

    微信非好友还能发消息(微信非好友还能转账吗)

  • 星标朋友有什么提醒么(星标朋友有什么用)

    星标朋友有什么提醒么(星标朋友有什么用)

  • 蓝牙充电仓怎么才算充满电(蓝牙充电仓怎么给蓝牙充电)

    蓝牙充电仓怎么才算充满电(蓝牙充电仓怎么给蓝牙充电)

  • 华为手机怎样召唤语音助手(华为手机怎样召唤小易)

    华为手机怎样召唤语音助手(华为手机怎样召唤小易)

  • 华为p10p支持无线充电吗(华为p10支持无线充电吗?)

    华为p10p支持无线充电吗(华为p10支持无线充电吗?)

  • 华为usb连接方式为什么一直是反向充电(华为usb连接方式一直显示反向充电怎么调换到文件接收)

    华为usb连接方式为什么一直是反向充电(华为usb连接方式一直显示反向充电怎么调换到文件接收)

  • frd-al00是华为什么型号(frd-al00什么型号)

    frd-al00是华为什么型号(frd-al00什么型号)

  • 手机号165开头是什么(手机号165开头是哪里的号码)

    手机号165开头是什么(手机号165开头是哪里的号码)

  • 电脑如何恢复出厂设置(电脑如何恢复出厂设置win10)

    电脑如何恢复出厂设置(电脑如何恢复出厂设置win10)

  • 魅族s6如何退出极限省电(魅族s6如何退出安全模式)

    魅族s6如何退出极限省电(魅族s6如何退出安全模式)

  • ppt全是图片怎么排版(ppt里的图片)

    ppt全是图片怎么排版(ppt里的图片)

  • 6.5寸是多少厘米手机(电视机65寸是多少厘米)

    6.5寸是多少厘米手机(电视机65寸是多少厘米)

  • mate20原装充电器多少瓦(mate20原装充电器多少钱)

    mate20原装充电器多少瓦(mate20原装充电器多少钱)

  • 知乎怎么删除自己的提问(知乎怎么删除自己回答)

    知乎怎么删除自己的提问(知乎怎么删除自己回答)

  • 苹果8p黑屏但没关机(苹果8p黑屏但没声音)

    苹果8p黑屏但没关机(苹果8p黑屏但没声音)

  • Vue3-路由跳转专题详细总结(vue路由跳转的三种方法)

    Vue3-路由跳转专题详细总结(vue路由跳转的三种方法)

  • 个税应纳税所得额是要上交的钱吗
  • 增值税专用发票电子发票可以抵扣吗
  • 支付的各项税费现金流量表怎么填
  • 何谓运输,交通和交通运输
  • 缴纳增值税会计处理
  • 预计净残值影响减值准备吗
  • 对公的etc怎么绑定怎么充值
  • 广告公司可以开劳务费吗
  • 服装租赁开票税目
  • 应交税费期初数比期末数大
  • 收到国家退税
  • 出口退税金额和进项税额不一致
  • 加工企业如何降成本
  • 免税销售额和免税额区别
  • 汽车用品包含
  • 递延所得税资产和负债怎么理解
  • 核定征收企业所得税的小型微利企业不得享受优惠政策
  • 资产原值包含残值吗
  • 小规模纳税人1%税收优惠
  • 在途物资非合理损耗
  • 增值税纳税申报表在哪里打印
  • 参加抽奖活动中奖却不发奖品
  • 按年缴纳年金的企业缴费部分,应按照全年一次性奖金
  • 工程结算如何做账
  • 微软汽车
  • excel表格怎么自制表格
  • 差旅费增值税专用发票少报销可以吗
  • 已计提的存货跌价准备计入成本吗
  • vue2动态路由
  • 在西伯利亚森林中是真实故事吗
  • 口腔门诊提供免费服务有哪些?
  • 纳税申报表填写说明
  • 委托研发技术合同登记
  • yolo v5 github
  • elementui动态表单数据回显
  • 企业所得税资产总额根据什么填
  • 建设工程审计报告包括哪些内容
  • 海关票怎么做账
  • 政府会计应付职工薪酬明细科目
  • 在SQL Server中使用存储过程的优点包括
  • mysql数据库导出xml的实现方法
  • 哪些属于发票
  • 哪些增值税专用发票不能抵扣进项税
  • 其他综合收益会影响未分配利润吗
  • 税收完税证明怎么做账
  • 补发工资如何计算个税
  • 财务报销单据粘贴视频
  • 公司收到现金货款怎么存银行
  • 一般纳税人房租租赁费的税率
  • 外币投资计入什么科目
  • 旅游费的发票可以进成本吗?
  • 不同利益主体之间的利益如何协调
  • 航天金税税控盘服务电话
  • 明细分类账的填写
  • mysqli修改表中数据
  • mysql索引用法
  • microsoft wlan
  • Vista下以真正的管理员登陆的设置方法
  • services.exe修改注册表
  • win8系统怎么做系统
  • mac画图的app叫什么
  • linux服务器宕机排查
  • win10系统怎么修改字体大小
  • linux tee命令详解
  • windows7无法关闭密码保护共享
  • redhat linux安装
  • jquery 插件写法
  • unity做安卓app
  • 处理及遍历xml文件怎么做
  • javascript性能优化写法
  • junit 原理
  • python ping检测
  • python socket模块
  • 如何查询纳税信用级别
  • 江苏省发票真伪查询网站
  • 个体户注销还要交税吗?
  • 安徽省手工发票
  • 办公厅机构设置方案
  • 签订设计合同
  • 轮胎消费税的征收环节
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设