mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 12:12:08 +08:00
enhancement #I5VJ85 循环组件支持获取当前循环的下标
This commit is contained in:
@@ -4,6 +4,7 @@ import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.core.FlowExecutorHolder;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.property.LiteflowConfig;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
@@ -58,4 +59,26 @@ public class LoopTest extends BaseTest{
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y==>z==>a==>d==>y", response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
//测试FOR循环中的index
|
||||
@Test
|
||||
public void testLoop6() throws Exception{
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("01234", context.getData("loop_e1"));
|
||||
Assert.assertEquals("01234", context.getData("loop_e2"));
|
||||
Assert.assertEquals("01234", context.getData("loop_e3"));
|
||||
}
|
||||
|
||||
//测试WHILE循环中的index
|
||||
@Test
|
||||
public void testLoop7() throws Exception{
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("01234", context.getData("loop_e1"));
|
||||
Assert.assertEquals("01234", context.getData("loop_e2"));
|
||||
Assert.assertEquals("01234", context.getData("loop_e3"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.test.loop.cmp;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
|
||||
public class ECmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
DefaultContext context = this.getFirstContextBean();
|
||||
String key = StrUtil.format("{}_{}", "loop", this.getTag());
|
||||
if (context.hasData(key)){
|
||||
String loopStr = context.getData(key);
|
||||
String loopStrReturn = StrUtil.format("{}{}", loopStr, this.getLoopIndex());
|
||||
context.setData(key, loopStrReturn);
|
||||
}else{
|
||||
context.setData(key, this.getLoopIndex().toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
<node id="b" class="com.yomahub.liteflow.test.loop.cmp.BCmp"/>
|
||||
<node id="c" class="com.yomahub.liteflow.test.loop.cmp.CCmp"/>
|
||||
<node id="d" class="com.yomahub.liteflow.test.loop.cmp.DCmp"/>
|
||||
<node id="e" class="com.yomahub.liteflow.test.loop.cmp.ECmp"/>
|
||||
<node id="x" class="com.yomahub.liteflow.test.loop.cmp.XCmp"/>
|
||||
<node id="y" class="com.yomahub.liteflow.test.loop.cmp.YCmp"/>
|
||||
<node id="z" class="com.yomahub.liteflow.test.loop.cmp.ZCmp"/>
|
||||
@@ -29,4 +30,24 @@
|
||||
<chain name="chain5">
|
||||
WHILE(z).DO(THEN(a,d)).BREAK(y);
|
||||
</chain>
|
||||
|
||||
<chain name="chain6">
|
||||
FOR(5).DO(
|
||||
WHEN(
|
||||
THEN(a, e.tag("e1")),
|
||||
THEN(c, e.tag("e2")),
|
||||
THEN(b, e.tag("e3"))
|
||||
)
|
||||
);
|
||||
</chain>
|
||||
|
||||
<chain name="chain7">
|
||||
WHILE(z).DO(
|
||||
WHEN(
|
||||
THEN(d, e.tag("e1")),
|
||||
THEN(a, e.tag("e2")),
|
||||
THEN(c, e.tag("e3"))
|
||||
)
|
||||
);
|
||||
</chain>
|
||||
</flow>
|
||||
Reference in New Issue
Block a user