当前位置:网站首页>Chapter 4: activiti RuntimeService settings get and get process variables, and the difference from taskService, set process variables when starting and completing tasks [easy to understand]
Chapter 4: activiti RuntimeService settings get and get process variables, and the difference from taskService, set process variables when starting and completing tasks [easy to understand]
2022-08-05 10:20:00 【Full stack programmer webmaster】
大家好,又见面了,我是你们的朋友全栈君.
上一章我们讲了taskServiceThe procedure for getting process variables,这里我们讲讲RuntimeServiceHow to set and get it,In fact, the process followstaskService是差不多的.
- RuntimeService Related to process instances and execution objects,The table for is:act_ru_execution
- TaskService 与任务相关 对应的表是act_ru_variable
代码如下:
/**
* RuntimeService设置流程变量数据
*/
@Test
public void setVariableRunTimeValue(){
// TaskService taskService=processEngine.getTaskService();//获取任务
RuntimeService runtimeService=processEngine.getRuntimeService();
String executionId="42501";//更加任务id知道是哪个人物,设置流程变量.可以更加查看任务方法查看任务的id,可以到数据库直接看
//下面设置任务的内容,比如请假流程,任务的第一节点也就是申请人要写请节哀的原因
runtimeService.setVariable(executionId, "days", 4);//请假天数
runtimeService.setVariable(executionId, "date", new Date());//请假日期
runtimeService.setVariable(executionId, "reason", "haha");//请假原因
//下面我们再测试一个额外的知识点,就是流程传输变量,这里我们再新建一个student对象,对象有id 和name两个属性,还有就是序列化传输
Student student=new Student();
student.setId(1);
student.setName("zhangsan");
runtimeService.setVariable(executionId, "student",student);//序列化对象
}
/**
* RunTimeService获取流程变量数据
*/
@Test
public void getVariableRunTimeValues(){
// TaskService taskService=processEngine.getTaskService();//获取任务
RuntimeService runtimeService=processEngine.getRuntimeService();
String executionId="42501";
Integer day=(Integer) runtimeService.getVariableLocal(executionId, "days");//获取请假天数
Date date=(Date) runtimeService.getVariable(executionId, "date");//请假日期
String reason=(String) runtimeService.getVariable(executionId, "reason");//请假原因
Student student2=(Student) runtimeService.getVariable(executionId, "student");//序列化对象
System.out.println("请假天数:"+day);
System.out.println("请假日期:"+date);
System.out.println("请假原因:"+reason);
System.err.println("请假对象:"+student2.getId()+",,,"+student2.getName());
}
执行过程是,start()启动一个流程实例,The object table is being executed at this pointact_ru_execution表生成数据,我们看看id值:
Then execute the set variable method,Look at the variable table and there will be corresponding values:
The result of executing the get variable table is the same:
请假天数:4
请假日期:Sun Apr 22 13:47:25 CST 2018
请假原因:haha
请假对象:1,,,zhangsan
For setting multiple process variables and setting access to local variables is followed bytaskService 是一样的,New readers can refer to the blog post:
https://blog.csdn.net/csdnliuxin123524/article/details/80037416
Of course, you can also create process variables directly when you start the process:
/**
* Process variables are set when the process is started
*/
@Test
public void RunTimeServicestart(){
Student student=new Student();
student.setId(1);
student.setName("zhangsan");
Map<String, Object> variables=new HashMap<String,Object>();
variables.put("days", 66);
variables.put("date",new Date());
variables.put("reason", "faShao21111");
variables.put("student", student);
//Define the flow chartKEY字段值,keyThe value is what we defined earlierkey,可在act_re_procdef表中的key_字段中找到,
//Run the startup processservicee
ProcessInstance pi=processEngine.getRuntimeService()
.startProcessInstanceByKey("studentLeaveProcess00",variables);
System.out.println(pi.getId());
System.out.println(pi.getProcessDefinitionId());
}
End the previous unfinished task first.Then just run the above method.
The variable table has the values we set into it.
Another is to set a process variable when the character ends,This is a very common interface,For example, the first node when asking for leave,We generally set the content of the application at the end of the application task.
代码如下:
/**
* 完成任务时设置流程变量
*/
@Test
public void completeTaskVariables(){
Student student=new Student();
student.setId(1);
student.setName("zhangsan");
Map<String, Object> variables=new HashMap<String,Object>();
variables.put("days", 66);
variables.put("date",new Date());
variables.put("reason", "enenene2222");
variables.put("student", student);
processEngine.getTaskService().complete("50002",variables);
}
zhe
Here I directly use the result of the execution of the variables set at startup above,In order to verify here, we mainly focus on the value of the field of the reason for leave,The value before execution is :
Below we execute the above code:
注意这里使用的id是任务id,不是对象id:
It can be seen that it has been modified.
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/106143.html原文链接:https://javaforall.cn
边栏推荐
- How does the official account operate and maintain?Public account operation and maintenance professional team
- Introduction to SD NAND Flash!
- 【 temperature warning program DE development 】 event driven model instance
- JS逆向入门学习之回收商网,手机号码简易加密解析
- SQL外连接之交集、并集、差集查询
- static linking and dynamic linking
- three物体围绕一周呈球形排列
- 第四章:activiti RuntimeService设置获和取流程变量,及与taskService的区别,开始和完成任务时设置流程变量[通俗易懂]
- 深入理解 Istio 流量管理的超时时间设置
- Jenkins manual (2) - software configuration
猜你喜欢
还在找网盘资源吗?快点收藏如下几个值得收藏的网盘资源搜索神器吧!
Jenkins使用手册(2) —— 软件配置
SQL Outer Join Intersection, Union, Difference Query
MySQL advanced (twenty-seven) database index principle
FPGA:开发环境Vivado的使用
告白数字化转型时代:麦聪软件以最简单的方式让企业把数据用起来
three.js debugging tool dat.gui use
E-sports, convenience, efficiency, security, key words for OriginOS functions
电气工程的标准是什么
linux下oracle常见操作以及日常积累知识点(函数、定时任务)
随机推荐
RT-Thread记录(一、RT-Thread 版本、RT-Thread Studio开发环境 及 配合CubeMX开发快速上手)
首次去中心化抢劫?近2亿美元损失:跨链桥Nomad 被攻击事件分析
第八章:activiti多用户任务分配
Why are RELTABLESPACE values 0 for many tables displayed in sys_class?
如何修改管理工具client_encoding
RT - Thread record (a, RT, RT Thread version - Thread Studio development environment and cooperate CubeMX quick-and-dirty)
Confessing in the era of digital transformation: Mai Cong Software allows enterprises to use data in the easiest way
Introduction to SD NAND Flash!
使用工具类把对象中的null值转换为空字符串(集合也可以使用)
项目成本控制如何帮助项目成功?
In-depth understanding of timeout settings for Istio traffic management
语音社交软件开发——充分发挥其价值
The host computer develops C# language: simulates the STC serial port assistant to receive the data sent by the microcontroller
【温度预警程序de开发】事件驱动模型实例运用
教你本地编译运行一个IDEA插件,在IDEA里聊天、下棋、斗地主!
Handwriting Currying - toString Comprehension
Wei Dongshan Digital Photo Frame Project Learning (6) Transplantation of tslib
第四章:activiti流程中,变量的传递和获取流程变量 ,设置和获取多个流程变量,设置和获取局部流程变量「建议收藏」
气象数据数据处理实例——matlab字符串切割匹配与R语言日期匹配(数据拼接)
Go编译原理系列6(类型检查)