processInstanceId是流程实例id
方式一:使用RuntimeService
RuntimeService runtimeService = processEngine.getRuntimeService();
String processInstanceId = "your_process_instance_id"; // 替换为实际的流程实例ID
// 检查流程实例是否已经结束
boolean isEnded = runtimeService.createProcessInstanceQuery()
.processInstanceId(processInstanceId)
.finished() // 查询已完成的流程实例
.count() > 0;
if (isEnded) {
System.out.println("流程实例已结束");
} else {
System.out.println("流程实例未结束或不存在");
}
方式二:使用HistoryService
HistoryService historyService = processEngine.getHistoryService();
String processInstanceId = "your_process_instance_id";
// 查询历史流程实例并判断是否结束
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery()
.processInstanceId(processInstanceId)
.singleResult();
// 也可以判断结束时间是否为空
if (historicProcessInstance != null && historicProcessInstance.getEndTime() != null) {
System.out.println("流程实例已结束");
} else {
System.out.println("流程实例未结束或不存在");
}
// 也可以判断结束节点是否有数据
if (historicProcessInstance != null && historicProcessInstance.getEndActivityId() != null) {
System.out.println("流程实例已结束");
} else {
System.out.println("流程实例未结束或不存在");
}
标签:flowable,流程,processInstanceId,System,实例,println,out
From: https://blog.51cto.com/u_16469255/9378818