(十)Activitivi5之启动流程/完成任务的时候设置流程变量
2024-08-25 00:27:02
一、启动流程的时候设置流程变量
1.1 案例
/**
* 启动流程实例
*/
@Test
public void start() {
Student student=new Student();
student.setId(1);
student.setName("张三"); Map<String, Object> variables=new HashMap<String,Object>();
variables.put("days", 2);
variables.put("date", new Date());
variables.put("reason", "发烧");
variables.put("student", student); ProcessInstance instance=processEngine.getRuntimeService() // 运行时Service
.startProcessInstanceByKey("StudentLeaveProcess",variables); // 流程定义表act_re_procdef的KEY字段值 System.out.println("流程实例ID:"+instance.getId());
System.out.println("流程定义ID:"+instance.getProcessDefinitionId());
}
- 如上述例子流程启动之后,任何任务节点都可以通过excutionId获取到流程变量的值。
/**
* 获取流程变量数据
*/
@Test
public void getVariableValues(){
RuntimeService runtimeService=processEngine.getRuntimeService();
String excutionId="52501";
Integer days=(Integer) runtimeService.getVariable(excutionId, "days");
Date date=(Date) runtimeService.getVariableLocal(excutionId, "date");
String reason=(String) runtimeService.getVariable(excutionId, "reason");
Student student=(Student) runtimeService.getVariable(excutionId, "student");
System.out.println("请假天数:"+days);
System.out.println("请假日期:"+date);
System.out.println("请假原因:"+reason);
System.out.println("请假对象:"+student.getId()+","+student.getName());
}
二、完成任务的时候设置流程变量
2.1 需求
- 在完成某个任务节点之后设置流程变量,接下来的任务节点都可以使用这个流程变量。
比如,当完成“学生请假”任务节点之后设置流程变量,然后在“班长审批”和“班主任审批”节点就可以获取该流程变量。
2.2 案例
/**
* 完成任务
*/
@Test
public void test_completeTask2() { Student student=new Student();
student.setId(1);
student.setName("张三"); Map<String, Object> variables=new HashMap<String,Object>();
variables.put("days", 2);
variables.put("date", new Date());
variables.put("reason", "发烧");
variables.put("student", student); processEngine.getTaskService().complete("62504",variables);
}
/**
* 获取流程变量数据
*/
@Test
public void getVariableValues(){
RuntimeService runtimeService=processEngine.getRuntimeService();
String excutionId="62501";
Integer days=(Integer) runtimeService.getVariable(excutionId, "days");
Date date=(Date) runtimeService.getVariableLocal(excutionId, "date");
String reason=(String) runtimeService.getVariable(excutionId, "reason");
Student student=(Student) runtimeService.getVariable(excutionId, "student");
System.out.println("请假天数:"+days);
System.out.println("请假日期:"+date);
System.out.println("请假原因:"+reason);
System.out.println("请假对象:"+student.getId()+","+student.getName());
}
最新文章
- ios9 之后,Xcode7不推荐使用UIAlertView,改用UIAlertController+UIAlertAction(按钮)
- 导入一个AndroidStudio工程作为一个Library Module
- Visual Studio 2013新功能
- 练习2 A - ASCII码排序
- Java图形化界面设计——布局管理器之GridLayout(网格布局)
- 【NOIP2012提高组】借教室
- os模块介绍
- aarch64的架构:unrecognized command line option &#39;-mfpu=neon&#39;
- 二叉树的简单操作(Binary Tree)
- spring security 学习
- dom4j解析xml时取消DTD验证
- pom.xml文件最详细的讲解
- JavaWeb后台购物车类的具体实现
- JavaWeb开发如何用Tomcat部署发布
- AIX查看CPU、内存等信息
- 某软件大赛C#版考题整理——【多选题】
- 6-16 Topological Sort(25 分)
- Memcached 之 .NET(C#)实例分析
- yugabyte cloud native db 基本试用
- [PY3]——字典排序问题总结—(zip()函数、OrderedDict、itemgetter函数)
热门文章
- DIOCP任务队列和工作线程
- Django 测试开发2
- nginx php-fpm安装配置 CentOS编译安装php7.2
- 简易的CRM系统案例之Struts2+Hibernate3+JSP+MySQL版本
- SurfaceView双缓冲技术引入
- zip格式压缩文件辅助类(ZipHelper)
- python中简化的验证码功能
- Python - Django - 显示作者列表
- 【VS开发】fatal error C1853: "Debug\sift.pch"预编译头文件来自编译器的早期版本
- 使用Apache服务部署网站(基于IP,域名,端口)