From b482efaf698d5fd3920ff63ccde1c819f9eb34ba Mon Sep 17 00:00:00 2001
From: houzhongjian <houzhongyi@126.com>
Date: 星期四, 26 十二月 2024 16:50:12 +0800
Subject: [PATCH] 修改菜单报错bug

---
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleDataConstructor.java |   83 +++++++++++++++++++++++++++++++++++------
 1 files changed, 70 insertions(+), 13 deletions(-)

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 e9443ca..e4539bf 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,11 +1,17 @@
 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;
 import com.iailab.module.data.api.point.dto.ApiPointValueQueryDTO;
+import com.iailab.module.data.common.ApiDataQueryDTO;
+import com.iailab.module.data.common.ApiDataValueDTO;
+import com.iailab.module.model.common.enums.OutResultType;
 import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity;
 import com.iailab.module.model.mcs.pre.service.MmItemOutputService;
+import com.iailab.module.model.mcs.pre.service.MmItemResultJsonService;
 import com.iailab.module.model.mcs.pre.service.MmItemResultService;
 import com.iailab.module.model.mcs.pre.service.MmItemTypeService;
 import com.iailab.module.model.mdk.common.enums.ModelParamType;
@@ -14,18 +20,21 @@
 import com.iailab.module.model.mdk.sample.dto.SampleData;
 import com.iailab.module.model.mdk.sample.dto.SampleInfo;
 import com.iailab.module.model.mdk.vo.DataValueVO;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
 
-import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
 
 /**
  * 预测样本数据构造
  */
+@Slf4j
 @Component
 public class PredictSampleDataConstructor extends SampleDataConstructor {
 
@@ -35,7 +44,13 @@
     private DataPointApi dataPointApi;
 
     @Autowired
+    private PlanItemApi planItemApi;
+
+    @Autowired
     private MmItemResultService mmItemResultService;
+
+    @Autowired
+    private MmItemResultJsonService mmItemResultJsonService;
 
     @Autowired
     private MmItemTypeService mmItemTypeService;
@@ -51,8 +66,10 @@
      * @return
      */
     @Override
-    public List<SampleData> prepareSampleData(SampleInfo sampleInfo) {
+    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匿名函数
@@ -74,11 +91,11 @@
             //对每一项依次进行数据查询,然后将查询出的值赋给matrix对应的位置
             for (int i = 0; i < entry.getColumnItemList().size(); i++) {
                 try {
-                    List<DataValueVO> dataEntityList = getData(entry.getColumnItemList().get(i));
+                    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) {
@@ -89,6 +106,7 @@
                     }
                 } catch (Exception e) {
                     e.printStackTrace();
+                    throw e;
                 }
             }
             SampleData sampleData = new SampleData();
@@ -102,20 +120,24 @@
      * getData
      *
      * @param columnItem
+     * @param pointMap
+     * @param planMap
      * @return
      * @throws Exception
      */
-    private List<DataValueVO> getData(ColumnItem columnItem) 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)) {
             case DATAPOINT:
-                ApiPointDTO point = dataPointApi.getInfoById(columnItem.getParamId());
                 ApiPointValueQueryDTO queryDto = new ApiPointValueQueryDTO();
-                queryDto.setPointNo(point.getPointNo());
+                queryDto.setPointNo(pointMap.get(columnItem.getParamId()).getPointNo());
                 queryDto.setStart(columnItem.getStartTime());
                 queryDto.setEnd(columnItem.getEndTime());
                 List<ApiPointValueDTO> pointValueList = dataPointApi.queryPointHistoryValue(queryDto);
+                if (CollectionUtils.isEmpty(pointValueList)) {
+                    break;
+                }
                 dataList = pointValueList.stream().map(t -> {
                     DataValueVO vo = new DataValueVO();
                     vo.setDataTime(t.getT());
@@ -123,17 +145,52 @@
                     return vo;
                 }).collect(Collectors.toList());
                 break;
-            case PREDICTITEM:
-                MmItemOutputEntity outPut = mmItemOutputService.getOutPutById(columnItem.getId());
-                dataList = mmItemResultService.getPredictValue(outPut.getId(),
-                        columnItem.getStartTime(), columnItem.getEndTime());
-                if (dataList == null) {
-                    throw new Exception("没有预测值");
+            case NORMALITEM:
+            case MERGEITEM:
+                MmItemOutputEntity outPut = mmItemOutputService.getOutPutById(columnItem.getParamId());
+                OutResultType outResultType = OutResultType.getEumByCode(outPut.getResultType());
+                List<DataValueVO> predictValue = new ArrayList<>();
+
+                // double类型特殊处理
+                if (OutResultType.D.equals(outResultType)) {
+                    // columnItem.getStartTime()就是预测时间
+                    String doubleData = mmItemResultJsonService.getDoubleData(outPut.getId(), columnItem.getStartTime());
+                    if (StringUtils.isNotBlank(doubleData)) {
+                        DataValueVO dataValueVO = new DataValueVO();
+                        dataValueVO.setDataTime(columnItem.getStartTime());
+                        dataValueVO.setDataValue(Double.valueOf(doubleData));
+                        predictValue.add(dataValueVO);
+                    }
+                } else {
+                    predictValue = mmItemResultService.getPredictValue(outPut.getId(), columnItem.getStartTime(), columnItem.getEndTime());
                 }
+
+                if (CollectionUtils.isEmpty(predictValue)) {
+                    break;
+                }
+                dataList = predictValue;
                 break;
+            case PLAN:
+                ApiDataQueryDTO queryPlanItemDto = new ApiDataQueryDTO();
+                queryPlanItemDto.setItemNo(planMap.get(columnItem.getParamId()).getItemNo());
+                queryPlanItemDto.setStart(columnItem.getStartTime());
+                queryPlanItemDto.setEnd(columnItem.getEndTime());
+                List<ApiDataValueDTO> planValueList = planItemApi.queryPlanItemHistoryValue(queryPlanItemDto);
+                if (CollectionUtils.isEmpty(planValueList)) {
+                    break;
+                }
+                dataList = planValueList.stream().map(t -> {
+                    DataValueVO vo = new DataValueVO();
+                    vo.setDataTime(t.getDataTime());
+                    vo.setDataValue(t.getDataValue());
+                    return vo;
+                }).collect(Collectors.toList());
             default:
                 break;
         }
+        // 避免生产环境日志过多,分级打印
+        log.debug("数据获取,columnItem:" + columnItem + ",dataList:" + dataList);
+        log.info("数据获取,columnItem:" + columnItem + ",dataListLength:" + dataList.size());
         return dataList;
     }
 }

--
Gitblit v1.9.3