方式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种方法的更多相关文章

  1. android 让一个控件按钮居于底部的几种方法

    android 让一个控件按钮居于底部的几种方法1.采用linearlayout布局:android:layout_height="0dp" <!-- 这里不能设置fill_ ...

  2. [转]android 让一个控件按钮居于底部的几种方法

    本文转自:http://www.cnblogs.com/zdz8207/archive/2012/12/13/2816906.html android 让一个控件按钮居于底部的几种方法 1.采用lin ...

  3. C# DropDownList绑定添加新数据的几种方法

    第一种:在前台手动绑定(适用于固定不变的数据项) <asp:DropDownList ID="DropDownList1" runat="server"& ...

  4. C# DropDownList绑定添加新数据的三种方法

    一.在前台手动绑定 <asp:DropDownList ID="DropDownList1" runat="server">    <asp: ...

  5. 创建一个 Spring Boot 项目,你会几种方法?

    我最早是 2016 年底开始写 Spring Boot 相关的博客,当时使用的版本还是 1.4.x ,文章发表在 CSDN 上,阅读量最大的一篇有 42W+,如下图: 2017 年由于种种原因,就没有 ...

  6. 牛客网:将两个单调递增的链表合并为一个单调递增的链表-Python实现-两种方法讲解

    方法一和方法二的执行效率,可以大致的计算时间复杂度加以对比,方法一优于方法二   1. 方法一: 思路: 1. 新创建一个链表节点头,假设这里就叫 head3: 2. 因为另外两个链表都为单调递增,所 ...

  7. linux下进程绑定cpu情况查看的几种方法

    1.pidstat命令 查看进程使用cpu情况,如果绑定了多个cpu会都显示出来 pidstat -p `pidof 进程名` -t 1 2.top命令 (1)top (2)按f键可以选择下面配置选项 ...

  8. JS004. 获取数组最后一个元素且不改变数组的四种方法

    TAG: Array.length Array.prototype.reverse() Array.prototype.slice() Array.prototype.pop() Array对象 - ...

  9. 在3G移动通信网络信令流程里获取用户电话号的一种方法(中国电信cdma2000)

    首先这些关于电话号的的寻找都是在分组域进行的 然后是首先在rp接口的A11接口寻找,没有看到,于是到pi接口,研究radius协议 发现在协议里也不含有与用户电话号码mdn相关的元素 然后偶遇一篇文档 ...

随机推荐

  1. 学习笔记01:《开放平台产品成长之路-POP》

    当看到一些比较好的书籍和视频内容时,希望自己可以总价归纳下来,一方面是好的东西希望可以分享给大家,另一方面希望自己能很好的吸收并转化成掌握的知识,所以有了这个系列的学习笔记,共勉,今天的你比昨天更博学 ...

  2. Vue-2:官方教程学习

    1,先把下面这些内容都按照官方教程敲一遍,打好基础,类似于“前戏”,其作用我想爸爸就不必多说了吧(づ。◕‿‿◕。)づ. https://cn.vuejs.org/v2/guide/ 同时可以配合配套视 ...

  3. 编写 Model 层的代码

    创建 App 这里把所有 Model 划分为三类:blog 相关.配置相关和评论相关.这么分的好处是便于独立维护各个模块,也便于在开发时分配任务. blog App 创建一个名为 blog 的 app ...

  4. ip地址后面的斜杠24

    ip地址后面的斜杠24表示掩码位是24位的,即用32位二进制表示的子网掩码中有连续的24个“1”:11111111 11111111 11111111 00000000,将其转化为十进制,就是:255 ...

  5. 使用 certbot 自动给 nginx 加上 https

    概述 目前,Let's Encrypt 可以算是最好用的 https 证书申请网站了吧.而 certbot 可以算是它的客户端,能够很方便的自动生成 https 证书.我把自己的使用经历记录下来,供以 ...

  6. SAS数据挖掘实战篇【三】

    SAS数据挖掘实战篇[三] 从数据挖掘概念到SAS EM模块和大概的流程介绍完之后,下面的规划是[SAS关联规则案例][SAS聚类][SAS预测]三个案例的具体操作步骤,[SAS的可视化技术]和[SA ...

  7. shell脚本安装python、pip-----非交互式的--批量执行函数

    首先把pip-.tgz 安装包放在 /usr/local 下面,按照顺序先安装pip,再安装python.不要先安装或只安装python,否则很容易出错, cat >>pip-python ...

  8. shader飞线改进版

    项目github地址:https://github.com/ecojust/flyline 前面写过一个飞线(基于THREE.Line进行的颜色变化),只是简单地将可视区片元颜色的alpha通道值设为 ...

  9. go中的数据结构-字典map

    1. map的使用 golang中的map是一种数据类型,将键与值绑定到一起,底层是用哈希表实现的,可以快速的通过键找到对应的值. 类型表示:map[keyType][valueType] key一定 ...

  10. 大觅网02Day

    docker环境搭建:(注:请先完成上一次的环境搭建) A.部署环境(导入上次系统的时候修改虚拟机的内存) 1.安装系统自带版本Docker:apt-get install docker.io 2.查 ...