From cddcd262f1a0e142847c0fc4bff7d1ffb86cdac0 Mon Sep 17 00:00:00 2001
From: dengzedong <dengzedong@email>
Date: 星期二, 15 四月 2025 09:38:50 +0800
Subject: [PATCH] - t_mm_predict_auto_adjust_config

---
 iailab-module-model/iailab-module-model-biz/src/main/resources/template/cpp.vm |   61 ++++++++++++------------------
 1 files changed, 24 insertions(+), 37 deletions(-)

diff --git a/iailab-module-model/iailab-module-model-biz/src/main/resources/template/cpp.vm b/iailab-module-model/iailab-module-model-biz/src/main/resources/template/cpp.vm
index 1025477..b2bb6d5 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/resources/template/cpp.vm
+++ b/iailab-module-model/iailab-module-model-biz/src/main/resources/template/cpp.vm
@@ -22,16 +22,22 @@
 		jmethodID getMID = env->GetMethodID(hashmapClass, "get", "(Ljava/lang/Object;)Ljava/lang/Object;");
 		jstring keyJString = env->NewStringUTF("pyFile");
 		jobject javaValueObj = env->CallObjectMethod(settings, getMID, keyJString);
-		const char* strValue = env->GetStringUTFChars((jstring)javaValueObj, NULL);
-		cout << strValue << endl;
-
+		jstring javaStringValue = (jstring)javaValueObj;
+		const char* strValue = env->GetStringUTFChars(javaStringValue, NULL);
+		//*************导入模型******************
 		PyObject* pModule = create_py_module(strValue);
-		/*PyObject* pModule = create_py_module("${pyModule}.${pyName}");*/
+		// 释放java占用内存
+		env->ReleaseStringUTFChars(javaStringValue, strValue);
+		env->DeleteLocalRef(javaStringValue);
+		env->DeleteLocalRef(javaValueObj);
+		env->DeleteLocalRef(keyJString);
+		env->DeleteLocalRef(hashmapClass);
 		if (pModule == NULL)
 		{
 			cout << "model error" << endl;
 			throw "模块调用失败!";
 		}
+		cout << "load pymodel finished" << endl;
 
 		//*************导入函数******************
 		PyObject* pFunc = PyObject_GetAttrString(pModule, "${entity.methodName}");
@@ -40,6 +46,7 @@
 			cout << "func error" << endl;
 			throw "函数调用失败!";
 		}
+		cout << "load pyfunc finished" << endl;
 #{foreach} ($column in [1..$entity.dataLength])
 		PyObject* data_${column} = ConvertJdarrToPydarr(env, data${column});
 #{end}
@@ -79,6 +86,18 @@
 			cout << "return error" << endl;
 			throw "函数返回值异常!";
 		}
+		cout << "load pyreturn finished" << endl;
+		PyObject* json_module = create_py_module("json");
+		PyObject* dumps_func = PyObject_GetAttrString(json_module, "dumps");
+		PyObject* json_str = PyObject_CallObject(dumps_func, PyTuple_Pack(1, pReturn));
+		if (json_str == NULL) {
+		cout << "json_str is null" << endl;
+		PyErr_Print();
+		return NULL;
+		}
+		const char* json_cstr = PyUnicode_AsUTF8(json_str);
+		cout << "pyreturn" << json_cstr << endl;
+
 		//*******************返回数据封装************************
 	   // 开辟返回数据内存空间,转换数据,拆分数据
 
@@ -87,40 +106,8 @@
 		if (result == NULL)
 		{
 			cout << "ConvertPydictToJhmap error" << endl;
-			throw "函数返回值异常!";
+			throw "函数返回值解析异常!";
 		}
-		/*delete pModule;
-		pModule = nullptr;
-		delete pModule;
-
-		delete pFunc;
-		pFunc = nullptr;
-		delete pFunc;
-
-#{foreach} ($column in [1..$entity.dataLength])
-		delete[] data_${column};
-		data_${column} = nullptr;
-		delete data_${column};
-
-#{end}
-#{if}($entity.model==1)
-		delete model_path;
-		model_path = nullptr;
-		delete model_path;
-#{end}
-
-		delete settings_1;
-		settings_1 = nullptr;
-		delete settings_1;
-
-		delete[] pArg;
-		pArg = nullptr;
-		delete pArg;
-
-		Py_DECREF(pReturn);
-		Py_DECREF(pFunc);
-		Py_DECREF(pModule);
-		Py_CLEAR(pModule);*/
 
 		return result;
 	}

--
Gitblit v1.9.3