增加配置文件
This commit is contained in:
7
.idea/jpa.xml
generated
Normal file
7
.idea/jpa.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="JpaBuddyIdeaProjectConfig">
|
||||||
|
<option name="defaultUnitInitialized" value="true" />
|
||||||
|
<option name="renamerInitialized" value="true" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
3
.idea/misc.xml
generated
3
.idea/misc.xml
generated
@@ -11,4 +11,7 @@
|
|||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="temurin-1.8" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="temurin-1.8" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="ProjectType">
|
||||||
|
<option name="id" value="jpab" />
|
||||||
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -23,6 +23,11 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-logging</artifactId>
|
<artifactId>spring-boot-starter-logging</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.lanyuanxiaoyao.flowable.jpa;
|
||||||
|
|
||||||
|
import com.lanyuanxiaoyao.flowable.core.manager.FlowableConfiguration;
|
||||||
|
import lombok.ToString;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置类
|
||||||
|
*
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250103
|
||||||
|
*/
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties("flowable")
|
||||||
|
public class SpringFlowableConfiguration extends FlowableConfiguration {
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.lanyuanxiaoyao.flowable.jpa;
|
package com.lanyuanxiaoyao.flowable.jpa;
|
||||||
|
|
||||||
|
import com.lanyuanxiaoyao.flowable.core.manager.FlowableConfiguration;
|
||||||
import com.lanyuanxiaoyao.flowable.core.manager.FlowableManager;
|
import com.lanyuanxiaoyao.flowable.core.manager.FlowableManager;
|
||||||
import com.lanyuanxiaoyao.flowable.core.repository.FlowableRepository;
|
import com.lanyuanxiaoyao.flowable.core.repository.FlowableRepository;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@@ -17,8 +18,9 @@ import org.springframework.stereotype.Service;
|
|||||||
public class SpringFlowableManager extends FlowableManager {
|
public class SpringFlowableManager extends FlowableManager {
|
||||||
private final ApplicationContext applicationContext;
|
private final ApplicationContext applicationContext;
|
||||||
|
|
||||||
public SpringFlowableManager(FlowableRepository flowableRepository, ApplicationContext applicationContext) {
|
public SpringFlowableManager(FlowableConfiguration configuration, FlowableRepository repository, ApplicationContext applicationContext) {
|
||||||
super(flowableRepository, () -> UUID.randomUUID().toString());
|
super(configuration, repository);
|
||||||
|
log.info("Configuration: {}", configuration);
|
||||||
this.applicationContext = applicationContext;
|
this.applicationContext = applicationContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,4 +40,9 @@ public class SpringFlowableManager extends FlowableManager {
|
|||||||
}
|
}
|
||||||
return targetObject;
|
return targetObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String createId() {
|
||||||
|
return UUID.randomUUID().toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.lanyuanxiaoyao.flowable.core.manager;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置项
|
||||||
|
*
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250103
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class FlowableConfiguration {
|
||||||
|
/**
|
||||||
|
* 在上下文中查询权限的key
|
||||||
|
*/
|
||||||
|
@Builder.Default
|
||||||
|
private String accessorKey = Constants.DEFAULT_ACCESSOR_KEY;
|
||||||
|
|
||||||
|
public interface Constants {
|
||||||
|
String DEFAULT_ACCESSOR_KEY = "accessor";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,40 +25,40 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public abstract class FlowableManager {
|
public abstract class FlowableManager {
|
||||||
private final FlowableRepository flowableRepository;
|
private final FlowableConfiguration configuration;
|
||||||
private final IdGenerator idGenerator;
|
private final FlowableRepository repository;
|
||||||
|
|
||||||
public FlowableManager(FlowableRepository flowableRepository, IdGenerator idGenerator) {
|
public FlowableManager(FlowableConfiguration configuration, FlowableRepository repository) {
|
||||||
this.flowableRepository = flowableRepository;
|
this.configuration = configuration;
|
||||||
this.idGenerator = idGenerator;
|
this.repository = repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FlowableNode> listNodes() {
|
public List<FlowableNode> listNodes() {
|
||||||
return flowableRepository.listNodes();
|
return repository.listNodes();
|
||||||
}
|
}
|
||||||
|
|
||||||
public FlowableNode getNode(String nodeId) {
|
public FlowableNode getNode(String nodeId) {
|
||||||
return flowableRepository.getNode(nodeId);
|
return repository.getNode(nodeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FlowableInstance> listInstances() {
|
public List<FlowableInstance> listInstances() {
|
||||||
return flowableRepository.listInstances();
|
return repository.listInstances();
|
||||||
}
|
}
|
||||||
|
|
||||||
public FlowableInstance getInstance(String instantId) {
|
public FlowableInstance getInstance(String instantId) {
|
||||||
return flowableRepository.getInstance(instantId);
|
return repository.getInstance(instantId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FlowableHistory> listHistories(String instanceId) {
|
public List<FlowableHistory> listHistories(String instanceId) {
|
||||||
return flowableRepository.listHistories(instanceId);
|
return repository.listHistories(instanceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FlowableHistory getHistory(String historyId) {
|
public FlowableHistory getHistory(String historyId) {
|
||||||
return flowableRepository.getHistory(historyId);
|
return repository.getHistory(historyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void create(FlowableNode... node) {
|
public void create(FlowableNode... node) {
|
||||||
flowableRepository.saveNode(ListHelper.of(node));
|
repository.saveNode(ListHelper.of(node));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String start(String nodeId) {
|
public String start(String nodeId) {
|
||||||
@@ -66,9 +66,9 @@ public abstract class FlowableManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String start(String nodeId, Map<String, Object> metadata) {
|
public String start(String nodeId, Map<String, Object> metadata) {
|
||||||
FlowableNode node = flowableRepository.getNode(nodeId);
|
FlowableNode node = repository.getNode(nodeId);
|
||||||
FlowableInstance instance = new FlowableInstance(idGenerator.createId(), node.getNodeId(), metadata);
|
FlowableInstance instance = new FlowableInstance(createId(), node.getNodeId(), metadata);
|
||||||
flowableRepository.saveInstance(instance);
|
repository.saveInstance(instance);
|
||||||
|
|
||||||
if (FlowableNode.Type.AUTOMATIC.equals(node.getType())) {
|
if (FlowableNode.Type.AUTOMATIC.equals(node.getType())) {
|
||||||
autoAction(instance, node, MapHelper.empty());
|
autoAction(instance, node, MapHelper.empty());
|
||||||
@@ -109,8 +109,8 @@ public abstract class FlowableManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void action(String instanceId, FlowableAction action, String comment, Map<String, Object> metadata) {
|
private void action(String instanceId, FlowableAction action, String comment, Map<String, Object> metadata) {
|
||||||
FlowableInstance instance = flowableRepository.getInstance(instanceId);
|
FlowableInstance instance = repository.getInstance(instanceId);
|
||||||
FlowableNode node = flowableRepository.getNode(instance.getCurrentNodeId());
|
FlowableNode node = repository.getNode(instance.getCurrentNodeId());
|
||||||
action(instance, node, action, comment, metadata);
|
action(instance, node, action, comment, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,7 +137,7 @@ public abstract class FlowableManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String nextNodeId = node.getTargets().get(action);
|
String nextNodeId = node.getTargets().get(action);
|
||||||
FlowableNode nextNode = flowableRepository.getNode(nextNodeId);
|
FlowableNode nextNode = repository.getNode(nextNodeId);
|
||||||
instance.setCurrentNodeId(nextNode.getNodeId());
|
instance.setCurrentNodeId(nextNode.getNodeId());
|
||||||
saveInstance(instance, FlowableInstance.Status.RUNNING, metadata, action, comment);
|
saveInstance(instance, FlowableInstance.Status.RUNNING, metadata, action, comment);
|
||||||
|
|
||||||
@@ -153,8 +153,8 @@ public abstract class FlowableManager {
|
|||||||
}
|
}
|
||||||
instance.setUpdatedTime(LocalDateTime.now());
|
instance.setUpdatedTime(LocalDateTime.now());
|
||||||
|
|
||||||
FlowableHistory history = new FlowableHistory(idGenerator.createId(), instance.getInstanceId(), action, comment);
|
FlowableHistory history = new FlowableHistory(createId(), instance.getInstanceId(), action, comment);
|
||||||
flowableRepository.saveInstanceAndHistory(instance, history);
|
repository.saveInstanceAndHistory(instance, history);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void callListeners(List<FlowableListener> listeners, Consumer<FlowableListener> handler) {
|
private void callListeners(List<FlowableListener> listeners, Consumer<FlowableListener> handler) {
|
||||||
@@ -165,7 +165,5 @@ public abstract class FlowableManager {
|
|||||||
|
|
||||||
protected abstract <T> T createBean(String classpath);
|
protected abstract <T> T createBean(String classpath);
|
||||||
|
|
||||||
public interface IdGenerator {
|
protected abstract String createId();
|
||||||
String createId();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,5 +7,5 @@ package com.lanyuanxiaoyao.flowable.core.model;
|
|||||||
* @version 20241231
|
* @version 20241231
|
||||||
*/
|
*/
|
||||||
public interface FlowableAccessor {
|
public interface FlowableAccessor {
|
||||||
void access(String accessor);
|
void access(Object accessor);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.lanyuanxiaoyao.flowable.test;
|
package com.lanyuanxiaoyao.flowable.test;
|
||||||
|
|
||||||
|
import com.lanyuanxiaoyao.flowable.core.manager.FlowableConfiguration;
|
||||||
import com.lanyuanxiaoyao.flowable.core.manager.FlowableManager;
|
import com.lanyuanxiaoyao.flowable.core.manager.FlowableManager;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
@@ -10,7 +11,7 @@ import lombok.SneakyThrows;
|
|||||||
*/
|
*/
|
||||||
public class SimpleFlowableManager extends FlowableManager {
|
public class SimpleFlowableManager extends FlowableManager {
|
||||||
public SimpleFlowableManager() {
|
public SimpleFlowableManager() {
|
||||||
super(new InMemoryFlowableRepository(), () -> UUID.randomUUID().toString());
|
super(FlowableConfiguration.builder().build(), new InMemoryFlowableRepository());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@@ -18,4 +19,9 @@ public class SimpleFlowableManager extends FlowableManager {
|
|||||||
protected <T> T createBean(String classpath) {
|
protected <T> T createBean(String classpath) {
|
||||||
return (T) Class.forName(classpath).newInstance();
|
return (T) Class.forName(classpath).newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String createId() {
|
||||||
|
return UUID.randomUUID().toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user