From 1a2b62d8d2f56f6cd67f225fdc82bb29705d9286 Mon Sep 17 00:00:00 2001
From: dengzedong <dengzedong@email>
Date: 星期五, 18 十月 2024 13:58:11 +0800
Subject: [PATCH] 模型运行方法 ItemStatus STATUS1(1, "启用"); 添加字段 mpkProjectId 模型运行api 其他bug调整

---
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/common/utils/DllUtils.java                            |   15 +++++++
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictModelHandlerImpl.java             |   19 +++++++--
 iailab-module-model/iailab-module-model-biz/src/main/resources/mapper/mcs/MmPredictItemDao.xml                                              |    4 +-
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmModelArithSettingsServiceImpl.java |    6 +-
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/vo/ItemVO.java                                        |    5 ++
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/service/impl/MpkFileServiceImpl.java                  |   16 ++++----
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleInfoConstructor.java              |    2 
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java                                       |    2 
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/entity/MmPredictModelEntity.java                  |    5 ++
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/controller/admin/MmPredictItemController.java     |    2 +
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/enums/ItemStatus.java                             |    2 
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmPredictItemServiceImpl.java        |    2 
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictModuleHandler.java                     |    2 
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/vo/PredictResultVO.java                               |    6 +++
 iailab-module-model/iailab-module-model-biz/src/main/resources/mapper/mcs/MmItemOutputDao.xml                                               |    2 
 15 files changed, 67 insertions(+), 23 deletions(-)

diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java
index e4ae4ab..a5d05a8 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java
@@ -143,7 +143,7 @@
             resp.setPredictTime(reqDTO.getPredictTime());
             log.info("预测计算结束: " + System.currentTimeMillis());
         } catch (Exception ex) {
-            log.info("预测计算异常: " + System.currentTimeMillis());
+            log.info("预测计算异常: " + System.currentTimeMillis(),ex);
             return resp;
         }
 
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/controller/admin/MmPredictItemController.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/controller/admin/MmPredictItemController.java
index ceeac24..a3cd858 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/controller/admin/MmPredictItemController.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/controller/admin/MmPredictItemController.java
@@ -1,5 +1,6 @@
 package com.iailab.module.model.mcs.pre.controller.admin;
 
+import cn.hutool.core.io.FileUtil;
 import com.baomidou.dynamic.datasource.annotation.DSTransactional;
 import com.iailab.framework.common.pojo.CommonResult;
 import com.iailab.framework.common.pojo.PageResult;
@@ -132,6 +133,7 @@
     @PostMapping("/upload-model")
     public CommonResult<Map<String, Object>> uploadModel(@RequestParam("file") MultipartFile file) throws Exception {
         String uploadDir = modelPath + file.getOriginalFilename();
+        FileUtil.mkParentDirs(uploadDir);
         file.transferTo(new File(uploadDir));
         Map<String, Object> result = iAILModelUtil.parseModel(uploadDir);
         result.put("originalFilename", file.getOriginalFilename().replace(CommonConstant.MDK_SUFFIX, ""));
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/entity/MmPredictModelEntity.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/entity/MmPredictModelEntity.java
index c182564..2833cb2 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/entity/MmPredictModelEntity.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/entity/MmPredictModelEntity.java
@@ -127,4 +127,9 @@
      * 预测阶段需要输入的数据长度
      */
     private Integer pdim;
+
+    /**
+     * 项目id
+     */
+    private String mpkprojectid;
 }
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/enums/ItemStatus.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/enums/ItemStatus.java
index a79dad0..5bb1b0f 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/enums/ItemStatus.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/enums/ItemStatus.java
@@ -12,7 +12,7 @@
 @AllArgsConstructor
 public enum ItemStatus {
     STATUS0(0, "禁用"),
-    STATUS1(0, "启用");
+    STATUS1(1, "启用");
 
     private Integer code;
     private String desc;
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmModelArithSettingsServiceImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmModelArithSettingsServiceImpl.java
index cf92cf3..e84ba70 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmModelArithSettingsServiceImpl.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmModelArithSettingsServiceImpl.java
@@ -49,8 +49,8 @@
 
     @Override
     public List<MmModelArithSettingsEntity> getByModelId(String modelId) {
-        QueryWrapper<MmModelArithSettingsEntity> queryWrapper = new QueryWrapper();
-        queryWrapper.eq("modelid", modelId);
-        return mmModelArithSettingsDao.selectList(queryWrapper);
+        Map<String, Object> params = new HashMap<>();
+        params.put("modelid", modelId);
+        return mmModelArithSettingsDao.getMmModelArithSettings(params);
     }
 }
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmPredictItemServiceImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmPredictItemServiceImpl.java
index f0ceded..7c2a365 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmPredictItemServiceImpl.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmPredictItemServiceImpl.java
@@ -216,7 +216,7 @@
     @Override
     public List<ItemVO> getByModuleId(String moduleId) {
         Map<String, Object> params = new HashMap<>();
-
+        params.put("MODULEID",moduleId);
         return mmPredictItemDao.getByModuleId(params);
     }
 
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictModuleHandler.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictModuleHandler.java
index 2e2b1a5..a43780e 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictModuleHandler.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictModuleHandler.java
@@ -38,7 +38,7 @@
 
         PredictResultVO predictResult = new PredictResultVO();
         for (ItemVO predictItem : predictItemList) {
-            if (!predictItem.getStatus().equals(ItemStatus.STATUS1)) {
+            if (!predictItem.getStatus().equals(ItemStatus.STATUS1.getCode())) {
                 continue;
             }
             try {
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictModelHandlerImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictModelHandlerImpl.java
index 7b47923..41246be 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictModelHandlerImpl.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictModelHandlerImpl.java
@@ -15,6 +15,7 @@
 import com.iailab.module.model.mdk.sample.SampleConstructor;
 import com.iailab.module.model.mdk.sample.dto.SampleData;
 import com.iailab.module.model.mdk.vo.PredictResultVO;
+import com.iailab.module.model.mpk.common.utils.DllUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
@@ -80,16 +81,26 @@
             log.info(String.valueOf(jsonObjParam2Values));
 
             //IAILMDK.run
-            HashMap<String, Object> modelResult = IAILMDK.run(newModelBean, param2Values);
+//            HashMap<String, Object> modelResult = IAILMDK.run(newModelBean, param2Values);
+            HashMap<String, Object> modelResult = DllUtils.run(newModelBean, param2Values, predictModel.getMpkprojectid());
             //打印结果
             JSONObject jsonObjResult = new JSONObject();
-            jsonObjResult.put("result", result);
+            jsonObjResult.put("result", modelResult);
             log.info(String.valueOf(jsonObjResult));
 
             MmModelResultstrEntity modelResultstr = mmModelResultstrService.getInfo(predictModel.getResultstrid());
             log.info("模型计算完成:modelId=" + modelId + result);
-            double[][] temp = (double[][]) modelResult.get(modelResultstr.getResultstr());
-            result.setPredictMatrix(temp);
+            if (modelResult.containsKey(modelResultstr.getResultstr())) {
+                Double[][] temp = (Double[][]) modelResult.get(modelResultstr.getResultstr());
+                double[][] temp1 = new double[temp.length][temp[0].length];
+                for (int i = 0; i < temp.length; i++) {
+                    for (int j = 0; j < temp[i].length; j++) {
+                        temp1[i][j] = temp[i][j].doubleValue();
+                    }
+                }
+                result.setPredictMatrix(temp1);
+            }
+            result.setModelResult(modelResult);
             result.setPredictTime(predictTime);
         } catch (Exception ex) {
             log.error("IAILModel对象构造失败,modelId=" + modelId);
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleInfoConstructor.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleInfoConstructor.java
index 17002f6..8b45b26 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleInfoConstructor.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleInfoConstructor.java
@@ -95,7 +95,7 @@
         int curDataLength = modelInputParamEntityList.get(0).getDatalength();
         for (MmModelParamEntity entry : modelInputParamEntityList) {
             columnInfo.setParamType(entry.getModelparamtype());
-            columnInfo.setId(entry.getModelparamid());
+            columnInfo.setParamId(entry.getModelparamid());
             columnInfo.setDataLength(entry.getDatalength());
             columnInfo.setModelParamOrder(entry.getModelparamorder());
             columnInfo.setModelParamPortOrder(entry.getModelparamportorder());
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/vo/ItemVO.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/vo/ItemVO.java
index 2068a7a..a6efdcf 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/vo/ItemVO.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/vo/ItemVO.java
@@ -26,4 +26,9 @@
      * 保留的预测点位 (T+2 则n=2, T+30则n=30, T+n则表示从最后点位开始,n=预测长度;n由系统配置得出)
      */
     private String saveIndex;
+
+    /**
+     * 项目id
+     */
+    private String mpkProjectId;
 }
\ No newline at end of file
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/vo/PredictResultVO.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/vo/PredictResultVO.java
index 3c36180..5606d9e 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/vo/PredictResultVO.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/vo/PredictResultVO.java
@@ -6,6 +6,7 @@
 import lombok.NoArgsConstructor;
 
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 
 @Data
@@ -48,4 +49,9 @@
      * 预测集合
      */
     private List<DataValueVO> predictList;
+
+    /**
+     * 模型结果
+     */
+    private HashMap<String, Object> modelResult;
 }
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 61cb7a8..947da19 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,6 +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;
@@ -207,4 +209,17 @@
         }
 
     }
+
+    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);
+            Class<?> clazz = classLoader.loadClass(model.getClassName());
+            Method method = clazz.getMethod(model.getMethodName(), model.getParamsArray());
+            return (HashMap)method.invoke(clazz.newInstance(), paramsValueArray);
+        }
+    }
 }
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/service/impl/MpkFileServiceImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/service/impl/MpkFileServiceImpl.java
index 84d5eb6..afe68d0 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/service/impl/MpkFileServiceImpl.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/service/impl/MpkFileServiceImpl.java
@@ -132,10 +132,10 @@
         modelMethodService.insertList(dto.getModelMethods(), entity.getId());
 
         // 替换环境变量MDK_PKGS下的py文件
-        String mdkPkgs = System.getenv("MDK_PKGS");
-        String pyFilePath = mdkPkgs + File.separator + entity.getPyModule().replace(".", File.separator) + File.separator + entity.getPyName() + ".pyd";
-        FileUtil.mkParentDirs(pyFilePath);
-        FileUtil.copy(entity.getFilePath(), pyFilePath, true);
+//        String mdkPkgs = System.getenv("MDK_PKGS");
+//        String pyFilePath = mdkPkgs + File.separator + entity.getPyModule().replace(".", File.separator) + File.separator + entity.getPyName() + ".pyd";
+//        FileUtil.mkParentDirs(pyFilePath);
+//        FileUtil.copy(entity.getFilePath(), pyFilePath, true);
     }
 
     @Override
@@ -149,10 +149,10 @@
         modelMethodService.insertList(dto.getModelMethods(), entity.getId());
 
         // 替换环境变量MDK_PKGS下的py文件
-        String mdkPkgs = System.getenv("MDK_PKGS");
-        String pyFilePath = mdkPkgs + File.separator + entity.getPyModule().replace(".", File.separator) + File.separator + entity.getPyName() + ".pyd";
-        FileUtil.mkParentDirs(pyFilePath);
-        FileUtil.copy(entity.getFilePath(), pyFilePath, true);
+//        String mdkPkgs = System.getenv("MDK_PKGS");
+//        String pyFilePath = mdkPkgs + File.separator + entity.getPyModule().replace(".", File.separator) + File.separator + entity.getPyName() + ".pyd";
+//        FileUtil.mkParentDirs(pyFilePath);
+//        FileUtil.copy(entity.getFilePath(), pyFilePath, true);
     }
 
     @Override
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/resources/mapper/mcs/MmItemOutputDao.xml b/iailab-module-model/iailab-module-model-biz/src/main/resources/mapper/mcs/MmItemOutputDao.xml
index d925891..37f3a81 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/resources/mapper/mcs/MmItemOutputDao.xml
+++ b/iailab-module-model/iailab-module-model-biz/src/main/resources/mapper/mcs/MmItemOutputDao.xml
@@ -30,7 +30,7 @@
                t1.outputorder
         FROM t_mm_item_output t1,
              t_mm_result_table t2
-        WHERE t1.itemid = #{value}
+        WHERE t1.itemid = #{itemid}
           AND t1.resulttableid = t2.id
         ORDER BY t1.outputorder
     </select>
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/resources/mapper/mcs/MmPredictItemDao.xml b/iailab-module-model/iailab-module-model-biz/src/main/resources/mapper/mcs/MmPredictItemDao.xml
index 06aa959..735b599 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/resources/mapper/mcs/MmPredictItemDao.xml
+++ b/iailab-module-model/iailab-module-model-biz/src/main/resources/mapper/mcs/MmPredictItemDao.xml
@@ -144,8 +144,8 @@
         t1.predictphase,
         t1.workchecked
         FROM
-        ${TABLESCHEMA}.t_mm_predict_item t1,
-        ${TABLESCHEMA}.t_mm_item_type t2
+        t_mm_predict_item t1,
+        t_mm_item_type t2
         WHERE t1.itemtypeid=t2.id
         <if test="ITEMID != null and ITEMID != ''">
             AND t1.id=#{ITEMID}

--
Gitblit v1.9.3