From 730d1944e3a13c517c77df2b0712df05645a38dd Mon Sep 17 00:00:00 2001
From: dengzedong <dengzedong@email>
Date: 星期一, 06 一月 2025 16:00:58 +0800
Subject: [PATCH] chartParamList api

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

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..ce370a3 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
@@ -2,23 +2,20 @@
 
 import com.iailab.module.data.api.ind.IndItemApi;
 import com.iailab.module.data.api.ind.dto.ApiIndItemDTO;
-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.TimeGranularityEnum;
 import com.iailab.module.data.enums.TimeGranularitySecEnum;
 import com.iailab.module.model.mcs.pre.service.MmPredictItemService;
 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;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.CollectionUtils;
 
 import java.util.Calendar;
 import java.util.Date;
-import java.util.List;
+import java.util.Map;
 
 /**
  * @author PanZhibao
@@ -26,12 +23,6 @@
  * @createTime 2024年09月03日
  */
 abstract class SampleInfoConstructor {
-
-    @Autowired
-    private DataPointApi dataPointApi;
-
-    @Autowired
-    private PlanItemApi planItemApi;
 
     @Autowired
     private IndItemApi indItemApi;
@@ -46,15 +37,9 @@
      * @param predictTime
      * @return
      */
-    protected SampleInfo prepareSampleInfo(String modelId, Date predictTime) {
-        SampleInfo sampleInfo = new SampleInfo();
-        //调用样本列数的方法
-//        sampleInfo.setSampleColumn(getSampleColumn(modelId));
+    protected SampleInfo prepareSampleInfo(String modelId, Date predictTime, Map<Integer, Integer> dynamicDataLength) {
         //样本的列信息
-        sampleInfo.setColumnInfo(getColumnInfo(modelId, predictTime));
-        //样本的采样周期
-//        sampleInfo.setSampleCycle(getSampleCycle(modelId));
-        return sampleInfo;
+        return getColumnInfo(modelId, predictTime, dynamicDataLength);
     }
 
     /**
@@ -73,7 +58,7 @@
      * @param predictTime
      * @return
      */
-    protected abstract List<ColumnItemPort> getColumnInfo(String modelId, Date predictTime);
+    protected abstract SampleInfo getColumnInfo(String modelId, Date predictTime, Map<Integer, Integer> dynamicDataLength);
 
     /**
      * 样本的采样周期
@@ -91,13 +76,13 @@
      * @return
      * @throws Exception
      */
-    protected Date getStartTime(ColumnItem columnItem, Date originalTime) {
+    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);
         switch (ModelParamType.getEumByCode(columnItem.getParamType())) {
             case DATAPOINT:
-                ApiPointDTO dataPoint = dataPointApi.getInfoById(columnItem.getParamId());
+                ApiPointDTO dataPoint = pointMap.get(columnItem.getParamId());
                 if (dataPoint == null) {
                     return null;
                 }
@@ -111,7 +96,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;
@@ -127,32 +116,23 @@
      * @return
      * @throws Exception
      */
-    protected Date getEndTime(ColumnItem columnItem, Date originalTime) {
+    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);
         switch (ModelParamType.getEumByCode(columnItem.getParamType())) {
             case DATAPOINT:
-                ApiPointDTO dataPoint = dataPointApi.getInfoById(columnItem.getParamId());
-                if (dataPoint == null) {
-                    return null;
-                }
                 dateTime = calendar.getTime();
                 break;
             case NORMALITEM:
             case MERGEITEM:
-                dateTime = calendar.getTime();
+                dateTime = calculateTime(originalTime, false, columnItem.getDataLength(), 60);
                 break;
             case IND:
                 dateTime = calendar.getTime();
                 break;
             case PLAN:
-                ApiPlanItemDTO planItem = planItemApi.getInfoByNo(columnItem.getParamId());
-                if (planItem == null) {
-                    return null;
-                }
-                dateTime = calculateDate(originalTime, false, columnItem.getDataLength(),
-                        TimeGranularityEnum.getEumByCode(planItem.getTimeGranularity()).getValue());
+                dateTime = calendar.getTime();
                 break;
             default:
                 break;
@@ -167,26 +147,24 @@
      * @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.getItemByIdFromCache(columnItem.getParamId()).getGranularity();
+                granularity = mmPredictItemService.getItemByOutPutId(columnItem.getParamId()).getGranularity();
                 break;
             case IND:
                 ApiIndItemDTO indItemDTO = indItemApi.getInfoById(columnItem.getParamId());
                 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:
@@ -220,19 +198,13 @@
         return calendar.getTime();
     }
 
-    public Date calculateDate(Date originalTime, Boolean backward, int dataLength, int field) {
-        int timeLength;
-        if (backward) {
-            timeLength = (-1) * dataLength;
-        } else {
-            timeLength = dataLength - 1;
+    protected int getDataLength(Map<Integer, Integer> dynamicDataLength, Integer port, Integer dataLength) {
+        if (CollectionUtils.isEmpty(dynamicDataLength)) {
+            return dataLength;
         }
-        Date desTime = originalTime;
-        Calendar calendar = Calendar.getInstance();
-        calendar.setTime(desTime);
-        calendar.set(Calendar.MILLISECOND, 0);
-        // 数据长度 * 粒度
-        calendar.add(Calendar.SECOND, timeLength);
-        return calendar.getTime();
+        if (dynamicDataLength.containsKey(port)) {
+            return dynamicDataLength.get(port);
+        }
+        return dataLength;
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3