调整一些接口参数
This commit is contained in:
@@ -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<FlowableAction, String> 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<String> 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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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("节点执行结果不能为空");
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<String> listeners;
|
||||
@Builder.Default
|
||||
private final List<String> listeners = ListHelper.empty();
|
||||
|
||||
@Builder.Default
|
||||
private final LocalDateTime createdTime = LocalDateTime.now();
|
||||
|
||||
@Builder.Default
|
||||
private LocalDateTime updatedTime = LocalDateTime.now();
|
||||
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user