【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相关的元素 然后偶遇一篇文档 ...
随机推荐
- Hive数据提取
Hive是基于Hadoop的ETL工具和数据仓库. 结构化数据 结构化数据就像RDBMS hive> create table structured_table(id int, name str ...
- 使用Aria2+Aria2Ng+OneIndex+OneDrive建立不限流量/离线BT下载/在线观看网盘/在线存储分享平台
获取OneDrive 自行搜索或者宝购买 安装 1.安装宝塔 #Centos系统 yum install -y wget && wget -O install.sh http://do ...
- 发布nuget包
首先在nuget(www.nuget.org)注册账号,这里可以使用微软账号直接登录 一般有两种方式 1:在工程上右键打包然后直接在网站上上传就可以 2:通过获取key,然后使用控制台提交 登录后在右 ...
- Selenium 2自动化测试实战24(webdriver原理)
一.webdriver原理 webdriver是按照Server-Client的经典设计模式设计的.Server端就是Remote Server,可以是任意的浏览器.当我们的脚本启动浏览器后,该浏览器 ...
- js __proto__ 和prototype的联系
1.Javascript中所有的对象都是Object的实例,并继承Object.prototype的属性和方法,也就是说,Object.prototype是所有对象的爸爸.(个人感觉搞清楚这一点很重要 ...
- Field in required a single bean, but 2 were found:
我在其他类注入的时候出现以下错误 @Autowired NodeAgentService nodeAgentService; 异常 Description: Field mibService in c ...
- linux下抓取tomcat相关内存、线程、文件句柄等快照,用于故障排除。
以下脚本推荐放在定时任务里,写好cron表达式,在不影响业务系统的情况下dump一些信息分析系统性能瓶颈以及故障排除. 因为每次dump的时候jvm会暂停(几秒到几十秒不等).所以在生产系统使用时慎用 ...
- springboot整合mybatis时java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone.
时区问题造成的,解决方法是在数据源配置文件中在数据库链接处增加参数&serverTimezone=GMT%2B8对时区进行配置,配置为东八区. 修改前:spring.datasource.ur ...
- 配置 Nginx 错误页面优雅显示
[root@localhost ~]# cat /usr/local/nginx/conf/nginx.conf ...... http { location / { root html/www; i ...
- 关于js中断ajax请求
停止javascript的ajax请求,一种是设置超时时间让ajax自动断开,另一种为手动去停止ajax请求,其核心是调用XMLHttpRequest对象上的abort方法,这里,我们以jquery举 ...