Compare commits
2 Commits
96dfcea7b8
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| e1d50571d1 | |||
| 6ef29b05c5 |
@@ -9,6 +9,9 @@ import java.util.UUID;
|
|||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.context.ApplicationContext;
|
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;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,14 +34,38 @@ public class SpringFlowableManager extends FlowableManager {
|
|||||||
return repository.listNodes(specification);
|
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) {
|
public List<com.lanyuanxiaoyao.flowable.core.model.FlowableInstance> listInstances(Specification<FlowableInstance> specification) {
|
||||||
return repository.listInstances(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) {
|
public List<com.lanyuanxiaoyao.flowable.core.model.FlowableHistory> listHistories(String instanceId, Specification<FlowableHistory> specification) {
|
||||||
return repository.listHistories(instanceId, 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
|
@SneakyThrows
|
||||||
@Override
|
@Override
|
||||||
protected <T> T createBean(String classpath) {
|
protected <T> T createBean(String classpath) {
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import java.util.List;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.StreamSupport;
|
import java.util.stream.StreamSupport;
|
||||||
import javax.transaction.Transactional;
|
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.Pageable;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
@@ -73,8 +75,9 @@ public class SpringFlowableRepository implements FlowableRepository {
|
|||||||
return toNodes(flowableNodeRepository.findAll(specification, sort));
|
return toNodes(flowableNodeRepository.findAll(specification, sort));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<com.lanyuanxiaoyao.flowable.core.model.FlowableNode> listNodes(Specification<FlowableNode> specification, Pageable pageable) {
|
public Page<com.lanyuanxiaoyao.flowable.core.model.FlowableNode> listNodes(Specification<FlowableNode> specification, Pageable pageable) {
|
||||||
return toNodes(flowableNodeRepository.findAll(specification, pageable));
|
Page<FlowableNode> page = flowableNodeRepository.findAll(specification, pageable);
|
||||||
|
return new PageImpl<>(toNodes(page.getContent()), pageable, page.getTotalElements());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -114,8 +117,9 @@ public class SpringFlowableRepository implements FlowableRepository {
|
|||||||
return toInstances(flowableInstanceRepository.findAll(specification, sort));
|
return toInstances(flowableInstanceRepository.findAll(specification, sort));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<com.lanyuanxiaoyao.flowable.core.model.FlowableInstance> listInstances(Specification<FlowableInstance> specification, Pageable pageable) {
|
public Page<com.lanyuanxiaoyao.flowable.core.model.FlowableInstance> listInstances(Specification<FlowableInstance> specification, Pageable pageable) {
|
||||||
return toInstances(flowableInstanceRepository.findAll(specification, pageable));
|
Page<FlowableInstance> page = flowableInstanceRepository.findAll(specification, pageable);
|
||||||
|
return new PageImpl<>(toInstances(page.getContent()), pageable, page.getTotalElements());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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) {
|
public Page<com.lanyuanxiaoyao.flowable.core.model.FlowableHistory> listHistories(String instanceId, Specification<FlowableHistory> specification, Pageable pageable) {
|
||||||
return toHistories(
|
Page<FlowableHistory> page = flowableHistoryRepository.findAll(
|
||||||
flowableHistoryRepository.findAll(
|
|
||||||
(root, query, builder) -> builder.and(
|
(root, query, builder) -> builder.and(
|
||||||
builder.equal(root.get("instanceId"), instanceId),
|
builder.equal(root.get("instanceId"), instanceId),
|
||||||
specification.toPredicate(root, query, builder)
|
specification.toPredicate(root, query, builder)
|
||||||
),
|
),
|
||||||
pageable
|
pageable
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
return new PageImpl<>(toHistories(page.getContent()), pageable, page.getTotalElements());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(rollbackOn = Exception.class)
|
@Transactional(rollbackOn = Exception.class)
|
||||||
|
|||||||
@@ -19,16 +19,6 @@ public class SimpleListener implements FlowableListener {
|
|||||||
@Resource
|
@Resource
|
||||||
private FlowableManager flowableManager;
|
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
|
@Override
|
||||||
public void onActionStart(FlowableInstance instance, FlowableNode node, FlowableAction action) {
|
public void onActionStart(FlowableInstance instance, FlowableNode node, FlowableAction action) {
|
||||||
log.info("onActionStart with spring: {}", flowableManager.listNodes());
|
log.info("onActionStart with spring: {}", flowableManager.listNodes());
|
||||||
|
|||||||
@@ -93,9 +93,8 @@ public abstract class FlowableManager {
|
|||||||
.extra(extra)
|
.extra(extra)
|
||||||
.build();
|
.build();
|
||||||
repository.saveInstance(instance);
|
repository.saveInstance(instance);
|
||||||
callListeners(node.getListeners(), listener -> listener.onFlowStart(instance, node));
|
|
||||||
if (FlowableNode.Type.AUTOMATIC.equals(node.getType())) {
|
if (FlowableNode.Type.AUTOMATIC.equals(node.getType())) {
|
||||||
automaticAction(instance, node);
|
automaticAction(instance);
|
||||||
}
|
}
|
||||||
return instance.getInstanceId();
|
return instance.getInstanceId();
|
||||||
}
|
}
|
||||||
@@ -141,15 +140,15 @@ public abstract class FlowableManager {
|
|||||||
if (MapHelper.isNotEmpty(metadata)) {
|
if (MapHelper.isNotEmpty(metadata)) {
|
||||||
instance.getMetadata().putAll(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());
|
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();
|
String handlerClass = node.getHandler();
|
||||||
if (StringHelper.isBlank(handlerClass)) {
|
if (StringHelper.isBlank(handlerClass)) {
|
||||||
throw new IllegalArgumentException("节点执行器为空");
|
throw new IllegalArgumentException("节点执行器为空");
|
||||||
@@ -185,14 +184,14 @@ public abstract class FlowableManager {
|
|||||||
|
|
||||||
if (FlowableAction.TERMINAL.equals(action)) {
|
if (FlowableAction.TERMINAL.equals(action)) {
|
||||||
saveInstance(instance, FlowableInstance.Status.TERMINAL, action, comment);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if (Objects.isNull(node.getTargets())
|
if (Objects.isNull(node.getTargets())
|
||||||
|| !node.getTargets().containsKey(action)
|
|| !node.getTargets().containsKey(action)
|
||||||
|| StringHelper.isBlank(node.getTargets().get(action))) {
|
|| StringHelper.isBlank(node.getTargets().get(action))) {
|
||||||
saveInstance(instance, FlowableInstance.Status.COMPLETED, action, comment);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
String nextNodeId = node.getTargets().get(action);
|
String nextNodeId = node.getTargets().get(action);
|
||||||
@@ -202,7 +201,7 @@ public abstract class FlowableManager {
|
|||||||
|
|
||||||
callListeners(node.getListeners(), listener -> listener.onActionComplete(instance, node, action));
|
callListeners(node.getListeners(), listener -> listener.onActionComplete(instance, node, action));
|
||||||
if (FlowableNode.Type.AUTOMATIC.equals(nextNode.getType())) {
|
if (FlowableNode.Type.AUTOMATIC.equals(nextNode.getType())) {
|
||||||
automaticAction(instance, nextNode);
|
automaticAction(instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,10 +7,6 @@ package com.lanyuanxiaoyao.flowable.core.model;
|
|||||||
* @version 20241231
|
* @version 20241231
|
||||||
*/
|
*/
|
||||||
public interface FlowableListener {
|
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 onActionStart(FlowableInstance instance, FlowableNode node, FlowableAction action);
|
||||||
|
|
||||||
void onAction(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);
|
void onActionComplete(FlowableInstance instance, FlowableNode node, FlowableAction action);
|
||||||
|
|
||||||
abstract class AbstractFlowableListener implements FlowableListener {
|
abstract class AbstractFlowableListener implements FlowableListener {
|
||||||
@Override
|
|
||||||
public void onFlowStart(FlowableInstance instance, FlowableNode node) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFlowEnd(FlowableInstance instance, FlowableNode node, FlowableAction action) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActionStart(FlowableInstance instance, FlowableNode node, FlowableAction action) {
|
public void onActionStart(FlowableInstance instance, FlowableNode node, FlowableAction action) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,16 +12,6 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SimpleListener implements FlowableListener {
|
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
|
@Override
|
||||||
public void onActionStart(FlowableInstance instance, FlowableNode node, FlowableAction action) {
|
public void onActionStart(FlowableInstance instance, FlowableNode node, FlowableAction action) {
|
||||||
log.info("onActionStart");
|
log.info("onActionStart");
|
||||||
|
|||||||
Reference in New Issue
Block a user