flowable新增或修改单个任务的历史变量

简介

场景:对历史任务进行关注,所以需要修改流程历史任务的本地变量
方法包含2个类
1)核心方法,flowable command类:HistoricTaskSingleVariableUpdateCmd
2)执行command类:BpmProcessCommandService
然后springboot 执行方法即可: bpmProcessCommandService.executeCreateHistorySingleVariable(taskId, 变量名, 变量值);
注:@AllArgsConstructor 来自 lombok 注解,其中工具类来自  hutool;这里就不做过多介绍;

1 核心方法、 HistoricTaskSingleVariableUpdateCmd

实现 flowable command类

package com.flowable.core.cmd;import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import lombok.AllArgsConstructor;
import org.flowable.common.engine.api.FlowableIllegalArgumentException;
import org.flowable.common.engine.impl.interceptor.Command;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.HistoryService;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.task.api.history.HistoricTaskInstance;
import org.flowable.variable.api.history.HistoricVariableInstance;
import org.flowable.variable.api.types.VariableType;
import org.flowable.variable.service.VariableServiceConfiguration;
import org.flowable.variable.service.impl.persistence.entity.HistoricVariableInstanceEntityImpl;
import org.flowable.variable.service.impl.persistence.entity.HistoricVariableInstanceEntityManager;
import org.flowable.variable.service.impl.persistence.entity.VariableInstanceEntityImpl;/*** 历史任务变量更新*/
@AllArgsConstructor
public class HistoricTaskSingleVariableUpdateCmd implements Command<Void> {// 任务编号protected String taskId;// 变量名protected String variableName;// 变量值protected Object variableValue;@Overridepublic Void execute(CommandContext commandContext) {// taskId 参数不能为空if (this.taskId == null) {throw new FlowableIllegalArgumentException("任务编号不能为空!");}// 1 获取运历史服务、历史变量管理器、变量管理器ProcessEngineConfigurationImpl procEngineConf = CommandContextUtil.getProcessEngineConfiguration(commandContext);HistoryService historyService = procEngineConf.getHistoryService();HistoricVariableInstanceEntityManager historicVariableInstanceEntityManager = procEngineConf.getVariableServiceConfiguration().getHistoricVariableInstanceEntityManager();VariableServiceConfiguration variableServiceConfiguration = procEngineConf.getVariableServiceConfiguration().getVariableServiceConfiguration();// 2 根据taskId查询历史任务HistoricTaskInstance historicTask = historyService.createHistoricTaskInstanceQuery().taskId(this.taskId).singleResult();// 3 查询是否存在历史变量是否存在HistoricVariableInstance hisVariable = historyService.createHistoricVariableInstanceQuery().processInstanceId(historicTask.getProcessInstanceId()).taskId(historicTask.getId()).variableName(variableName).singleResult();if (ObjectUtil.isNotNull(hisVariable)) {// 4 根据当前变量,修改历史变量的值HistoricVariableInstanceEntityImpl historicVariableImpl = (HistoricVariableInstanceEntityImpl) hisVariable;VariableInstanceEntityImpl variableInstanceEntity = createVariable(historicTask, variableServiceConfiguration);historicVariableInstanceEntityManager.copyVariableFields(historicVariableImpl, variableInstanceEntity, DateUtil.date());historicVariableInstanceEntityManager.update(historicVariableImpl);} else {// 5 新增历史变量VariableInstanceEntityImpl variableInstanceEntity = createVariable(historicTask, variableServiceConfiguration);historicVariableInstanceEntityManager.createAndInsert(variableInstanceEntity, DateUtil.date());}return null;}/*** 根据变量名 和变量值,构建变量** @param historicTask                 历史人物* @param variableServiceConfiguration 变量管理器* @return 变量构造器*/private VariableInstanceEntityImpl createVariable(HistoricTaskInstance historicTask, VariableServiceConfiguration variableServiceConfiguration) {VariableInstanceEntityImpl variableInstanceEntity = new VariableInstanceEntityImpl();variableInstanceEntity.setName(variableName);variableInstanceEntity.setProcessInstanceId(historicTask.getProcessInstanceId());variableInstanceEntity.setExecutionId(historicTask.getExecutionId());variableInstanceEntity.setTaskId(historicTask.getId());VariableType variableType = variableServiceConfiguration.getVariableTypes().findVariableType(variableValue);variableInstanceEntity.setTypeName(variableType.getTypeName());variableInstanceEntity.setType(variableType);variableInstanceEntity.setValue(variableValue);return variableInstanceEntity;}
}

2 执行类方法 BpmProcessCommandService

执行command 需要注入 ManagementService

package com.flowable.core.service;import com.flowable.core.cmd.HistoricTaskSingleVariableUpdateCmd;
import jakarta.annotation.Resource;
import org.flowable.engine.ManagementService;
import org.springframework.stereotype.Service;import java.util.List;@Service
public class BpmProcessCommandService {@Resourceprivate ManagementService managementService;/*** 执行更新任务历史变量** @param taskId        任务ID* @param variableName  变量名* @param variableValue 变量值*/public void executeCreateHistorySingleVariable(String taskId, String variableName, Object variableValue) {// 实例化创建历史流程变量 command 类HistoricTaskSingleVariableUpdateCmd historicTaskSingleVariableUpdateCmd = new HistoricTaskSingleVariableUpdateCmd(taskId, variableName, variableValue);// 通过 managementService 管理服务,执行创建历史流程变量 command 类managementService.executeCommand(historicTaskSingleVariableUpdateCmd);}
}

然后springboot 正常调用该方法即可

bpmProcessCommandService.executeCreateHistorySingleVariable(taskId, 变量名, 变量值);

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/73243.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Netty基础—4.NIO的使用简介一

大纲 1.Buffer缓冲区 2.Channel通道 3.BIO编程 4.伪异步IO编程 5.改造程序以支持长连接 6.NIO三大核心组件 7.NIO服务端的创建流程 8.NIO客户端的创建流程 9.NIO优点总结 10.NIO问题总结 1.Buffer缓冲区 (1)Buffer缓冲区的作用 (2)Buffer缓冲区的4个核心概念 (3)使…

python元组(被捆绑的列表)

元组&#xff08;tuple&#xff09; 1.元组一旦形成就不可更改,元组所指向的内存单元中内容不变 定义&#xff1a;定义元组使用小括号&#xff0c;并且使用逗号进行隔开&#xff0c;数据可以是不同的数据类型 定义元组自变量&#xff08;元素&#xff0c;元素&#xff0c;元素…

输入:0.5元/百万tokens(缓存命中)或2元(未命中) 输出:8元/百万tokens

这句话描述了一种 定价模型&#xff0c;通常用于云计算、API 服务或数据处理服务中&#xff0c;根据资源使用情况&#xff08;如缓存命中与否&#xff09;来收费。以下是对这句话的详细解释&#xff1a; 1. 关键术语解释 Tokens&#xff1a;在自然语言处理&#xff08;NLP&…

计算机视觉算法实战——驾驶员玩手机检测(主页有源码)

✨个人主页欢迎您的访问 ✨期待您的三连 ✨ ✨个人主页欢迎您的访问 ✨期待您的三连 ✨ ✨个人主页欢迎您的访问 ✨期待您的三连✨ ​ ​​​ 1. 领域简介&#xff1a;玩手机检测的重要性与技术挑战 驾驶员玩手机检测是智能交通安全领域的核心课题。根据NHTSA数据&#xff0…

Java糊涂包(Hutool)的安装教程并进行网络爬虫

Hutool的使用教程 1&#xff1a;在官网下载jar模块文件 Central Repository: cn/hutool/hutool-all/5.8.26https://repo1.maven.org/maven2/cn/hutool/hutool-all/5.8.26/ 下载后缀只用jar的文件 2&#xff1a;复制并到idea当中&#xff0c;右键这个模块点击增加到库 3&…

深度学习项目--基于DenseNet网络的“乳腺癌图像识别”,准确率090%+,pytorch复现

&#x1f368; 本文为&#x1f517;365天深度学习训练营 中的学习记录博客&#x1f356; 原作者&#xff1a;K同学啊 前言 如果说最经典的神经网络&#xff0c;ResNet肯定是一个&#xff0c;从ResNet发布后&#xff0c;很多人做了修改&#xff0c;denseNet网络无疑是最成功的…

优化用户体验:关键 Web 性能指标的获取、分析、优化方法

前言 在当今互联网高速发展的时代用户对于网页的加载速度和响应时间越来越敏感。一个性能表现不佳的网页不仅会影响用户体验&#xff0c;还可能导致用户流失。 因此&#xff0c;了解和优化网页性能指标是每个开发者的必修课。今天我们就来聊聊常见的网页性能指标以及如何获取这…

vs code配置 c/C++

1、下载VSCode Visual Studio Code - Code Editing. Redefined 安装目录可改 勾选创建桌面快捷方式 安装即可 2、汉化VSCode 点击确定 下载MinGW 由于vsCode 只是一个编辑器&#xff0c;他没有自带编译器&#xff0c;所以需要下载一个编译器"MinGW". https://…

Kotlin关键字`when`的详细用法

Kotlin关键字when的详细用法 在Kotlin中&#xff0c;when是一个强大的控制流语句&#xff0c;相当于其他语言中的switch语句&#xff0c;但更加强大且灵活。本文将详细讲解when的用法及其常见场景&#xff0c;并与Java的switch语句进行对比。 一、基本语法 基本的when语法如…

MFCday01、模式对话框

对话框类和应用程序类。 MFC中 Combo Box List Box List Control三种列表控件&#xff0c;日期控件Date Time Picker

接口测试笔记

4、接口测试自动化 接口自动化概述 HttpClient HttpClient开发过程 创建Java工程 新建libs库目录 HttpClient 工具下载及引入 https://hc.apache.org/index.html工程中引入jar包 Get请求 HttpGet方法---发起Get请求 创建HttpClient对象 CloseableHttpClient httpclient …

查找sql中涉及的表名称

import pandas as pd import datetime todaystr(datetime.date.today())filepath/Users/kangyongqing/Documents/kangyq/202303/分析模版/sql表引用提取/ file101试听课明细.txt newfilefile1.title().split(.)[0]with open(filepathfile1,r) as file:contentfile.read().lower…

如何在Ubuntu上构建编译LLVM和ISPC,以及Ubuntu上ISPC的使用方法

之前一直在 Mac 上使用 ISPC&#xff0c;奈何核心/线程太少了。最近想在 Ubuntu 上搞搞&#xff0c;但是 snap 安装的 ISPC不知道为什么只能单核&#xff0c;很奇怪&#xff0c;就想着编译一下&#xff0c;需要 Clang 和 LLVM。但是 Ubuntu 很搞&#xff0c;他的很多软件版本是…

【Spring IOC/AOP】

IOC 参考&#xff1a; Spring基础 - Spring核心之控制反转(IOC) | Java 全栈知识体系 (pdai.tech) 概述&#xff1a; Ioc 即 Inverse of Control &#xff08;控制反转&#xff09;&#xff0c;是一种设计思想&#xff0c;就是将原本在程序中手动创建对象的控制权&#xff…

电感与电容的具体应用

文章目录 一、电感应用1.​电源滤波&#xff1a;2. 储能——平滑“电流波浪”​ ​3. 调谐——校准“频率乐器”​4. 限流——防止“洪水灾害”​二、电容应用1.核心特性理解2.应用场景 三.电容电感对比 一、电感应用 1.​电源滤波&#xff1a; ​场景&#xff1a;工业设备中…

前端面试:axios 请求的底层依赖是什么?

在前端开发中&#xff0c;Axios 是一个流行的 JavaScript 库&#xff0c;用于发送 HTTP 请求。它简化了与 RESTful APIs 的交互&#xff0c;并提供了许多便利的方法与配置选项。要理解 Axios 的底层依赖&#xff0c;需要从以下几个方面进行分析&#xff1a; 1. Axios 基于 XML…

springboot 3 集成Redisson

maven 依赖 <parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>3.2.12</version></parent><dependencies><dependency><groupId>org.red…

C#中继承的核心定义‌

1. 继承的核心定义‌ ‌继承‌ 是面向对象编程&#xff08;OOP&#xff09;的核心特性之一&#xff0c;允许一个类&#xff08;称为‌子类/派生类‌&#xff09;基于另一个类&#xff08;称为‌父类/基类‌&#xff09;构建&#xff0c;自动获得父类的成员&#xff08;字段、属…

Deep research深度研究:ChatGPT/ Gemini/ Perplexity/ Grok哪家最强?(实测对比分析)

目前推出深度研究和深度检索的AI大模型有四家&#xff1a; OpenAI和Gemini 的deep research&#xff0c;以及Perplexity 和Grok的deep search&#xff0c;都能生成带参考文献引用的主题报告。 致力于“几分钟之内生成一份完整的主题调研报告&#xff0c;解决人力几小时甚至几天…

Android SharedPreference 详解

前提&#xff1a;基于 Android API 30 1. 认识 SharedPreference SharedPreference 是 Android 提供的轻量级的&#xff0c;线程安全的数据存储机制&#xff0c;使用 key-value 键值对的方式将数据存储在 xml 文件中&#xff0c;存储路径为 /data/data/yourPackageName/share…