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/SampleDataConstructor.java |  100 ++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 88 insertions(+), 12 deletions(-)

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 bee81d5..dba4323 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
@@ -1,17 +1,31 @@
 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.enums.DataPointFreqEnum;
+import com.iailab.module.data.enums.TimeGranularitySecEnum;
+import com.iailab.module.model.mdk.common.enums.ModelParamType;
 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 org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.CollectionUtils;
 
+import java.sql.Timestamp;
 import java.util.*;
 
 abstract class SampleDataConstructor {
 
     private Logger logger = LoggerFactory.getLogger(getClass());
+
+    @Autowired
+    private DataPointApi dataPointApi;
+    @Autowired
+    private PlanItemApi planItemApi;
 
     /**
      * prepareSampleData
@@ -19,7 +33,7 @@
      * @param sampleInfo
      * @return
      */
-    public abstract List<SampleData> prepareSampleData(SampleInfo sampleInfo);
+    public abstract List<SampleData> prepareSampleData(SampleInfo sampleInfo) throws Exception;
 
     /**
      * 补全数据
@@ -30,23 +44,88 @@
      * @param endTime
      * @return
      */
-    public List<DataValueVO> completionData(int length, List<DataValueVO> dataEntityList, Date startTime, Date endTime, int granularity) {
-        if (CollectionUtils.isEmpty(dataEntityList) || length <= dataEntityList.size()) {
+    public List<DataValueVO> completionData(int length, List<DataValueVO> dataEntityList, Date startTime, Date endTime,
+                                            String paramId, String paramType) {
+        if (CollectionUtils.isEmpty(dataEntityList) || length == dataEntityList.size()) {
             return dataEntityList;
+        } else if (length < dataEntityList.size()) {
+            return dataEntityList.subList(dataEntityList.size() - length, dataEntityList.size());
         }
-        logger.info("补全数据, length =" + length + "; size = " + dataEntityList.size() + "; startTime = " + startTime.getTime() + "; endTime = " + endTime.getTime());
-        logger.info("补全前:" + dataEntityList);
 
+        List<DataValueVO> completionDataEntityList = new ArrayList<>();
+        long oneMin = 0L;
+
+        long start = startTime.getTime();
+        long end = endTime.getTime();
+        long mins = 0L;
+
+        switch (ModelParamType.getEumByCode(paramType)) {
+            case NORMALITEM:
+            case MERGEITEM:
+                // 预测值
+                Calendar calendar = Calendar.getInstance();
+                calendar.setTime(startTime);
+                calendar.set(Calendar.HOUR_OF_DAY, 0);
+                calendar.set(Calendar.MINUTE, 0);
+                calendar.set(Calendar.SECOND, 0);
+                calendar.add(Calendar.DAY_OF_YEAR, 1);
+                startTime = calendar.getTime();
+                start = startTime.getTime();
+
+                calendar.setTime(endTime);
+                calendar.set(Calendar.HOUR_OF_DAY, 0);
+                calendar.set(Calendar.MINUTE, 0);
+                calendar.set(Calendar.SECOND, 0);
+                endTime = calendar.getTime();
+                end = endTime.getTime();
+
+                oneMin = 60 * 1000L;
+                mins = ((end - start) / oneMin);
+                break;
+            case DATAPOINT:
+                // 测点值
+                ApiPointDTO dataPoint = dataPointApi.getInfoById(paramId);
+                oneMin = 1000L * DataPointFreqEnum.getEumByCode(dataPoint.getMinfreqid()).getValue();
+                // 设置时间偏移量
+                start = start - (start % oneMin) + oneMin;
+                end = end - (end % oneMin) + oneMin;
+                mins = ((end - start) / oneMin);
+                break;
+            case IND:
+                // 指标数据
+                oneMin = 24 * 60 * 60 * 1000;
+                Calendar calendar2 = Calendar.getInstance();
+                calendar2.setTime(startTime);
+                calendar2.set(Calendar.HOUR_OF_DAY, 0);
+                calendar2.set(Calendar.MINUTE, 0);
+                calendar2.set(Calendar.SECOND, 0);
+                start = calendar2.getTime().getTime();
+
+                calendar2.setTime(endTime);
+                calendar2.set(Calendar.HOUR_OF_DAY, 0);
+                calendar2.set(Calendar.MINUTE, 0);
+                calendar2.set(Calendar.SECOND, 0);
+                end = calendar2.getTime().getTime();
+                mins = ((end - start) / oneMin);
+                break;
+            case PLAN:
+                // 计划数据
+                ApiPlanItemDTO planItem = planItemApi.getInfoById(paramId);
+                oneMin = 1000L * TimeGranularitySecEnum.getEumByCode(planItem.getTimeGranularity()).getValue();
+                // 设置时间偏移量
+                start = start - (start % oneMin) + oneMin;
+                end = end - (end % oneMin) + oneMin;
+                mins = ((end - start) / oneMin);
+                break;
+            default:
+                break;
+        }
         Map<Long, Double> sourceDataMap = new HashMap<>(dataEntityList.size());
         for (DataValueVO dataEntity : dataEntityList) {
             sourceDataMap.put(dataEntity.getDataTime().getTime(), dataEntity.getDataValue());
         }
 
         //找出缺少项
-        long oneMin = 1000 * granularity;
-        long start = startTime.getTime();
-        long end = endTime.getTime();
-        long mins = ((end - start) / oneMin) + 1;
         Map<Long, Double> dataMap = new LinkedHashMap<>();
         for (int i = 0; i < mins; i++) {
             Long key = start + oneMin * i;
@@ -57,7 +136,6 @@
         //补充缺少项
         int k = 0;
         Map.Entry<Long, Double> lastItem = null;
-        List<DataValueVO> completionDataEntityList = new ArrayList<>();
         for (Map.Entry<Long, Double> item : dataMap.entrySet()) {
             if (k == 0 && item.getValue() == null) {
                 item.setValue(getFirstValue(dataMap));
@@ -72,8 +150,6 @@
             dataEntity.setDataValue(item.getValue());
             completionDataEntityList.add(dataEntity);
         }
-
-        logger.info("补全后:" + completionDataEntityList);
         return completionDataEntityList;
     }
 

--
Gitblit v1.9.3