From 6eeac9efdb16f92d19536bf23a2d1471705fe752 Mon Sep 17 00:00:00 2001
From: dongyukun <1208714201@qq.com>
Date: 星期二, 31 十二月 2024 18:34:38 +0800
Subject: [PATCH] 调度模型下发

---
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/common/utils/DllUtils.java |   51 ++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 36 insertions(+), 15 deletions(-)

diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/common/utils/DllUtils.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/common/utils/DllUtils.java
index 94b3964..ae18b35 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/common/utils/DllUtils.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/common/utils/DllUtils.java
@@ -1,5 +1,8 @@
 package com.iailab.module.model.mpk.common.utils;
 
+import cn.hutool.core.io.FileUtil;
+import com.iail.model.IAILModel;
+import com.iail.utils.RSAUtils;
 import com.iailab.module.model.mpk.common.MdkConstant;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
@@ -181,27 +184,45 @@
                         String jarFilePath = bakPath + File.separator + projectId + MdkConstant.SPLIT + historyId + ".jar";
                         String dllFilePath = bakPath + File.separator + projectId + MdkConstant.SPLIT + historyId + ".dll";
 
-                        URLClassLoader urlClassLoader = null;
-                        try {
-                            // 加载新的jar
-                            urlClassLoader = DllUtils.loadJar(jarFilePath);
-                        } catch (Exception e) {
-                            throw new RuntimeException("加载jar异常",e);
-                        }
+                        if (FileUtil.exist(jarFilePath) && FileUtil.exist(dllFilePath)) {
+                            URLClassLoader urlClassLoader = null;
+                            try {
+                                // 加载新的jar
+                                urlClassLoader = loadJar(jarFilePath);
+                            } catch (Exception e) {
+                                throw new RuntimeException("加载jar异常",e);
+                            }
 
-                        try {
-                            // 加载新的dll
-                            DllUtils.loadDll(urlClassLoader.loadClass("iail.mdk.model.common.Environment"),dllFilePath);
-                        } catch (Exception e) {
-                            DllUtils.unloadJar(urlClassLoader);
-                            throw new RuntimeException("加载dll异常",e);
+                            try {
+                                // 加载新的dll
+                                loadDll(urlClassLoader.loadClass("iail.mdk.model.common.Environment"),dllFilePath);
+                            } catch (Exception e) {
+                                unloadJar(urlClassLoader);
+                                throw new RuntimeException("加载dll异常",e);
+                            }
+                            // 都加载成功后加入缓存
+                            addClassLoaderCache(projectId,urlClassLoader);
                         }
-                        // 都加载成功后加入缓存
-                        DllUtils.addClassLoaderCache(projectId,urlClassLoader);
                     }
                 }
             }
         }
 
     }
+
+    public static HashMap<String, Object> run(IAILModel model, Object[] paramsValueArray, String projectId) throws Exception {
+        if (RSAUtils.checkLisenceBean().getCode() != 1) {
+            throw new SecurityException("Lisence 不可用!");
+        } else if (model == null) {
+            throw new RuntimeException("模型文件不能为空!");
+        } else {
+            URLClassLoader classLoader = DllUtils.getClassLoader(projectId);
+            if (null == classLoader) {
+                throw new RuntimeException("dll未发布,classLoader为null");
+            }
+            Class<?> clazz = classLoader.loadClass(model.getClassName());
+            Method method = clazz.getMethod(model.getMethodName(), model.getParamsArray());
+            return (HashMap)method.invoke(clazz.newInstance(), paramsValueArray);
+        }
+    }
 }

--
Gitblit v1.9.3