【Activiti】为每一个流程绑定相应的业务对象的2种方法
方式1:
在保存每一个流程实例时,设置多个流程变量,通过多个流程变量的组合来过滤筛选符合该组合条件的流程实例,以后在需要查询对应业务对象所对应的流程实例时,只需查询包含该流程变量的值的流程实例即可.
设置过程:
public void startProcess(Long id) {
Customer cus = get(id);
if (cus != null) {
// 修改客户的状态
cus.setStatus(1);
updateStatus(cus);
// 将客户的追踪销售员的nickName放入流程变量,该seller变量可用于查询包括该seller的流程实例
Map<String, Object> map = new HashMap<String, Object>();
if (cus.getSeller() != null) {
map.put("seller", cus.getSeller().getNickname());
}
// 将客户的类型和id放入流程变量,此2个流程变量可用于查询该客户对象所对应的流程实例
String classType = cus.getClass().getSimpleName();
map.put("classType", classType);
map.put("objId", id);
// 获取processDefinitionKey,默认为类型简单名称加上Flow
String processDefinitionKey = classType + "Flow";
// 开启流程实例
workFlowService.startProcessInstanceByKeyAndVariables(processDefinitionKey, map);
} }
查询过程:
/**
* 测试根据变量值的限定获取相应的流程实例
*
* @throws Exception
*/
@Test
public void testGetFromVariable() throws Exception {
Employee sller = new Employee();
sller.setNickname("员工2");
sller.setId(4L);
List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery()
.variableValueEquals("classType", sller.getClass().getSimpleName())
.list();
System.out.println(processInstances);
for (ProcessInstance processInstance : processInstances) {
System.out.println(processInstance); }
//=====================================================================================================
Customer cus = new Customer();
cus.setId(4L);
List<ProcessInstance> processInstances1 = runtimeService.createProcessInstanceQuery()
.variableValueEquals("classType", cus.getClass().getSimpleName())
.variableValueEquals("objId", cus.getId()).list();
System.out.println(processInstances);
for (ProcessInstance processInstance : processInstances1) {
System.out.println(processInstance); }
}
方式2:
使用 businessKey,在开启流程实例时设置businessKey作为业务对象关联流程实例的关联键
设置过程:
/**
* 使用businessKey作为流程实例关联业务对象的关联键
*
* @throws Exception
*/
@Test
public void testBusKey() throws Exception {
//设置businessKey
Customer customer = new Customer();
customer.setId(2L);
//businessKey采用简单类名+主键的格式
String busniessKey = customer.getClass().getSimpleName() + customer.getId();
String definitionKey = customer.getClass().getSimpleName() + "Flow";
Map<String, Object> map = new HashMap<String, Object>();
map.put("seller", "admin");
//开启流程
runtimeService.startProcessInstanceByKey(definitionKey, busniessKey, map);
}
查询过程:
/**
* 使用businessKey查询相应业务对象的流程实例
*
* @throws Exception
*/
@Test
public void testgetByBusKey() throws Exception {
List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery()
.processInstanceBusinessKey("Customer2", "CustomerFlow").list();
System.out.println(processInstances); }
【Activiti】为每一个流程绑定相应的业务对象的2种方法的更多相关文章
- android 让一个控件按钮居于底部的几种方法
android 让一个控件按钮居于底部的几种方法1.采用linearlayout布局:android:layout_height="0dp" <!-- 这里不能设置fill_ ...
- [转]android 让一个控件按钮居于底部的几种方法
本文转自:http://www.cnblogs.com/zdz8207/archive/2012/12/13/2816906.html android 让一个控件按钮居于底部的几种方法 1.采用lin ...
- C# DropDownList绑定添加新数据的几种方法
第一种:在前台手动绑定(适用于固定不变的数据项) <asp:DropDownList ID="DropDownList1" runat="server"& ...
- C# DropDownList绑定添加新数据的三种方法
一.在前台手动绑定 <asp:DropDownList ID="DropDownList1" runat="server"> <asp: ...
- 创建一个 Spring Boot 项目,你会几种方法?
我最早是 2016 年底开始写 Spring Boot 相关的博客,当时使用的版本还是 1.4.x ,文章发表在 CSDN 上,阅读量最大的一篇有 42W+,如下图: 2017 年由于种种原因,就没有 ...
- 牛客网:将两个单调递增的链表合并为一个单调递增的链表-Python实现-两种方法讲解
方法一和方法二的执行效率,可以大致的计算时间复杂度加以对比,方法一优于方法二 1. 方法一: 思路: 1. 新创建一个链表节点头,假设这里就叫 head3: 2. 因为另外两个链表都为单调递增,所 ...
- linux下进程绑定cpu情况查看的几种方法
1.pidstat命令 查看进程使用cpu情况,如果绑定了多个cpu会都显示出来 pidstat -p `pidof 进程名` -t 1 2.top命令 (1)top (2)按f键可以选择下面配置选项 ...
- JS004. 获取数组最后一个元素且不改变数组的四种方法
TAG: Array.length Array.prototype.reverse() Array.prototype.slice() Array.prototype.pop() Array对象 - ...
- 在3G移动通信网络信令流程里获取用户电话号的一种方法(中国电信cdma2000)
首先这些关于电话号的的寻找都是在分组域进行的 然后是首先在rp接口的A11接口寻找,没有看到,于是到pi接口,研究radius协议 发现在协议里也不含有与用户电话号码mdn相关的元素 然后偶遇一篇文档 ...
随机推荐
- redis如何清空当前缓存和所有缓存
Windows环境下使用命令行进行redis缓存清理1.redis安装目录下输入cmd2.redis-cli -p 端口号3.flushdb 清除当前数据库缓存4.flushall 清除 ...
- springboot备忘
1.springboot中有ApplicationRunner类,如果项目中的启动类名称也是ApplicationRunner,单元测试时需要注意:import不要import到springboot的 ...
- android 实例-弱引用示例 Handler正确使用方法
实际问题 android 习惯性问题:在使用handler的时候喜欢使用内部类形式. private final Handler handler = new Handler(){ @Override ...
- centos7 - mysql修改密码
set password for 'root'@'localhost'=password('MyNewPass4!'); mysql5.7默认安装了密码安全检查插件(validate_password ...
- ccf 201512-3 画图(90)
ccf 201512-3 画图(90) #include<iostream> #include<cstring> #include<algorithm> using ...
- DP&图论 DAY 5 下午
DP&图论 DAY 5 下午 树链剖分 每一条边要么属于重链要么轻边 证明: https://www.cnblogs.com/sagitta/p/5660749.html 轻边重链都是交 ...
- JAVA静态数据的初始化;
①:Java首次会自动对变量进行初始化,其顺序优于构造器: ②:如果一个域是静态的的基本类型域,且也没有对它进行初始化,那么它就会获得基本类型的标准初值,如果它是一个对象引用,那么他的默认初始化值为n ...
- Copy-On-Write in Swift
Premature optimisation is the root of all evil. But, there are moments where we need to optimise our ...
- LC 966. Vowel Spellchecker
Given a wordlist, we want to implement a spellchecker that converts a query word into a correct word ...
- WCF绑定(Binding)
一个Binding由一个有序的binding元素栈所组成,其中的每一个元素都指定了连接到ServiceEndpoint的一个方面.在这个栈中的最底两层都是必须要有的.最底下的一层是传输binding元 ...