From babbb668e1b305be8cb754b0b4d5efab908bc9ec Mon Sep 17 00:00:00 2001 From: 秦芳睿 <1425609123@qq.com> Date: 星期四, 20 三月 2025 18:27:41 +0800 Subject: [PATCH] feat(server): 新增维度管理、样本管理、角色管理等功能 --- JAVA/SMTAIServer/src/main/resources/requestmap/system_manager.json | 38 +++ JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/control/SMTMetricsManagerControl.java | 77 ++++++ JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/javaai/jsonflow/core/SMTJsonFlowManager.java | 17 - JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/javaai/jsonflow/node/SMTJsonFlowNodeN8n.java | 144 +++++++++++++ JAVA/SMTAIServer/src/main/resources/requestmap/workflow_manager.json | 16 + JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/control/SMTSystemManagerControl.java | 61 +++++ JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/control/SMTWorkflowManagerControl.java | 128 +++++++++++ JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/control/SMTAIServerControl.java | 76 ++++++ JAVA/SMTAIServer/src/main/resources/requestmap/metric_manager.json | 45 ++++ JAVA/SMTAIServer/src/main/resources/requestmap/server_api.json | 54 ++++ 10 files changed, 633 insertions(+), 23 deletions(-) diff --git a/JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/control/SMTAIServerControl.java b/JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/control/SMTAIServerControl.java index 9053997..05f2d4b 100644 --- a/JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/control/SMTAIServerControl.java +++ b/JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/control/SMTAIServerControl.java @@ -530,8 +530,82 @@ db.close(); } } + public ModelAndView addSceneSample(SMTAIServerRequest tranReq) throws Exception { + String groupId = tranReq.convParamToString("group_id", true); + String sampleId = tranReq.convParamToString("sample_id", true); + String sampleQuestion = tranReq.convParamToString("sample_question", true); + String sampleTitle = tranReq.convParamToString("sample_title", true); + String sampleEnable = tranReq.convParamToString("sample_enable", true); + String autoTestSupervisor = tranReq.convParamToString("auto_test_supervisor", false); + String autoTestJson = tranReq.convParamToString("auto_test_json", false); + String autoTestMacro = tranReq.convParamToString("auto_test_macro", false); + String autoTestNote = tranReq.convParamToString("auto_test_note", false); + String autoTestEnable = tranReq.convParamToString("auto_test_enable", false); + String sampleMatch = tranReq.convParamToString("sample_match", false); - public ModelAndView createHistoryGroup(SMTAIServerRequest tranReq) throws Exception + SMTDatabase db = SMTAIServerApp.getApp().allocDatabase(); + + try { + // 妫�鏌ユ牱鏈琁D鏄惁宸插瓨鍦� + String selectSql = "SELECT * FROM ai_doc.ai_scene_sample WHERE sample_id = ?"; + Object[] selectParams = {sampleId}; + if (db.querySQL(selectSql, selectParams).getRowCount() > 0) { + return tranReq.returnJsonState(false, "鏍锋湰ID宸插瓨鍦�", null); + } + + // 鎻掑叆鏂版牱鏈� + String insertSql = "INSERT INTO ai_doc.ai_scene_sample (group_id, sample_id, sample_question, sample_title, sample_enable, auto_test_supervisor, auto_test_json, auto_test_macro, auto_test_note, auto_test_enable, sample_match) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + Object[] insertParams = {groupId, sampleId, sampleQuestion, sampleTitle, sampleEnable, autoTestSupervisor, autoTestJson, autoTestMacro, autoTestNote, autoTestEnable, sampleMatch}; + + db.executeSQL(insertSql, insertParams); + + // 杩斿洖 JSON 缁撴灉 + SMTJsonWriter jsonWr = tranReq.newReturnJsonWriter(true, null, null); + return tranReq.returnJson(jsonWr); + } finally { + db.close(); + } + } + + public ModelAndView updateSceneSample(SMTAIServerRequest tranReq) throws Exception { + String sampleId = tranReq.convParamToString("sample_id", true); + String sampleQuestion = tranReq.convParamToString("sample_question", false); + String sampleTitle = tranReq.convParamToString("sample_title", false); + String sampleEnable = tranReq.convParamToString("sample_enable", false); + String autoTestSupervisor = tranReq.convParamToString("auto_test_supervisor", false); + String autoTestJson = tranReq.convParamToString("auto_test_json", false); + String autoTestMacro = tranReq.convParamToString("auto_test_macro", false); + String autoTestNote = tranReq.convParamToString("auto_test_note", false); + String autoTestEnable = tranReq.convParamToString("auto_test_enable", false); + String sampleMatch = tranReq.convParamToString("sample_match", false); + + SMTDatabase db = SMTAIServerApp.getApp().allocDatabase(); + + try { + // 妫�鏌ユ牱鏈琁D鏄惁瀛樺湪 + String selectSql = "SELECT * FROM ai_doc.ai_scene_sample WHERE sample_id = ?"; + Object[] selectParams = {sampleId}; + if (db.querySQL(selectSql, selectParams).getRowCount() == 0) { + return tranReq.returnJsonState(false, "鏍锋湰ID涓嶅瓨鍦�", null); + } + + // 鏇存柊鏍锋湰淇℃伅 + String updateSql = "UPDATE ai_doc.ai_scene_sample SET sample_question = ?, sample_title = ?, sample_enable = ?, auto_test_supervisor = ?, auto_test_json = ?, auto_test_macro = ?, auto_test_note = ?, auto_test_enable = ?, sample_match = ? WHERE sample_id = ?"; + Object[] updateParams = {sampleQuestion, sampleTitle, sampleEnable, autoTestSupervisor, autoTestJson, autoTestMacro, autoTestNote, autoTestEnable, sampleMatch, sampleId}; + + db.executeSQL(updateSql, updateParams); + + // 杩斿洖 JSON 缁撴灉 + SMTJsonWriter jsonWr = tranReq.newReturnJsonWriter(true, null, null); + return tranReq.returnJson(jsonWr); + } finally { + db.close(); + } + } + + + public ModelAndView createHistoryGroup(SMTAIServerRequest tranReq) throws Exception { String groupTitle = tranReq.convParamToString("group_title", true); SMTDatabase db = SMTAIServerApp.getApp().allocDatabase(); diff --git a/JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/control/SMTMetricsManagerControl.java b/JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/control/SMTMetricsManagerControl.java index 4207eda..f54cee3 100644 --- a/JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/control/SMTMetricsManagerControl.java +++ b/JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/control/SMTMetricsManagerControl.java @@ -108,7 +108,82 @@ db.close(); } } - + public ModelAndView addDimension(SMTAIServerRequest tranReq) throws Exception { + String loginUserId = tranReq.getLoginUserId(); + + // 瑙f瀽璇锋眰鍙傛暟 + String dimId = tranReq.convParamToString("dim_id", true); + String dimTitle = tranReq.convParamToString("dim_title", true); + String dimType = tranReq.convParamToString("dim_type", true); + String dimAlias = tranReq.convParamToString("dim_alias", false); + String dimName = tranReq.convParamToString("dim_name", true); + String dimGroup = tranReq.convParamToString("dim_group", false); + String dimUnit = tranReq.convParamToString("dim_unit", false); + String dimValueList = tranReq.convParamToString("dim_value_list", false); + + SMTDatabase db = SMTAIServerApp.getApp().allocDatabase(); + + try { + // 妫�鏌ョ淮搴D鏄惁宸插瓨鍦� + String selectSql = "SELECT * FROM ai_doc.ai_dimension WHERE dim_id = ?"; + Object[] selectParams = {dimId}; + if (db.querySQL(selectSql, selectParams).getRowCount() > 0) { + return tranReq.returnJsonState(false, "缁村害ID宸插瓨鍦�", null); + } + + // 鏋勫缓 SQL 璇彞 + String insertSql = "INSERT INTO ai_doc.ai_dimension (dim_id, dim_title, dim_type, dim_alias, dim_name, dim_group, dim_unit, dim_value_list) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; + Object[] insertParams = {dimId, dimTitle, dimType, dimAlias, dimName, dimGroup, dimUnit, dimValueList}; + + // 鎵ц鎻掑叆鎿嶄綔 + db.executeSQL(insertSql, insertParams); + + // 杩斿洖 JSON 缁撴灉 + SMTJsonWriter jsonWr = tranReq.newReturnJsonWriter(true, null, null); + return tranReq.returnJson(jsonWr); + } finally { + db.close(); + } + } + public ModelAndView updateDimension(SMTAIServerRequest tranReq) throws Exception { + // 瑙f瀽璇锋眰鍙傛暟 + String dimId = tranReq.convParamToString("dim_id", true); + String dimTitle = tranReq.convParamToString("dim_title", false); + String dimType = tranReq.convParamToString("dim_type", false); + String dimAlias = tranReq.convParamToString("dim_alias", false); + String dimName = tranReq.convParamToString("dim_name", false); + String dimGroup = tranReq.convParamToString("dim_group", false); + String dimUnit = tranReq.convParamToString("dim_unit", false); + String dimValueList = tranReq.convParamToString("dim_value_list", false); + + SMTDatabase db = SMTAIServerApp.getApp().allocDatabase(); + + try { + // 妫�鏌ョ淮搴D鏄惁瀛樺湪 + String selectSql = "SELECT * FROM ai_doc.ai_dimension WHERE dim_id = ?"; + Object[] selectParams = {dimId}; + if (db.querySQL(selectSql, selectParams).getRowCount() == 0) { + return tranReq.returnJsonState(false, "缁村害ID涓嶅瓨鍦�", null); + } + + // 鏋勫缓 SQL 璇彞 + String updateSql = "UPDATE ai_doc.ai_dimension SET dim_title = ?, dim_type = ?, dim_alias = ?, dim_name = ?, dim_group = ?, dim_unit = ?, dim_value_list = ? " + + "WHERE dim_id = ?"; + Object[] updateParams = {dimTitle, dimType, dimAlias, dimName, dimGroup, dimUnit, dimValueList, dimId}; + + // 鎵ц鏇存柊鎿嶄綔 + db.executeSQL(updateSql, updateParams); + + // 杩斿洖 JSON 缁撴灉 + SMTJsonWriter jsonWr = tranReq.newReturnJsonWriter(true, null, null); + return tranReq.returnJson(jsonWr); + } finally { + db.close(); + } + } + + public ModelAndView checkMetricsAgentValidate(SMTAIServerRequest tranReq) throws Exception { String agentId = tranReq.convParamToString("agent_id", true); diff --git a/JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/control/SMTSystemManagerControl.java b/JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/control/SMTSystemManagerControl.java index 0b0f542..3b045a0 100644 --- a/JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/control/SMTSystemManagerControl.java +++ b/JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/control/SMTSystemManagerControl.java @@ -167,8 +167,65 @@ { db.close(); } - } - + } + + public ModelAndView addRoleInfo(SMTAIServerRequest tranReq) throws Exception { + String roleId = tranReq.convParamToString("role_id", true); + String roleTitle = tranReq.convParamToString("role_title", true); + + SMTDatabase db = SMTAIServerApp.getApp().allocDatabase(); + + try { + // 妫�鏌ヨ鑹睮D鏄惁宸插瓨鍦� + String selectSql = "SELECT * FROM ai_sys.sys_role_info WHERE role_id = ?"; + Object[] selectParams = {roleId}; + if (db.querySQL(selectSql, selectParams).getRowCount() > 0) { + return tranReq.returnJsonState(false, "瑙掕壊ID宸插瓨鍦�", null); + } + + // 鎻掑叆鏂拌鑹� + String insertSql = "INSERT INTO ai_sys.sys_role_info (role_id, role_title) VALUES (?, ?)"; + Object[] insertParams = {roleId, roleTitle}; + + db.executeSQL(insertSql, insertParams); + + // 杩斿洖 JSON 缁撴灉 + SMTJsonWriter jsonWr = tranReq.newReturnJsonWriter(true, null, null); + return tranReq.returnJson(jsonWr); + } finally { + db.close(); + } + } + + public ModelAndView updateRoleInfo(SMTAIServerRequest tranReq) throws Exception { + String roleId = tranReq.convParamToString("role_id", true); + String roleTitle = tranReq.convParamToString("role_title", false); + + SMTDatabase db = SMTAIServerApp.getApp().allocDatabase(); + + try { + // 妫�鏌ヨ鑹睮D鏄惁瀛樺湪 + String selectSql = "SELECT * FROM ai_sys.sys_role_info WHERE role_id = ?"; + Object[] selectParams = {roleId}; + if (db.querySQL(selectSql, selectParams).getRowCount() == 0) { + return tranReq.returnJsonState(false, "瑙掕壊ID涓嶅瓨鍦�", null); + } + + // 鏇存柊瑙掕壊淇℃伅 + String updateSql = "UPDATE ai_sys.sys_role_info SET role_title = ? WHERE role_id = ?"; + Object[] updateParams = {roleTitle, roleId}; + + db.executeSQL(updateSql, updateParams); + + // 杩斿洖 JSON 缁撴灉 + SMTJsonWriter jsonWr = tranReq.newReturnJsonWriter(true, null, null); + return tranReq.returnJson(jsonWr); + } finally { + db.close(); + } + } + + public ModelAndView addUserInfo(SMTAIServerRequest tranReq) throws Exception { String userName = tranReq.convParamToString("user_name", true); diff --git a/JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/control/SMTWorkflowManagerControl.java b/JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/control/SMTWorkflowManagerControl.java index 5710d1d..e88c30b 100644 --- a/JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/control/SMTWorkflowManagerControl.java +++ b/JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/control/SMTWorkflowManagerControl.java @@ -1,9 +1,17 @@ package com.smtaiserver.smtaiserver.control; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import cn.hutool.http.HttpUtil; +import cn.hutool.json.JSON; +import com.smtservlet.util.Json; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; import org.dom4j.Document; import org.springframework.web.servlet.ModelAndView; @@ -18,8 +26,11 @@ import com.smtservlet.util.SMTJsonWriter; import com.smtservlet.util.SMTStatic; +import static jdk.nashorn.internal.runtime.GlobalFunctions.encodeURIComponent; + public class SMTWorkflowManagerControl { + public static final String GET_WORKFLOWS = "http://localhost:15678/api/v1/workflows?"; private static String[] _flowFuncNames = new String[] { "assessment", "璇勪及" }; @@ -399,4 +410,115 @@ } } + /** + * 鏌ヨn8n宸ヤ綔娴佸垪琛� + * @param tranReq + * @return + * @throws Exception + */ + public ModelAndView getN8NNameList(SMTRequest tranReq) throws Exception { + String active = tranReq.convParamToString("active", true); + String tags = tranReq.convParamToString("tags", false); + String name = tranReq.convParamToString("name", false); + String projectId = tranReq.convParamToString("projectId", false); + String excludePinnedData = tranReq.convParamToString("excludePinnedData", false); + int limit = 250; // 涓婇檺250鏉� + + // 鏋勫缓璇锋眰URL + String requestUrl = buildUrl(active, tags, name, projectId, excludePinnedData, limit); + + // 鍒涘缓OkHttpClient瀵硅薄 + OkHttpClient client = new OkHttpClient(); + + String n8nApiKey = (String) SMTAIServerApp.getApp().getGlobalConfig("n8n_api_key", null); + // 鍒涘缓璇锋眰澶� + Request request = new Request.Builder() + .url(requestUrl) + .addHeader("X-N8N-API-KEY", n8nApiKey) + .addHeader("accept", "application/json") + .build(); + Response response = client.newCall(request).execute(); + String res = response.body().string(); + Json.Reader reader = new Json.Reader(); + Json read = (Json) reader.read(res, null); + SMTJsonWriter jsonWriter = new SMTJsonWriter(false); + + // 鏋勫缓鏈�缁堢殑杩斿洖鏁版嵁缁撴瀯 + List<Json> resultList = new ArrayList<>(); + + try { + if (response.body() != null) { + List<Json> data = read.safeGetJsonList("data"); + for (Json date : data) { + String flOWName = date.safeGetStr("name", null); + String id = date.safeGetStr("id", null); + + // 鍒涘缓涓�涓柊鐨� JSON 瀵硅薄 + SMTJsonWriter flowObj = new SMTJsonWriter(false); + flowObj.addKeyValue("id", id); + flowObj.addKeyValue("flOWName", flOWName); + + List<Json> nodeList = date.safeGetJsonList("nodes"); + for (Json node : nodeList) { + String type = node.safeGetStr("type", null); + if (type.equals("n8n-nodes-base.webhook")) { + Json parameters = node.safeGetJson("parameters"); + String path = parameters.safeGetStr("path", null); + Pattern pattern = Pattern.compile("/:?([^/]+)"); + List<String> pathRes = extractParts(path, pattern); + flowObj.addKeyValue("path", pathRes); + } + } + // 灏嗗垱寤虹殑 flowObj 娣诲姞鍒� resultList 涓� + resultList.add(flowObj.getRootJson()); + } + + // 灏� resultList 璁剧疆涓� "data" 閿殑鍊� + jsonWriter.addKeyValue("data", resultList); + } + + return tranReq.returnJson(jsonWriter); + } catch (Exception e) { + throw new Exception(e); + } + } + + + public static String buildUrl(String active, String tags, String name, String projectId, String excludePinnedData, int limit) throws UnsupportedEncodingException { + // 浣跨敤Map鏉ュ瓨鍌ㄥ弬鏁� + Map<String, String> params = new HashMap<>(); + params.put("active", active); + params.put("tags", tags); + params.put("name", name != null ? URLEncoder.encode(name, "UTF-8") : null); + params.put("projectId", projectId); + params.put("excludePinnedData", excludePinnedData); + params.put("limit", String.valueOf(limit)); + + // 鍩烘湰URL + StringBuilder urlBuilder = new StringBuilder(GET_WORKFLOWS); + + // 閬嶅巻map骞舵瀯寤篣RL + for (Map.Entry<String, String> entry : params.entrySet()) { + if (entry.getValue() != null) { + urlBuilder.append(entry.getKey()) + .append("=") + .append(entry.getValue()) + .append("&"); + } + } + // 鍘婚櫎鏈�鍚庝竴涓浣欑殑&绗﹀彿 + String requestUrl = urlBuilder.toString(); + if (requestUrl.endsWith("&")) { + requestUrl = requestUrl.substring(0, requestUrl.length() - 1); + } + return requestUrl; + } + private static List<String> extractParts(String input, Pattern pattern) { + Matcher matcher = pattern.matcher(input); + List<String> results = new ArrayList<>(); + while (matcher.find()) { + results.add(matcher.group(1)); // 鎻愬彇绗竴涓崟鑾风粍鍐呭 + } + return results; + } } diff --git a/JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/javaai/jsonflow/core/SMTJsonFlowManager.java b/JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/javaai/jsonflow/core/SMTJsonFlowManager.java index 92ecdd5..f18b592 100644 --- a/JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/javaai/jsonflow/core/SMTJsonFlowManager.java +++ b/JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/javaai/jsonflow/core/SMTJsonFlowManager.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.Map; +import com.smtaiserver.smtaiserver.javaai.jsonflow.node.*; import org.apache.commons.pool2.BasePooledObjectFactory; import org.apache.commons.pool2.PooledObject; import org.apache.commons.pool2.impl.DefaultPooledObject; @@ -11,16 +12,6 @@ import org.apache.commons.pool2.impl.GenericObjectPoolConfig; import com.smtaiserver.smtaiserver.core.SMTAIServerRequest; import com.smtaiserver.smtaiserver.javaai.SMTJavaAIError; -import com.smtaiserver.smtaiserver.javaai.jsonflow.node.SMTJsonFlowNodeAgent; -import com.smtaiserver.smtaiserver.javaai.jsonflow.node.SMTJsonFlowNodeCondJson; -import com.smtaiserver.smtaiserver.javaai.jsonflow.node.SMTJsonFlowNodeEnd; -import com.smtaiserver.smtaiserver.javaai.jsonflow.node.SMTJsonFlowNodeLLM; -import com.smtaiserver.smtaiserver.javaai.jsonflow.node.SMTJsonFlowNodeProcedure; -import com.smtaiserver.smtaiserver.javaai.jsonflow.node.SMTJsonFlowNodePython; -import com.smtaiserver.smtaiserver.javaai.jsonflow.node.SMTJsonFlowNodeScript; -import com.smtaiserver.smtaiserver.javaai.jsonflow.node.SMTJsonFlowNodeStart; -import com.smtaiserver.smtaiserver.javaai.jsonflow.node.SMTJsonFlowNodeTextResource; -import com.smtaiserver.smtaiserver.javaai.jsonflow.node.SMTJsonFlowNodeUserAsk; import com.smtaiserver.smtaiserver.javaai.llm.core.SMTLLMConnect; import com.smtservlet.util.Json; @@ -98,6 +89,10 @@ else if("python_code".equals(nodeType)) { wfNode = new SMTJsonFlowNodePython(); + } + else if("n8n".equals(nodeType)) + { + wfNode = new SMTJsonFlowNodeN8n(); } else @@ -178,7 +173,7 @@ execArg._stackNodeExec.addLast(_startNode.createFlowNodeExec()); // 鎵цexecArg._stackNode涓殑鑺傜偣锛岀洿鑷崇粨鏉� - while(execArg._stackNodeExec.size() > 0) + while(!execArg._stackNodeExec.isEmpty()) { // 鎵ц涓嬩竴涓妭鐐� SMTJsonFlowNodeExec flowNodeExec = execArg._stackNodeExec.pollFirst(); diff --git a/JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/javaai/jsonflow/node/SMTJsonFlowNodeN8n.java b/JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/javaai/jsonflow/node/SMTJsonFlowNodeN8n.java new file mode 100644 index 0000000..a9f3dee --- /dev/null +++ b/JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/javaai/jsonflow/node/SMTJsonFlowNodeN8n.java @@ -0,0 +1,144 @@ +package com.smtaiserver.smtaiserver.javaai.jsonflow.node; + +import com.smtaiserver.smtaiserver.core.SMTAIServerApp; +import com.smtaiserver.smtaiserver.javaai.SMTJavaAIError; +import com.smtaiserver.smtaiserver.javaai.jsonflow.core.SMTJsonFlowExecArg; +import com.smtaiserver.smtaiserver.javaai.jsonflow.core.SMTJsonFlowManager; +import com.smtaiserver.smtaiserver.javaai.jsonflow.core.SMTJsonFlowNodeOnlyOutput; +import com.smtaiserver.smtaiserver.javaai.qwen.SMTQwenApp; +import com.smtservlet.util.Json; +import com.smtservlet.util.SMTStatic; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.io.BufferedReader; +import java.io.File; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +public class SMTJsonFlowNodeN8n extends SMTJsonFlowNodeOnlyOutput +{ + private String[] _inputArg; + private String _outputArg; + private String _code; + private static Logger _logger = LogManager.getLogger(SMTQwenApp.class); + + @Override + public void initInstane(SMTJsonFlowManager manager, Json jsonNode) throws Exception + { + super.initInstane(manager, jsonNode); + + List<Json> jsonGroupParams = jsonNode.getJsonPath("data|group_params|", false).asJsonList(); + for(Json jsonParams : jsonGroupParams) + { + String type = jsonParams.getJsonPath("params|0|type", false).asString(); + if("code_input".equals(type)) + { + String sInputArg = jsonParams.getJsonPath("params|0|value|value", false).asString(); + if(!SMTStatic.isNullOrEmpty(sInputArg)) + _inputArg = sInputArg.split(","); + } + else if("code_output".equals(type)) + { + _outputArg = jsonParams.getJsonPath("params|0|value|value", false).asString(); + } + else if("code".equals(type)) + { + _code = jsonParams.getJsonPath("params|0|value", false).asString(); + } + } + + } + + @Override + public void afterInstance() throws Exception + { + super.afterInstance(); + + if(SMTStatic.isNullOrEmpty(_code)) + throw new Exception("script function code is not define"); + } + + @Override + public SMTJavaAIError executeFlowNode(SMTJsonFlowExecArg execArg) throws Exception + { + Json jsonPython = (Json)SMTAIServerApp.getApp().getGlobalConfig("python_env"); + String pyPath = jsonPython.getJson("path").asString(); + + String argText = ""; + + if(_inputArg != null && _inputArg.length > 0) + { + Json jsonArg = Json.object(); + for(String key : _inputArg) + { + jsonArg.set(key, execArg._jsonArgs.getJson(key)); + } + argText = jsonArg.toString(); + } + + String id = SMTStatic.newUUID(); + + File inputFile = new File(pyPath, "py_i_" + id); + File outputFile = new File(pyPath, "py_o_" + id); + File executeFile = new File(pyPath, "py_x_" + id); + outputFile.delete(); + SMTStatic.saveTextFile(inputFile , argText); + SMTStatic.saveTextFile(executeFile , _code); + try + { + List<String> params = new ArrayList<String>(); + params.add(jsonPython.getJson("exec").asString()); + params.add(executeFile.getAbsolutePath()); + params.add(inputFile.getAbsolutePath()); + params.add(outputFile.getAbsolutePath()); + + _logger.info("python : start : " + executeFile.getAbsolutePath()); + ProcessBuilder pbuilder=new ProcessBuilder(SMTStatic.convProcessArg(params)); + pbuilder.directory(new File(pyPath)); + pbuilder.redirectErrorStream(true); + Process process = pbuilder.start(); + + BufferedReader bufferedStdout = new BufferedReader(new InputStreamReader(process.getInputStream(), SMTStatic.getStdoutEncode())); + execArg._tranReq.sendChunkedBlock("begin_stream", ""); + try + { + int size; + char[] sBuf = new char[1024]; + while((size = bufferedStdout.read(sBuf)) > 0) + { + String text = new String(sBuf, 0, size); + execArg._tranReq.sendChunkedStreamBlock(text); + } + } + finally + { + execArg._tranReq.sendChunkedBlock("end_stream", ""); + } + int exitCode = process.waitFor(); + _logger.info("python : end : " + exitCode + " : " + executeFile.getAbsolutePath()); + + if(!SMTStatic.isNullOrEmpty(_outputArg)) + { + if(outputFile.exists()) + { + String text = SMTStatic.readAllText(outputFile); + execArg._jsonArgs.set(_outputArg, text); + } + else + { + execArg._jsonArgs.set(_outputArg, ""); + } + } + } + finally + { + inputFile.delete(); + outputFile.delete(); + executeFile.delete(); + } + + return super.executeFlowNode(execArg); + } +} diff --git a/JAVA/SMTAIServer/src/main/resources/requestmap/metric_manager.json b/JAVA/SMTAIServer/src/main/resources/requestmap/metric_manager.json index ecf2cc9..3a46ca3 100644 --- a/JAVA/SMTAIServer/src/main/resources/requestmap/metric_manager.json +++ b/JAVA/SMTAIServer/src/main/resources/requestmap/metric_manager.json @@ -8,6 +8,51 @@ } ] }, + "admin/dimension/add_dimension": { + "map": { + "class": "#SMTMetricsManagerControl", + "method": "addDimension" + }, + "swaggers": [ + { + "tags": ["缁村害绠$悊"], + "title": "鏂板缁村害", + "parameters": [ + {"name": "dim_id", "title": "缁村害ID", "required": true}, + {"name": "dim_title", "title": "缁村害鏍囬", "required": true}, + {"name": "dim_type", "title": "缁村害绫诲瀷", "required": true}, + {"name": "dim_alias", "title": "缁村害鍒悕", "required": false}, + {"name": "dim_name", "title": "缁村害鍚嶇О", "required": true}, + {"name": "dim_group", "title": "缁村害鍒嗙粍", "required": false}, + {"name": "dim_unit", "title": "缁村害鍗曚綅", "required": false}, + {"name": "dim_value_list", "title": "缁村害鍊煎垪琛�", "required": false} + ] + } + ] + }, + "admin/dimension/update_dimension": { + "map": { + "class": "#SMTMetricsManagerControl", + "method": "updateDimension" + }, + "swaggers": [ + { + "tags": ["缁村害绠$悊"], + "title": "淇敼缁村害", + "parameters": [ + {"name": "dim_id", "title": "缁村害ID", "required": true}, + {"name": "dim_title", "title": "缁村害鏍囬", "required": false}, + {"name": "dim_type", "title": "缁村害绫诲瀷", "required": false}, + {"name": "dim_alias", "title": "缁村害鍒悕", "required": false}, + {"name": "dim_name", "title": "缁村害鍚嶇О", "required": false}, + {"name": "dim_group", "title": "缁村害鍒嗙粍", "required": false}, + {"name": "dim_unit", "title": "缁村害鍗曚綅", "required": false}, + {"name": "dim_value_list", "title": "缁村害鍊煎垪琛�", "required": false} + ] + } + ] + }, + "admin/metrics/get_metrics_agent_list":{"map":{"class":"#SMTMetricsManagerControl", "method":"getMetricsAgentList"}, "swaggers":[ diff --git a/JAVA/SMTAIServer/src/main/resources/requestmap/server_api.json b/JAVA/SMTAIServer/src/main/resources/requestmap/server_api.json index 146a194..0a50561 100644 --- a/JAVA/SMTAIServer/src/main/resources/requestmap/server_api.json +++ b/JAVA/SMTAIServer/src/main/resources/requestmap/server_api.json @@ -110,8 +110,58 @@ } ] }, - - + "admin/sample/add_scene_sample": { + "map": { + "class": "#AIServerControl", + "method": "addSceneSample" + }, + "swaggers": [ + { + "tags": ["鏍锋湰绠$悊"], + "title": "鏂板鍦烘櫙鏍锋湰", + "parameters": [ + {"name": "group_id", "title": "鍒嗙粍鍞竴鏍囪瘑", "required": true}, + {"name": "sample_id", "title": "鏍锋湰鍞竴鏍囪瘑", "required": true}, + {"name": "sample_question", "title": "鏍锋湰闂鍐呭", "required": true}, + {"name": "sample_title", "title": "鏍锋湰鏍囬", "required": true}, + {"name": "sample_enable", "title": "鏍锋湰鏄惁鍚敤(Y/N)", "required": true}, + {"name": "auto_test_supervisor", "title": "鑷姩娴嬭瘯鐩戠潱鍛�", "required": false}, + {"name": "auto_test_json", "title": "鑷姩娴嬭瘯JSON閰嶇疆", "required": false}, + {"name": "auto_test_macro", "title": "鑷姩娴嬭瘯瀹忛厤缃�", "required": false}, + {"name": "auto_test_note", "title": "鑷姩娴嬭瘯澶囨敞", "required": false}, + {"name": "auto_test_enable", "title": "鑷姩娴嬭瘯鏄惁鍚敤(Y/N)", "required": false}, + {"name": "sample_match", "title": "鏍锋湰鍖归厤瑙勫垯", "required": false} + ] + } + ] + }, + + "admin/sample/update_scene_sample": { + "map": { + "class": "#AIServerControl", + "method": "updateSceneSample" + }, + "swaggers": [ + { + "tags": ["鏍锋湰绠$悊"], + "title": "鏇存柊鍦烘櫙鏍锋湰", + "parameters": [ + {"name": "sample_id", "title": "鏍锋湰鍞竴鏍囪瘑", "required": true}, + {"name": "sample_question", "title": "鏍锋湰闂鍐呭", "required": false}, + {"name": "sample_title", "title": "鏍锋湰鏍囬", "required": false}, + {"name": "sample_enable", "title": "鏍锋湰鏄惁鍚敤(Y/N)", "required": false}, + {"name": "auto_test_supervisor", "title": "鑷姩娴嬭瘯鐩戠潱鍛�", "required": false}, + {"name": "auto_test_json", "title": "鑷姩娴嬭瘯JSON閰嶇疆", "required": false}, + {"name": "auto_test_macro", "title": "鑷姩娴嬭瘯瀹忛厤缃�", "required": false}, + {"name": "auto_test_note", "title": "鑷姩娴嬭瘯澶囨敞", "required": false}, + {"name": "auto_test_enable", "title": "鑷姩娴嬭瘯鏄惁鍚敤(Y/N)", "required": false}, + {"name": "sample_match", "title": "鏍锋湰鍖归厤瑙勫垯", "required": false} + ] + } + ] + }, + + "history/create_history_group":{"map":{"class":"#AIServerControl", "method":"createHistoryGroup"}, "swaggers":[ { "tags" : ["AI鎿嶄綔"], diff --git a/JAVA/SMTAIServer/src/main/resources/requestmap/system_manager.json b/JAVA/SMTAIServer/src/main/resources/requestmap/system_manager.json index d4f5ab1..0796aa0 100644 --- a/JAVA/SMTAIServer/src/main/resources/requestmap/system_manager.json +++ b/JAVA/SMTAIServer/src/main/resources/requestmap/system_manager.json @@ -91,6 +91,40 @@ } ] }, + "admin/role/add_role_info": { + "map": { + "class": "#SMTSystemManagerControl", + "method": "addRoleInfo" + }, + "swaggers": [ + { + "tags": ["瑙掕壊绠$悊"], + "title": "鏂板瑙掕壊淇℃伅", + "parameters": [ + {"name": "role_id", "title": "瑙掕壊鍞竴鏍囪瘑ID", "required": true}, + {"name": "role_title", "title": "瑙掕壊鍚嶇О", "required": true} + ] + } + ] + }, + + "admin/role/update_role_info": { + "map": { + "class": "#SMTSystemManagerControl", + "method": "updateRoleInfo" + }, + "swaggers": [ + { + "tags": ["瑙掕壊绠$悊"], + "title": "鏇存柊瑙掕壊淇℃伅", + "parameters": [ + {"name": "role_id", "title": "瑙掕壊鍞竴鏍囪瘑ID", "required": true}, + {"name": "role_title", "title": "瑙掕壊鍚嶇О", "required": false} + ] + } + ] + }, + "admin/log/get_operate_log":{"map":{"class":"#SMTSystemManagerControl", "method":"getOperateLog"}, "swaggers":[ { "tags" : ["鏃ュ織绠$悊"], @@ -252,7 +286,7 @@ } ] }, - "admin/sample/add_question_replace": {"map": {"class": "#SMTSystemManagerControl", "method": "addQuestionReplace"} ,"no_shrio": true, + "admin/sample/add_question_replace": {"map": {"class": "#SMTSystemManagerControl", "method": "addQuestionReplace"}, "swaggers": [{ "tags": ["鏂板闂缃崲鍙傛暟"], "title": "鏂板闂缃崲鍙傛暟", @@ -267,7 +301,7 @@ } ] }, - "admin/sample/update_question_replace": {"map": {"class": "#SMTSystemManagerControl", "method": "updateQuestionReplace"},"no_shrio": true , + "admin/sample/update_question_replace": {"map": {"class": "#SMTSystemManagerControl", "method": "updateQuestionReplace"} , "swaggers": [{ "tags": ["鏇存柊闂鏇挎崲閰嶇疆"], "title": "鏇存柊闂鏇挎崲閰嶇疆", diff --git a/JAVA/SMTAIServer/src/main/resources/requestmap/workflow_manager.json b/JAVA/SMTAIServer/src/main/resources/requestmap/workflow_manager.json index 8949099..32fcc5a 100644 --- a/JAVA/SMTAIServer/src/main/resources/requestmap/workflow_manager.json +++ b/JAVA/SMTAIServer/src/main/resources/requestmap/workflow_manager.json @@ -121,6 +121,20 @@ ] } ] + }, + "n8n/get_n8n_name_list":{"map":{"class":"#SMTWorkflowManagerControl", "method":"getN8NNameList"},"no_shrio": true, + "swaggers":[ + { "tags" : ["鏌ヨn8n宸ヤ綔娴乴ist"], + "title" : "鏌ヨn8n宸ヤ綔娴乴ist", + "parameters" : [ + {"name":"active", "title":"active", "required":false}, + {"name":"tags", "title":"tags", "required":false}, + {"name":"name", "title":"name", "required":false}, + {"name":"projectId", "title":"projectId", "required":false}, + {"name":"excludePinnedData", "title":"excludePinnedData", "required":false} + ] + } + ] } - + } \ No newline at end of file -- Gitblit v1.9.3