From 69bd5efa5e2849a560e604d0aa608d5492113915 Mon Sep 17 00:00:00 2001
From: dengzedong <dengzedong@email>
Date: 星期二, 12 十一月 2024 15:44:52 +0800
Subject: [PATCH] 模型运行输出配置

---
 iailab-module-model/iailab-module-model-biz/src/main/resources/mapper/mcs/MmItemResultDao.xml                                           |    2 
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/dto/MmPredictItemDTO.java                     |    2 
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictModelHandlerImpl.java         |   47 ++++++--
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/entity/MmItemStatusEntity.java                |    2 
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/entity/MmItemOutputEntity.java                |   16 +++
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemStatusServiceImpl.java     |    1 
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/MmItemOutputService.java              |    6 
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemOutputServiceImpl.java     |   18 ++-
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java                                   |   43 ++++++--
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemResultServiceImpl.java     |   71 ++++++++------
 iailab-module-model/iailab-module-model-biz/db/mysql.sql                                                                                |   13 ++
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/entity/MmPredictModelEntity.java              |    6 -
 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/service/impl/MmPredictItemServiceImpl.java    |   20 ++-
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictResultHandler.java                 |   38 +++---
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/vo/PredictResultVO.java                           |   11 ++
 16 files changed, 197 insertions(+), 101 deletions(-)

diff --git a/iailab-module-model/iailab-module-model-biz/db/mysql.sql b/iailab-module-model/iailab-module-model-biz/db/mysql.sql
index 5efad45..2cdaff8 100644
--- a/iailab-module-model/iailab-module-model-biz/db/mysql.sql
+++ b/iailab-module-model/iailab-module-model-biz/db/mysql.sql
@@ -856,4 +856,15 @@
     duration  bigint(20)  DEFAULT NULL COMMENT '耗时(s)',
     primary key (id),
     UNIQUE INDEX uk_item_id (item_id)
-) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '测项状态表' ROW_FORMAT = Dynamic;
\ No newline at end of file
+) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '测项状态表' ROW_FORMAT = Dynamic;
+
+-- 模型输出
+ALTER TABLE t_mm_predict_model DROP COLUMN `resultstrid`;
+alter table t_mm_item_output add column `resultstr` varchar(50) DEFAULT NULL;
+alter table t_mm_item_output add column `result_type` smallint DEFAULT NULL COMMENT '参数类型{1:一维数组;2:二维数组}';
+alter table t_mm_item_output add column `result_index` int DEFAULT NULL;
+
+-- 字典
+INSERT INTO `iailab_plat_system`.`system_dict_type` (`id`, `name`, `type`, `status`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `deleted_time`) VALUES (644, '模型结果数据类型', 'model_result_type', 0, '', '141', '2024-11-11 15:16:58', '141', '2024-11-11 15:16:58', b'0', '1970-01-01 00:00:00');
+INSERT INTO `iailab_plat_system`.`system_dict_data` (`id`, `sort`, `label`, `value`, `dict_type`, `status`, `color_type`, `css_class`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (1628, 1, 'double[]', '1', 'model_result_type', 0, '', '', '', '141', '2024-11-11 15:21:05', '141', '2024-11-11 15:21:05', b'0');
+INSERT INTO `iailab_plat_system`.`system_dict_data` (`id`, `sort`, `label`, `value`, `dict_type`, `status`, `color_type`, `css_class`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (1629, 2, 'double[][]', '2', 'model_result_type', 0, '', '', '', '141', '2024-11-11 15:21:17', '141', '2024-11-11 15:21:17', b'0');
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 1fd8c7f..89994ce 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
@@ -70,6 +70,9 @@
     @Override
     public MdkPredictModuleRespDTO predictModule(MdkPredictReqDTO reqDTO) {
         MdkPredictModuleRespDTO resp = new MdkPredictModuleRespDTO();
+        resp.setPredictTime(reqDTO.getPredictTime());
+        resp.setModuleType(reqDTO.getModuleType());
+
         Map<String, MdkPredictItemRespDTO> predictItemRespMap = new HashMap<>();
         try {
             if (reqDTO.getPredictTime() == null) {
@@ -96,18 +99,34 @@
                 }
                 List<ItemVO> predictItemList = mmPredictItemService.getByModuleId(module.getId());
                 Map<String, PredictResultVO> predictResultMap = predictModuleHandler.predict(predictItemList, reqDTO.getPredictTime(), intervalTime);
-                for (Map.Entry<String, PredictResultVO> entry : predictResultMap.entrySet()) {
-                    List<MdkPredictDataDTO> predictData = entry.getValue().getPredictList().stream().map(t-> {
-                        MdkPredictDataDTO dto1 = new MdkPredictDataDTO();
-                        dto1.setDataTime(t.getDataTime());
-                        dto1.setDataValue(t.getDataValue());
-                        return dto1;
-                    }).collect(Collectors.toList());
-                    MdkPredictItemRespDTO itemResp = new MdkPredictItemRespDTO();
-                    itemResp.setItemId(entry.getValue().getPredictId());
-                    itemResp.setPredictData(predictData);
-                    predictItemRespMap.put(entry.getKey(), itemResp);
-                }
+
+//                for (Map.Entry<String, PredictResultVO> entry : predictResultMap.entrySet()) {
+//                    for (Map.Entry<String, List<DataValueVO>> dataListEntry : entry.getValue().getPredictLists().entrySet()) {
+//                        List<MdkPredictDataDTO> predictData = dataListEntry.getValue().stream().map(t -> {
+//                            MdkPredictDataDTO dto1 = new MdkPredictDataDTO();
+//                            dto1.setDataTime(t.getDataTime());
+//                            dto1.setDataValue(t.getDataValue());
+//                            return dto1;
+//                        }).collect(Collectors.toList());
+//                        MdkPredictItemRespDTO itemResp = new MdkPredictItemRespDTO();
+//                        itemResp.setItemId(dataListEntry.getKey());
+//                        itemResp.setPredictData(predictData);
+//                        predictItemRespMap.put(entry.getKey(), itemResp);
+//                    }
+//                }
+
+//                for (Map.Entry<String, PredictResultVO> entry : predictResultMap.entrySet()) {
+//                    List<MdkPredictDataDTO> predictData = entry.getValue().getPredictList().stream().map(t-> {
+//                        MdkPredictDataDTO dto1 = new MdkPredictDataDTO();
+//                        dto1.setDataTime(t.getDataTime());
+//                        dto1.setDataValue(t.getDataValue());
+//                        return dto1;
+//                    }).collect(Collectors.toList());
+//                    MdkPredictItemRespDTO itemResp = new MdkPredictItemRespDTO();
+//                    itemResp.setItemId(entry.getValue().getPredictId());
+//                    itemResp.setPredictData(predictData);
+//                    predictItemRespMap.put(entry.getKey(), itemResp);
+//                }
             }
             log.info("预测计算结束: " + System.currentTimeMillis());
         } catch (Exception ex) {
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 a3cd858..7bfdc9e 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
@@ -215,7 +215,7 @@
         for (int i = 0; i < itemIdList.size(); i++) {
             PreDataViewVO viewDto = new PreDataViewVO();
             String itemId = itemIdList.get(i);
-            MmItemOutputEntity mmItemOutput = mmItemOutputService.getByItemid(itemId);
+//            MmItemOutputEntity mmItemOutput = mmItemOutputService.getByItemid(itemId);
             MmPredictItemEntity predictItem = mmPredictItemService.getById(itemId);
             if (predictItem == null) {
                 log.info("itemId=" + itemId + "; is null");
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/dto/MmPredictItemDTO.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/dto/MmPredictItemDTO.java
index b46875e..871679f 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/dto/MmPredictItemDTO.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/dto/MmPredictItemDTO.java
@@ -21,7 +21,7 @@
 
     private DmModuleItemEntity dmModuleItem;
 
-    private MmItemOutputEntity mmItemOutput;
+    private List<MmItemOutputEntity> mmItemOutputList;
 
     private MmPredictModelEntity mmPredictModel;
 
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/entity/MmItemOutputEntity.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/entity/MmItemOutputEntity.java
index e8d2bbd..c5871aa 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/entity/MmItemOutputEntity.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/entity/MmItemOutputEntity.java
@@ -40,6 +40,22 @@
     private String resulttableid;
 
     /**
+     * 结果
+     */
+    @NotBlank(message="结果不能为空")
+    private String resultstr;
+
+    /**
+     * 结果类型
+     */
+    private Integer resultType;
+
+    /**
+     * 结果索引
+     */
+    private Integer resultIndex;
+
+    /**
      * 数据点名称
      */
     @NotBlank(message="数据点名称不能为空")
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/entity/MmItemStatusEntity.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/entity/MmItemStatusEntity.java
index a5c6d85..e99af9c 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/entity/MmItemStatusEntity.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/entity/MmItemStatusEntity.java
@@ -26,7 +26,7 @@
     /**
      * 预测项ID
      */
-    private String itemid;
+    private String itemId;
 
     /**
      * 最新运行时间
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 2833cb2..c9fdec7 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
@@ -103,12 +103,6 @@
     private String modelparamstructure;
 
     /**
-     * 结果
-     */
-    @NotBlank(message="结果不能为空")
-    private String resultstrid;
-
-    /**
      * 模型设置
      */
     private String settingmap;
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/MmItemOutputService.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/MmItemOutputService.java
index 9904df2..dd45baa 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/MmItemOutputService.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/MmItemOutputService.java
@@ -13,7 +13,7 @@
  */
 public interface MmItemOutputService{
 
-    void saveMmItemOutput(MmItemOutputEntity mmItemOutput);
+    void saveMmItemOutput(List<MmItemOutputEntity> mmItemOutput);
 
     void update(MmItemOutputEntity mmItemOutput);
 
@@ -25,5 +25,7 @@
 
     List<MmItemOutputVO> getOutPutByPointId(String pointid);
 
-    MmItemOutputEntity getByItemid(String itemid);
+    List<MmItemOutputEntity> getByItemid(String itemid);
+
+    void deleteByItemId(String itemId);
 }
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemOutputServiceImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemOutputServiceImpl.java
index 059ae27..f678832 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemOutputServiceImpl.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemOutputServiceImpl.java
@@ -26,8 +26,7 @@
     private MmItemOutputDao mmItemOutputDao;
     
     @Override
-    public void saveMmItemOutput(MmItemOutputEntity mmItemOutput) {
-        mmItemOutput.setId(UUID.randomUUID().toString());
+    public void saveMmItemOutput(List<MmItemOutputEntity> mmItemOutput) {
         mmItemOutputDao.insert(mmItemOutput);
     }
 
@@ -43,14 +42,19 @@
     }
 
     @Override
-    public MmItemOutputEntity getByItemid(String itemid) {
+    public List<MmItemOutputEntity> getByItemid(String itemid) {
         QueryWrapper<MmItemOutputEntity> queryWrapper = new QueryWrapper();
         queryWrapper.eq("itemid", itemid);
+        queryWrapper.orderByAsc("outputorder");
         List<MmItemOutputEntity> list = mmItemOutputDao.selectList(queryWrapper);
-        if (CollectionUtils.isEmpty(list)) {
-            return new MmItemOutputEntity();
-        }
-        return list.get(0);
+        return list;
+    }
+
+    @Override
+    public void deleteByItemId(String itemId) {
+        QueryWrapper<MmItemOutputEntity> queryWrapper = new QueryWrapper();
+        queryWrapper.eq("itemid", itemId);
+        mmItemOutputDao.delete(queryWrapper);
     }
 
     @Override
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemResultServiceImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemResultServiceImpl.java
index 51c9c47..b69168a 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemResultServiceImpl.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemResultServiceImpl.java
@@ -62,6 +62,7 @@
     public void savePredictValue(Map<String, List<DataValueVO>> predictValueMap, int t, String nIndex, Date predictTime) {
         List<MmItemResultEntity> importList = new ArrayList<>();
         List<MmItemResultEntity> lastList = new ArrayList<>();
+
         for (Map.Entry<String, List<DataValueVO>> entry : predictValueMap.entrySet()) {
             for (DataValueVO dataVo : entry.getValue()) {
                 MmItemResultEntity importData = new MmItemResultEntity();
@@ -104,39 +105,49 @@
             map4.put("TABLENAME", "T_MM_ITEM_RESULT_JSON");
             map4.put("entity", resultJson);
             mmItemResultDao.savePredictJsonValue(map4);
+
+            Map<String, Object> params = new HashMap(4);
+            params.put("TABLENAME", T_MM_ITEM_RESULT);
+            params.put("OUTPUTID", entry.getKey());
+            params.put("STARTTIME", importList.get(0).getDatatime());
+            params.put("ENDTIME", importList.get(importList.size() - 1).getDatatime());
+            mmItemResultDao.deletePredictValue(params);
+
+
         }
 
-        Map<String, Object> params = new HashMap(4);
-        params.put("TABLENAME", T_MM_ITEM_RESULT);
-        params.put("OUTPUTID", importList.get(0).getOutputid());
-        params.put("STARTTIME", importList.get(0).getDatatime());
-        params.put("ENDTIME", importList.get(importList.size() - 1).getDatatime());
-        mmItemResultDao.deletePredictValue(params);
+//        Map<String, Object> params = new HashMap(4);
+//        params.put("TABLENAME", T_MM_ITEM_RESULT);
+//        params.put("OUTPUTID", importList.get(0).getOutputid());
+//        params.put("STARTTIME", importList.get(0).getDatatime());
+//        params.put("ENDTIME", importList.get(importList.size() - 1).getDatatime());
+//        mmItemResultDao.deletePredictValue(params);
 
-        int num1 = importList.size() / max_group_count;
-        int num2 = importList.size() % max_group_count;
-        if (num2 != 0) {
-            num1++;
-        }
-
-        List<MmItemResultEntity> tempList;
-        //先删除已经存在的数据,再插入新数据
-        for (int i = 0; i < num1; i++) {
-            int startIndex = max_group_count * i;
-            int count = max_group_count;
-            if (num2!=0 && i == num1 - 1) {
-                count = num2;
-            }
-            tempList = new ArrayList<>();
-            //获取某个索引范围内的对象集合
-            for (int j = startIndex; j < startIndex + count; j++) {
-                tempList.add(importList.get(j));
-            }
-            Map<String, Object> map2 = new HashMap<>(2);
-            map2.put("TABLENAME", T_MM_ITEM_RESULT);
-            map2.put("list", tempList);
-            mmItemResultDao.savePredictValue(map2);
-        }
+//        int num1 = importList.size() / max_group_count;
+//        int num2 = importList.size() % max_group_count;
+//        if (num2 != 0) {
+//            num1++;
+//        }
+//
+//        List<MmItemResultEntity> tempList;
+//        //先删除已经存在的数据,再插入新数据
+//        for (int i = 0; i < num1; i++) {
+//            int startIndex = max_group_count * i;
+//            int count = max_group_count;
+//            if (num2!=0 && i == num1 - 1) {
+//                count = num2;
+//            }
+//            tempList = new ArrayList<>();
+//            //获取某个索引范围内的对象集合
+//            for (int j = startIndex; j < startIndex + count; j++) {
+//                tempList.add(importList.get(j));
+//            }
+//            Map<String, Object> map2 = new HashMap<>(2);
+//            map2.put("TABLENAME", T_MM_ITEM_RESULT);
+//            map2.put("list", tempList);
+//            mmItemResultDao.savePredictValue(map2);
+//        }
+        mmItemResultDao.insertBatch(importList,max_group_count);
 
         Map<String, Object> map3 = new HashMap<>(2);
         map3.put("TABLENAME", "T_MM_ITEM_RESULT_LAST_POINT");
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemStatusServiceImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemStatusServiceImpl.java
index f5f5b04..545ef61 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemStatusServiceImpl.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemStatusServiceImpl.java
@@ -30,6 +30,7 @@
         if (entity == null) {
             entity = new MmItemStatusEntity();
             entity.setId(UUID.randomUUID().toString());
+            entity.setItemId(itemId);
             entity.setLastTime(new Date());
             entity.setStatus(status.getCode());
             entity.setDuration(duration);
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 828c7fd..a1bf58c 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
@@ -127,8 +127,11 @@
         dmModuleItem.setItemid(predictItem.getId());
         dmModuleItemService.saveModuleItem(dmModuleItem);
 
-        MmItemOutputEntity mmItemOutput = mmPredictItemDto.getMmItemOutput();
-        mmItemOutput.setItemid(predictItem.getId());
+        List<MmItemOutputEntity> mmItemOutput = mmPredictItemDto.getMmItemOutputList();
+        mmItemOutput.forEach(e -> {
+            e.setId(UUID.randomUUID().toString());
+            e.setItemid(predictItem.getId());
+        });
         mmItemOutputService.saveMmItemOutput(mmItemOutput);
     }
 
@@ -162,10 +165,13 @@
         if (!"".equals(dmModuleItem.getId()) && dmModuleItem.getId() != null) {
             dmModuleItemService.update(dmModuleItem);
         }
-        MmItemOutputEntity mmItemOutput = mmPredictItemDto.getMmItemOutput();
-        if (!"".equals(mmItemOutput.getId()) && dmModuleItem.getId() != null) {
-            mmItemOutputService.update(mmItemOutput);
-        }
+        mmItemOutputService.deleteByItemId(predictItem.getId());
+        List<MmItemOutputEntity> mmItemOutput = mmPredictItemDto.getMmItemOutputList();
+        mmItemOutput.forEach(e -> {
+            e.setId(UUID.randomUUID().toString());
+            e.setItemid(predictItem.getId());
+        });
+        mmItemOutputService.saveMmItemOutput(mmItemOutput);
     }
 
     @DSTransactional(rollbackFor = Exception.class)
@@ -183,7 +189,7 @@
         MmPredictItemDTO mmPredictItemDto = BeanUtils.toBean(predictItem, MmPredictItemDTO.class);
         mmPredictItemDto.setMmPredictItem(predictItem);
         mmPredictItemDto.setDmModuleItem(dmModuleItemService.getByItemid(id));
-        mmPredictItemDto.setMmItemOutput(mmItemOutputService.getByItemid(id));
+        mmPredictItemDto.setMmItemOutputList(mmItemOutputService.getByItemid(id));
         MmItemTypeEntity itemType = mmItemTypeImpl.getById(predictItem.getItemtypeid());
         if (itemType != null && ItemTypeEnum.NORMAL_ITEM.getName().equals(itemType.getItemtypename())) {
             MmPredictModelEntity mmPredictModel = mmPredictModelService.getByItemid(id);
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictResultHandler.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictResultHandler.java
index ca8d21a..8bc9517 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictResultHandler.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictResultHandler.java
@@ -1,12 +1,14 @@
 package com.iailab.module.model.mdk.predict;
 
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
 import com.iailab.module.data.api.point.DataPointApi;
 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.service.MmItemResultService;
 import com.iailab.module.model.mdk.factory.ItemEntityFactory;
-import com.iailab.module.model.mdk.vo.MmItemOutputVO;
 import com.iailab.module.model.mdk.vo.DataValueVO;
+import com.iailab.module.model.mdk.vo.MmItemOutputVO;
 import com.iailab.module.model.mdk.vo.PredictResultVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
@@ -40,29 +42,26 @@
             resultMap.put(itemOutPutList.get(0).getId(), predictResult.getPredictList());
             return resultMap;
         }
-        ApiPointDTO point = dataPointApi.getInfoById(itemOutPutList.get(0).getPointId());
-        List<Date> dateTimeList = new ArrayList<>();
-        Integer rows = predictResult.getPredictMatrix().length;
-        Integer columns = predictResult.getPredictMatrix()[0].length;
-        Date tempTime = predictResult.getPredictTime();
-        for (Integer i = 0; i < rows; i++) {
-            dateTimeList.add(tempTime);
-            Calendar calendar = Calendar.getInstance();
-            calendar.setTime(tempTime);
-            calendar.add(Calendar.SECOND, DataPointFreqEnum.getEumByCode(point.getMinfreqid()).getValue());
-            tempTime = calendar.getTime();
-        }
-        for (Integer i = 0; i < columns; i++) {
+        Map<MmItemOutputEntity, double[]> predictMatrixs = predictResult.getPredictMatrixs();
+        HashMap<String,List<DataValueVO>> predictLists = new HashMap<>();
+        for (Map.Entry<MmItemOutputEntity, double[]> entry : predictMatrixs.entrySet()) {
+            ApiPointDTO point = dataPointApi.getInfoById(entry.getKey().getPointid());
+            Integer pointMinfreq = DataPointFreqEnum.getEumByCode(point.getMinfreqid()).getValue();
+            Integer rows = entry.getValue().length;
             List<DataValueVO> predictDataList = new ArrayList<>();
-            for (Integer j = 0; j < rows; j++) {
+            Calendar calendar = Calendar.getInstance();
+            calendar.setTime(predictResult.getPredictTime());
+            for (Integer i = 0; i < rows; i++) {
                 DataValueVO predictData = new DataValueVO();
-                predictData.setDataTime(dateTimeList.get(j));
-                predictData.setDataValue(Double.valueOf(predictResult.getPredictMatrix()[j][i]));
+                predictData.setDataTime(calendar.getTime());
+                predictData.setDataValue(Double.valueOf(entry.getValue()[i]));
                 predictDataList.add(predictData);
+
+                calendar.add(Calendar.SECOND, pointMinfreq);
             }
-            resultMap.put(itemOutPutList.get(i).getId(), predictDataList);
-            predictResult.setPredictList(predictDataList);
+            resultMap.put(entry.getKey().getId(), predictDataList);
         }
+        predictResult.setPredictLists(predictLists);
         return resultMap;
     }
 
@@ -72,6 +71,7 @@
      * @param predictResult
      */
     @Async
+    @DSTransactional
     public void savePredictResult(PredictResultVO predictResult) {
         Map<String, List<DataValueVO>> resultMap = convertToPredictData(predictResult);
         mmItemResultService.savePredictValue(resultMap, predictResult.getLt(), "n", predictResult.getPredictTime());
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 ef75d02..0f05ef4 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
@@ -4,9 +4,12 @@
 import com.alibaba.fastjson.JSONObject;
 import com.iail.IAILMDK;
 import com.iail.model.IAILModel;
+import com.iailab.module.model.mcs.pre.controller.admin.MmItemOutputController;
+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.MmModelResultstrEntity;
 import com.iailab.module.model.mcs.pre.entity.MmPredictModelEntity;
+import com.iailab.module.model.mcs.pre.service.MmItemOutputService;
 import com.iailab.module.model.mcs.pre.service.MmModelArithSettingsService;
 import com.iailab.module.model.mcs.pre.service.MmModelResultstrService;
 import com.iailab.module.model.mdk.common.enums.TypeA;
@@ -18,12 +21,10 @@
 import com.iailab.module.model.mpk.common.utils.DllUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.parameters.P;
 import org.springframework.stereotype.Component;
 
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
+import java.util.*;
 
 /**
  * @author PanZhibao
@@ -39,6 +40,8 @@
 
     @Autowired
     private MmModelResultstrService mmModelResultstrService;
+    @Autowired
+    private MmItemOutputService mmItemOutputService;
 
     @Autowired
     private SampleConstructor sampleConstructor;
@@ -93,18 +96,36 @@
             jsonObjResult.put("result", modelResult);
             log.info(String.valueOf(jsonObjResult));
 
-            MmModelResultstrEntity modelResultstr = mmModelResultstrService.getInfo(predictModel.getResultstrid());
-            log.info("模型计算完成:modelId=" + modelId + result);
-            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();
+            List<MmItemOutputEntity> ItemOutputList = mmItemOutputService.getByItemid(predictModel.getItemid());
+            log.info("模型计算完成:modelId=" + modelId + modelResult);
+
+            Map<MmItemOutputEntity,double[]> predictMatrixs = new HashMap<>(ItemOutputList.size());
+
+            for (MmItemOutputEntity outputEntity : ItemOutputList) {
+                String resultStr = outputEntity.getResultstr();
+                if (modelResult.containsKey(resultStr)) {
+                    if (outputEntity.getResultType() == 1) {
+                        // 一维数组
+                        Double[] temp = (Double[]) modelResult.get(resultStr);
+                        double[] temp1 = new double[temp.length];
+                        for (int i = 0; i < temp.length; i++) {
+                            temp1[i] = temp[i].doubleValue();
+                        }
+                        predictMatrixs.put(outputEntity,temp1);
+                    }else if (outputEntity.getResultType() == 2) {
+                        // 二维数组
+                        Double[][] temp = (Double[][]) modelResult.get(resultStr);
+                        Double[] temp2 = temp[outputEntity.getResultIndex()];
+                        double[] temp1 = new double[temp2.length];
+                        for (int i = 0; i < temp2.length; i++) {
+                            temp1[i] = temp2[i].doubleValue();
+                        }
+                        predictMatrixs.put(outputEntity,temp1);
                     }
                 }
-                result.setPredictMatrix(temp1);
             }
+
+            result.setPredictMatrixs(predictMatrixs);
             result.setModelResult(modelResult);
             result.setPredictTime(predictTime);
         } catch (Exception ex) {
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 5606d9e..b7d334a 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
@@ -1,5 +1,6 @@
 package com.iailab.module.model.mdk.vo;
 
+import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity;
 import lombok.AllArgsConstructor;
 import lombok.Builder;
 import lombok.Data;
@@ -8,6 +9,7 @@
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 @Data
 @AllArgsConstructor
@@ -31,6 +33,11 @@
     private double[][] predictMatrix;
 
     /**
+     * 统一预测入口的预测类型(循环调用、手动调用) Map<MmItemOutputEntity,double[]>
+     */
+    private Map<MmItemOutputEntity,double[]> predictMatrixs;
+
+    /**
      * 时间间隔 (当前预测时间 与 上一次预测时间 相差的分钟数;系统计算得出)
      */
     private int t;
@@ -49,6 +56,10 @@
      * 预测集合
      */
     private List<DataValueVO> predictList;
+    /**
+     * 预测集合
+     */
+    private HashMap<String,List<DataValueVO>> predictLists;
 
     /**
      * 模型结果
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/resources/mapper/mcs/MmItemResultDao.xml b/iailab-module-model/iailab-module-model-biz/src/main/resources/mapper/mcs/MmItemResultDao.xml
index 910200c..ec7a065 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/resources/mapper/mcs/MmItemResultDao.xml
+++ b/iailab-module-model/iailab-module-model-biz/src/main/resources/mapper/mcs/MmItemResultDao.xml
@@ -18,7 +18,7 @@
         (id,outputid,datatime,datavalue)
         VALUES
         <foreach item="item" collection="list" separator=",">
-            (#{item.id},#{item.outputId},#{item.dataTime},#{item.dataValue})
+            (#{item.id},#{item.outputid},#{item.datatime},#{item.datavalue})
         </foreach>
     </insert>
 

--
Gitblit v1.9.3