From 7f0bcd00c556889ba890e5e68c681f1b5d4267e1 Mon Sep 17 00:00:00 2001
From: dengzedong <dengzedong@email>
Date: 星期四, 19 十二月 2024 18:07:20 +0800
Subject: [PATCH] 预测项状态添加模型结果异常

---
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/enums/ItemRunStatusEnum.java               |    3 ++-
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictModelHandler.java               |    3 ++-
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictModelHandlerImpl.java      |    4 +++-
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictItemHandler.java                |    3 ++-
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictModuleHandler.java              |   13 ++++++-------
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemNormalHandlerImpl.java |    5 +++--
 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/mdk/predict/impl/PredictItemMergeHandlerImpl.java  |    3 ++-
 8 files changed, 21 insertions(+), 15 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 fb32f7f..21864c0 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
@@ -156,7 +156,7 @@
             Map<String, List<MdkPredictDataDTO>> predictData = new HashMap<>();
             ItemVO predictItem = itemEntityFactory.getItemByItemNo(reqDTO.getItemNo());
             PredictItemHandler predictItemHandler = predictItemFactory.create(predictItem.getId());
-            PredictResultVO predictResult = predictItemHandler.predict(reqDTO.getPredictTime(), predictItem,null);
+            PredictResultVO predictResult = predictItemHandler.predict(reqDTO.getPredictTime(), predictItem,null,null);
             Map<String, List<DataValueVO>> resultMap = predictResultHandler.convertToPredictData(predictResult);
             if (!CollectionUtils.isEmpty(resultMap)) {
                 for (Map.Entry<String, List<DataValueVO>> entry : resultMap.entrySet()) {
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/enums/ItemRunStatusEnum.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/enums/ItemRunStatusEnum.java
index ae3d3f4..f9eb810 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/enums/ItemRunStatusEnum.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/enums/ItemRunStatusEnum.java
@@ -13,7 +13,8 @@
 public enum ItemRunStatusEnum {
     PROCESSING(1, "处理中"),
     SUCCESS(2, "成功"),
-    FAIL(3, "失败");
+    FAIL(3, "失败"),
+    MODELRESULTERROR(4, "模型结果异常");
 
     private Integer code;
     private String desc;
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictItemHandler.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictItemHandler.java
index 27352dd..2ce4fe7 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictItemHandler.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictItemHandler.java
@@ -1,5 +1,6 @@
 package com.iailab.module.model.mdk.predict;
 
+import com.iailab.module.model.mcs.pre.enums.ItemRunStatusEnum;
 import com.iailab.module.model.mdk.common.exceptions.ItemInvokeException;
 import com.iailab.module.model.mdk.vo.ItemVO;
 import com.iailab.module.model.mdk.vo.PredictResultVO;
@@ -22,5 +23,5 @@
      * @return
      * @throws ItemInvokeException
      */
-    PredictResultVO predict(Date predictTime, ItemVO predictItemDto, Map<String, double[]> predictValueMap) throws ItemInvokeException;
+    PredictResultVO predict(Date predictTime, ItemVO predictItemDto, Map<String, double[]> predictValueMap, ItemRunStatusEnum itemRunStatusEnum) throws ItemInvokeException;
 }
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictModelHandler.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictModelHandler.java
index 1f3050b..a6c11eb 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictModelHandler.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictModelHandler.java
@@ -1,6 +1,7 @@
 package com.iailab.module.model.mdk.predict;
 
 import com.iailab.module.model.mcs.pre.entity.MmPredictModelEntity;
+import com.iailab.module.model.mcs.pre.enums.ItemRunStatusEnum;
 import com.iailab.module.model.mdk.common.exceptions.ModelInvokeException;
 import com.iailab.module.model.mdk.vo.PredictResultVO;
 
@@ -21,5 +22,5 @@
      * @return
      * @throws ModelInvokeException
      */
-    PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel,String itemName) throws ModelInvokeException;
+    PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel,String itemName, ItemRunStatusEnum itemRunStatusEnum) throws ModelInvokeException;
 }
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 391be24..bf5be31 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
@@ -65,17 +65,15 @@
                 continue;
             }
             Long totalDur = 0L;
+            ItemRunStatusEnum itemRunStatusEnum = ItemRunStatusEnum.PROCESSING;
             try {
-                mmItemStatusService.recordStatus(predictItem.getId(), ItemRunStatusEnum.PROCESSING, totalDur, predictTime);
+                mmItemStatusService.recordStatus(predictItem.getId(), itemRunStatusEnum, totalDur, predictTime);
                 PredictItemHandler predictItemHandler = predictItemFactory.create(predictItem.getId());
                 long start = System.currentTimeMillis();
                 try {
                     // 预测项开始预测
-                    predictResult = predictItemHandler.predict(predictTime, predictItem, predictValueMap);
+                    predictResult = predictItemHandler.predict(predictTime, predictItem, predictValueMap,itemRunStatusEnum);
                 } catch (Exception e) {
-//                    e.printStackTrace();
-//                    log.error(String.valueOf(e));
-                    mmItemStatusService.recordStatus(predictItem.getId(), ItemRunStatusEnum.FAIL, totalDur, predictTime);
                     continue;
                 }
                 long end = System.currentTimeMillis();
@@ -95,13 +93,14 @@
                 log.info(MessageFormat.format("预测项:{0},保存时间:{1}ms", predictItem.getItemName(),
                         drtSave));
                 totalDur = totalDur + drtSave;
-                mmItemStatusService.recordStatus(predictItem.getId(), ItemRunStatusEnum.SUCCESS, totalDur, predictTime);
                 predictResultMap.put(predictItem.getItemNo(), predictResult);
             } catch (Exception e) {
                 e.printStackTrace();
                 log.error(MessageFormat.format("预测项编号:{0},预测项名称:{1},预测失败:{2} 预测时刻:{3}",
                         predictItem.getId(), predictItem.getItemName(), e.getMessage(), predictTime));
-                mmItemStatusService.recordStatus(predictItem.getId(), ItemRunStatusEnum.FAIL, totalDur, predictTime);
+                itemRunStatusEnum = ItemRunStatusEnum.FAIL;
+            } finally {
+                mmItemStatusService.recordStatus(predictItem.getId(), itemRunStatusEnum, totalDur, predictTime);
             }
         }
     }
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemMergeHandlerImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemMergeHandlerImpl.java
index e9385d7..dd8b826 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemMergeHandlerImpl.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemMergeHandlerImpl.java
@@ -4,6 +4,7 @@
 import com.iailab.module.data.api.point.dto.ApiPointDTO;
 import com.iailab.module.data.enums.DataPointFreqEnum;
 import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity;
+import com.iailab.module.model.mcs.pre.enums.ItemRunStatusEnum;
 import com.iailab.module.model.mcs.pre.service.MmItemOutputService;
 import com.iailab.module.model.mcs.pre.service.MmItemResultService;
 import com.iailab.module.model.mdk.common.enums.ItemPredictStatus;
@@ -59,7 +60,7 @@
      * @throws ItemInvokeException
      */
     @Override
-    public PredictResultVO predict(Date predictTime, ItemVO predictItemDto,Map<String, double[]> predictValueMap)
+    public PredictResultVO predict(Date predictTime, ItemVO predictItemDto, Map<String, double[]> predictValueMap, ItemRunStatusEnum itemRunStatusEnum)
             throws ItemInvokeException {
         PredictResultVO predictResult = new PredictResultVO();
         ItemPredictStatus itemStatus = ItemPredictStatus.PREDICTING;
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemNormalHandlerImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemNormalHandlerImpl.java
index 0fc07b2..cb54cce 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemNormalHandlerImpl.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemNormalHandlerImpl.java
@@ -1,6 +1,7 @@
 package com.iailab.module.model.mdk.predict.impl;
 
 import com.iailab.module.model.mcs.pre.entity.MmPredictModelEntity;
+import com.iailab.module.model.mcs.pre.enums.ItemRunStatusEnum;
 import com.iailab.module.model.mcs.pre.service.MmPredictModelService;
 import com.iailab.module.model.mdk.common.exceptions.ItemInvokeException;
 import com.iailab.module.model.mdk.common.exceptions.ModelInvokeException;
@@ -38,7 +39,7 @@
      * @throws ItemInvokeException
      */
     @Override
-    public PredictResultVO predict(Date predictTime, ItemVO predictItemDto, Map<String, double[]> predictValueMap) throws ItemInvokeException {
+    public PredictResultVO predict(Date predictTime, ItemVO predictItemDto, Map<String, double[]> predictValueMap, ItemRunStatusEnum itemRunStatusEnum) throws ItemInvokeException {
         PredictResultVO predictResult = new PredictResultVO();
         String itemId = predictItemDto.getId();
         try {
@@ -47,7 +48,7 @@
                 throw new ModelInvokeException(MessageFormat.format("{0},itemId={1}",
                         ModelInvokeException.errorGetModelEntity, itemId));
             }
-            predictResult = predictModelHandler.predictByModel(predictTime, predictModel,predictItemDto.getItemName());
+            predictResult = predictModelHandler.predictByModel(predictTime, predictModel,predictItemDto.getItemName(),itemRunStatusEnum);
             predictResult.setPredictId(itemId);
         } catch (Exception ex) {
             throw new ItemInvokeException(MessageFormat.format("{0},itemId={1}",
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 c39f706..f2c3cef 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
@@ -9,6 +9,7 @@
 import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity;
 import com.iailab.module.model.mcs.pre.entity.MmModelArithSettingsEntity;
 import com.iailab.module.model.mcs.pre.entity.MmPredictModelEntity;
+import com.iailab.module.model.mcs.pre.enums.ItemRunStatusEnum;
 import com.iailab.module.model.mcs.pre.service.MmItemOutputService;
 import com.iailab.module.model.mcs.pre.service.MmModelArithSettingsService;
 import com.iailab.module.model.mdk.common.enums.TypeA;
@@ -55,7 +56,7 @@
      * @throws ModelInvokeException
      */
     @Override
-    public synchronized PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel,String itemName) throws ModelInvokeException {
+    public synchronized PredictResultVO predictByModel(Date predictTime, MmPredictModelEntity predictModel,String itemName, ItemRunStatusEnum itemRunStatusEnum) throws ModelInvokeException {
         PredictResultVO result = new PredictResultVO();
         if (predictModel == null) {
             throw new ModelInvokeException("modelEntity is null");
@@ -99,6 +100,7 @@
             HashMap<String, Object> modelResult = DllUtils.run(newModelBean, param2Values, predictModel.getMpkprojectid());
             if (!modelResult.containsKey(CommonConstant.MDK_STATUS_CODE) || !modelResult.containsKey(CommonConstant.MDK_RESULT) ||
                     !modelResult.get(CommonConstant.MDK_STATUS_CODE).toString().equals(CommonConstant.MDK_STATUS_100)) {
+                itemRunStatusEnum = ItemRunStatusEnum.MODELRESULTERROR;
                 throw new RuntimeException("模型结果异常:" + modelResult);
             }
             modelResult = (HashMap<String, Object>) modelResult.get(CommonConstant.MDK_RESULT);

--
Gitblit v1.9.3