过滤器仅camunda系列有
- 过滤器的继承
- 过滤器查询对象使用
- 过滤器删除
一、过滤器各种场景下的使用
创建Filter:
/**
* insert into ACT_RU_FILTER (ID_, RESOURCE_TYPE_, NAME_, OWNER_, QUERY_, PROPERTIES_, REV_) values ( ?, ?, ?, ?, ?, ?, 1 )
* 1201(String), Task(String), peng个人偏好(String), peng(String), java.io.StringReader@5df417a7(StringReader), java.io.StringReader@7c041b41(StringReader)
*/
@Test
public void saveFilter() {
TaskQuery taskQuery = taskService.createTaskQuery().taskAssignee("peng");
Map<String, Object> map = new HashMap<>();
map.put("peng-1", "peng1");
map.put("peng-2", "peng2");
map.put("peng-3", "peng3");
Filter filter1 = filterService.newTaskFilter()
.setName("peng个人偏好")
.setOwner("peng")
.setQuery(taskQuery)
.setProperties(map);
filterService.saveFilter(filter1);
System.out.println(filter1.getId() + "," + filter1.getQuery() + "," + filter1.getProperties() + "," + filter1.getResourceType() + ","
+ filter1.getOwner() + "," + filter1.getName());
}
创建时注意事项filter.setName(null)
、filter.setName("")
、filter.setQuery((Query<?,?>)null)
会报错
查询Filter:
/**
* select * from ACT_RU_FILTER where ID_ = ?
*/
@Test
public void getFilter() {
String filterId = "1201";
Filter filter = filterService.getFilter(filterId);
System.out.println("########" + filter);
}
Filter继承:
/**
* insert into ACT_RU_FILTER (ID_, RESOURCE_TYPE_, NAME_, OWNER_, QUERY_, PROPERTIES_, REV_) values ( ?, ?, ?, ?, ?, ?, 1 )
* 1301(String), Task(String), peng个人偏好(String), peng(String), java.io.StringReader@664a9613(StringReader), java.io.StringReader@5118388b(StringReader)
*/
@Test
public void extend() {
String filterId = "1201";
Filter filter1 = filterService.getFilter(filterId);
TaskQuery taskQuery = taskService.createTaskQuery().taskName("name-1").taskCandidateUser("peng");
Filter newFilter = filter1.extend(taskQuery);
filterService.saveFilter(newFilter);
}
Filter删除:
/**
* delete from ACT_RU_FILTER where ID_ = ? and REV_ = ?
*/
@Test
public void deleteFilter() {
String filterId = "1201";
filterService.deleteFilter(filterId);
}
Filter查询query使用,需要配合自定义命令类执行
/**
* select distinct RES.REV_, RES.ID_, RES.NAME_, RES.PARENT_TASK_ID_, RES.DESCRIPTION_, RES.PRIORITY_, RES.CREATE_TIME_, RES.OWNER_, RES.ASSIGNEE_, RES.DELEGATION_, RES.EXECUTION_ID_, RES.PROC_INST_ID_, RES.PROC_DEF_ID_, RES.CASE_EXECUTION_ID_, RES.CASE_INST_ID_, RES.CASE_DEF_ID_, RES.TASK_DEF_KEY_, RES.DUE_DATE_, RES.FOLLOW_UP_DATE_, RES.SUSPENSION_STATE_, RES.TENANT_ID_
* from ACT_RU_TASK RES WHERE ( 1 = 1 and RES.ASSIGNEE_ = ? ) order by RES.ID_ asc LIMIT ? OFFSET ?
*/
@Test
public void getQuery() {
String filterId = "1401";
Filter filter1 = filterService.getFilter(filterId);
//执行自定义命令类
ServiceImpl service = (ServiceImpl) filterService;
service.getCommandExecutor().execute(new CustomerCmd(filter1));
}
注意:filterService.newTaskFilter()
,方法里面传递的resourceType
的类型是Task,说明开源版本的过滤器只支持任务的过滤查询。商业版应该是支持其他类型的
query`的
代码参考:https://github.com/zhoupengwa/ProcessEngineDemo
学习来源:腾讯课堂