调整一些接口参数
This commit is contained in:
@@ -2,6 +2,7 @@ package com.lanyuanxiaoyao.flowable.jpa.entity;
|
|||||||
|
|
||||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableAction;
|
import com.lanyuanxiaoyao.flowable.core.model.FlowableAction;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.persistence.CollectionTable;
|
import javax.persistence.CollectionTable;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
@@ -13,7 +14,6 @@ import javax.persistence.EnumType;
|
|||||||
import javax.persistence.Enumerated;
|
import javax.persistence.Enumerated;
|
||||||
import javax.persistence.ForeignKey;
|
import javax.persistence.ForeignKey;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.MapKeyColumn;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -44,13 +44,18 @@ public class FlowableNode {
|
|||||||
@Enumerated(EnumType.STRING)
|
@Enumerated(EnumType.STRING)
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private com.lanyuanxiaoyao.flowable.core.model.FlowableNode.Type type;
|
private com.lanyuanxiaoyao.flowable.core.model.FlowableNode.Type type;
|
||||||
|
@Column(nullable = false)
|
||||||
private String handler;
|
private String handler;
|
||||||
@ElementCollection(fetch = javax.persistence.FetchType.EAGER)
|
@ElementCollection(fetch = javax.persistence.FetchType.EAGER)
|
||||||
@MapKeyColumn(name = "action")
|
|
||||||
@Column(name = "nodeId")
|
|
||||||
@CollectionTable(name = "flowable_node_targets", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
@CollectionTable(name = "flowable_node_targets", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||||
private Map<FlowableAction, String> targets;
|
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
|
@CreatedDate
|
||||||
private LocalDateTime createdTime;
|
private LocalDateTime createdTime;
|
||||||
@LastModifiedDate
|
@LastModifiedDate
|
||||||
@@ -63,6 +68,8 @@ public class FlowableNode {
|
|||||||
this.type = node.getType();
|
this.type = node.getType();
|
||||||
this.handler = node.getHandler();
|
this.handler = node.getHandler();
|
||||||
this.targets = node.getTargets();
|
this.targets = node.getTargets();
|
||||||
|
this.accessor = node.getAccessor();
|
||||||
|
this.listeners = node.getListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
public com.lanyuanxiaoyao.flowable.core.model.FlowableNode toFlowableNode() {
|
public com.lanyuanxiaoyao.flowable.core.model.FlowableNode toFlowableNode() {
|
||||||
@@ -73,6 +80,8 @@ public class FlowableNode {
|
|||||||
.type(type)
|
.type(type)
|
||||||
.handler(handler)
|
.handler(handler)
|
||||||
.targets(targets)
|
.targets(targets)
|
||||||
|
.accessor(accessor)
|
||||||
|
.listeners(listeners)
|
||||||
.createdTime(createdTime)
|
.createdTime(createdTime)
|
||||||
.updatedTime(updateTime)
|
.updatedTime(updateTime)
|
||||||
.build();
|
.build();
|
||||||
|
|||||||
@@ -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.model.FlowableAction;
|
import com.lanyuanxiaoyao.flowable.core.model.FlowableAction;
|
||||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableHandler;
|
import com.lanyuanxiaoyao.flowable.core.model.FlowableHandler;
|
||||||
@@ -18,7 +19,7 @@ public class SimpleAutoAction implements FlowableHandler {
|
|||||||
private FlowableManager flowableManager;
|
private FlowableManager flowableManager;
|
||||||
|
|
||||||
@Override
|
@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());
|
log.info("Initial with spring: {}", flowableManager.listNodes());
|
||||||
return FlowableAction.APPROVE;
|
return FlowableAction.APPROVE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ public abstract class FlowableManager {
|
|||||||
throw new IllegalArgumentException("权限检查器为空");
|
throw new IllegalArgumentException("权限检查器为空");
|
||||||
}
|
}
|
||||||
FlowableAccessor accessor = createBean(accessorClass);
|
FlowableAccessor accessor = createBean(accessorClass);
|
||||||
if (!accessor.access(instance.getMetadata())) {
|
if (!accessor.access(configuration, instance, node, action)) {
|
||||||
throw new IllegalArgumentException("权限校验不通过");
|
throw new IllegalArgumentException("权限校验不通过");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,7 +151,7 @@ public abstract class FlowableManager {
|
|||||||
throw new IllegalArgumentException("节点执行器为空");
|
throw new IllegalArgumentException("节点执行器为空");
|
||||||
}
|
}
|
||||||
FlowableHandler handler = createBean(handlerClass);
|
FlowableHandler handler = createBean(handlerClass);
|
||||||
action = handler.handle(instance, node, action);
|
action = handler.handle(configuration, instance, node, action);
|
||||||
if (Objects.isNull(action)) {
|
if (Objects.isNull(action)) {
|
||||||
throw new IllegalArgumentException("节点执行结果不能为空");
|
throw new IllegalArgumentException("节点执行结果不能为空");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.lanyuanxiaoyao.flowable.core.model;
|
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
|
* @version 20241231
|
||||||
*/
|
*/
|
||||||
public interface FlowableAccessor {
|
public interface FlowableAccessor {
|
||||||
boolean access(FlowableMetadata metadata);
|
boolean access(FlowableConfiguration configuration, FlowableInstance instance, FlowableNode node, FlowableAction action);
|
||||||
|
|
||||||
class DefaultFlowableAccessor implements FlowableAccessor {
|
class DefaultFlowableAccessor implements FlowableAccessor {
|
||||||
@Override
|
@Override
|
||||||
public boolean access(FlowableMetadata metadata) {
|
public boolean access(FlowableConfiguration configuration, FlowableInstance instance, FlowableNode node, FlowableAction action) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.lanyuanxiaoyao.flowable.core.model;
|
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
|
* @version 20250103
|
||||||
*/
|
*/
|
||||||
public interface FlowableHandler {
|
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 {
|
class DefaultFlowableHandler implements FlowableHandler {
|
||||||
@Override
|
@Override
|
||||||
public FlowableAction handle(FlowableInstance instance, FlowableNode node, FlowableAction action) {
|
public FlowableAction handle(FlowableConfiguration configuration, FlowableInstance instance, FlowableNode node, FlowableAction action) {
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.lanyuanxiaoyao.flowable.core.model;
|
package com.lanyuanxiaoyao.flowable.core.model;
|
||||||
|
|
||||||
|
import com.lanyuanxiaoyao.flowable.core.helper.ListHelper;
|
||||||
import com.lanyuanxiaoyao.flowable.core.helper.MapHelper;
|
import com.lanyuanxiaoyao.flowable.core.helper.MapHelper;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -31,10 +32,11 @@ public class FlowableNode {
|
|||||||
|
|
||||||
@Builder.Default
|
@Builder.Default
|
||||||
private final String accessor = FlowableAccessor.DefaultFlowableAccessor.class.getName();
|
private final String accessor = FlowableAccessor.DefaultFlowableAccessor.class.getName();
|
||||||
private final List<String> listeners;
|
@Builder.Default
|
||||||
|
private final List<String> listeners = ListHelper.empty();
|
||||||
|
|
||||||
@Builder.Default
|
@Builder.Default
|
||||||
private final LocalDateTime createdTime = LocalDateTime.now();
|
private final LocalDateTime createdTime = LocalDateTime.now();
|
||||||
|
|
||||||
@Builder.Default
|
@Builder.Default
|
||||||
private LocalDateTime updatedTime = LocalDateTime.now();
|
private LocalDateTime updatedTime = LocalDateTime.now();
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,22 @@
|
|||||||
package com.lanyuanxiaoyao.flowable.test.accessor;
|
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.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.FlowableMetadata;
|
||||||
|
import com.lanyuanxiaoyao.flowable.core.model.FlowableNode;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lanyuanxiaoyao
|
* @author lanyuanxiaoyao
|
||||||
* @version 20250103
|
* @version 20250103
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
public class RoleCheckAccessor implements FlowableAccessor {
|
public class RoleCheckAccessor implements FlowableAccessor {
|
||||||
@Override
|
@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");
|
return metadata.containsKey("role");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.lanyuanxiaoyao.flowable.test.handler;
|
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.FlowableAction;
|
||||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableHandler;
|
import com.lanyuanxiaoyao.flowable.core.model.FlowableHandler;
|
||||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance;
|
import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance;
|
||||||
@@ -18,7 +19,7 @@ public class TwoApproveHandler implements FlowableHandler {
|
|||||||
private static final String KEY = "approve-times";
|
private static final String KEY = "approve-times";
|
||||||
|
|
||||||
@Override
|
@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());
|
log.info("{}", instance.getMetadata());
|
||||||
FlowableMetadata metadata = instance.getMetadata();
|
FlowableMetadata metadata = instance.getMetadata();
|
||||||
int approveCount = metadata.getIntOrDefault(KEY, 0);
|
int approveCount = metadata.getIntOrDefault(KEY, 0);
|
||||||
|
|||||||
@@ -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.model.FlowableAction;
|
import com.lanyuanxiaoyao.flowable.core.model.FlowableAction;
|
||||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableHandler;
|
import com.lanyuanxiaoyao.flowable.core.model.FlowableHandler;
|
||||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance;
|
import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance;
|
||||||
@@ -13,7 +14,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class SimpleAutoHandler implements FlowableHandler {
|
public class SimpleAutoHandler implements FlowableHandler {
|
||||||
@Override
|
@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");
|
log.info("Simple handler initial");
|
||||||
return FlowableAction.APPROVE;
|
return FlowableAction.APPROVE;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user