From 9f5cac925eb8be622d852e880452120703c93cef Mon Sep 17 00:00:00 2001 From: lixiaolong <702156524@qq.com> Date: Tue, 17 Mar 2026 17:21:35 +0800 Subject: [PATCH] =?UTF-8?q?refactor(flow):=20=E4=BC=98=E5=8C=96=E8=BE=B9?= =?UTF-8?q?=E7=BC=98=E7=9B=B8=E6=9C=BA=E6=93=8D=E4=BD=9C=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=92=8C=E4=BB=A3=E7=A0=81=E8=8A=82=E7=82=B9=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 EdgeCameraOperateService 中图像URL获取逻辑,使用 getRGBDImages 方法替代硬编码URL - 在 FlowCodeNodeHandler 中将执行结果包装为统一的JSON对象格式 - 更新 NashornJsExecutor 返回类型从 JSONObject 改为 Object 以支持多种返回值类型 - 移除 JSON 结果解析直接返回字符串避免序列化问题 - 在 SecurityConfig 中扩展允许匿名访问的路径配置 --- .../cmvr/framework/config/SecurityConfig.java | 4 +++- .../dispatcher/FlowCodeNodeHandler.java | 5 ++-- .../edge/EdgeCameraOperateService.java | 24 ++++++++++--------- .../com/cmvr/test/util/NashornJsExecutor.java | 12 +++++----- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/cmvr-iot-framework/src/main/java/com/cmvr/framework/config/SecurityConfig.java b/cmvr-iot-framework/src/main/java/com/cmvr/framework/config/SecurityConfig.java index 11270f5..072eb59 100644 --- a/cmvr-iot-framework/src/main/java/com/cmvr/framework/config/SecurityConfig.java +++ b/cmvr-iot-framework/src/main/java/com/cmvr/framework/config/SecurityConfig.java @@ -114,7 +114,9 @@ public class SecurityConfig requests.antMatchers("/login", "/register", "/captchaImage").permitAll() // 静态资源,可匿名访问 .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll() - .antMatchers("/system/file/upload","/evaluation/callback","/flow/**","/flowise/**","/kws/**","/ws/**","/api/grpc/**","/show/**","/node-red/**","/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll() + .antMatchers("/system/file/upload","/evaluation/callback","/flow/**","/flowise/**","/kws/**","/ws/**","/api/grpc/**","/show/**", + "/node-red/**","/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**", + "/ti/ui/findNextClickToFunction", "/ti/function/**").permitAll() // 除上面外的所有请求全部需要鉴权认证 .anyRequest().authenticated(); }) diff --git a/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/dispatcher/FlowCodeNodeHandler.java b/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/dispatcher/FlowCodeNodeHandler.java index 4844b87..df672a9 100644 --- a/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/dispatcher/FlowCodeNodeHandler.java +++ b/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/dispatcher/FlowCodeNodeHandler.java @@ -23,8 +23,9 @@ public class FlowCodeNodeHandler implements FlowNodeTypeHandler { String code = inputParams.getString("code"); inputParams.remove("code"); log.info("code 节点 {} 开始执行", nodeId); - JSONObject execute = nashornJsExecutor.execute(code, inputParams); + Object execute = nashornJsExecutor.execute(code, inputParams); + log.info("code 节点 {} 执行完成", nodeId); - return TaskNodeExecuteResult.success(execute); + return TaskNodeExecuteResult.success(JSONObject.of("result", execute)); } } diff --git a/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/edge/EdgeCameraOperateService.java b/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/edge/EdgeCameraOperateService.java index 93c53dc..b6b2e94 100644 --- a/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/edge/EdgeCameraOperateService.java +++ b/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/edge/EdgeCameraOperateService.java @@ -1,6 +1,8 @@ package com.cmvr.test.flow.runtime.operator.edge; +import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; import com.cmvr.common.enums.FileType; import com.cmvr.common.exception.GlobalException; @@ -85,18 +87,18 @@ public class EdgeCameraOperateService implements EdgeOperateService { // // 驾驶偏好 // imageUrl = "http://192.168.1.100:9000/cmvr-iot/FILE/20250822/1755849654731.jpg"; // } - String imageUrl = "http://192.168.1.100:9000/cmvr-iot/IMAGE/20250901/1756718594725.jpg"; -// String imageUrl = edgeCameraService.getRGBDImages(terminalId, deviceId); +// String imageUrl = "http://192.168.1.100:9000/cmvr-iot/IMAGE/20250901/1756718594725.jpg"; + String imageUrl = edgeCameraService.getRGBDImages(edgeCommonVO); -// JSONArray imageUrls = new JSONArray(); -// if (ObjUtil.isNotEmpty(upstreamOutput)) { -// JSONArray upstream = upstreamOutput.getJSONArray("imageUrl"); -// if (ObjUtil.isNotEmpty(upstream)) { -// imageUrls.addAll(upstream); -// } -// } -// -// imageUrls.add(imageUrl); + JSONArray imageUrls = new JSONArray(); + if (ObjUtil.isNotEmpty(upstreamOutput)) { + JSONArray upstream = upstreamOutput.getJSONArray("imageUrl"); + if (ObjUtil.isNotEmpty(upstream)) { + imageUrls.addAll(upstream); + } + } + + imageUrls.add(imageUrl); output.put("imageUrl", imageUrl); output.put("type", FileType.IMAGE.code()); break; diff --git a/cmvr-iot-test/src/main/java/com/cmvr/test/util/NashornJsExecutor.java b/cmvr-iot-test/src/main/java/com/cmvr/test/util/NashornJsExecutor.java index 27dd3db..4900a47 100644 --- a/cmvr-iot-test/src/main/java/com/cmvr/test/util/NashornJsExecutor.java +++ b/cmvr-iot-test/src/main/java/com/cmvr/test/util/NashornJsExecutor.java @@ -68,14 +68,14 @@ public class NashornJsExecutor { * @param params 传入的参数(Map 或 POJO) * @return 执行结果 Map */ - public JSONObject execute(String jsCode, Object params) { + public Object execute(String jsCode, Object params) { // 1. 代码安全检查 validateCode(jsCode); // 2. 提交到线程池执行(支持超时中断) - Future future = executor.submit(new Callable() { + Future future = executor.submit(new Callable() { @Override - public JSONObject call() throws Exception { + public Object call() throws Exception { return doExecute(jsCode, params); } }); @@ -97,7 +97,7 @@ public class NashornJsExecutor { /** * 实际执行逻辑 */ - private JSONObject doExecute(String jsCode, Object params) throws ScriptException { + private Object doExecute(String jsCode, Object params) throws ScriptException { // 将参数转为 JSON 字符串 String jsonParams = toJson(params); @@ -117,9 +117,9 @@ public class NashornJsExecutor { if (resultJson.length() > MAX_RESULT_SIZE) { throw new RuntimeException("返回结果超过 " + (MAX_RESULT_SIZE/1024/1024) + "MB 限制"); } - + return resultJson; // 解析为 Map - return fromJson(resultJson); +// return fromJson(resultJson); } // 更简单的版本:不覆盖 eval,依赖其他安全措施