c 网站开发案例详解光盘,wordpress发号系统,北京比较大的软件开发公司,深圳专业建网站公司#x1f496;专栏简介
✔️本专栏将从Camunda(卡蒙达) 7中的关键概念到实现中国式工作流相关功能。
✔️文章中只包含演示核心代码及测试数据#xff0c;完整代码可查看作者的开源项目snail-camunda
✔️请给snail-camunda 点颗星吧#x1f618;
#x1f496;设计流程定… 专栏简介
✔️本专栏将从Camunda(卡蒙达) 7中的关键概念到实现中国式工作流相关功能。
✔️文章中只包含演示核心代码及测试数据完整代码可查看作者的开源项目snail-camunda
✔️请给snail-camunda 点颗星吧
设计流程定义
在Modeler中设计一个简单的流程定义
?xml version1.0 encodingUTF-8?
bpmn:definitions xmlns:bpmnhttp://www.omg.org/spec/BPMN/20100524/MODEL xmlns:bpmndihttp://www.omg.org/spec/BPMN/20100524/DI xmlns:dchttp://www.omg.org/spec/DD/20100524/DC xmlns:camundahttp://camunda.org/schema/1.0/bpmn xmlns:dihttp://www.omg.org/spec/DD/20100524/DI xmlns:modelerhttp://camunda.org/schema/modeler/1.0 idDefinitions_0o0413o targetNamespacehttp://bpmn.io/schema/bpmn exporterCamunda Modeler exporterVersion5.19.0 modeler:executionPlatformCamunda Platform modeler:executionPlatformVersion7.15.0bpmn:process idProcess_1pobt6o isExecutabletruebpmn:startEvent idStartEvent_1bpmn:outgoingFlow_1k7cbz8/bpmn:outgoing/bpmn:startEventbpmn:sequenceFlow idFlow_1k7cbz8 sourceRefStartEvent_1 targetRefroot /bpmn:userTask idroot name发起人 camunda:assignee${initiator}bpmn:incomingFlow_1k7cbz8/bpmn:incomingbpmn:outgoingFlow_1qx1hmd/bpmn:outgoing/bpmn:userTaskbpmn:sequenceFlow idFlow_1qx1hmd sourceRefroot targetRefActivity_1kwa01y /bpmn:userTask idActivity_1kwa01y name经理 camunda:assignee${manager}bpmn:incomingFlow_1qx1hmd/bpmn:incomingbpmn:outgoingFlow_1rx0p95/bpmn:outgoing/bpmn:userTaskbpmn:endEvent idEvent_0es4idvbpmn:incomingFlow_1rx0p95/bpmn:incoming/bpmn:endEventbpmn:sequenceFlow idFlow_1rx0p95 sourceRefActivity_1kwa01y targetRefEvent_0es4idv //bpmn:processbpmndi:BPMNDiagram idBPMNDiagram_1bpmndi:BPMNPlane idBPMNPlane_1 bpmnElementProcess_1pobt6obpmndi:BPMNShape id_BPMNShape_StartEvent_2 bpmnElementStartEvent_1dc:Bounds x179 y99 width36 height36 //bpmndi:BPMNShapebpmndi:BPMNShape idActivity_1sk7cxf_di bpmnElementrootdc:Bounds x270 y77 width100 height80 //bpmndi:BPMNShapebpmndi:BPMNShape idActivity_1rko3sb_di bpmnElementActivity_1kwa01ydc:Bounds x430 y77 width100 height80 /bpmndi:BPMNLabel //bpmndi:BPMNShapebpmndi:BPMNShape idEvent_0es4idv_di bpmnElementEvent_0es4idvdc:Bounds x592 y99 width36 height36 //bpmndi:BPMNShapebpmndi:BPMNEdge idFlow_1k7cbz8_di bpmnElementFlow_1k7cbz8di:waypoint x215 y117 /di:waypoint x270 y117 //bpmndi:BPMNEdgebpmndi:BPMNEdge idFlow_1qx1hmd_di bpmnElementFlow_1qx1hmddi:waypoint x370 y117 /di:waypoint x430 y117 //bpmndi:BPMNEdgebpmndi:BPMNEdge idFlow_1rx0p95_di bpmnElementFlow_1rx0p95di:waypoint x530 y117 /di:waypoint x592 y117 //bpmndi:BPMNEdge/bpmndi:BPMNPlane/bpmndi:BPMNDiagram
/bpmn:definitions
这种是最简单的用户任务节点该节点只允许分配一个任务给用户。 版本兼容
以下为版本对应表本专栏所有案例基于Camunda 7.19.0Spring Boot 2.7.7 Spring Boot Starter version Camunda Platform version Spring Boot version 7.13.x 7.13.3*** 7.13.x 7.13.3 2.2.x.RELEASE 2.3.x.RELEASE 7.14.x 7.14.2*** 7.14.x 7.14.2 2.3.x.RELEASE 2.4.x 7.15.x 7.15.3*** 7.15.x 7.15.3 2.4.x 2.5.x 7.16.x 7.16.3*** 7.16.x 7.16.3 2.5.x 2.6.x 7.17.x 7.17.2*** 7.17.x 7.17.2 2.6.x 2.7.x 7.18.x 7.19.x 7.18.x 7.19.x 2.7.x 7.20.x 7.20.x 3.1.x
创建项目
新建SpringBoot项目后引入相关的场景启动器
dependencygroupIdorg.camunda.bpm.springboot/groupIdartifactIdcamunda-bpm-spring-boot-starter/artifactIdversion7.19.0/version
/dependencydependencygroupIdorg.camunda.bpm.springboot/groupIdartifactIdcamunda-bpm-spring-boot-starter-webapp/artifactIdversion7.19.0/version
/dependencydependencygroupIdmysql/groupIdartifactIdmysql-connector-java/artifactId
/dependency
在properties或yml文件中进行相关属性值配置
###数据源相关配置
spring.datasource.typecom.zaxxer.hikari.HikariDataSource
spring.datasource.driver-class-namecom.mysql.cj.jdbc.Driver
spring.datasource.urljdbc:mysql://localhost:3306/数据库名?useSSLfalseuseUnicodetruecharacterEncodingutf-8serverTimezoneGMT%2B8nullCatalogMeansCurrenttrueallowPublicKeyRetrievaltrue
spring.datasource.usernameroot
spring.datasource.passwordroot###Camunda相关配置
#关闭自动部署
camunda.bpm.auto-deployment-enabledfalse
camunda.bpm.history-levelfull
camunda.bpm.admin-user.iddemo
camunda.bpm.admin-user.passworddemo
camunda.bpm.admin-user.first-namedemo
camunda.bpm.filter.createAll tasks
Camunda的自动部署路径是【classpath*:**/*.bpmn20.xml 】所以我们在resources目录下新建名称为bpmn的文件夹用于放置设计的流程定义。 之后按照部署流程定义、发起流程实例、完成任务的顺序来完成。为方便演示这里省略分层代码在Controller中完成。
/*** 流程定义相关接口* author lonewalker*/
RequestMapping(/process/definition)
AllArgsConstructor
RestController
public class ProcessDefinitionController {private final RepositoryService repositoryService;/*** 部署流程定义** return 提示信息*/PostMapping(/deploy)public String deployProcessDefinition(){repositoryService.createDeployment().addClasspathResource(bpmn/1.bpmn).name(演示).deploy();return 部署成功;}
} /*** 流程实例相关接口** author lonewalker*/
RequestMapping(/process/instance)
RequiredArgsConstructor
RestController
public class ProcessInstanceController {private final RuntimeService runtimeService;private final TaskService taskService;/*** 根据流程定义key发起流程实例** param requestParam 请求参数* return 流程实例id*/PostMapping(/startProcessInstanceByKey)public String startProcessInstanceByKey(RequestBody StartProcessRequest requestParam) {MapString, Object paramMap new HashMap(4);paramMap.put(initiator, 10086);paramMap.put(manager, 10087);ProcessInstance processInstance runtimeService.startProcessInstanceByKey(requestParam.getProcessDefinitionKey(), requestParam.getBusinessKey(), paramMap);return processInstance.getProcessInstanceId();}/*** 完成单个任务** param requestParam 请求参数* return 任务所在节点信息*/PostMapping(/completeSingleTask)public Boolean completeSingleTask(RequestBody Validated CompleteTaskRequest requestParam) {taskService.complete(requestParam.getTaskId());return true;}
}
发起流程实例的参数类这里省略了get、set方法大家可以使用lombok
/*** author lonewalker*/
Data
public class StartProcessRequest {/*** 流程定义key*/private String processDefinitionKey;/*** 业务key*/private String businessKey;/*** 发起人*/private String initiator;
}
完成待办任务的参数类
/*** author lonewalker*/
Data
public class CompleteTaskRequest {NotBlank(message 流程实例id不能为空)private String processInstanceId;NotBlank(message 任务id不能为空)private String taskId;}
测试接口
启动项目后会自动生成49张表 访问localhost:端口号 可以看到camunda的webapp页面输入配置的账号、密码 调用部署接口后来到驾驶舱中可以看到已经部署成功。 紧接着发起流程实例所需的processDefinitionKey参数也就是bpmn文件中的id。当然你从驾驶舱中也可以获取到。 调用接口后可以从驾驶舱流程实例详情页面获取Task ID 将所有待办任务依次审批即可流程实例结束后在驾驶舱是无法查看的