From 07890ec0dcb75572740f25a29c80f6d7bddb39e0 Mon Sep 17 00:00:00 2001
From: dengzedong <dengzedong@email>
Date: 星期四, 19 十二月 2024 15:45:46 +0800
Subject: [PATCH] 模型运行测点数据获取方式修改 merge预测模型数据获取方式修改

---
 iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/DataPointApi.java                           |    4 +
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/ScheduleSampleInfoConstructor.java      |   19 ++++
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/impl/DaPointServiceImpl.java            |    9 +-
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/schedule/impl/ScheduleModelHandlerImpl.java    |   15 ++-
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleInfoConstructor.java       |   18 ++++
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java              |    9 +-
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemNormalHandlerImpl.java |    3 
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java                                |   15 +++
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemMergeHandlerImpl.java  |   94 ++++++++++++-----------
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java                       |   11 ++
 iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointDTO.java                        |    3 
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictItemHandler.java                |    3 
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/DaPointService.java                     |    3 
 iailab-module-model/iailab-module-model-api/src/main/java/com/iailab/module/model/api/mdk/dto/MdkScheduleReqDTO.java                 |    2 
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictModuleHandler.java              |   27 ++++--
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/vo/PredictResultVO.java                        |    4 +
 16 files changed, 159 insertions(+), 80 deletions(-)

diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/DataPointApi.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/DataPointApi.java
index a4244f6..6a8c3f5 100644
--- a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/DataPointApi.java
+++ b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/DataPointApi.java
@@ -30,6 +30,10 @@
     @Operation(summary = "根据测点ID查询测点信息")
     ApiPointDTO getInfoById(@PathVariable("pointId") String pointId);
 
+    @PostMapping(PREFIX + "/info/ids")
+    @Operation(summary = "根据多个测点ID查询测点信息")
+    List<ApiPointDTO> getInfoByIds(@RequestParam("pointNos") List<String> pointIds);
+
     @PostMapping(PREFIX + "/query-points/real-value")
     @Operation(summary = "查询多个测点当前值")
     Map<String, Object> queryPointsRealValue(@RequestParam("pointNos") List<String> pointNos);
diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointDTO.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointDTO.java
index 24972b3..e98d182 100644
--- a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointDTO.java
+++ b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointDTO.java
@@ -15,6 +15,9 @@
 public class ApiPointDTO implements Serializable {
     private static final long serialVersionUID = 1L;
 
+    @Schema(description = "id", required = true)
+    private String id;
+
     @Schema(description = "测点编码", required = true)
     private String pointNo;
 
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java
index dd9b84a..d57f185 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java
@@ -38,7 +38,16 @@
 
     @Override
     public ApiPointDTO getInfoById(String pointId) {
-        return ConvertUtils.sourceToTarget(daPointService.getSimpleInfoById(pointId), ApiPointDTO.class);
+        return daPointService.getSimpleInfoById(pointId);
+    }
+
+    @Override
+    public List<ApiPointDTO> getInfoByIds(List<String> pointIds) {
+        List<ApiPointDTO> result = new ArrayList<>(pointIds.size());
+        for (String pointId : pointIds) {
+            result.add(daPointService.getSimpleInfoById(pointId));
+        }
+        return result;
     }
 
     @Override
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/DaPointService.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/DaPointService.java
index 34bc23e..5157f2a 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/DaPointService.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/DaPointService.java
@@ -1,6 +1,7 @@
 package com.iailab.module.data.point.service;
 
 import com.iailab.framework.common.pojo.PageResult;
+import com.iailab.module.data.api.point.dto.ApiPointDTO;
 import com.iailab.module.data.point.dto.DaPointDTO;
 import com.iailab.module.data.point.vo.*;
 
@@ -17,7 +18,7 @@
 
     DaPointDTO info(String id);
 
-    DaPointDTO getSimpleInfoById(String id);
+    ApiPointDTO getSimpleInfoById(String id);
 
     DaPointDTO getSimpleInfoByNo(String no);
 
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/impl/DaPointServiceImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/impl/DaPointServiceImpl.java
index 53c8b35..b9742f0 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/impl/DaPointServiceImpl.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/impl/DaPointServiceImpl.java
@@ -9,6 +9,7 @@
 import com.iailab.framework.common.pojo.PageResult;
 import com.iailab.framework.common.util.object.BeanUtils;
 import com.iailab.framework.common.util.object.ConvertUtils;
+import com.iailab.module.data.api.point.dto.ApiPointDTO;
 import com.iailab.module.data.channel.common.service.ChannelSourceService;
 import com.iailab.module.data.common.enums.CommonConstant;
 import com.iailab.module.data.common.enums.IsEnableEnum;
@@ -67,7 +68,7 @@
     @Resource
     private DaPointCollectStatusService daPointCollectStatusService;
 
-    private static Map<String, DaPointDTO> pointIdMap = new ConcurrentHashMap<>();
+    private static Map<String, ApiPointDTO> pointIdMap = new ConcurrentHashMap<>();
 
     private static Map<String, DaPointDTO> pointNoMap = new ConcurrentHashMap<>();
 
@@ -112,16 +113,16 @@
     }
 
     @Override
-    public DaPointDTO getSimpleInfoById(String id) {
+    public ApiPointDTO getSimpleInfoById(String id) {
         if (pointIdMap.containsKey(id)) {
             return pointIdMap.get(id);
         }
-        DaPointDTO dto = ConvertUtils.sourceToTarget(daPointDao.selectById(id), DaPointDTO.class);
+        ApiPointDTO dto = ConvertUtils.sourceToTarget(daPointDao.selectById(id), ApiPointDTO.class);
         if (dto == null) {
             return null;
         }
         pointIdMap.put(id, dto);
-        return pointIdMap.get(id);
+        return dto;
     }
 
     @Override
diff --git a/iailab-module-model/iailab-module-model-api/src/main/java/com/iailab/module/model/api/mdk/dto/MdkScheduleReqDTO.java b/iailab-module-model/iailab-module-model-api/src/main/java/com/iailab/module/model/api/mdk/dto/MdkScheduleReqDTO.java
index 6e1d455..589d7f1 100644
--- a/iailab-module-model/iailab-module-model-api/src/main/java/com/iailab/module/model/api/mdk/dto/MdkScheduleReqDTO.java
+++ b/iailab-module-model/iailab-module-model-api/src/main/java/com/iailab/module/model/api/mdk/dto/MdkScheduleReqDTO.java
@@ -1,5 +1,6 @@
 package com.iailab.module.model.api.mdk.dto;
 
+import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 
@@ -22,5 +23,6 @@
 
     @Schema(description = "调度方案时间")
     @NotNull(message="调度方案时间不能为空")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
     private Date scheduleTime;
 }
\ No newline at end of file
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 9fe6967..fb32f7f 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
@@ -97,7 +97,16 @@
                     intervalTime = (int) (reqDTO.getPredictTime().getTime() - module.getPredicttime().getTime()) / (1000 * 60);
                 }
                 List<ItemVO> predictItemList = mmPredictItemService.getByModuleId(module.getId());
-                Map<String, PredictResultVO> predictResultMap = predictModuleHandler.predict(predictItemList, reqDTO.getPredictTime(), intervalTime);
+                Map<String, PredictResultVO> predictResultMap = new HashMap<>(predictItemList.size());
+                // 分组,先运行normal预测项,再将结果传递给merge预测项
+                List<ItemVO> normalItems = predictItemList.stream().filter(e -> e.getItemType().equals("NormalItem")).collect(Collectors.toList());
+                if (!CollectionUtils.isEmpty(normalItems)) {
+                    predictModuleHandler.predict(normalItems, reqDTO.getPredictTime(), intervalTime,predictResultMap);
+                    List<ItemVO> mergeItem = predictItemList.stream().filter(e -> e.getItemType().equals("MergeItem")).collect(Collectors.toList());
+                    if (!CollectionUtils.isEmpty(mergeItem)) {
+                        predictModuleHandler.predict(mergeItem, reqDTO.getPredictTime(), intervalTime,predictResultMap);
+                    }
+                }
                 // 更新Module时间
                 dmModuleService.updatePredictTime(module.getId(), reqDTO.getPredictTime());
                 if (reqDTO.getIsResult() == null || !reqDTO.getIsResult()) {
@@ -147,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);
+            PredictResultVO predictResult = predictItemHandler.predict(reqDTO.getPredictTime(), predictItem,null);
             Map<String, List<DataValueVO>> resultMap = predictResultHandler.convertToPredictData(predictResult);
             if (!CollectionUtils.isEmpty(resultMap)) {
                 for (Map.Entry<String, List<DataValueVO>> entry : resultMap.entrySet()) {
@@ -198,7 +207,7 @@
             log.info("预测计算结束: " + System.currentTimeMillis());
         } catch (Exception ex) {
             log.info("调度计算异常: " + System.currentTimeMillis());
-            ex.printStackTrace();
+//            ex.printStackTrace();
             return resp;
         }
         return resp;
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 c0d15dc..27352dd 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
@@ -5,6 +5,7 @@
 import com.iailab.module.model.mdk.vo.PredictResultVO;
 
 import java.util.Date;
+import java.util.Map;
 
 /**
  * @author PanZhibao
@@ -21,5 +22,5 @@
      * @return
      * @throws ItemInvokeException
      */
-    PredictResultVO predict(Date predictTime, ItemVO predictItemDto) throws ItemInvokeException;
+    PredictResultVO predict(Date predictTime, ItemVO predictItemDto, Map<String, double[]> predictValueMap) throws ItemInvokeException;
 }
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 9a5f462..391be24 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
@@ -1,5 +1,6 @@
 package com.iailab.module.model.mdk.predict;
 
+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.enums.ItemStatus;
 import com.iailab.module.model.mcs.pre.service.MmItemStatusService;
@@ -9,6 +10,7 @@
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
 
 import java.text.MessageFormat;
 import java.time.Duration;
@@ -46,10 +48,18 @@
      * @param intervalTime
      * @return
      */
-    public Map<String, PredictResultVO> predict(List<ItemVO> predictItemList, Date predictTime, int intervalTime) {
-        Map<String, PredictResultVO> result = new HashMap<>();
-
-        PredictResultVO predictResult = new PredictResultVO();
+    public void predict(List<ItemVO> predictItemList, Date predictTime, int intervalTime,Map<String, PredictResultVO> predictResultMap) {
+        PredictResultVO predictResult;
+        Map<String, double[]> predictValueMap = null;
+        if (!CollectionUtils.isEmpty(predictResultMap)) {
+            // 将predictResultMap处理成Map<outPutId, double[]>
+            predictValueMap = new HashMap<>();
+            for (Map.Entry<String, PredictResultVO> entry : predictResultMap.entrySet()) {
+                for (Map.Entry<MmItemOutputEntity, double[]> mmItemOutputEntityEntry : entry.getValue().getPredictMatrixs().entrySet()) {
+                    predictValueMap.put(mmItemOutputEntityEntry.getKey().getId(),mmItemOutputEntityEntry.getValue());
+                }
+            }
+        }
         for (ItemVO predictItem : predictItemList) {
             if (!predictItem.getStatus().equals(ItemStatus.STATUS1.getCode())) {
                 continue;
@@ -61,10 +71,10 @@
                 long start = System.currentTimeMillis();
                 try {
                     // 预测项开始预测
-                    predictResult = predictItemHandler.predict(predictTime, predictItem);
+                    predictResult = predictItemHandler.predict(predictTime, predictItem, predictValueMap);
                 } catch (Exception e) {
-                    e.printStackTrace();
-                    log.error(String.valueOf(e));
+//                    e.printStackTrace();
+//                    log.error(String.valueOf(e));
                     mmItemStatusService.recordStatus(predictItem.getId(), ItemRunStatusEnum.FAIL, totalDur, predictTime);
                     continue;
                 }
@@ -86,7 +96,7 @@
                         drtSave));
                 totalDur = totalDur + drtSave;
                 mmItemStatusService.recordStatus(predictItem.getId(), ItemRunStatusEnum.SUCCESS, totalDur, predictTime);
-                result.put(predictItem.getItemNo(), predictResult);
+                predictResultMap.put(predictItem.getItemNo(), predictResult);
             } catch (Exception e) {
                 e.printStackTrace();
                 log.error(MessageFormat.format("预测项编号:{0},预测项名称:{1},预测失败:{2} 预测时刻:{3}",
@@ -94,6 +104,5 @@
                 mmItemStatusService.recordStatus(predictItem.getId(), ItemRunStatusEnum.FAIL, totalDur, predictTime);
             }
         }
-        return result;
     }
 }
\ No newline at end of file
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 ef85630..e9385d7 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
@@ -21,6 +21,7 @@
 
 import java.sql.Timestamp;
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @author PanZhibao
@@ -58,7 +59,7 @@
      * @throws ItemInvokeException
      */
     @Override
-    public PredictResultVO predict(Date predictTime, ItemVO predictItemDto)
+    public PredictResultVO predict(Date predictTime, ItemVO predictItemDto,Map<String, double[]> predictValueMap)
             throws ItemInvokeException {
         PredictResultVO predictResult = new PredictResultVO();
         ItemPredictStatus itemStatus = ItemPredictStatus.PREDICTING;
@@ -67,7 +68,6 @@
             String expression = itemEntityFactory.getMergeItem(itemId).getExpression();
             int predictLength = itemEntityFactory.getItemById(itemId).getPredictLength();
             double[][] predictResultMat = new double[predictLength][1];
-            Map<String, List<DataValueVO>> predictValueMap = new HashMap<>();
             String[] mathOutPutId = expression.split("[\\+ \\-]");
             ArrayList<Character> operator = new ArrayList<>();
             for (int i = 0; i < expression.length(); i++) {
@@ -75,63 +75,65 @@
                     operator.add(expression.charAt(i));
                 }
             }
-            String[] compositionItem = expression.split(String.valueOf("&".toCharArray()));
+//            String[] compositionItem = expression.split(String.valueOf("&".toCharArray()));
             //是否为计算预测项
             if (mathOutPutId.length > 1) {
-                for (String outPutId : mathOutPutId) {
-                    if (outPutId.length() > 4) {
-                        Date endTime = predictTime;
-//                        ItemVO itemEntity = itemEntityFactory.getItemByItemNo(itemNo);
-//                        List<MmItemOutputEntity> outPutList = itemEntityFactory.getOutPutByItemId(itemEntity.getId());
-                        MmItemOutputEntity outPut = mmItemOutputService.getOutPutById(outPutId);
-                        ApiPointDTO pointEntity = dataPointApi.getInfoById(outPut.getPointid());
+//                Map<String, List<DataValueVO>> predictValueMap = new HashMap<>();
+//                for (String outPutId : mathOutPutId) {
+//                    if (outPutId.length() > 4) {
+//                        Date endTime = predictTime;
+////                        ItemVO itemEntity = itemEntityFactory.getItemByItemNo(itemNo);
+////                        List<MmItemOutputEntity> outPutList = itemEntityFactory.getOutPutByItemId(itemEntity.getId());
+//                        MmItemOutputEntity outPut = mmItemOutputService.getOutPutById(outPutId);
+//                        ApiPointDTO pointEntity = dataPointApi.getInfoById(outPut.getPointid());
+//
+//                        Calendar calendar = Calendar.getInstance();
+//                        calendar.setTime(endTime);
+//                        calendar.add(Calendar.SECOND, (predictLength - 1) * DataPointFreqEnum.getEumByCode(pointEntity.getMinfreqid()).getValue());
+//                        endTime = new Timestamp(calendar.getTime().getTime());
+////                        List<DataValueVO> predictValueList = predictResultHandler.getPredictValueByItemNo(itemNo, predictTime, endTime);
+//                        List<DataValueVO> predictValueList = mmItemResultService.getPredictValue(outPutId, predictTime, endTime);
+//                        if (predictValueList.size() != predictLength) {
+//                            log.debug("merge项融合失败:缺少子项预测数据,对应子项outPutId=" + outPutId);
+//                            return null;
+//                        }
+//                        predictValueMap.put(outPutId, predictValueList);
+//                    }
+//                }
 
-                        Calendar calendar = Calendar.getInstance();
-                        calendar.setTime(endTime);
-                        calendar.add(Calendar.SECOND, (predictLength - 1) * DataPointFreqEnum.getEumByCode(pointEntity.getMinfreqid()).getValue());
-                        endTime = new Timestamp(calendar.getTime().getTime());
-//                        List<DataValueVO> predictValueList = predictResultHandler.getPredictValueByItemNo(itemNo, predictTime, endTime);
-                        List<DataValueVO> predictValueList = mmItemResultService.getPredictValue(outPutId, predictTime, endTime);
-                        if (predictValueList.size() != predictLength) {
-                            log.debug("merge项融合失败:缺少子项预测数据,对应子项outPutId=" + outPutId);
-                            return null;
-                        }
-                        predictValueMap.put(outPutId, predictValueList);
-                    }
-                }
                 for (Integer i = 0; i < predictLength; i++) {
                     double sum =0.0;
-                    sum = predictValueMap.get(mathOutPutId[0]).get(i).getDataValue();
+                    sum = predictValueMap.get(mathOutPutId[0])[i];
                     for (int j = 1; j < mathOutPutId.length; j++) {
                         if (operator.get(j-1)=='+')
-                        {sum += predictValueMap.get(mathOutPutId[j]).get(i).getDataValue();}
+                        {sum += predictValueMap.get(mathOutPutId[j])[i];}
                         if (operator.get(j-1)=='-')
-                        {sum -= predictValueMap.get(mathOutPutId[j]).get(i).getDataValue();}
+                        {sum -= predictValueMap.get(mathOutPutId[j])[i];}
                     }
                     predictResultMat[i][0] = sum;
                 }
             }
             //是否为组合预测项
-            if (compositionItem.length > 1) {
-                Map<String, PredictResultVO> predictResultMap = new HashMap<>();
-                Integer columnTotalNumber = 0;
-                Integer rowNumber = 0;
-                for (String itemNo : compositionItem) {
-                    PredictItemHandler predictItem = (PredictItemHandler) predictItemFactory.create(itemEntityFactory.
-                            getItemByItemNo(itemNo).getId());
-                    predictResult = predictItem.predict(predictTime, predictItemDto);
-                    columnTotalNumber += Integer.valueOf(predictResult.getPredictMatrix().length);
-                    predictResultMap.put(itemNo, predictItem.predict(predictTime, predictItemDto));
-                }
-                double[][] matrix = new double[columnTotalNumber][1];
-                for (String itemNo : compositionItem) {
-                    for (Integer i = 0; i < predictResultMap.get(itemNo).getPredictMatrix().length; i++) {
-                        matrix[rowNumber][0] = predictResultMap.get(itemNo).getPredictMatrix()[i][0];
-                        rowNumber++;
-                    }
-                }
-                predictResult.setPredictMatrix(matrix);
-            }
+//            if (compositionItem.length > 1) {
+//                Map<String, PredictResultVO> predictResultMap = new HashMap<>();
+//                Integer columnTotalNumber = 0;
+//                Integer rowNumber = 0;
+//                for (String itemNo : compositionItem) {
+//                    PredictItemHandler predictItem = (PredictItemHandler) predictItemFactory.create(itemEntityFactory.
+//                            getItemByItemNo(itemNo).getId());
+//                    predictResult = predictItem.predict(predictTime, predictItemDto);
+//                    columnTotalNumber += Integer.valueOf(predictResult.getPredictMatrix().length);
+//                    predictResultMap.put(itemNo, predictItem.predict(predictTime, predictItemDto));
+//                }
+//                double[][] matrix = new double[columnTotalNumber][1];
+//                for (String itemNo : compositionItem) {
+//                    for (Integer i = 0; i < predictResultMap.get(itemNo).getPredictMatrix().length; i++) {
+//                        matrix[rowNumber][0] = predictResultMap.get(itemNo).getPredictMatrix()[i][0];
+//                        rowNumber++;
+//                    }
+//                }
+//                predictResult.setPredictMatrix(matrix);
+//            }
             predictResult.setPredictId(itemId);
             predictResult.setPredictMatrix(predictResultMat);
             predictResult.setPredictTime(predictTime);
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 37c9d0d..0fc07b2 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
@@ -13,6 +13,7 @@
 
 import java.text.MessageFormat;
 import java.util.Date;
+import java.util.Map;
 
 /**
  * @author PanZhibao
@@ -37,7 +38,7 @@
      * @throws ItemInvokeException
      */
     @Override
-    public PredictResultVO predict(Date predictTime, ItemVO predictItemDto) throws ItemInvokeException {
+    public PredictResultVO predict(Date predictTime, ItemVO predictItemDto, Map<String, double[]> predictValueMap) throws ItemInvokeException {
         PredictResultVO predictResult = new PredictResultVO();
         String itemId = predictItemDto.getId();
         try {
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 582a1b9..0be1977 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
@@ -1,9 +1,12 @@
 package com.iailab.module.model.mdk.sample;
 
+import com.iailab.module.data.api.point.DataPointApi;
+import com.iailab.module.data.api.point.dto.ApiPointDTO;
 import com.iailab.module.model.mcs.pre.entity.MmModelParamEntity;
 import com.iailab.module.model.mcs.pre.service.MmModelParamService;
 import com.iailab.module.model.mcs.pre.service.MmPredictItemService;
 import com.iailab.module.model.mcs.pre.service.MmPredictModelService;
+import com.iailab.module.model.mdk.common.enums.ModelParamType;
 import com.iailab.module.model.mdk.sample.dto.ColumnItem;
 import com.iailab.module.model.mdk.sample.dto.ColumnItemPort;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -13,6 +16,9 @@
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
 /**
  * @author PanZhibao
@@ -30,6 +36,9 @@
 
     @Autowired
     private MmPredictItemService mmPredictItemService;
+
+    @Autowired
+    private DataPointApi dataPointApi;
 
     /**
      * 返回样本矩阵的列数
@@ -63,14 +72,19 @@
         int curPortOrder = modelInputParamEntityList.get(0).getModelparamportorder();
         //设置当前查询数据长度,初始值为最小端口数据长度
         int curDataLength = modelInputParamEntityList.get(0).getDatalength();
+        // 统一获取测点的信息
+        List<String> pointIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.DATAPOINT)).map(MmModelParamEntity::getModelparamid).collect(Collectors.toList());
+        List<ApiPointDTO> points = dataPointApi.getInfoByIds(pointIds);
+        Map<String, ApiPointDTO> pointMap = points.stream().collect(Collectors.toMap(ApiPointDTO::getId, Function.identity()));
+
         for (MmModelParamEntity entry : modelInputParamEntityList) {
             columnInfo.setParamType(entry.getModelparamtype());
             columnInfo.setParamId(entry.getModelparamid());
             columnInfo.setDataLength(entry.getDatalength());
             columnInfo.setModelParamOrder(entry.getModelparamorder());
             columnInfo.setModelParamPortOrder(entry.getModelparamportorder());
-            columnInfo.setStartTime(getStartTime(columnInfo, predictTime));
-            columnInfo.setEndTime(getEndTime(columnInfo, predictTime));
+            columnInfo.setStartTime(getStartTime(columnInfo, predictTime,pointMap));
+            columnInfo.setEndTime(getEndTime(columnInfo, predictTime,pointMap));
             columnInfo.setGranularity(super.getGranularity(columnInfo));
 
             //对每一个爪进行数据项归并
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java
index 54dea55..515637b 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java
@@ -19,6 +19,7 @@
 import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author PanZhibao
@@ -91,13 +92,13 @@
      * @return
      * @throws Exception
      */
-    protected Date getStartTime(ColumnItem columnItem, Date originalTime) {
+    protected Date getStartTime(ColumnItem columnItem, Date originalTime, Map<String, ApiPointDTO> pointMap) {
         Date dateTime = new Date();
         Calendar calendar = Calendar.getInstance();
         calendar.setTime(originalTime);
         switch (ModelParamType.getEumByCode(columnItem.getParamType())) {
             case DATAPOINT:
-                ApiPointDTO dataPoint = dataPointApi.getInfoById(columnItem.getParamId());
+                ApiPointDTO dataPoint = pointMap.get(columnItem.getParamId());
                 if (dataPoint == null) {
                     return null;
                 }
@@ -127,13 +128,13 @@
      * @return
      * @throws Exception
      */
-    protected Date getEndTime(ColumnItem columnItem, Date originalTime) {
+    protected Date getEndTime(ColumnItem columnItem, Date originalTime,Map<String, ApiPointDTO> pointMap) {
         Date dateTime = new Date();
         Calendar calendar = Calendar.getInstance();
         calendar.setTime(originalTime);
         switch (ModelParamType.getEumByCode(columnItem.getParamType())) {
             case DATAPOINT:
-                ApiPointDTO dataPoint = dataPointApi.getInfoById(columnItem.getParamId());
+                ApiPointDTO dataPoint = pointMap.get(columnItem.getParamId());
                 if (dataPoint == null) {
                     return null;
                 }
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/ScheduleSampleInfoConstructor.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/ScheduleSampleInfoConstructor.java
index 6b62536..f8547d6 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/ScheduleSampleInfoConstructor.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/ScheduleSampleInfoConstructor.java
@@ -1,7 +1,11 @@
 package com.iailab.module.model.mdk.sample;
 
+import com.iailab.module.data.api.point.DataPointApi;
+import com.iailab.module.data.api.point.dto.ApiPointDTO;
+import com.iailab.module.model.mcs.pre.entity.MmModelParamEntity;
 import com.iailab.module.model.mcs.sche.entity.StScheduleModelParamEntity;
 import com.iailab.module.model.mcs.sche.service.StScheduleModelParamService;
+import com.iailab.module.model.mdk.common.enums.ModelParamType;
 import com.iailab.module.model.mdk.sample.dto.ColumnItem;
 import com.iailab.module.model.mdk.sample.dto.ColumnItemPort;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -11,12 +15,18 @@
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
 @Component
 public class ScheduleSampleInfoConstructor extends SampleInfoConstructor {
 
     @Autowired
     private StScheduleModelParamService stScheduleModelParamService;
+
+    @Autowired
+    private DataPointApi dataPointApi;
 
     @Override
     protected Integer getSampleColumn(String modelId) {
@@ -37,14 +47,19 @@
         int curPortOrder = modelInputParamEntityList.get(0).getModelparamportorder();
         //设置当前查询数据长度,初始值为最小端口数据长度
         int curDataLength = modelInputParamEntityList.get(0).getDatalength();
+        // 统一获取测点的信息
+        List<String> pointIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.DATAPOINT)).map(StScheduleModelParamEntity::getModelparamid).collect(Collectors.toList());
+        List<ApiPointDTO> points = dataPointApi.getInfoByIds(pointIds);
+        Map<String, ApiPointDTO> pointMap = points.stream().collect(Collectors.toMap(ApiPointDTO::getId, Function.identity()));
+
         for (StScheduleModelParamEntity entry : modelInputParamEntityList) {
             columnInfo.setParamType(entry.getModelparamtype());
             columnInfo.setParamId(entry.getModelparamid());
             columnInfo.setDataLength(entry.getDatalength());
             columnInfo.setModelParamOrder(entry.getModelparamorder());
             columnInfo.setModelParamPortOrder(entry.getModelparamportorder());
-            columnInfo.setStartTime(getStartTime(columnInfo, predictTime));
-            columnInfo.setEndTime(getEndTime(columnInfo, predictTime));
+            columnInfo.setStartTime(getStartTime(columnInfo, predictTime,pointMap));
+            columnInfo.setEndTime(getEndTime(columnInfo, predictTime,pointMap));
             columnInfo.setGranularity(super.getGranularity(columnInfo));
 
             //对每一个爪进行数据项归并
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/schedule/impl/ScheduleModelHandlerImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/schedule/impl/ScheduleModelHandlerImpl.java
index 26a3f6c..0282148 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/schedule/impl/ScheduleModelHandlerImpl.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/schedule/impl/ScheduleModelHandlerImpl.java
@@ -1,5 +1,6 @@
 package com.iailab.module.model.mdk.schedule.impl;
 
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.iail.model.IAILModel;
@@ -61,7 +62,9 @@
         String modelId = scheduleModel.getId();
         try {
             //1.根据模型id构造模型输入样本
+            long now = System.currentTimeMillis();
             List<SampleData> sampleDataList = sampleConstructor.constructSample(TypeA.Schedule.name(), modelId, scheduleTime);
+            log.info("构造模型输入样本消耗时长:" + (System.currentTimeMillis() - now) / 1000 + "秒");
             if (CollectionUtils.isEmpty(sampleDataList)) {
                 log.info("调度模型构造样本失败,schemeCode=" + schemeCode);
                 return null;
@@ -86,12 +89,12 @@
             param2Values[portLength] = settings;
 
             log.info("#######################调度模型 " + scheduleModel.getModelName() + " ##########################");
-            JSONObject jsonObjNewModelBean = new JSONObject();
-            jsonObjNewModelBean.put("newModelBean", newModelBean);
-            log.info(String.valueOf(jsonObjNewModelBean));
-            JSONObject jsonObjParam2Values = new JSONObject();
-            jsonObjParam2Values.put("param2Values", param2Values);
-            log.info(String.valueOf(jsonObjParam2Values));
+//            JSONObject jsonObjNewModelBean = new JSONObject();
+//            jsonObjNewModelBean.put("newModelBean", newModelBean);
+//            log.info(String.valueOf(jsonObjNewModelBean));
+//            JSONObject jsonObjParam2Values = new JSONObject();
+//            jsonObjParam2Values.put("param2Values", param2Values);
+            log.info("参数: " + JSON.toJSONString(param2Values));
 
             //IAILMDK.run
             HashMap<String, Object> modelResult = DllUtils.run(newModelBean, param2Values, scheduleScheme.getMpkprojectid());
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 51b1aad..67dbf8d 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
@@ -36,6 +36,10 @@
      * 统一预测入口的预测类型(循环调用、手动调用) Map<MmItemOutputEntity,double[]>
      */
     private Map<MmItemOutputEntity, double[]> predictMatrixs;
+
+    /**
+     * double类型的模型输出
+     */
     private Map<MmItemOutputEntity, Double> predictDoubleValues;
 
     /**

--
Gitblit v1.9.3