diff --git a/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/entity/FlowableNode.java b/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/entity/FlowableNode.java index c17063b..15bec8e 100644 --- a/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/entity/FlowableNode.java +++ b/adapter/flowable-spring-boot-jpa-starter/src/main/java/com/lanyuanxiaoyao/flowable/jpa/entity/FlowableNode.java @@ -2,6 +2,7 @@ package com.lanyuanxiaoyao.flowable.jpa.entity; import com.lanyuanxiaoyao.flowable.core.model.FlowableAction; import java.time.LocalDateTime; +import java.util.List; import java.util.Map; import javax.persistence.CollectionTable; import javax.persistence.Column; @@ -13,7 +14,6 @@ import javax.persistence.EnumType; import javax.persistence.Enumerated; import javax.persistence.ForeignKey; import javax.persistence.Id; -import javax.persistence.MapKeyColumn; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -44,13 +44,18 @@ public class FlowableNode { @Enumerated(EnumType.STRING) @Column(nullable = false) private com.lanyuanxiaoyao.flowable.core.model.FlowableNode.Type type; + @Column(nullable = false) private String handler; @ElementCollection(fetch = javax.persistence.FetchType.EAGER) - @MapKeyColumn(name = "action") - @Column(name = "nodeId") @CollectionTable(name = "flowable_node_targets", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) private Map targets; + @Column(nullable = false) + private String accessor; + @ElementCollection(fetch = javax.persistence.FetchType.EAGER) + @CollectionTable(name = "flowable_node_listeners", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) + private List listeners; + @CreatedDate private LocalDateTime createdTime; @LastModifiedDate @@ -63,6 +68,8 @@ public class FlowableNode { this.type = node.getType(); this.handler = node.getHandler(); this.targets = node.getTargets(); + this.accessor = node.getAccessor(); + this.listeners = node.getListeners(); } public com.lanyuanxiaoyao.flowable.core.model.FlowableNode toFlowableNode() { @@ -73,6 +80,8 @@ public class FlowableNode { .type(type) .handler(handler) .targets(targets) + .accessor(accessor) + .listeners(listeners) .createdTime(createdTime) .updatedTime(updateTime) .build(); diff --git a/adapter/flowable-spring-boot-jpa-starter/src/test/java/com/lanyuanxiaoyao/flowable/jpa/SimpleAutoAction.java b/adapter/flowable-spring-boot-jpa-starter/src/test/java/com/lanyuanxiaoyao/flowable/jpa/SimpleAutoAction.java index e07cc71..eaf0c54 100644 --- a/adapter/flowable-spring-boot-jpa-starter/src/test/java/com/lanyuanxiaoyao/flowable/jpa/SimpleAutoAction.java +++ b/adapter/flowable-spring-boot-jpa-starter/src/test/java/com/lanyuanxiaoyao/flowable/jpa/SimpleAutoAction.java @@ -1,5 +1,6 @@ package com.lanyuanxiaoyao.flowable.jpa; +import com.lanyuanxiaoyao.flowable.core.manager.FlowableConfiguration; import com.lanyuanxiaoyao.flowable.core.manager.FlowableManager; import com.lanyuanxiaoyao.flowable.core.model.FlowableAction; import com.lanyuanxiaoyao.flowable.core.model.FlowableHandler; @@ -18,7 +19,7 @@ public class SimpleAutoAction implements FlowableHandler { private FlowableManager flowableManager; @Override - public FlowableAction handle(FlowableInstance instance, FlowableNode node, FlowableAction action) { + public FlowableAction handle(FlowableConfiguration configuration, FlowableInstance instance, FlowableNode node, FlowableAction action) { log.info("Initial with spring: {}", flowableManager.listNodes()); return FlowableAction.APPROVE; } diff --git a/flowable-core/src/main/java/com/lanyuanxiaoyao/flowable/core/manager/FlowableManager.java b/flowable-core/src/main/java/com/lanyuanxiaoyao/flowable/core/manager/FlowableManager.java index a63c69a..74c4f10 100644 --- a/flowable-core/src/main/java/com/lanyuanxiaoyao/flowable/core/manager/FlowableManager.java +++ b/flowable-core/src/main/java/com/lanyuanxiaoyao/flowable/core/manager/FlowableManager.java @@ -142,7 +142,7 @@ public abstract class FlowableManager { throw new IllegalArgumentException("权限检查器为空"); } FlowableAccessor accessor = createBean(accessorClass); - if (!accessor.access(instance.getMetadata())) { + if (!accessor.access(configuration, instance, node, action)) { throw new IllegalArgumentException("权限校验不通过"); } @@ -151,7 +151,7 @@ public abstract class FlowableManager { throw new IllegalArgumentException("节点执行器为空"); } FlowableHandler handler = createBean(handlerClass); - action = handler.handle(instance, node, action); + action = handler.handle(configuration, instance, node, action); if (Objects.isNull(action)) { throw new IllegalArgumentException("节点执行结果不能为空"); } diff --git a/flowable-core/src/main/java/com/lanyuanxiaoyao/flowable/core/model/FlowableAccessor.java b/flowable-core/src/main/java/com/lanyuanxiaoyao/flowable/core/model/FlowableAccessor.java index 8dadcc0..c465c2e 100644 --- a/flowable-core/src/main/java/com/lanyuanxiaoyao/flowable/core/model/FlowableAccessor.java +++ b/flowable-core/src/main/java/com/lanyuanxiaoyao/flowable/core/model/FlowableAccessor.java @@ -1,5 +1,7 @@ package com.lanyuanxiaoyao.flowable.core.model; +import com.lanyuanxiaoyao.flowable.core.manager.FlowableConfiguration; + /** * 权限校验 * @@ -7,11 +9,11 @@ package com.lanyuanxiaoyao.flowable.core.model; * @version 20241231 */ public interface FlowableAccessor { - boolean access(FlowableMetadata metadata); + boolean access(FlowableConfiguration configuration, FlowableInstance instance, FlowableNode node, FlowableAction action); class DefaultFlowableAccessor implements FlowableAccessor { @Override - public boolean access(FlowableMetadata metadata) { + public boolean access(FlowableConfiguration configuration, FlowableInstance instance, FlowableNode node, FlowableAction action) { return true; } } diff --git a/flowable-core/src/main/java/com/lanyuanxiaoyao/flowable/core/model/FlowableHandler.java b/flowable-core/src/main/java/com/lanyuanxiaoyao/flowable/core/model/FlowableHandler.java index f77c212..f336251 100644 --- a/flowable-core/src/main/java/com/lanyuanxiaoyao/flowable/core/model/FlowableHandler.java +++ b/flowable-core/src/main/java/com/lanyuanxiaoyao/flowable/core/model/FlowableHandler.java @@ -1,5 +1,7 @@ package com.lanyuanxiaoyao.flowable.core.model; +import com.lanyuanxiaoyao.flowable.core.manager.FlowableConfiguration; + /** * 处理器 * @@ -7,11 +9,11 @@ package com.lanyuanxiaoyao.flowable.core.model; * @version 20250103 */ public interface FlowableHandler { - FlowableAction handle(FlowableInstance instance, FlowableNode node, FlowableAction action); + FlowableAction handle(FlowableConfiguration configuration, FlowableInstance instance, FlowableNode node, FlowableAction action); class DefaultFlowableHandler implements FlowableHandler { @Override - public FlowableAction handle(FlowableInstance instance, FlowableNode node, FlowableAction action) { + public FlowableAction handle(FlowableConfiguration configuration, FlowableInstance instance, FlowableNode node, FlowableAction action) { return action; } } diff --git a/flowable-core/src/main/java/com/lanyuanxiaoyao/flowable/core/model/FlowableNode.java b/flowable-core/src/main/java/com/lanyuanxiaoyao/flowable/core/model/FlowableNode.java index 24439da..48735d8 100644 --- a/flowable-core/src/main/java/com/lanyuanxiaoyao/flowable/core/model/FlowableNode.java +++ b/flowable-core/src/main/java/com/lanyuanxiaoyao/flowable/core/model/FlowableNode.java @@ -1,5 +1,6 @@ package com.lanyuanxiaoyao.flowable.core.model; +import com.lanyuanxiaoyao.flowable.core.helper.ListHelper; import com.lanyuanxiaoyao.flowable.core.helper.MapHelper; import java.time.LocalDateTime; import java.util.List; @@ -31,10 +32,11 @@ public class FlowableNode { @Builder.Default private final String accessor = FlowableAccessor.DefaultFlowableAccessor.class.getName(); - private final List listeners; + @Builder.Default + private final List listeners = ListHelper.empty(); + @Builder.Default private final LocalDateTime createdTime = LocalDateTime.now(); - @Builder.Default private LocalDateTime updatedTime = LocalDateTime.now(); diff --git a/flowable-example/src/main/java/com/lanyuanxiaoyao/flowable/test/accessor/RoleCheckAccessor.java b/flowable-example/src/main/java/com/lanyuanxiaoyao/flowable/test/accessor/RoleCheckAccessor.java index f38b77d..101cf2d 100644 --- a/flowable-example/src/main/java/com/lanyuanxiaoyao/flowable/test/accessor/RoleCheckAccessor.java +++ b/flowable-example/src/main/java/com/lanyuanxiaoyao/flowable/test/accessor/RoleCheckAccessor.java @@ -1,15 +1,22 @@ package com.lanyuanxiaoyao.flowable.test.accessor; +import com.lanyuanxiaoyao.flowable.core.manager.FlowableConfiguration; import com.lanyuanxiaoyao.flowable.core.model.FlowableAccessor; +import com.lanyuanxiaoyao.flowable.core.model.FlowableAction; +import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance; import com.lanyuanxiaoyao.flowable.core.model.FlowableMetadata; +import com.lanyuanxiaoyao.flowable.core.model.FlowableNode; +import lombok.extern.slf4j.Slf4j; /** * @author lanyuanxiaoyao * @version 20250103 */ +@Slf4j public class RoleCheckAccessor implements FlowableAccessor { @Override - public boolean access(FlowableMetadata metadata) { + public boolean access(FlowableConfiguration configuration, FlowableInstance instance, FlowableNode node, FlowableAction action) { + FlowableMetadata metadata = instance.getMetadata(); return metadata.containsKey("role"); } } diff --git a/flowable-example/src/main/java/com/lanyuanxiaoyao/flowable/test/handler/TwoApproveHandler.java b/flowable-example/src/main/java/com/lanyuanxiaoyao/flowable/test/handler/TwoApproveHandler.java index 26cb732..0de7d42 100644 --- a/flowable-example/src/main/java/com/lanyuanxiaoyao/flowable/test/handler/TwoApproveHandler.java +++ b/flowable-example/src/main/java/com/lanyuanxiaoyao/flowable/test/handler/TwoApproveHandler.java @@ -1,5 +1,6 @@ package com.lanyuanxiaoyao.flowable.test.handler; +import com.lanyuanxiaoyao.flowable.core.manager.FlowableConfiguration; import com.lanyuanxiaoyao.flowable.core.model.FlowableAction; import com.lanyuanxiaoyao.flowable.core.model.FlowableHandler; import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance; @@ -18,7 +19,7 @@ public class TwoApproveHandler implements FlowableHandler { private static final String KEY = "approve-times"; @Override - public FlowableAction handle(FlowableInstance instance, FlowableNode node, FlowableAction action) { + public FlowableAction handle(FlowableConfiguration configuration, FlowableInstance instance, FlowableNode node, FlowableAction action) { log.info("{}", instance.getMetadata()); FlowableMetadata metadata = instance.getMetadata(); int approveCount = metadata.getIntOrDefault(KEY, 0); diff --git a/flowable-example/src/test/java/com/lanyuanxiaoyao/flowable/test/SimpleAutoHandler.java b/flowable-example/src/test/java/com/lanyuanxiaoyao/flowable/test/SimpleAutoHandler.java index a71a8cb..ec60314 100644 --- a/flowable-example/src/test/java/com/lanyuanxiaoyao/flowable/test/SimpleAutoHandler.java +++ b/flowable-example/src/test/java/com/lanyuanxiaoyao/flowable/test/SimpleAutoHandler.java @@ -1,5 +1,6 @@ package com.lanyuanxiaoyao.flowable.test; +import com.lanyuanxiaoyao.flowable.core.manager.FlowableConfiguration; import com.lanyuanxiaoyao.flowable.core.model.FlowableAction; import com.lanyuanxiaoyao.flowable.core.model.FlowableHandler; import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance; @@ -13,7 +14,7 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public class SimpleAutoHandler implements FlowableHandler { @Override - public FlowableAction handle(FlowableInstance instance, FlowableNode node, FlowableAction action) { + public FlowableAction handle(FlowableConfiguration configuration, FlowableInstance instance, FlowableNode node, FlowableAction action) { log.info("Simple handler initial"); return FlowableAction.APPROVE; }