- 根据流程定义ID和发起人,获取流程实例。还可以区分其中运行和结束。通过endTime是否为空判断
获取全部
String userIdStr = TaskUtils.getUserId();
List<HistoricProcessInstance> historicProcessInstances =
historyService.createHistoricProcessInstanceQuery().processDefinitionId(procDefId).startedBy(userIdStr).list();
if (CollUtil.isNotEmpty(historicProcessInstances)) {
throw new ServiceException("请勿重复发起流程.");
}
- 查询条件的使用
- 使用businessKey查询。精确和模糊查询两种
String businessKey = "project-12345:user001";
List<HistoricProcessInstance> instances = historyService.createHistoricProcessInstanceQuery()
.processInstanceBusinessKeyLike("project-12345:%") // 匹配所有该项目下的申请
.list();
boolean hasApplied = !historyService.createHistoricProcessInstanceQuery()
.startedBy("user001")
.processInstanceBusinessKey("project-12345:user001")
.list().isEmpty();
if (hasApplied) {
throw new ServiceException("您已为此项目发起过流程");
}
- 使用条件组合查询
variables.put("projectId", "12345");
variables.put("applicantId", "user001");
variables.put("patientSysUserId", "patient-001");
List<HistoricProcessInstance> instances = historyService.createHistoricProcessInstanceQuery()
.processVariableValueEquals("projectId", "12345")
.processVariableValueEquals("applicantId", "user001")
.list();
- 总结