diff --git a/src/main/java/com/wflow/workflow/service/impl/ProcessInstanceServiceImpl.java b/src/main/java/com/wflow/workflow/service/impl/ProcessInstanceServiceImpl.java index 68785ac..0d15104 100644 --- a/src/main/java/com/wflow/workflow/service/impl/ProcessInstanceServiceImpl.java +++ b/src/main/java/com/wflow/workflow/service/impl/ProcessInstanceServiceImpl.java @@ -44,9 +44,12 @@ import org.flowable.engine.history.HistoricActivityInstance; import org.flowable.engine.history.HistoricProcessInstance; import org.flowable.engine.history.HistoricProcessInstanceQuery; import org.flowable.engine.repository.ProcessDefinition; +import org.flowable.engine.runtime.Execution; import org.flowable.engine.runtime.ProcessInstance; +import org.flowable.engine.runtime.ProcessInstanceQuery; import org.flowable.task.api.Task; import org.flowable.task.api.TaskInfo; +import org.flowable.task.api.TaskQuery; import org.flowable.variable.api.history.HistoricVariableInstance; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -431,9 +434,35 @@ public class ProcessInstanceServiceImpl implements ProcessInstanceService { instanceQuery.processInstanceTenantId(TenantContextHolder.getTenantId()); //(x=1 or x=2) and if (Objects.equals(customStatus, 1)) { - instanceQuery.or().startedBy(startUser + "").involvedUser(startUser + "").endOr(); + HistoricProcessInstanceQuery baseQuery = historyService.createHistoricProcessInstanceQuery() + .or().startedBy(startUser) + .involvedUser(startUser) + .endOr() + .unfinished(); + List processInstanceIds = baseQuery.list() + .stream() + .map(HistoricProcessInstance::getId) + .collect(Collectors.toList()); + // 获取当前用户待处理任务的流程实例ID + TaskQuery taskQuery = taskService.createTaskQuery(); + ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery(); + Set stringSet = processInstanceQuery.list().stream().map(Execution::getProcessInstanceId).collect(Collectors.toSet()); + taskQuery.active().taskTenantId(TenantContextHolder.getTenantId()) + .processInstanceIdIn(stringSet) + .taskCandidateOrAssigned(startUser); + List activeTaskProcessIds = taskQuery.list() + .stream() + .map(Task::getProcessInstanceId) + .collect(Collectors.toList()); + // 排除待处理的流程实例ID + processInstanceIds.removeAll(activeTaskProcessIds); + if (processInstanceIds.isEmpty()) { + processInstanceIds.add("-100"); + } + // 构造最终查询并分页 + instanceQuery.processInstanceIds(new HashSet<>(processInstanceIds)); } else if (Objects.equals(customStatus, 2)) { - instanceQuery.or().startedBy(startUser + "").involvedUser(startUser + "").endOr(); + instanceQuery.or().startedBy(startUser).involvedUser(startUser).endOr(); instanceQuery.finished(); } if (!Objects.equals(customStatus, 1) && !Objects.equals(customStatus, 2)) {