feat: 新增获取循环对象节点

This commit is contained in:
stream 2026-03-17 16:52:30 +08:00
parent f365d94077
commit 264eb3e5ad
6 changed files with 52 additions and 18 deletions

View File

@ -11,7 +11,6 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
@ -108,20 +107,4 @@ public class ViCorpusController extends BaseController {
public AjaxResult continuousRemove(@RequestBody String[] parentIds) { public AjaxResult continuousRemove(@RequestBody String[] parentIds) {
return toAjax(viCorpusService.deleteViCorpusByParentIds(parentIds)); return toAjax(viCorpusService.deleteViCorpusByParentIds(parentIds));
} }
/* @ApiOperation("批量修改")
@PreAuthorize("@ss.hasPermi('vi:corpus:edit')")
@PostMapping("/updateBatch")
public AjaxResult updateBatch(@RequestBody List<ViCorpus> data) {
return toAjax(viCorpusService.updateBatch(data));
}*/
/* @ApiOperation("批量新增/修改")
@PreAuthorize("@ss.hasPermi('vi:corpus:edit')")
@PostMapping("/insertOrUpdateBatch")
public AjaxResult insertOrUpdateBatch(@RequestBody List<ViCorpus> data) {
return toAjax(viCorpusService.insertOrUpdateBatch(data));
}*/
} }

View File

@ -25,6 +25,7 @@ public enum ActionEnum {
SLEEP("NONE", "SLEEP", "延迟节点"), SLEEP("NONE", "SLEEP", "延迟节点"),
HTTP("NONE", "HTTP", "HTTP调用"), HTTP("NONE", "HTTP", "HTTP调用"),
CODE("NONE", "CODE", "代码执行"), CODE("NONE", "CODE", "代码执行"),
GET_CURRENT_OBJECT("NONE", "GET_CURRENT_OBJECT", "获取当前循环对象"),
// AI评估 // AI评估
AI_EVALUATION_PRE("AE", "AI_EVALUATION_PRE", "AI评估预处理"), AI_EVALUATION_PRE("AE", "AI_EVALUATION_PRE", "AI评估预处理"),
// AI评估 // AI评估

View File

@ -20,6 +20,7 @@ public enum NodeTypeEnum {
SLEEP("sleep"), SLEEP("sleep"),
HTTP("http"), HTTP("http"),
CODE("code"), CODE("code"),
GET_CURRENT_OBJECT("getCurrentObject"),
SUB_END("subEnd"), SUB_END("subEnd"),
; ;

View File

@ -290,6 +290,8 @@ public class FlowModelBuilder {
return NodeTypeEnum.HTTP; return NodeTypeEnum.HTTP;
case "code": case "code":
return NodeTypeEnum.CODE; return NodeTypeEnum.CODE;
case "currentloop":
return NodeTypeEnum.GET_CURRENT_OBJECT;
default: default:
return NodeTypeEnum.FUNCTION; return NodeTypeEnum.FUNCTION;
} }

View File

@ -0,0 +1,40 @@
package com.cmvr.test.flow.runtime.dispatcher;
import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.cmvr.test.flow.runtime.message.TaskNodeExecuteMessage;
import com.cmvr.test.flow.runtime.message.TaskNodeExecuteResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.List;
@Slf4j
@Component("GET_CURRENT_OBJECT")
public class FlowGetCurrentObjNodeHandler implements FlowNodeTypeHandler {
@Override
public TaskNodeExecuteResult handle(TaskNodeExecuteMessage message) {
try {
JSONObject inputParams = message.getInputParams();
JSONArray jsonArray = inputParams.getJSONArray("array");
List<Integer> iterations = message.getIterations();
int last = CollUtil.getLast(iterations) - 1;
Object o = jsonArray.get(last);
JSONObject output = new JSONObject();
output.put("index", last);
output.put("object", o);
return TaskNodeExecuteResult.success(output);
} catch (Exception e) {
log.error("[FLOW][GET_CURRENT_OBJECT] 执行异常", e);
return TaskNodeExecuteResult.failure(e.getMessage());
}
}
}

View File

@ -1,6 +1,7 @@
package com.cmvr.test.flow.runtime.engine.support; package com.cmvr.test.flow.runtime.engine.support;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.cmvr.common.exception.GlobalException; import com.cmvr.common.exception.GlobalException;
@ -99,7 +100,13 @@ public class FlowNodeParamPreparer {
loopCount = ((Number) target).intValue(); loopCount = ((Number) target).intValue();
} else if (target != null) { } else if (target != null) {
try { try {
loopCount = Integer.parseInt(target.toString()); String string = target.toString();
if (string.startsWith("[")) {
JSONArray array = JSON.parseArray(string);
loopCount = array.size();
}else {
loopCount = Integer.parseInt(string);
}
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw new GlobalException("loopNum 参数格式错误: " + loopNumVal); throw new GlobalException("loopNum 参数格式错误: " + loopNumVal);
} }