diff --git a/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/SpringFlowableManager.java b/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/SpringFlowableManager.java index 09e7ac8..bc2528c 100644 --- a/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/SpringFlowableManager.java +++ b/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/SpringFlowableManager.java @@ -9,6 +9,9 @@ import java.util.UUID; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.springframework.context.ApplicationContext; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; import org.springframework.data.jpa.domain.Specification; /** @@ -31,14 +34,38 @@ public class SpringFlowableManager extends FlowableManager { return repository.listNodes(specification); } + public List listNodes(Specification specification, Sort sort) { + return repository.listNodes(specification, sort); + } + + public Page listNodes(Specification specification, Pageable pageable) { + return repository.listNodes(specification, pageable); + } + public List listInstances(Specification specification) { return repository.listInstances(specification); } + public List listInstances(Specification specification, Sort sort) { + return repository.listInstances(specification, sort); + } + + public Page listInstances(Specification specification, Pageable pageable) { + return repository.listInstances(specification, pageable); + } + public List listHistories(String instanceId, Specification specification) { return repository.listHistories(instanceId, specification); } + public List listHistories(String instanceId, Specification specification, Sort sort) { + return repository.listHistories(instanceId, specification, sort); + } + + public Page listHistories(String instanceId, Specification specification, Pageable pageable) { + return repository.listHistories(instanceId, specification, pageable); + } + @SneakyThrows @Override protected T createBean(String classpath) { diff --git a/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/SpringFlowableRepository.java b/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/SpringFlowableRepository.java index 09927a3..f5ad74d 100644 --- a/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/SpringFlowableRepository.java +++ b/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/SpringFlowableRepository.java @@ -11,6 +11,8 @@ import java.util.List; import java.util.stream.Collectors; import java.util.stream.StreamSupport; import javax.transaction.Transactional; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.data.jpa.domain.Specification; @@ -73,8 +75,9 @@ public class SpringFlowableRepository implements FlowableRepository { return toNodes(flowableNodeRepository.findAll(specification, sort)); } - public List listNodes(Specification specification, Pageable pageable) { - return toNodes(flowableNodeRepository.findAll(specification, pageable)); + public Page listNodes(Specification specification, Pageable pageable) { + Page page = flowableNodeRepository.findAll(specification, pageable); + return new PageImpl<>(toNodes(page.getContent()), pageable, page.getTotalElements()); } @Override @@ -114,8 +117,9 @@ public class SpringFlowableRepository implements FlowableRepository { return toInstances(flowableInstanceRepository.findAll(specification, sort)); } - public List listInstances(Specification specification, Pageable pageable) { - return toInstances(flowableInstanceRepository.findAll(specification, pageable)); + public Page listInstances(Specification specification, Pageable pageable) { + Page page = flowableInstanceRepository.findAll(specification, pageable); + return new PageImpl<>(toInstances(page.getContent()), pageable, page.getTotalElements()); } @Override @@ -170,16 +174,15 @@ public class SpringFlowableRepository implements FlowableRepository { ); } - public List listHistories(String instanceId, Specification specification, Pageable pageable) { - return toHistories( - flowableHistoryRepository.findAll( - (root, query, builder) -> builder.and( - builder.equal(root.get("instanceId"), instanceId), - specification.toPredicate(root, query, builder) - ), - pageable - ) + public Page listHistories(String instanceId, Specification specification, Pageable pageable) { + Page page = flowableHistoryRepository.findAll( + (root, query, builder) -> builder.and( + builder.equal(root.get("instanceId"), instanceId), + specification.toPredicate(root, query, builder) + ), + pageable ); + return new PageImpl<>(toHistories(page.getContent()), pageable, page.getTotalElements()); } @Transactional(rollbackOn = Exception.class)