1
0

新增自动节点

This commit is contained in:
2025-01-02 17:43:40 +08:00
parent 7d88674c66
commit c3ca027f72
9 changed files with 138 additions and 17 deletions

View File

@@ -3,15 +3,40 @@ package com.lanyuanxiaoyao.flowable.jpa;
import com.lanyuanxiaoyao.flowable.core.manager.FlowableManager;
import com.lanyuanxiaoyao.flowable.core.repository.FlowableRepository;
import java.util.UUID;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
/**
* @author lanyuanxiaoyao
* @version 20241231
*/
@Slf4j
@Service
public class SpringFlowableManager extends FlowableManager {
public SpringFlowableManager(FlowableRepository flowableRepository) {
private final ApplicationContext applicationContext;
public SpringFlowableManager(FlowableRepository flowableRepository, ApplicationContext applicationContext) {
super(flowableRepository, () -> UUID.randomUUID().toString());
this.applicationContext = applicationContext;
}
@SneakyThrows
@Override
protected <T> T createBean(String classpath) {
Class<?> clazz = Class.forName(classpath);
T targetObject = null;
try {
targetObject = (T) applicationContext.getBean(clazz);
} catch (Exception springException) {
log.warn("{} not found in spring context", springException);
try {
targetObject = (T) clazz.newInstance();
} catch (Exception javaException) {
throw new IllegalArgumentException(javaException);
}
}
return targetObject;
}
}

View File

@@ -43,14 +43,17 @@ public class JpaFlowableNode {
@Column(nullable = false)
private String name;
private String description;
@Enumerated(EnumType.STRING)
@Column(nullable = false)
private FlowableNode.Type type;
private String automaticAction;
@ElementCollection(fetch = javax.persistence.FetchType.EAGER)
@MapKeyColumn(name = "action")
@Column(name = "nodeId")
@CollectionTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private Map<FlowableAction, String> nextNodes;
@CollectionTable(name = "flowable_node_manual_actions", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private Map<FlowableAction, String> manualActions;
@CreatedDate
private LocalDateTime createdTime;
@LastModifiedDate
@@ -61,11 +64,12 @@ public class JpaFlowableNode {
this.name = node.getName();
this.description = node.getDescription();
this.type = node.getType();
this.nextNodes = node.getNextNodes();
this.automaticAction = node.getAutomaticAction();
this.manualActions = node.getManualActions();
}
public FlowableNode toFlowableNode() {
FlowableNode node = new FlowableNode(nodeId, name, description, type, nextNodes, null, createdTime);
FlowableNode node = new FlowableNode(nodeId, name, description, type, automaticAction, manualActions, null, createdTime);
node.setUpdatedTime(updateTime);
return node;
}

View File

@@ -0,0 +1,25 @@
package com.lanyuanxiaoyao.flowable.core;
import com.lanyuanxiaoyao.flowable.core.manager.FlowableManager;
import com.lanyuanxiaoyao.flowable.core.model.FlowableAction;
import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance;
import com.lanyuanxiaoyao.flowable.core.model.FlowableNode;
import java.util.Map;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
/**
* @author lanyuanxiaoyao
* @version 20250102
*/
@Slf4j
public class SimpleAutoAction implements FlowableNode.AutoAction {
@Resource
private FlowableManager flowableManager;
@Override
public FlowableAction action(FlowableInstance instance, FlowableNode node, Map<String, Object> metadata) {
log.info("Initial with spring: {}", flowableManager.listNodes());
return FlowableAction.APPROVE;
}
}

View File

@@ -1,7 +1,9 @@
package com.lanyuanxiaoyao.flowable.jpa;
import com.lanyuanxiaoyao.flowable.core.SimpleAutoAction;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
/**
@@ -14,4 +16,9 @@ public class SpringFlowableApplication {
public static void main(String[] args) {
SpringApplication.run(SpringFlowableApplication.class, args);
}
@Bean
public SimpleAutoAction simpleAutoAction() {
return new SimpleAutoAction();
}
}