From 8bf5531fcc2566bd932216e1a8dafab2a59f4f78 Mon Sep 17 00:00:00 2001
From: dengzedong <dengzedong@email>
Date: 星期一, 23 十二月 2024 15:58:46 +0800
Subject: [PATCH] sampleInfo.setPlanMap 统一获取计划数据的信息,避免重复查询

---
 iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/plan/PlanItemApi.java                        |   15 ++++---
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/plan/PlanItemApiImpl.java                    |    9 ++++
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/PlanItemService.java           |    4 ++
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/impl/PlanItemServiceImpl.java  |    6 +++
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleDataConstructor.java  |   11 +++--
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/ScheduleSampleInfoConstructor.java |   17 ++++++--
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/dto/SampleInfo.java                |    3 +
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleInfoConstructor.java  |   16 ++++++-
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java         |   25 ++++++------
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleDataConstructor.java         |    8 ++--
 10 files changed, 81 insertions(+), 33 deletions(-)

diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/plan/PlanItemApi.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/plan/PlanItemApi.java
index b54bd3b..1d42428 100644
--- a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/plan/PlanItemApi.java
+++ b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/plan/PlanItemApi.java
@@ -2,19 +2,18 @@
 
 import com.iailab.module.data.api.plan.dto.ApiPlanDataDTO;
 import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO;
+import com.iailab.module.data.api.point.dto.ApiPointDTO;
 import com.iailab.module.data.common.ApiDataQueryDTO;
 import com.iailab.module.data.common.ApiDataValueDTO;
 import com.iailab.module.data.enums.ApiConstants;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import org.springframework.cloud.openfeign.FeignClient;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Set;
 
 /**
  * @author PanZhibao
@@ -36,10 +35,14 @@
     LinkedHashMap<String, List<ApiPlanDataDTO>> queryPlanItemRecordValue(@RequestBody ApiDataQueryDTO dto);
 
     @GetMapping(PREFIX + "/info/no/{itemNo}")
-    @Operation(summary = "根据测点编号查询测点信息")
+    @Operation(summary = "根据编号查询计划数据信息")
     ApiPlanItemDTO getInfoByNo(@PathVariable("itemNo") String itemNo);
 
     @GetMapping(PREFIX + "/info/id/{id}")
-    @Operation(summary = "根据测点编号查询测点信息")
+    @Operation(summary = "根据id查询计划数据信息")
     ApiPlanItemDTO getInfoById(@PathVariable("id") String id);
+
+    @PostMapping(PREFIX + "/info/ids")
+    @Operation(summary = "根据多个id查询计划数据信息")
+    List<ApiPlanItemDTO> getInfoByIds(@RequestParam("planIds") Set<String> planIds);
 }
\ No newline at end of file
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/plan/PlanItemApiImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/plan/PlanItemApiImpl.java
index b37fc51..ac3c99d 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/plan/PlanItemApiImpl.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/plan/PlanItemApiImpl.java
@@ -3,6 +3,7 @@
 import com.iailab.framework.common.util.object.ConvertUtils;
 import com.iailab.module.data.api.plan.dto.ApiPlanDataDTO;
 import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO;
+import com.iailab.module.data.api.point.dto.ApiPointDTO;
 import com.iailab.module.data.common.ApiDataQueryDTO;
 import com.iailab.module.data.common.ApiDataValueDTO;
 import com.iailab.module.data.plan.item.collection.PlanItemCollector;
@@ -16,8 +17,10 @@
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Set;
 
 /**
  * @author PanZhibao
@@ -65,4 +68,10 @@
         return ConvertUtils.sourceToTarget(entity, ApiPlanItemDTO.class);
     }
 
+    @Override
+    public List<ApiPlanItemDTO> getInfoByIds(Set<String> planIds) {
+        List<PlanItemEntity> plans = planItemService.getInfoByIds(planIds);
+        return ConvertUtils.sourceToTarget(plans,ApiPlanItemDTO.class);
+    }
+
 }
\ No newline at end of file
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/PlanItemService.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/PlanItemService.java
index 5556f7d..6204f18 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/PlanItemService.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/PlanItemService.java
@@ -2,6 +2,7 @@
 
 import com.iailab.framework.common.pojo.PageResult;
 import com.iailab.framework.common.service.BaseService;
+import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO;
 import com.iailab.module.data.plan.item.entity.PlanItemEntity;
 import com.iailab.module.data.plan.item.vo.PlanItemDataVO;
 import com.iailab.module.data.plan.item.vo.PlanItemPageReqVO;
@@ -9,6 +10,7 @@
 
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 /**
  * @author PanZhibao
@@ -32,4 +34,6 @@
     void delete(String id);
 
     List<PlanItemDataVO> getSourceValue(Map<String, Object> params);
+
+    List<PlanItemEntity> getInfoByIds(Set<String> planIds);
 }
\ No newline at end of file
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/impl/PlanItemServiceImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/impl/PlanItemServiceImpl.java
index 6b89b39..155475e 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/impl/PlanItemServiceImpl.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/impl/PlanItemServiceImpl.java
@@ -4,6 +4,7 @@
 import com.iailab.framework.common.pojo.PageResult;
 import com.iailab.framework.common.service.impl.BaseServiceImpl;
 import com.iailab.framework.common.util.object.BeanUtils;
+import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO;
 import com.iailab.module.data.plan.item.dao.PlanItemDao;
 import com.iailab.module.data.plan.item.entity.PlanItemEntity;
 import com.iailab.module.data.plan.item.service.PlanItemService;
@@ -78,4 +79,9 @@
     public List<PlanItemDataVO> getSourceValue(Map<String, Object> params) {
         return baseDao.getSourceValue(params);
     }
+
+    @Override
+    public List<PlanItemEntity> getInfoByIds(Set<String> planIds) {
+        return baseDao.selectBatchIds(planIds);
+    }
 }
\ No newline at end of file
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleDataConstructor.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleDataConstructor.java
index 9cb12d7..093156e 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleDataConstructor.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleDataConstructor.java
@@ -1,6 +1,7 @@
 package com.iailab.module.model.mdk.sample;
 
 import com.iailab.module.data.api.plan.PlanItemApi;
+import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO;
 import com.iailab.module.data.api.point.DataPointApi;
 import com.iailab.module.data.api.point.dto.ApiPointDTO;
 import com.iailab.module.data.api.point.dto.ApiPointValueDTO;
@@ -62,6 +63,7 @@
     public List<SampleData>  prepareSampleData(SampleInfo sampleInfo) throws Exception {
         List<SampleData> sampleDataList = new ArrayList<>();
         Map<String, ApiPointDTO> pointMap = sampleInfo.getPointMap();
+        Map<String, ApiPlanItemDTO> planMap = sampleInfo.getPlanMap();
         //对每个爪分别进行计算
         for (ColumnItemPort entry : sampleInfo.getColumnInfo()) {
             //先依据爪内数据项的modelParamOrder进行排序——重写comparator匿名函数
@@ -83,11 +85,11 @@
             //对每一项依次进行数据查询,然后将查询出的值赋给matrix对应的位置
             for (int i = 0; i < entry.getColumnItemList().size(); i++) {
                 try {
-                    List<DataValueVO> dataEntityList = getData(entry.getColumnItemList().get(i),pointMap);
+                    List<DataValueVO> dataEntityList = getData(entry.getColumnItemList().get(i),pointMap,planMap);
                     //补全数据
                     ColumnItem columnItem = entry.getColumnItemList().get(i);
                     dataEntityList = super.completionData(matrix.length, dataEntityList, columnItem.startTime, columnItem.endTime,
-                            columnItem.paramId, columnItem.getParamType());
+                            columnItem.paramId, columnItem.getParamType(),pointMap,planMap);
 
                     /** 如果数据取不满,把缺失的数据点放在后面 */
                     if (dataEntityList != null && dataEntityList.size() != 0) {
@@ -113,10 +115,11 @@
      *
      * @param columnItem
      * @param pointMap
+     * @param planMap
      * @return
      * @throws Exception
      */
-    private List<DataValueVO> getData(ColumnItem columnItem, Map<String, ApiPointDTO> pointMap) throws Exception {
+    private List<DataValueVO> getData(ColumnItem columnItem, Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) throws Exception {
         List<DataValueVO> dataList = new ArrayList<>();
         String paramType = columnItem.getParamType();
         switch (ModelParamType.getEumByCode(paramType)) {
@@ -147,7 +150,7 @@
                 break;
             case PLAN:
                 ApiDataQueryDTO queryPlanItemDto = new ApiDataQueryDTO();
-                queryPlanItemDto.setItemNo(columnItem.getParamId());
+                queryPlanItemDto.setItemNo(planMap.get(columnItem.getParamId()).getItemNo());
                 queryPlanItemDto.setStart(columnItem.getStartTime());
                 queryPlanItemDto.setEnd(columnItem.getEndTime());
                 List<ApiDataValueDTO> planValueList = planItemApi.queryPlanItemHistoryValue(queryPlanItemDto);
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 c79b974..4104e2d 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,5 +1,7 @@
 package com.iailab.module.model.mdk.sample;
 
+import com.iailab.module.data.api.plan.PlanItemApi;
+import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO;
 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;
@@ -38,6 +40,9 @@
     @Autowired
     private DataPointApi dataPointApi;
 
+    @Autowired
+    private PlanItemApi planItemApi;
+
     /**
      * 返回样本矩阵的列数
      *
@@ -75,6 +80,10 @@
         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));
+        // 统一获取计划数据的信息
+        Set<String> planIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.PLAN)).map(MmModelParamEntity::getModelparamid).collect(Collectors.toSet());
+        List<ApiPlanItemDTO> plans = planItemApi.getInfoByIds(planIds);
+        Map<String, ApiPlanItemDTO> planMap = plans.stream().collect(Collectors.toMap(ApiPlanItemDTO::getId, Function.identity(), (e1,e2) -> e1));
 
         for (MmModelParamEntity entry : modelInputParamEntityList) {
             columnInfo.setParamType(entry.getModelparamtype());
@@ -82,9 +91,9 @@
             columnInfo.setDataLength(entry.getDatalength());
             columnInfo.setModelParamOrder(entry.getModelparamorder());
             columnInfo.setModelParamPortOrder(entry.getModelparamportorder());
-            columnInfo.setStartTime(getStartTime(columnInfo, predictTime,pointMap));
-            columnInfo.setEndTime(getEndTime(columnInfo, predictTime,pointMap));
-            columnInfo.setGranularity(super.getGranularity(columnInfo));
+            columnInfo.setStartTime(getStartTime(columnInfo, predictTime,pointMap,planMap));
+            columnInfo.setEndTime(getEndTime(columnInfo, predictTime,pointMap,planMap));
+            columnInfo.setGranularity(super.getGranularity(columnInfo,pointMap,planMap));
 
             //对每一个爪进行数据项归并
             if (curPortOrder != entry.getModelparamportorder()){
@@ -109,6 +118,7 @@
         resultList.add(curPort);
         sampleInfo.setColumnInfo(resultList);
         sampleInfo.setPointMap(pointMap);
+        sampleInfo.setPlanMap(planMap);
         return sampleInfo;
     }
 
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleDataConstructor.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleDataConstructor.java
index dba4323..c25dae4 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleDataConstructor.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleDataConstructor.java
@@ -15,7 +15,6 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.CollectionUtils;
 
-import java.sql.Timestamp;
 import java.util.*;
 
 abstract class SampleDataConstructor {
@@ -42,10 +41,11 @@
      * @param dataEntityList
      * @param startTime
      * @param endTime
+     * @param planMap
      * @return
      */
     public List<DataValueVO> completionData(int length, List<DataValueVO> dataEntityList, Date startTime, Date endTime,
-                                            String paramId, String paramType) {
+                                            String paramId, String paramType, Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) {
         if (CollectionUtils.isEmpty(dataEntityList) || length == dataEntityList.size()) {
             return dataEntityList;
         } else if (length < dataEntityList.size()) {
@@ -84,7 +84,7 @@
                 break;
             case DATAPOINT:
                 // 测点值
-                ApiPointDTO dataPoint = dataPointApi.getInfoById(paramId);
+                ApiPointDTO dataPoint = pointMap.get(paramId);
                 oneMin = 1000L * DataPointFreqEnum.getEumByCode(dataPoint.getMinfreqid()).getValue();
                 // 设置时间偏移量
                 start = start - (start % oneMin) + oneMin;
@@ -110,7 +110,7 @@
                 break;
             case PLAN:
                 // 计划数据
-                ApiPlanItemDTO planItem = planItemApi.getInfoById(paramId);
+                ApiPlanItemDTO planItem = planMap.get(paramId);
                 oneMin = 1000L * TimeGranularitySecEnum.getEumByCode(planItem.getTimeGranularity()).getValue();
                 // 设置时间偏移量
                 start = start - (start % oneMin) + oneMin;
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 1ed6feb..3f8f72b 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
@@ -86,7 +86,7 @@
      * @return
      * @throws Exception
      */
-    protected Date getStartTime(ColumnItem columnItem, Date originalTime, Map<String, ApiPointDTO> pointMap) {
+    protected Date getStartTime(ColumnItem columnItem, Date originalTime, Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) {
         Date dateTime = new Date();
         Calendar calendar = Calendar.getInstance();
         calendar.setTime(originalTime);
@@ -106,7 +106,11 @@
                 dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), 60);
                 break;
             case PLAN:
-                dateTime = calendar.getTime();
+                ApiPlanItemDTO apiPlanItemDTO = planMap.get(columnItem.getParamId());
+                if (apiPlanItemDTO == null) {
+                    return null;
+                }
+                dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), TimeGranularitySecEnum.getEumByCode(apiPlanItemDTO.getTimeGranularity()).getValue());
                 break;
             default:
                 break;
@@ -122,7 +126,7 @@
      * @return
      * @throws Exception
      */
-    protected Date getEndTime(ColumnItem columnItem, Date originalTime,Map<String, ApiPointDTO> pointMap) {
+    protected Date getEndTime(ColumnItem columnItem, Date originalTime,Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) {
         Date dateTime = new Date();
         Calendar calendar = Calendar.getInstance();
         calendar.setTime(originalTime);
@@ -142,12 +146,11 @@
                 dateTime = calendar.getTime();
                 break;
             case PLAN:
-                ApiPlanItemDTO planItem = planItemApi.getInfoByNo(columnItem.getParamId());
-                if (planItem == null) {
+                ApiPlanItemDTO apiPlanItemDTO = planMap.get(columnItem.getParamId());
+                if (apiPlanItemDTO == null) {
                     return null;
                 }
-                dateTime = calculateDate(originalTime, false, columnItem.getDataLength(),
-                        TimeGranularityEnum.getEumByCode(planItem.getTimeGranularity()).getValue());
+                dateTime = calculateDate(originalTime, false, columnItem.getDataLength(), TimeGranularitySecEnum.getEumByCode(apiPlanItemDTO.getTimeGranularity()).getValue());
                 break;
             default:
                 break;
@@ -162,17 +165,15 @@
      * @return
      * @throws Exception
      */
-    protected Integer getGranularity(ColumnItem columnItem) {
+    protected Integer getGranularity(ColumnItem columnItem,Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) {
         // 默认60s
         Integer granularity = 60;
         switch (ModelParamType.getEumByCode(columnItem.getParamType())) {
             case DATAPOINT:
-                ApiPointDTO dataPoint = dataPointApi.getInfoById(columnItem.getParamId());
+                ApiPointDTO dataPoint = pointMap.get(columnItem.getParamId());
                 granularity = DataPointFreqEnum.getEumByCode(dataPoint.getMinfreqid()).getValue();
                 break;
             case NORMALITEM:
-                granularity = mmPredictItemService.getItemByOutPutId(columnItem.getParamId()).getGranularity();
-                break;
             case MERGEITEM:
                 granularity = mmPredictItemService.getItemByOutPutId(columnItem.getParamId()).getGranularity();
                 break;
@@ -181,7 +182,7 @@
                 granularity = TimeGranularitySecEnum.getEumByCode(indItemDTO.getTimeGranularity()).getValue();;
                 break;
             case PLAN:
-                ApiPlanItemDTO apiPlanItemDTO = planItemApi.getInfoById(columnItem.getParamId());
+                ApiPlanItemDTO apiPlanItemDTO = planMap.get(columnItem.getParamId());
                 granularity = TimeGranularitySecEnum.getEumByCode(apiPlanItemDTO.getTimeGranularity()).getValue();
                 break;
             default:
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 3dc2e7e..bc58d7b 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,8 +1,9 @@
 package com.iailab.module.model.mdk.sample;
 
+import com.iailab.module.data.api.plan.PlanItemApi;
+import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO;
 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;
@@ -25,6 +26,9 @@
 
     @Autowired
     private DataPointApi dataPointApi;
+
+    @Autowired
+    private PlanItemApi planItemApi;
 
     @Override
     protected Integer getSampleColumn(String modelId) {
@@ -50,6 +54,10 @@
         Set<String> pointIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.DATAPOINT)).map(StScheduleModelParamEntity::getModelparamid).collect(Collectors.toSet());
         List<ApiPointDTO> points = dataPointApi.getInfoByIds(pointIds);
         Map<String, ApiPointDTO> pointMap = points.stream().collect(Collectors.toMap(ApiPointDTO::getId, Function.identity()));
+        // 统一获取计划数据的信息
+        Set<String> planIds = modelInputParamEntityList.stream().filter(e -> ModelParamType.getEumByCode(e.getModelparamtype()).equals(ModelParamType.PLAN)).map(StScheduleModelParamEntity::getModelparamid).collect(Collectors.toSet());
+        List<ApiPlanItemDTO> plans = planItemApi.getInfoByIds(planIds);
+        Map<String, ApiPlanItemDTO> planMap = plans.stream().collect(Collectors.toMap(ApiPlanItemDTO::getId, Function.identity(), (e1,e2) -> e1));
 
         for (StScheduleModelParamEntity entry : modelInputParamEntityList) {
             columnInfo.setParamType(entry.getModelparamtype());
@@ -57,9 +65,9 @@
             columnInfo.setDataLength(entry.getDatalength());
             columnInfo.setModelParamOrder(entry.getModelparamorder());
             columnInfo.setModelParamPortOrder(entry.getModelparamportorder());
-            columnInfo.setStartTime(getStartTime(columnInfo, predictTime,pointMap));
-            columnInfo.setEndTime(getEndTime(columnInfo, predictTime,pointMap));
-            columnInfo.setGranularity(super.getGranularity(columnInfo));
+            columnInfo.setStartTime(getStartTime(columnInfo, predictTime,pointMap,planMap));
+            columnInfo.setEndTime(getEndTime(columnInfo, predictTime,pointMap,planMap));
+            columnInfo.setGranularity(super.getGranularity(columnInfo,pointMap,planMap));
 
             //对每一个爪进行数据项归并
             if (curPortOrder != entry.getModelparamportorder()){
@@ -84,6 +92,7 @@
         resultList.add(curPort);
         sampleInfo.setColumnInfo(resultList);
         sampleInfo.setPointMap(pointMap);
+        sampleInfo.setPlanMap(planMap);
         return sampleInfo;
     }
 
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/dto/SampleInfo.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/dto/SampleInfo.java
index 0c7548f..39bea32 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/dto/SampleInfo.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/dto/SampleInfo.java
@@ -1,5 +1,6 @@
 package com.iailab.module.model.mdk.sample.dto;
 
+import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO;
 import com.iailab.module.data.api.point.dto.ApiPointDTO;
 import lombok.AllArgsConstructor;
 import lombok.Builder;
@@ -34,4 +35,6 @@
     private BigDecimal[][] deviation;
     // 所有测点信息,避免重复查询
     private Map<String, ApiPointDTO> pointMap;
+    // 所有计划数据信息,避免重复查询
+    private Map<String, ApiPlanItemDTO> planMap;
 }
\ No newline at end of file

--
Gitblit v1.9.3