核心api实操-Activiti7从入门到专家(5)

2024-04-13 21:52

本文主要是介绍核心api实操-Activiti7从入门到专家(5),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

背景

上一节已经搭建了,具体的开发环境,数据库,并且找了一个可以用bpmnjs流程设计器,这一些,我们对核心api做个基础的实操,有个感性的认知,另外对数据库和基本数据流动有个理解。

部署

模板部署

为了接口调用,暂时不使用线上的流程设计器,使用安装的可视化流程设计器插件

然后如下目录结构下,构建一个标准的bpmn文件

画的比较急促,usertask中,都没有名字,下面的数据库中也没有名字,当然这节我们是感性认知,主要能能跑一些接口就行

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/processdef"><process id="apply" name="apply" isExecutable="true"><startEvent id="sid-93eb9656-e7fa-46db-b867-5bf8c8ccfd28"/><userTask id="sid-f436faf4-75c5-4004-993d-fde4c2efbd15" activiti:assignee="starter"/><userTask id="sid-d78d057a-230f-4d2d-9b73-74907342c644" activiti:assignee="manager"/><userTask id="sid-110669bd-2386-4fd1-a66f-82250f2971b9" activiti:candidateUsers="duster,hrer"/><sequenceFlow id="sid-cf63b67a-6287-4b98-ad3d-3f5a6aab6456" sourceRef="sid-93eb9656-e7fa-46db-b867-5bf8c8ccfd28" targetRef="sid-f436faf4-75c5-4004-993d-fde4c2efbd15"/><sequenceFlow id="sid-dc3e5702-3c9e-4f4f-a5aa-5d12d62e0531" sourceRef="sid-f436faf4-75c5-4004-993d-fde4c2efbd15" targetRef="sid-d78d057a-230f-4d2d-9b73-74907342c644"/><sequenceFlow id="sid-f68d50f0-438c-42e6-b4a8-5441554908c7" sourceRef="sid-d78d057a-230f-4d2d-9b73-74907342c644" targetRef="sid-110669bd-2386-4fd1-a66f-82250f2971b9"/><endEvent id="sid-68257716-77d4-464b-a07d-8a62969df00d"/><sequenceFlow id="sid-b9534685-9617-4e88-9e24-622d58959337" sourceRef="sid-110669bd-2386-4fd1-a66f-82250f2971b9" targetRef="sid-68257716-77d4-464b-a07d-8a62969df00d"/></process><bpmndi:BPMNDiagram id="BPMNDiagram_apply"><bpmndi:BPMNPlane bpmnElement="apply" id="BPMNPlane_apply"><bpmndi:BPMNShape id="shape-b4673c70-2eb5-4096-9631-454c2d4f35f4" bpmnElement="sid-93eb9656-e7fa-46db-b867-5bf8c8ccfd28"><omgdc:Bounds x="-100.0" y="-65.0" width="30.0" height="30.0"/></bpmndi:BPMNShape><bpmndi:BPMNShape id="shape-6cfc9bde-25fa-42f3-82fd-9a681b20e3eb" bpmnElement="sid-f436faf4-75c5-4004-993d-fde4c2efbd15"><omgdc:Bounds x="-35.0" y="-90.0" width="100.0" height="80.0"/></bpmndi:BPMNShape><bpmndi:BPMNShape id="shape-6d9ee9d0-6a3e-4b3b-82ab-d901adcaac05" bpmnElement="sid-d78d057a-230f-4d2d-9b73-74907342c644"><omgdc:Bounds x="115.0" y="-90.0" width="100.0" height="80.0"/></bpmndi:BPMNShape><bpmndi:BPMNShape id="shape-6d716fe2-0c5c-47f5-ab0b-fb5265c9fe58" bpmnElement="sid-110669bd-2386-4fd1-a66f-82250f2971b9"><omgdc:Bounds x="250.0" y="-90.0" width="100.0" height="80.0"/></bpmndi:BPMNShape><bpmndi:BPMNEdge id="edge-edb64b8a-b281-4f74-9d4c-3b41480e7f15" bpmnElement="sid-cf63b67a-6287-4b98-ad3d-3f5a6aab6456"><omgdi:waypoint x="-70.0" y="-50.0"/><omgdi:waypoint x="-35.0" y="-50.0"/></bpmndi:BPMNEdge><bpmndi:BPMNEdge id="edge-0a7821f9-6b78-4009-a6cd-70ad14e278cf" bpmnElement="sid-dc3e5702-3c9e-4f4f-a5aa-5d12d62e0531"><omgdi:waypoint x="65.0" y="-50.0"/><omgdi:waypoint x="115.0" y="-50.0"/></bpmndi:BPMNEdge><bpmndi:BPMNEdge id="edge-5e5f8326-5409-417a-85ab-4b455830a086" bpmnElement="sid-f68d50f0-438c-42e6-b4a8-5441554908c7"><omgdi:waypoint x="215.0" y="-50.0"/><omgdi:waypoint x="250.0" y="-50.0"/></bpmndi:BPMNEdge><bpmndi:BPMNShape id="shape-de420915-45e2-4275-9a4a-8096e3f5b152" bpmnElement="sid-68257716-77d4-464b-a07d-8a62969df00d"><omgdc:Bounds x="385.0" y="-65.0" width="30.0" height="30.0"/></bpmndi:BPMNShape><bpmndi:BPMNEdge id="edge-2fe4e62f-ea4a-442c-9842-8b9690acb4f5" bpmnElement="sid-b9534685-9617-4e88-9e24-622d58959337"><omgdi:waypoint x="350.0" y="-50.0"/><omgdi:waypoint x="385.0" y="-50.0"/></bpmndi:BPMNEdge></bpmndi:BPMNPlane></bpmndi:BPMNDiagram>
</definitions>

以下是流程发布代码

  @Test
public void GetDeployInfos() {// 流程模板部署,发布
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();RepositoryService repositoryService = processEngine.getRepositoryService();Deployment deployment = repositoryService.createDeployment().addClasspathResource("apply.bpmn20.xml").addClasspathResource("apply.png").name("申请示例").key("apply").deploy();System.out.println(deployment.getId());

这是print的内容:

2024-04-12 18:07:26.602 INFO 21652 --- [ main] o.a.e.impl.bpmn.deployer.BpmnDeployer : Process deployed: {id: apply:1:76ccd0ba-f8b4-11ee-a0f0-8c8caa7a4f9c, key: apply, name: apply }

76b996d7-f8b4-11ee-a0f0-8c8caa7a4f9c

这是相关的数据库:

发布查询

// 部署后,查询流程模板
//  查询流程部署
Deployment deployment = repositoryService.createDeploymentQuery().deploymentKey("apply").singleResult();
//  查询流程定义
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
//  流程定义是否被挂起/暂停
boolean suspended = processDefinition.isSuspended();
System.out.println(deployment.getId() + "当前流程状态:"+suspended);
//  删除部署       repositoryService.deleteDeployment(deployment.getId());//  挂起/暂停流程定义
repositoryService.suspendProcessDefinitionById(processDefinition.getId());
processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
//  流程定义是否被挂起/暂停
suspended = processDefinition.isSuspended();
System.out.println(deployment.getId() + "当前流程状态:"+suspended);
//  激活流程定义
repositoryService.activateProcessDefinitionById(processDefinition.getId());
processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
//  流程定义是否被挂起/暂停
suspended = processDefinition.isSuspended();
System.out.println(deployment.getId() + "当前流程状态:"+suspended);

启动流程实例

// 启动实例
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();RuntimeService runtimeService= processEngine.getRuntimeService();
Map<String, Object> userVariables = new HashMap<>();
//小兵申请,经理审批  user
userVariables.put("starter", "xiaobing");
userVariables.put("manager", "jingli");ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("apply", userVariables);
// runtimeService.startProcessInstanceByKey("apply");System.out.println(processInstance.getProcessInstanceId());
System.out.println(processInstance.getProcessDefinitionId());

用户任务

ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
TaskService taskService = processEngine.getTaskService();
//  查询待办任务
List<Task> taskList = taskService.createTaskQuery().taskAssignee("starter").list();for (Task task : taskList) {System.out.println("taskID:"+task.getId());//  完成任务taskService.complete(task.getId());

taskID:73cd61cd-f8b6-11ee-b5e3-8c8caa7a4f9c

接着是到了经理的任务

我们继续执行

ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
TaskService taskService = processEngine.getTaskService();
//  查询待办任务
List<Task> taskList = taskService.createTaskQuery().taskAssignee("manager").list();for (Task task : taskList) {System.out.println("taskID:"+task.getId());//  完成任务taskService.complete(task.getId());
}

taskID:82209be4-f8b8-11ee-9d92-8c8caa7a4f9c

历史记录

ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();HistoryService historyService = processEngine.getHistoryService();//  历史查询List<HistoricActivityInstance> list = historyService.createHistoricActivityInstanceQuery().processInstanceId("73cb8d05-f8b6-11ee-b5e3-8c8caa7a4f9c").orderByHistoricActivityInstanceStartTime().asc().list();
for (HistoricActivityInstance historicActivityInstance : list) {System.out.println(historicActivityInstance.getActivityName() + ":" + historicActivityInstance.getAssignee());}

由于是为了清楚使用接口,并没有构建复杂场景,我们会一个个的完成基础学习,分开解构各个小细节。

总结

  1. 基本的接口会用了,知道如何调用了
  2. 表结构并没有很细的解构
  3. 各个方法细节没有解构
  4. 业务逻辑,还有一些特殊的指令用法,网关,参数,等具体用法,当我们把各个bpmn概念理一遍以后,这些内容随着场景案例就会一一呈现在我们面前

这篇关于核心api实操-Activiti7从入门到专家(5)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/901318

相关文章

Java调用DeepSeek API的最佳实践及详细代码示例

《Java调用DeepSeekAPI的最佳实践及详细代码示例》:本文主要介绍如何使用Java调用DeepSeekAPI,包括获取API密钥、添加HTTP客户端依赖、创建HTTP请求、处理响应、... 目录1. 获取API密钥2. 添加HTTP客户端依赖3. 创建HTTP请求4. 处理响应5. 错误处理6.

Deepseek R1模型本地化部署+API接口调用详细教程(释放AI生产力)

《DeepseekR1模型本地化部署+API接口调用详细教程(释放AI生产力)》本文介绍了本地部署DeepSeekR1模型和通过API调用将其集成到VSCode中的过程,作者详细步骤展示了如何下载和... 目录前言一、deepseek R1模型与chatGPT o1系列模型对比二、本地部署步骤1.安装oll

浅析如何使用Swagger生成带权限控制的API文档

《浅析如何使用Swagger生成带权限控制的API文档》当涉及到权限控制时,如何生成既安全又详细的API文档就成了一个关键问题,所以这篇文章小编就来和大家好好聊聊如何用Swagger来生成带有... 目录准备工作配置 Swagger权限控制给 API 加上权限注解查看文档注意事项在咱们的开发工作里,API

一分钟带你上手Python调用DeepSeek的API

《一分钟带你上手Python调用DeepSeek的API》最近DeepSeek非常火,作为一枚对前言技术非常关注的程序员来说,自然都想对接DeepSeek的API来体验一把,下面小编就来为大家介绍一下... 目录前言免费体验API-Key申请首次调用API基本概念最小单元推理模型智能体自定义界面总结前言最

JAVA调用Deepseek的api完成基本对话简单代码示例

《JAVA调用Deepseek的api完成基本对话简单代码示例》:本文主要介绍JAVA调用Deepseek的api完成基本对话的相关资料,文中详细讲解了如何获取DeepSeekAPI密钥、添加H... 获取API密钥首先,从DeepSeek平台获取API密钥,用于身份验证。添加HTTP客户端依赖使用Jav

C#使用DeepSeek API实现自然语言处理,文本分类和情感分析

《C#使用DeepSeekAPI实现自然语言处理,文本分类和情感分析》在C#中使用DeepSeekAPI可以实现多种功能,例如自然语言处理、文本分类、情感分析等,本文主要为大家介绍了具体实现步骤,... 目录准备工作文本生成文本分类问答系统代码生成翻译功能文本摘要文本校对图像描述生成总结在C#中使用Deep

5分钟获取deepseek api并搭建简易问答应用

《5分钟获取deepseekapi并搭建简易问答应用》本文主要介绍了5分钟获取deepseekapi并搭建简易问答应用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需... 目录1、获取api2、获取base_url和chat_model3、配置模型参数方法一:终端中临时将加

使用DeepSeek API 结合VSCode提升开发效率

《使用DeepSeekAPI结合VSCode提升开发效率》:本文主要介绍DeepSeekAPI与VisualStudioCode(VSCode)结合使用,以提升软件开发效率,具有一定的参考价值... 目录引言准备工作安装必要的 VSCode 扩展配置 DeepSeek API1. 创建 API 请求文件2.

使用SpringBoot创建一个RESTful API的详细步骤

《使用SpringBoot创建一个RESTfulAPI的详细步骤》使用Java的SpringBoot创建RESTfulAPI可以满足多种开发场景,它提供了快速开发、易于配置、可扩展、可维护的优点,尤... 目录一、创建 Spring Boot 项目二、创建控制器类(Controller Class)三、运行

Spring Security 从入门到进阶系列教程

Spring Security 入门系列 《保护 Web 应用的安全》 《Spring-Security-入门(一):登录与退出》 《Spring-Security-入门(二):基于数据库验证》 《Spring-Security-入门(三):密码加密》 《Spring-Security-入门(四):自定义-Filter》 《Spring-Security-入门(五):在 Sprin