Jay
8 天以前 443339e98893164231eb8af1857f7b9e150002fa
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/controller/admin/MdkController.java
@@ -38,6 +38,7 @@
import java.util.*;
import java.util.stream.Collectors;
import static com.iailab.framework.common.exception.enums.GlobalErrorCodeConstants.NOT_GENERAT;
import static com.iailab.framework.common.pojo.CommonResult.error;
import static com.iailab.framework.common.pojo.CommonResult.success;
@@ -72,11 +73,13 @@
        try {
            File jarFile = new File(mpkTenantBakFilePath + File.separator + MdkConstant.JAR + File.separator + dto.getPyName() + ".jar");
            if (!jarFile.exists()) {
                throw new RuntimeException("jar包不存在,请先生成代码。jarPath:" + jarFile.getAbsolutePath());
                log.error("jar包不存在,请先生成代码。jarPath:" + jarFile.getAbsolutePath());
                return CommonResult.error(NOT_GENERAT.getCode(),NOT_GENERAT.getMsg());
            }
            File dllFile = new File(mpkTenantBakFilePath + File.separator + MdkConstant.DLL + File.separator + dto.getPyName() + ".dll");
            if (!dllFile.exists()) {
                throw new RuntimeException("dll文件不存在,请先生成代码。dllPath:" + dllFile.getAbsolutePath());
                log.error("dll文件不存在,请先生成代码。dllPath:" + dllFile.getAbsolutePath());
                return CommonResult.error(NOT_GENERAT.getCode(),NOT_GENERAT.getMsg());
            }
            // 加载jar包
            classLoader = DllUtils.loadJar(jarFile.getAbsolutePath());
@@ -104,8 +107,10 @@
                        return error(GlobalErrorCodeConstants.BAD_REQUEST.getCode(),"请重新导入模型参数");
                    }
                    JSONArray jsonArray = JSON.parseArray(cache.get(uuid));
                    double[][] data = new double[jsonArray.size()][jsonArray.getJSONArray(0).size()];
                    double[][] data = new double[jsonArray.size()][];
                    for (int j = 0; j < jsonArray.size(); j++) {
                        data[j] = new double[jsonArray.getJSONArray(j).size()];
                        for (int k = 0; k < jsonArray.getJSONArray(j).size(); k++) {
                            data[j][k] = jsonArray.getJSONArray(j).getDoubleValue(k);
                        }
@@ -137,7 +142,10 @@
                return error(GlobalErrorCodeConstants.BAD_REQUEST.getCode(),"模型设置错误,请检查!");
            }
            log.info("#######################测试运行模型 " + dto.getPyName() + " ##########################");
            log.info("参数: " + JSON.toJSONString(paramsValueArray));
            HashMap result = (HashMap) clazz.getDeclaredMethod(dto.getMethodName(), paramsArray).invoke(clazz.newInstance(), paramsValueArray);
            log.info("model test run result:" + result);
            return success(JSON.toJSONString(result));
        } catch (Exception ex) {
            ex.printStackTrace();
@@ -147,7 +155,6 @@
                DllUtils.unloadDll(classLoader);
                DllUtils.unloadJar(classLoader);
            }
            System.gc();
        }
    }