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.pswp.cn/bicheng/73243.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/73243.shtml
英文地址,請注明出處:http://en.pswp.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…