增加挂起操作
This commit is contained in:
@@ -6,6 +6,7 @@ import com.lanyuanxiaoyao.flowable.core.model.FlowableAction;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableHandler;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableNode;
|
||||
import com.lanyuanxiaoyao.flowable.test.handler.TwoApproveHandler;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -121,6 +122,27 @@ public abstract class TestFlowableManager {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> manager.approve(instanceId));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuspend() {
|
||||
FlowableManager manager = flowableManager();
|
||||
FlowableNode node = new FlowableNode(
|
||||
"edf1b7b0-f45b-4256-b696-ce84857f03f7",
|
||||
"edf1b7b0-f45b-4256-b696-ce84857f03f7",
|
||||
"edf1b7b0-f45b-4256-b696-ce84857f03f7",
|
||||
FlowableNode.Type.MANUAL,
|
||||
TwoApproveHandler.class,
|
||||
null
|
||||
);
|
||||
manager.create(node);
|
||||
|
||||
String instanceId = manager.start(node.getNodeId());
|
||||
Assertions.assertEquals(FlowableInstance.Status.RUNNING, manager.getInstance(instanceId).getStatus());
|
||||
manager.approve(instanceId);
|
||||
Assertions.assertEquals(FlowableInstance.Status.RUNNING, manager.getInstance(instanceId).getStatus());
|
||||
manager.approve(instanceId);
|
||||
Assertions.assertEquals(FlowableInstance.Status.COMPLETED, manager.getInstance(instanceId).getStatus());
|
||||
}
|
||||
|
||||
protected abstract Class<? extends FlowableHandler> getAutomaticNodeClass();
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.lanyuanxiaoyao.flowable.test.handler;
|
||||
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableAction;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableHandler;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableNode;
|
||||
import java.util.Map;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 同意两次才能通过的自动节点
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250103
|
||||
*/
|
||||
@Slf4j
|
||||
public class TwoApproveHandler implements FlowableHandler {
|
||||
private static final String KEY = "approve-times";
|
||||
|
||||
@Override
|
||||
public FlowableAction handle(FlowableAction action, FlowableInstance instance, FlowableNode node, Map<String, Object> metadata) {
|
||||
log.info("{}", metadata);
|
||||
int approveCount = (int) metadata.getOrDefault(KEY, 0);
|
||||
if (approveCount + 1 > 1) {
|
||||
return FlowableAction.APPROVE;
|
||||
}
|
||||
metadata.put(KEY, approveCount + 1);
|
||||
return FlowableAction.SUSPEND;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user