1.JAVA代码
我的待办
分页获取列表
TaskQuery query = taskService.createTaskQuery().taskCandidateOrAssigned(loginName)
.orderByTaskCreateTime().desc();//.listPage((pageNum-1)*pageSize, pageSize);
List<Task> myTaskList = query.listPage((pageNum - 1) * pageSize, pageSize);
遍历根据流程实例 ID ,获取 任务id,流程名,流程发起时间,流程创建者id
String processInstanceId = e.getProcessInstanceId();
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery()
.processInstanceId(processInstanceId).singleResult();
vo.setTaskId(e.getId());
vo.setProcessName(historicProcessInstance.getProcessDefinitionName());
vo.setCreateTime(historicProcessInstance.getStartTime());
vo.setCreater(historicProcessInstance.getStartUserId());
vo.setInstanceId(processInstanceId);
审批表单
//根据任务id 获取 任务
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
//节点不存在或节点的代理人不是当前用户
if(task == null || (task.getAssignee() != null && !StringUtils.equals(task.getAssignee(), loginName))){
return null;
}
//检查任务的受理人
taskService.claim(taskId, loginName);
//查询此节点是否在当前流程实例中发生过
List<HistoricTaskInstance> historicTaskList = historyService
.createHistoricTaskInstanceQuery()
.processInstanceId(task.getProcessInstanceId())
.taskDefinitionKey(task.getTaskDefinitionKey())
.orderByHistoricTaskInstanceEndTime().desc()
.finished()
.list();
//如果当前节点没有formKey,并且当前节点有历史,则去历史里拿formKey
if(StringUtils.isBlank(formKey)){
if(historicTaskList.size() > 0){
HistoricTaskInstance historicTaskInstance = historicTaskList.get(0);
List<HistoricVariableInstance> list = historyService
.createHistoricVariableInstanceQuery()
.taskId(historicTaskInstance.getId())
.list();
for(HistoricVariableInstance e : list){
if(StringUtils.isBlank(formKey) && StringUtils.equals(e.getVariableName(), "formKey")){
if(e.getValue() != null){
formKey = e.getValue().toString();
}
}
}
}
}
//根据 formKey 查库获取表单
审批操作
map里装着页面传来的参数
Task task = this.taskService.createTaskQuery().taskId(taskId).singleResult();
//formKey以task节点配置的为准
String formKey = task.getFormKey();
//如果task节点没有配置formKey,再以页面传递的formKey为准
if(StringUtils.isBlank(formKey)){
formKey = this.getRequest().getParameter("formKey");
}
//如果页面也没有传递formKey,则复制公用扁担key
if(StringUtils.isBlank(formKey)){
formKey = "approveTask_common";
}
map.put("formKey", formKey);
map.put("assignee", loginName);
taskService.setVariablesLocal(task.getId(), map);
taskService.complete(taskId, map);
任务交还
String loginName = ShiroUtils.getLoginName();
Task task = taskService.createTaskQuery().taskId(taskId)
.taskAssignee(loginName)
.singleResult();
if(task == null){
return AjaxResult.error("你没有拾取该任务,无法交还");
}
taskService.setAssignee(taskId, null);//归还任务
我的发起
条件查询 历史流程实例
HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery()
.startedBy(loginName)
.orderByProcessInstanceStartTime()
.desc();
query.processInstanceNameLike(name);
Date beginTime_date = DateUtils.parseDate(beginTime, "yyyy-MM-dd");
query.startedAfter(beginTime_date);
Date endTime_date = DateUtils.parseDate(endTime, "yyyy-MM-dd");
query.startedBefore(endTime_date);
query.processDefinitionKey(processKey);
if(StringUtils.isNotBlank(status)){
if(StringUtils.equals("act_complete_type_001", status)){
//已完成
query.finished();
}else{
//未完成
query.unfinished();
}
}
List<HistoricProcessInstance> listPage = query.listPage((pageNum - 1) * pageSize, pageSize);
流程开启
- 无表单参数:
//设置发起人
identityService.setAuthenticatedUserId(loginName);
Map<String, Object> map1 = new HashMap<>();
map1.put("starter", loginName);
ProcessInstance processInstance = this.runtimeService.startProcessInstanceByKey(processkey, map1);
审批历史
- 获取审批记录,一个节点一条
List<HistoricTaskInstance> historicTaskInstanceList =
historyService
.createHistoricTaskInstanceQuery()
.processInstanceId(instanceId)
.orderByHistoricTaskInstanceEndTime().asc()
.finished()
.list();
- 根据历史任务实例ID,获取流程传递过程中的 参数值
List<HistoricVariableInstance> list = historyService
.createHistoricVariableInstanceQuery()
.taskId(historicTaskInstance.getId())
.list();
- list里遍历的单个值,找到指派人
2.表解释
3.流程管理
查询
//获取所有部署的流程列表
ProcessDefinitionQuery processDefinitionQuery = repositoryService
.createProcessDefinitionQuery()
.orderByDeploymentId().asc();
//添加查询条件
//名称
processDefinitionQuery.processDefinitionNameLike("%" + processDefinition.getName() + "%");
//流程KEY
processDefinitionQuery.processDefinitionKeyLike("%" + processDefinition.getKey() + "%");
//所属分类
processDefinitionQuery.processDefinitionCategoryLike("%" + processDefinition.getCategory() + "%");
//查询 获取结果集
List<ProcessDefinition> processDefinitionList = processDefinitionQuery
.listPage((pageNum - 1) * pageSize, pageSize);
//查询 获取总数
processDefinitionQuery.count();
//根据部署id查询流程部署信息
Deployment deployment = repositoryService.createDeploymentQuery()
.deploymentId(processDefinition.getDeploymentId())
.singleResult();
//部署时间
deployment.getDeploymentTime();
//流程图
processDefinition.getDiagramResourceName();
//流程定义的 XML
definition.getResourceName();
//查询 部署流程的状态
ProcessDefinitionEntityImpl entityImpl = (ProcessDefinitionEntityImpl) processDefinition;
entity.setSuspendState(entityImpl.getSuspensionState() + "");
if (entityImpl.getSuspensionState() == 1) {
entity.setSuspendStateName("已激活");
} else {
entity.setSuspendStateName("已挂起");
}
激活或挂起流程
// 当流程定义被挂起时,已经发起的该流程定义的流程实例不受影响(如果选择级联挂起则流程实例也会被挂起)。
// 当流程定义被挂起时,无法发起新的该流程定义的流程实例。会抛出异常
// 直观变化:act_re_procdef 的 SUSPENSION_STATE_ 为 2
repositoryService.suspendProcessDefinitionById(id);
repositoryService.activateProcessDefinitionById(id);
每操作一次,REV_ 乐观锁标记会自增1
删除流程定义
通过 deploymentId 删除,删除前需要保证没有运行实例
List<ProcessInstance> instanceList = runtimeService.createProcessInstanceQuery()
.deploymentId(deploymentId)
.list();
if (!CollectionUtils.isEmpty(instanceList)) {
// 存在流程实例的流程定义
throw new Exception("删除失败,存在运行中的流程实例");
}
// true 表示级联删除引用,比如 act_ru_execution 数据
repositoryService.deleteDeployment(deploymentId, true);