核心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

相关文章

Spring Boot + MyBatis Plus 高效开发实战从入门到进阶优化(推荐)

《SpringBoot+MyBatisPlus高效开发实战从入门到进阶优化(推荐)》本文将详细介绍SpringBoot+MyBatisPlus的完整开发流程,并深入剖析分页查询、批量操作、动... 目录Spring Boot + MyBATis Plus 高效开发实战:从入门到进阶优化1. MyBatis

基于Flask框架添加多个AI模型的API并进行交互

《基于Flask框架添加多个AI模型的API并进行交互》:本文主要介绍如何基于Flask框架开发AI模型API管理系统,允许用户添加、删除不同AI模型的API密钥,感兴趣的可以了解下... 目录1. 概述2. 后端代码说明2.1 依赖库导入2.2 应用初始化2.3 API 存储字典2.4 路由函数2.5 应

Linux find 命令完全指南及核心用法

《Linuxfind命令完全指南及核心用法》find是Linux系统最强大的文件搜索工具,支持嵌套遍历、条件筛选、执行动作,下面给大家介绍Linuxfind命令完全指南,感兴趣的朋友一起看看吧... 目录一、基础搜索模式1. 按文件名搜索(精确/模糊匹配)2. 排除指定目录/文件二、根据文件类型筛选三、时间

MySQL中实现多表查询的操作方法(配sql+实操图+案例巩固 通俗易懂版)

《MySQL中实现多表查询的操作方法(配sql+实操图+案例巩固通俗易懂版)》本文主要讲解了MySQL中的多表查询,包括子查询、笛卡尔积、自连接、多表查询的实现方法以及多列子查询等,通过实际例子和操... 目录复合查询1. 回顾查询基本操作group by 分组having1. 显示部门号为10的部门名,员

Python FastAPI入门安装使用

《PythonFastAPI入门安装使用》FastAPI是一个现代、快速的PythonWeb框架,用于构建API,它基于Python3.6+的类型提示特性,使得代码更加简洁且易于绶护,这篇文章主要介... 目录第一节:FastAPI入门一、FastAPI框架介绍什么是ASGI服务(WSGI)二、FastAP

C#集成DeepSeek模型实现AI私有化的流程步骤(本地部署与API调用教程)

《C#集成DeepSeek模型实现AI私有化的流程步骤(本地部署与API调用教程)》本文主要介绍了C#集成DeepSeek模型实现AI私有化的方法,包括搭建基础环境,如安装Ollama和下载DeepS... 目录前言搭建基础环境1、安装 Ollama2、下载 DeepSeek R1 模型客户端 ChatBo

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基本概念最小单元推理模型智能体自定义界面总结前言最