方式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. 黑马lavarel教程---12、lavarel验证码

    黑马lavarel教程---12.lavarel验证码 一.总结 一句话总结: 用插件的时候仔细看插件的版本要求 1.lavarel安装验证码插件的时候,如果(可选)需要定义自己的配置,则需要生成配置 ...

  2. Python中导入类

    python导入类与导入函数,模块基本一样,一个模块fun,其中包含三个类 class Dog(): def __init__(self,name): self.name=name def bark( ...

  3. leetcode-hard-array-287. Find the Duplicate Number

    mycode   77.79% class Solution(object): def findDuplicate(self, nums): """ :type nums ...

  4. cad二次开发中DBText对象的外框GeometricExtents有问题?

    CAD2007版本 acDoc.Editor.WriteMessage( string.Format("[{0:F1},{1:F1},{2:F1}] - [{3:F1},{4:F1},{5: ...

  5. LC 851. Loud and Rich

    In a group of N people (labelled 0, 1, 2, ..., N-1), each person has different amounts of money, and ...

  6. Failed to start LSB: start and stop MariaDB

    Failed to start LSB: start and stop MariaDB */--> Failed to start LSB: start and stop MariaDB Tab ...

  7. Dialog对话框的几种方式使用实现

    package com.loaderman.dialogdemo; import android.app.ProgressDialog; import android.content.DialogIn ...

  8. 五十五:WTForms表单验证之渲染模板

    此功能看似强大,实则鸡肋 from wtforms import Form, StringField, BooleanField, SelectFieldfrom wtforms.validators ...

  9. php使用装饰模式无侵入式加缓存

    <?php namespace App\Services; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\ ...

  10. 【Linux开发】linux设备驱动归纳总结(十三):1.触摸屏与ADC时钟

    linux设备驱动归纳总结(十三):1.触摸屏与ADC时钟 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ...