流程定义查询,act_re_procdef
原创
©著作权归作者所有:来自51CTO博客作者小大宇51CTO的原创作品,请联系作者获取转载授权,否则将追究法律责任
流程定义查询的Service与流程部署的Service一样,是RepositoryService接口实现。
核心知识点如下:
//开启流程之前先寻找最新版本的请假流程定义
ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery();
//添加查询条件,KEY
query.processDefinitionKey("myProcess_1");
//最新版本过滤
query.latestVersion();
//查询
ProcessDefinition definition = query.singleResult();
//获取流程定义id
String processDefId = definition.getId();
//通过指定流程定义的id,开启流程定义,得到流程实例。流程实例是一系列任务的集合
ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefId);
@RequestMapping(value = {URL_DEPLOY_PROCESS_DEF_LIST})
@ResponseBody
public PagedQueryExtResult<ProcessDefEntity> processDefListForExtJs(ProcessDefQueryCondition condition) {
LOGGER.info("obtain Process Def for ExtJs,condition={}",condition);
ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery();//重点!!!!!!!!
//总条数
long size = query.count();
//分页查询
query.listPage(condition.getStart(),condition.getLimit());
//根据KEY查询
query.processDefinitionKey("myProcess_1");
List<ProcessDefinition> list = query.list();
//创建我们自己的list,用于前后端交互
List<ProcessDefEntity> myList = new ArrayList<>();
//将查询出来的流程定义中的数据,加载到我们自己的list中
for(ProcessDefinition def : list){
ProcessDefEntity entity = new ProcessDefEntity();
entity.setId(def.getId());
entity.setName(def.getName());
entity.setKey(def.getKey());
entity.setDeploymentId(def.getDeploymentId());
entity.setResourceName(def.getResourceName());
entity.setVersion(def.getVersion());
myList.add(entity);
}
//创建分页查询结果实体
PagedQueryExtResult<ProcessDefEntity> result = new PagedQueryExtResult<>();
//设置本次分页查询结果
result.setResults(myList);
//设置总数
result.setTotal((int)size);
//设置本次响应成功
result.setSuccess(true);
return result;
}
本方法的参数,是ProcessDefQueryCondition,用于封装Ext的面板的查询参数,有三个查询条件,很简单
package com.ssi.domains.workflow.queryCondition;
import com.ssi.web.AbstractPaginationExtQueryCondition;
/**
* Created by jay.zhou on 2018/6/25.
*/
public class ProcessDefQueryCondition extends AbstractPaginationExtQueryCondition {
}
package com.ssi.web;
import lombok.Getter;
import lombok.Setter;
/**
* Created by jay.zhou on 2018/6/25.
*/
@Getter
@Setter
public abstract class AbstractPaginationExtQueryCondition {
private int page;
private int start;
private int limit;
}
返回的结果基本与数据库中 act_re_procdef 字段保持一致。返回结果实体对象
package com.ssi.domains.workflow.entity;
import lombok.Getter;
import lombok.Setter;
/**
* Created by jay.zhou on 2018/6/25.
*/
@Getter
@Setter
public class ProcessDefEntity {
private String id;
private String name;
private String key;
private int version;
private String resourceName;
private String deploymentId;
}
另外,方法的返回值根据当前前端框架进行编写相关Java代码。本小节重点是,通过工作流的RepositoryService接口实现,根据相关条件,比如分页查询、根据流程定义表的KEY字段进行查询。