1
0

Compare commits

..

2 Commits

Author SHA1 Message Date
e1d50571d1 增加分页查询 2025-01-24 11:01:38 +08:00
6ef29b05c5 优化监听器事件,移除错误的流程始末事件 2025-01-08 10:39:42 +08:00
6 changed files with 55 additions and 58 deletions

View File

@@ -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<com.lanyuanxiaoyao.flowable.core.model.FlowableNode> listNodes(Specification<FlowableNode> specification, Sort sort) {
return repository.listNodes(specification, sort);
}
public Page<com.lanyuanxiaoyao.flowable.core.model.FlowableNode> listNodes(Specification<FlowableNode> specification, Pageable pageable) {
return repository.listNodes(specification, pageable);
}
public List<com.lanyuanxiaoyao.flowable.core.model.FlowableInstance> listInstances(Specification<FlowableInstance> specification) {
return repository.listInstances(specification);
}
public List<com.lanyuanxiaoyao.flowable.core.model.FlowableInstance> listInstances(Specification<FlowableInstance> specification, Sort sort) {
return repository.listInstances(specification, sort);
}
public Page<com.lanyuanxiaoyao.flowable.core.model.FlowableInstance> listInstances(Specification<FlowableInstance> specification, Pageable pageable) {
return repository.listInstances(specification, pageable);
}
public List<com.lanyuanxiaoyao.flowable.core.model.FlowableHistory> listHistories(String instanceId, Specification<FlowableHistory> specification) {
return repository.listHistories(instanceId, specification);
}
public List<com.lanyuanxiaoyao.flowable.core.model.FlowableHistory> listHistories(String instanceId, Specification<FlowableHistory> specification, Sort sort) {
return repository.listHistories(instanceId, specification, sort);
}
public Page<com.lanyuanxiaoyao.flowable.core.model.FlowableHistory> listHistories(String instanceId, Specification<FlowableHistory> specification, Pageable pageable) {
return repository.listHistories(instanceId, specification, pageable);
}
@SneakyThrows
@Override
protected <T> T createBean(String classpath) {

View File

@@ -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<com.lanyuanxiaoyao.flowable.core.model.FlowableNode> listNodes(Specification<FlowableNode> specification, Pageable pageable) {
return toNodes(flowableNodeRepository.findAll(specification, pageable));
public Page<com.lanyuanxiaoyao.flowable.core.model.FlowableNode> listNodes(Specification<FlowableNode> specification, Pageable pageable) {
Page<FlowableNode> 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<com.lanyuanxiaoyao.flowable.core.model.FlowableInstance> listInstances(Specification<FlowableInstance> specification, Pageable pageable) {
return toInstances(flowableInstanceRepository.findAll(specification, pageable));
public Page<com.lanyuanxiaoyao.flowable.core.model.FlowableInstance> listInstances(Specification<FlowableInstance> specification, Pageable pageable) {
Page<FlowableInstance> 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<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
)
public Page<com.lanyuanxiaoyao.flowable.core.model.FlowableHistory> listHistories(String instanceId, Specification<FlowableHistory> specification, Pageable pageable) {
Page<FlowableHistory> 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)

View File

@@ -19,16 +19,6 @@ public class SimpleListener implements FlowableListener {
@Resource
private FlowableManager flowableManager;
@Override
public void onFlowStart(FlowableInstance instance, FlowableNode node) {
log.info("onFlowStart with spring: {}", flowableManager.listNodes());
}
@Override
public void onFlowEnd(FlowableInstance instance, FlowableNode node, FlowableAction action) {
log.info("onFlowEnd with spring: {}", flowableManager.listNodes());
}
@Override
public void onActionStart(FlowableInstance instance, FlowableNode node, FlowableAction action) {
log.info("onActionStart with spring: {}", flowableManager.listNodes());

View File

@@ -93,9 +93,8 @@ public abstract class FlowableManager {
.extra(extra)
.build();
repository.saveInstance(instance);
callListeners(node.getListeners(), listener -> listener.onFlowStart(instance, node));
if (FlowableNode.Type.AUTOMATIC.equals(node.getType())) {
automaticAction(instance, node);
automaticAction(instance);
}
return instance.getInstanceId();
}
@@ -141,15 +140,15 @@ public abstract class FlowableManager {
if (MapHelper.isNotEmpty(metadata)) {
instance.getMetadata().putAll(metadata);
}
action(instance, action, comment);
}
private void automaticAction(FlowableInstance instance) {
action(instance, null, "系统自动执行");
}
private void action(FlowableInstance instance, final FlowableAction inputAction, String comment) {
FlowableNode node = repository.getNode(instance.getCurrentNodeId());
action(instance, node, action, comment);
}
private void automaticAction(FlowableInstance instance, FlowableNode node) {
action(instance, node, null, "系统自动执行");
}
private void action(FlowableInstance instance, FlowableNode node, final FlowableAction inputAction, String comment) {
String handlerClass = node.getHandler();
if (StringHelper.isBlank(handlerClass)) {
throw new IllegalArgumentException("节点执行器为空");
@@ -185,14 +184,14 @@ public abstract class FlowableManager {
if (FlowableAction.TERMINAL.equals(action)) {
saveInstance(instance, FlowableInstance.Status.TERMINAL, action, comment);
callListeners(node.getListeners(), listener -> listener.onFlowEnd(instance, node, action));
callListeners(node.getListeners(), listener -> listener.onActionComplete(instance, node, action));
return;
}
if (Objects.isNull(node.getTargets())
|| !node.getTargets().containsKey(action)
|| StringHelper.isBlank(node.getTargets().get(action))) {
saveInstance(instance, FlowableInstance.Status.COMPLETED, action, comment);
callListeners(node.getListeners(), listener -> listener.onFlowEnd(instance, node, action));
callListeners(node.getListeners(), listener -> listener.onActionComplete(instance, node, action));
return;
}
String nextNodeId = node.getTargets().get(action);
@@ -202,7 +201,7 @@ public abstract class FlowableManager {
callListeners(node.getListeners(), listener -> listener.onActionComplete(instance, node, action));
if (FlowableNode.Type.AUTOMATIC.equals(nextNode.getType())) {
automaticAction(instance, nextNode);
automaticAction(instance);
}
}

View File

@@ -7,10 +7,6 @@ package com.lanyuanxiaoyao.flowable.core.model;
* @version 20241231
*/
public interface FlowableListener {
void onFlowStart(FlowableInstance instance, FlowableNode node);
void onFlowEnd(FlowableInstance instance, FlowableNode node, FlowableAction action);
void onActionStart(FlowableInstance instance, FlowableNode node, FlowableAction action);
void onAction(FlowableInstance instance, FlowableNode node, FlowableAction action);
@@ -18,14 +14,6 @@ public interface FlowableListener {
void onActionComplete(FlowableInstance instance, FlowableNode node, FlowableAction action);
abstract class AbstractFlowableListener implements FlowableListener {
@Override
public void onFlowStart(FlowableInstance instance, FlowableNode node) {
}
@Override
public void onFlowEnd(FlowableInstance instance, FlowableNode node, FlowableAction action) {
}
@Override
public void onActionStart(FlowableInstance instance, FlowableNode node, FlowableAction action) {
}

View File

@@ -12,16 +12,6 @@ import lombok.extern.slf4j.Slf4j;
*/
@Slf4j
public class SimpleListener implements FlowableListener {
@Override
public void onFlowStart(FlowableInstance instance, FlowableNode node) {
log.info("onFlowStart");
}
@Override
public void onFlowEnd(FlowableInstance instance, FlowableNode node, FlowableAction action) {
log.info("onFlowEnd");
}
@Override
public void onActionStart(FlowableInstance instance, FlowableNode node, FlowableAction action) {
log.info("onActionStart");