优化存储读写,增加一些查询接口
This commit is contained in:
@@ -22,6 +22,18 @@ public class SpringFlowableManager extends FlowableManager {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
public List<com.lanyuanxiaoyao.flowable.core.model.FlowableNode> listNodes(Specification<FlowableNode> specification) {
|
||||
return repository.listNodes(specification);
|
||||
}
|
||||
|
||||
public List<com.lanyuanxiaoyao.flowable.core.model.FlowableInstance> listInstances(Specification<FlowableInstance> specification) {
|
||||
return repository.listInstances(specification);
|
||||
}
|
||||
|
||||
public List<com.lanyuanxiaoyao.flowable.core.model.FlowableHistory> listHistories(String instanceId, Specification<FlowableHistory> specification) {
|
||||
return repository.listHistories(instanceId, specification);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
protected <T> T createBean(String classpath) {
|
||||
|
||||
@@ -9,7 +9,11 @@ import com.lanyuanxiaoyao.flowable.jpa.repository.FlowableInstanceRepository;
|
||||
import com.lanyuanxiaoyao.flowable.jpa.repository.FlowableNodeRepository;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
import javax.transaction.Transactional;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
@@ -26,6 +30,11 @@ public class SpringFlowableRepository implements FlowableRepository {
|
||||
this.flowableHistoryRepository = flowableHistoryRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsNode(String nodeId) {
|
||||
return flowableNodeRepository.existsById(nodeId);
|
||||
}
|
||||
|
||||
@Transactional(rollbackOn = Exception.class)
|
||||
@Override
|
||||
public void saveNode(com.lanyuanxiaoyao.flowable.core.model.FlowableNode node) {
|
||||
@@ -45,14 +54,34 @@ public class SpringFlowableRepository implements FlowableRepository {
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<com.lanyuanxiaoyao.flowable.core.model.FlowableNode> listNodes() {
|
||||
return flowableNodeRepository.findAll()
|
||||
.stream()
|
||||
private List<com.lanyuanxiaoyao.flowable.core.model.FlowableNode> toNodes(Iterable<FlowableNode> nodes) {
|
||||
return StreamSupport.stream(nodes.spliterator(), false)
|
||||
.map(FlowableNode::toFlowableNode)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<com.lanyuanxiaoyao.flowable.core.model.FlowableNode> listNodes() {
|
||||
return toNodes(flowableNodeRepository.findAll());
|
||||
}
|
||||
|
||||
public List<com.lanyuanxiaoyao.flowable.core.model.FlowableNode> listNodes(Specification<FlowableNode> specification) {
|
||||
return toNodes(flowableNodeRepository.findAll(specification));
|
||||
}
|
||||
|
||||
public List<com.lanyuanxiaoyao.flowable.core.model.FlowableNode> listNodes(Specification<FlowableNode> specification, Sort sort) {
|
||||
return toNodes(flowableNodeRepository.findAll(specification, sort));
|
||||
}
|
||||
|
||||
public List<com.lanyuanxiaoyao.flowable.core.model.FlowableNode> listNodes(Specification<FlowableNode> specification, Pageable pageable) {
|
||||
return toNodes(flowableNodeRepository.findAll(specification, pageable));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsInstance(String instanceId) {
|
||||
return flowableInstanceRepository.existsById(instanceId);
|
||||
}
|
||||
|
||||
@Transactional(rollbackOn = Exception.class)
|
||||
@Override
|
||||
public void saveInstance(com.lanyuanxiaoyao.flowable.core.model.FlowableInstance instance) {
|
||||
@@ -66,14 +95,34 @@ public class SpringFlowableRepository implements FlowableRepository {
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<com.lanyuanxiaoyao.flowable.core.model.FlowableInstance> listInstances() {
|
||||
return flowableInstanceRepository.findAll()
|
||||
.stream()
|
||||
private List<com.lanyuanxiaoyao.flowable.core.model.FlowableInstance> toInstances(Iterable<FlowableInstance> instances) {
|
||||
return StreamSupport.stream(instances.spliterator(), false)
|
||||
.map(FlowableInstance::toFlowableInstance)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<com.lanyuanxiaoyao.flowable.core.model.FlowableInstance> listInstances() {
|
||||
return toInstances(flowableInstanceRepository.findAll());
|
||||
}
|
||||
|
||||
public List<com.lanyuanxiaoyao.flowable.core.model.FlowableInstance> listInstances(Specification<FlowableInstance> specification) {
|
||||
return toInstances(flowableInstanceRepository.findAll(specification));
|
||||
}
|
||||
|
||||
public List<com.lanyuanxiaoyao.flowable.core.model.FlowableInstance> listInstances(Specification<FlowableInstance> specification, Sort sort) {
|
||||
return toInstances(flowableInstanceRepository.findAll(specification, sort));
|
||||
}
|
||||
|
||||
public List<com.lanyuanxiaoyao.flowable.core.model.FlowableInstance> listInstances(Specification<FlowableInstance> specification, Pageable pageable) {
|
||||
return toInstances(flowableInstanceRepository.findAll(specification, pageable));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsHistory(String historyId) {
|
||||
return flowableHistoryRepository.existsById(historyId);
|
||||
}
|
||||
|
||||
@Transactional(rollbackOn = Exception.class)
|
||||
@Override
|
||||
public void saveHistory(com.lanyuanxiaoyao.flowable.core.model.FlowableHistory history) {
|
||||
@@ -87,14 +136,52 @@ public class SpringFlowableRepository implements FlowableRepository {
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<com.lanyuanxiaoyao.flowable.core.model.FlowableHistory> listHistories(String instanceId) {
|
||||
return flowableHistoryRepository.findAllByInstanceId(instanceId)
|
||||
.stream()
|
||||
private List<com.lanyuanxiaoyao.flowable.core.model.FlowableHistory> toHistories(Iterable<FlowableHistory> histories) {
|
||||
return StreamSupport.stream(histories.spliterator(), false)
|
||||
.map(FlowableHistory::toFlowableHistory)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<com.lanyuanxiaoyao.flowable.core.model.FlowableHistory> listHistories(String instanceId) {
|
||||
return toHistories(flowableHistoryRepository.findAllByInstanceId(instanceId));
|
||||
}
|
||||
|
||||
public List<com.lanyuanxiaoyao.flowable.core.model.FlowableHistory> listHistories(String instanceId, Specification<FlowableHistory> specification) {
|
||||
return toHistories(
|
||||
flowableHistoryRepository.findAll(
|
||||
(root, query, builder) -> builder.and(
|
||||
builder.equal(root.get("instanceId"), instanceId),
|
||||
specification.toPredicate(root, query, builder)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public List<com.lanyuanxiaoyao.flowable.core.model.FlowableHistory> listHistories(String instanceId, Specification<FlowableHistory> specification, Sort sort) {
|
||||
return toHistories(
|
||||
flowableHistoryRepository.findAll(
|
||||
(root, query, builder) -> builder.and(
|
||||
builder.equal(root.get("instanceId"), instanceId),
|
||||
specification.toPredicate(root, query, builder)
|
||||
),
|
||||
sort
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public List<com.lanyuanxiaoyao.flowable.core.model.FlowableHistory> listHistories(String instanceId, Specification<FlowableHistory> specification, Pageable pageable) {
|
||||
return toHistories(
|
||||
flowableHistoryRepository.findAll(
|
||||
(root, query, builder) -> builder.and(
|
||||
builder.equal(root.get("instanceId"), instanceId),
|
||||
specification.toPredicate(root, query, builder)
|
||||
),
|
||||
pageable
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Transactional(rollbackOn = Exception.class)
|
||||
@Override
|
||||
public void saveInstanceAndHistory(com.lanyuanxiaoyao.flowable.core.model.FlowableInstance instance, com.lanyuanxiaoyao.flowable.core.model.FlowableHistory history) {
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.lanyuanxiaoyao.flowable.jpa.repository;
|
||||
import com.lanyuanxiaoyao.flowable.jpa.entity.FlowableHistory;
|
||||
import java.util.List;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.repository.query.QueryByExampleExecutor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
@@ -10,6 +12,6 @@ import org.springframework.stereotype.Repository;
|
||||
* @version 20250102
|
||||
*/
|
||||
@Repository
|
||||
public interface FlowableHistoryRepository extends JpaRepository<FlowableHistory, String> {
|
||||
public interface FlowableHistoryRepository extends JpaRepository<FlowableHistory, String>, JpaSpecificationExecutor<FlowableHistory>, QueryByExampleExecutor<FlowableHistory> {
|
||||
List<FlowableHistory> findAllByInstanceId(String instanceId);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.lanyuanxiaoyao.flowable.jpa.repository;
|
||||
|
||||
import com.lanyuanxiaoyao.flowable.jpa.entity.FlowableInstance;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.repository.query.QueryByExampleExecutor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
@@ -9,5 +11,5 @@ import org.springframework.stereotype.Repository;
|
||||
* @version 20250102
|
||||
*/
|
||||
@Repository
|
||||
public interface FlowableInstanceRepository extends JpaRepository<FlowableInstance, String> {
|
||||
public interface FlowableInstanceRepository extends JpaRepository<FlowableInstance, String>, JpaSpecificationExecutor<FlowableInstance>, QueryByExampleExecutor<FlowableInstance> {
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.lanyuanxiaoyao.flowable.jpa.repository;
|
||||
|
||||
import com.lanyuanxiaoyao.flowable.jpa.entity.FlowableNode;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.repository.query.QueryByExampleExecutor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
@@ -9,5 +11,5 @@ import org.springframework.stereotype.Repository;
|
||||
* @version 20250102
|
||||
*/
|
||||
@Repository
|
||||
public interface FlowableNodeRepository extends JpaRepository<FlowableNode, String> {
|
||||
public interface FlowableNodeRepository extends JpaRepository<FlowableNode, String>, JpaSpecificationExecutor<FlowableNode>, QueryByExampleExecutor<FlowableNode> {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user