From 50084de4a140dece61019b64fd91df041d242e47 Mon Sep 17 00:00:00 2001
From: dengzedong <dengzedong@email>
Date: 星期一, 23 十二月 2024 15:28:53 +0800
Subject: [PATCH] getInfoByIds(Set<String> pointIds) 模型输入计划数据获取、补全 模型输入mergeitem存默认生成的outputid sampleInfo.setPointMap 避免重复查询point

---
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleInfoConstructor.java |   67 +++++++++++++--------------------
 1 files changed, 26 insertions(+), 41 deletions(-)

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 8b45b26..c79b974 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.factory.ItemEntityFactory;
-import com.iailab.module.model.mdk.factory.ModelEntityFactory;
+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 com.iailab.module.model.mdk.sample.dto.SampleInfo;
@@ -11,9 +14,9 @@
 import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
 
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
 /**
  * @author PanZhibao
@@ -27,15 +30,13 @@
     private MmPredictModelService mmPredictModelService;
 
     @Autowired
-    private ModelEntityFactory modelEntityFactory;
+    private MmModelParamService mmModelParamService;
 
     @Autowired
-    private ItemEntityFactory itemEntityFactory;
+    private MmPredictItemService mmPredictItemService;
 
-    @Override
-    public SampleInfo prepareSampleInfo(String modelId, Date predictTime) {
-        return super.prepareSampleInfo(modelId, predictTime);
-    }
+    @Autowired
+    private DataPointApi dataPointApi;
 
     /**
      * 返回样本矩阵的列数
@@ -49,30 +50,6 @@
     }
 
     /**
-     * 返回样本的开始时间
-     *
-     * @param columnItem
-     * @param predictTime
-     * @return
-     */
-    @Override
-    protected Date getStartTime(ColumnItem columnItem, Date predictTime) {
-        return super.getStartTime(columnItem, predictTime);
-    }
-
-    /**
-     * 返回样本的结束时间
-     *
-     * @param columnItem
-     * @param predictTime
-     * @return
-     */
-    @Override
-    protected Date getEndTime(ColumnItem columnItem, Date predictTime) {
-        return super.getEndTime(columnItem, predictTime);
-    }
-
-    /**
      * 样本的列信息
      *
      * @param modelId
@@ -80,12 +57,13 @@
      * @return
      */
     @Override
-    protected List<ColumnItemPort> getColumnInfo(String modelId, Date predictTime) {
+    protected SampleInfo getColumnInfo(String modelId, Date predictTime) {
+        SampleInfo sampleInfo = new SampleInfo();
         List<ColumnItemPort> resultList = new ArrayList<>();
         List<ColumnItem> columnItemList = new ArrayList<>();
         ColumnItem columnInfo = new ColumnItem();
         ColumnItemPort curPort = new ColumnItemPort();  //当前端口
-        List<MmModelParamEntity> modelInputParamEntityList = modelEntityFactory.getModelInputParam(modelId);
+        List<MmModelParamEntity> modelInputParamEntityList = mmModelParamService.getByModelidFromCache(modelId);
         if (CollectionUtils.isEmpty(modelInputParamEntityList)) {
             return null;
         }
@@ -93,14 +71,19 @@
         int curPortOrder = modelInputParamEntityList.get(0).getModelparamportorder();
         //设置当前查询数据长度,初始值为最小端口数据长度
         int curDataLength = modelInputParamEntityList.get(0).getDatalength();
+        // 统一获取测点的信息
+        Set<String> pointIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.DATAPOINT)).map(MmModelParamEntity::getModelparamid).collect(Collectors.toSet());
+        List<ApiPointDTO> points = dataPointApi.getInfoByIds(pointIds);
+        Map<String, ApiPointDTO> pointMap = points.stream().collect(Collectors.toMap(ApiPointDTO::getId, Function.identity(), (e1,e2) -> e1));
+
         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));
 
             //对每一个爪进行数据项归并
@@ -124,7 +107,9 @@
         curPort.setDataLength(curDataLength);
         curPort.setPortOrder(curPortOrder);
         resultList.add(curPort);
-        return resultList;
+        sampleInfo.setColumnInfo(resultList);
+        sampleInfo.setPointMap(pointMap);
+        return sampleInfo;
     }
 
     /**
@@ -135,7 +120,7 @@
      */
     @Override
     protected Integer getSampleCycle(String modelId) {
-        return itemEntityFactory.getItemById(modelEntityFactory.getModelEntity(modelId).getItemid()).getGranularity();
+        return mmPredictItemService.getItemByIdFromCache(mmPredictModelService.getInfoFromCatch(modelId).getItemid()).getGranularity();
     }
 
 

--
Gitblit v1.9.3