mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-06-13 19:18:16 +08:00
enhancement #I8UQR4 while组件本身加入loopIndex
This commit is contained in:
@@ -39,7 +39,7 @@ public class WhileCondition extends LoopCondition {
|
||||
int index = 0;
|
||||
if(!this.isParallel()){
|
||||
//串行循环
|
||||
while (getWhileResult(slotIndex)) {
|
||||
while (getWhileResult(slotIndex, index)) {
|
||||
executableItem.setCurrChainId(this.getCurrChainId());
|
||||
setLoopIndex(executableItem, index);
|
||||
executableItem.execute(slotIndex);
|
||||
@@ -60,7 +60,7 @@ public class WhileCondition extends LoopCondition {
|
||||
List<CompletableFuture<LoopFutureObj>> futureList = new ArrayList<>();
|
||||
//获取并行循环的线程池
|
||||
ExecutorService parallelExecutor = ExecutorHelper.loadInstance().buildLoopParallelExecutor();
|
||||
while (getWhileResult(slotIndex)){
|
||||
while (getWhileResult(slotIndex, index)){
|
||||
CompletableFuture<LoopFutureObj> future =
|
||||
CompletableFuture.supplyAsync(new LoopParallelSupplier(executableItem, this.getCurrChainId(), slotIndex, index), parallelExecutor);
|
||||
futureList.add(future);
|
||||
@@ -81,10 +81,11 @@ public class WhileCondition extends LoopCondition {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean getWhileResult(Integer slotIndex) throws Exception {
|
||||
Executable whileItem = this.getWhileItem();
|
||||
private boolean getWhileResult(Integer slotIndex, int loopIndex) throws Exception {
|
||||
Node whileItem = (Node) this.getWhileItem();
|
||||
// 执行while组件
|
||||
whileItem.setCurrChainId(this.getCurrChainId());
|
||||
whileItem.setLoopIndex(loopIndex);
|
||||
whileItem.execute(slotIndex);
|
||||
|
||||
return whileItem.getItemResultMetaValue(slotIndex);
|
||||
|
||||
@@ -15,7 +15,6 @@ public class CCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println(this.getLoopIndex());
|
||||
System.out.println("CCmp executed!");
|
||||
}
|
||||
|
||||
|
||||
@@ -16,15 +16,7 @@ public class DCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
DefaultContext context = this.getFirstContextBean();
|
||||
String key = "test";
|
||||
if (context.hasData(key)) {
|
||||
int count = context.getData(key);
|
||||
context.setData(key, ++count);
|
||||
}
|
||||
else {
|
||||
context.setData(key, 1);
|
||||
}
|
||||
System.out.println("DCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,9 +10,7 @@ public class YCmp extends NodeBreakComponent {
|
||||
|
||||
@Override
|
||||
public boolean processBreak() throws Exception {
|
||||
DefaultContext context = this.getFirstContextBean();
|
||||
int count = context.getData("test");
|
||||
return count > 3;
|
||||
return this.getLoopIndex() > 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,15 +10,7 @@ public class ZCmp extends NodeWhileComponent {
|
||||
|
||||
@Override
|
||||
public boolean processWhile() throws Exception {
|
||||
DefaultContext context = this.getFirstContextBean();
|
||||
String key = "test";
|
||||
if (context.hasData(key)) {
|
||||
int count = context.getData("test");
|
||||
return count < 5;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
return this.getLoopIndex()<5;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user