From 271fed395d4d3e4ab8cdb44ccf466859ba485e46 Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期四, 09 一月 2025 17:45:33 +0800
Subject: [PATCH] Merge branch 'master' of http://dlindusit.com:53929/r/iailab-plat

---
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/enums/PredGranularityEnum.java        |    4 +
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleDataConstructor.java  |    8 ++-
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/ScheduleSampleInfoConstructor.java |    4 +-
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleInfoConstructor.java  |    4 +-
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java         |   32 ++++------------
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictModuleHandler.java         |   25 ++++++++----
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/McsApiImpl.java                           |    6 +-
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java                           |    9 ----
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleDataConstructor.java         |   19 ++-------
 9 files changed, 44 insertions(+), 67 deletions(-)

diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/McsApiImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/McsApiImpl.java
index d918e48..fcf9866 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/McsApiImpl.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/McsApiImpl.java
@@ -253,20 +253,20 @@
         if (startTime == null) {
             Calendar calendar = Calendar.getInstance();
             calendar.setTime(predictItem.getLastTime());
-            calendar.add(Calendar.MINUTE, -1 * predictItem.getPredictLength());
+            calendar.add(Calendar.SECOND, -1 * predictItem.getPredictLength() * predictItem.getGranularity());
             startTime = calendar.getTime();
         }
         Date endTime = reqVO.getEndTime();
         if (endTime == null) {
             Calendar calendar = Calendar.getInstance();
             calendar.setTime(predictItem.getLastTime());
-            calendar.add(Calendar.MINUTE, predictItem.getPredictLength());
+            calendar.add(Calendar.SECOND, predictItem.getPredictLength() * predictItem.getGranularity());
             endTime = calendar.getTime();
         }
         if (endTime.getTime() <= startTime.getTime()) {
             Calendar calendar = Calendar.getInstance();
             calendar.setTime(startTime);
-            calendar.add(Calendar.MINUTE, predictItem.getPredictLength());
+            calendar.add(Calendar.SECOND, predictItem.getPredictLength() * predictItem.getGranularity());
             endTime = calendar.getTime();
         }
 
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java
index c6511d1..d2ba7ba 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java
@@ -98,15 +98,8 @@
             if (reqDTO.getModuleType() == null) {
                 throw new Exception("ModuleType不能为空");
             }
-            Calendar calendar = Calendar.getInstance();
-            calendar.setTime(reqDTO.getPredictTime());
-            calendar.set(Calendar.MILLISECOND, 0);
-            calendar.set(Calendar.SECOND, 0);
-            reqDTO.setPredictTime(calendar.getTime());
+
             log.info("预测参数:" + JSON.toJSONString(reqDTO));
-            MdkPredictModuleRespDTO result = new MdkPredictModuleRespDTO();
-            result.setPredictTime(reqDTO.getPredictTime());
-            result.setModuleType(reqDTO.getModuleType());
             List<DmModuleEntity> moduleList = dmModuleService.getModuleByModuleType(reqDTO.getModuleType());
             log.info("预测计算开始: " + System.currentTimeMillis());
             for (DmModuleEntity module : moduleList) {
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/enums/PredGranularityEnum.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/enums/PredGranularityEnum.java
index 2f1a592..d36d317 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/enums/PredGranularityEnum.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/enums/PredGranularityEnum.java
@@ -13,7 +13,9 @@
 @Getter
 @AllArgsConstructor
 public enum PredGranularityEnum {
-    MIN1(60, "1min");
+    MIN1(60, "1min"),
+    H1(3600, "1h"),
+    D1(86400, "1d");
 
     private Integer code;
     private String desc;
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictModuleHandler.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictModuleHandler.java
index 47596e7..76d88ec 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictModuleHandler.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictModuleHandler.java
@@ -4,6 +4,7 @@
 import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity;
 import com.iailab.module.model.mcs.pre.enums.ItemRunStatusEnum;
 import com.iailab.module.model.mcs.pre.enums.ItemStatus;
+import com.iailab.module.model.mcs.pre.enums.PredGranularityEnum;
 import com.iailab.module.model.mcs.pre.service.MmItemStatusService;
 import com.iailab.module.model.mdk.factory.PredictItemFactory;
 import com.iailab.module.model.mdk.vo.ItemVO;
@@ -14,12 +15,7 @@
 import org.springframework.util.CollectionUtils;
 
 import java.text.MessageFormat;
-import java.time.Duration;
-import java.time.Instant;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * @author PanZhibao
@@ -61,6 +57,17 @@
             }
         }
         for (ItemVO predictItem : predictItemList) {
+            // 根据item粒度处理预测时间
+            Calendar calendar = Calendar.getInstance();
+            calendar.setTime(predictTime);
+            calendar.set(Calendar.MILLISECOND, 0);
+            calendar.set(Calendar.SECOND, 0);
+            if (PredGranularityEnum.H1.getCode().equals(predictItem.getGranularity())) {
+                calendar.set(Calendar.MINUTE,0);
+            }else if (PredGranularityEnum.D1.getCode().equals(predictItem.getGranularity())) {
+                calendar.set(Calendar.MINUTE,0);
+                calendar.set(Calendar.HOUR_OF_DAY,0);
+            }
             PredictResultVO predictResult;
             if (!predictItem.getStatus().equals(ItemStatus.STATUS1.getCode())) {
                 continue;
@@ -68,12 +75,12 @@
             Long totalDur = 0L;
             ItemRunStatusEnum itemRunStatusEnum = ItemRunStatusEnum.PROCESSING;
             try {
-                mmItemStatusService.recordStatus(predictItem.getId(), itemRunStatusEnum, totalDur, predictTime);
+                mmItemStatusService.recordStatus(predictItem.getId(), itemRunStatusEnum, totalDur, calendar.getTime());
                 PredictItemHandler predictItemHandler = predictItemFactory.create(predictItem.getId());
                 long start = System.currentTimeMillis();
                 try {
                     // 预测项开始预测
-                    predictResult = predictItemHandler.predict(predictTime, predictItem, predictValueMap);
+                    predictResult = predictItemHandler.predict(calendar.getTime(), predictItem, predictValueMap);
                 } catch (ModelResultErrorException e) {
                     itemRunStatusEnum = ItemRunStatusEnum.MODELRESULTERROR;
                     continue;
@@ -109,7 +116,7 @@
                 log.error(MessageFormat.format("预测项编号:{0},预测项名称:{1},预测失败:{2} 预测时刻:{3}",
                         predictItem.getId(), predictItem.getItemName(), e.getMessage(), predictTime));
             } finally {
-                mmItemStatusService.recordStatus(predictItem.getId(), itemRunStatusEnum, totalDur, predictTime);
+                mmItemStatusService.recordStatus(predictItem.getId(), itemRunStatusEnum, totalDur, calendar.getTime());
             }
         }
     }
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 5c680ed..9fb4dd6 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
@@ -94,14 +94,16 @@
                     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(), pointMap, planMap);
+                    dataEntityList = super.completionData(matrix.length, dataEntityList, columnItem.startTime, columnItem.endTime, columnItem.getParamType(),columnItem.getGranularity());
 
                     /** 如果数据取不满,把缺失的数据点放在后面 */
                     if (dataEntityList != null && dataEntityList.size() != 0) {
                         logger.info("设置matrix, i = " + i + ", size = " + dataEntityList.size());
                         for (int k = 0; k < dataEntityList.size(); k++) {
-                            matrix[k][i] = dataEntityList.get(k).getDataValue();
+                            Double dataValue = dataEntityList.get(k).getDataValue();
+                            if (null != dataValue) {
+                                matrix[k][i] = dataValue;
+                            }
                         }
                     }
                 } catch (Exception e) {
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 ae066fe..5a162f0 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
@@ -91,9 +91,9 @@
             columnInfo.setDataLength(super.getDataLength(dynamicDataLength, entry.getModelparamportorder(), entry.getDatalength()));
             columnInfo.setModelParamOrder(entry.getModelparamorder());
             columnInfo.setModelParamPortOrder(entry.getModelparamportorder());
-            columnInfo.setStartTime(getStartTime(columnInfo, predictTime, pointMap, planMap));
-            columnInfo.setEndTime(getEndTime(columnInfo, predictTime, pointMap, planMap));
             columnInfo.setGranularity(super.getGranularity(columnInfo, pointMap, planMap));
+            columnInfo.setStartTime(getStartTime(columnInfo, predictTime));
+            columnInfo.setEndTime(getEndTime(columnInfo, predictTime));
 
             //对每一个爪进行数据项归并
             if (curPortOrder != entry.getModelparamportorder()) {
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 cdaa7ec..5f5befc 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
@@ -42,11 +42,9 @@
      * @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, Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) {
+    public List<DataValueVO> completionData(int length, List<DataValueVO> dataEntityList, Date startTime, Date endTime, String paramType, Integer granularity) {
         if (CollectionUtils.isEmpty(dataEntityList) || length == dataEntityList.size()) {
             return dataEntityList;
         } else if (length < dataEntityList.size()) {
@@ -64,15 +62,15 @@
             case NORMALITEM:
             case MERGEITEM:
                 // 预测值
-                oneMin = PredGranularityEnum.MIN1.getCode() * 1000L;
+                oneMin = granularity * 1000L;
                 start = start - (start % oneMin);
                 end = end - (end % oneMin);
                 mins = ((end - start) / oneMin);
                 break;
             case DATAPOINT:
+            case PLAN:
                 // 测点值
-                ApiPointDTO dataPoint = pointMap.get(paramId);
-                oneMin = 1000L * DataPointFreqEnum.getEumByCode(dataPoint.getMinfreqid()).getValue();
+                oneMin = 1000L * granularity;
                 // 设置时间偏移量
                 start = start - (start % oneMin) + oneMin;
                 end = end - (end % oneMin) + oneMin;
@@ -93,15 +91,6 @@
                 calendar2.set(Calendar.MINUTE, 0);
                 calendar2.set(Calendar.SECOND, 0);
                 end = calendar2.getTime().getTime();
-                mins = ((end - start) / oneMin);
-                break;
-            case PLAN:
-                // 计划数据
-                ApiPlanItemDTO planItem = planMap.get(paramId);
-                oneMin = 1000L * TimeGranularitySecEnum.getEumByCode(planItem.getTimeGranularity()).getValue();
-                // 设置时间偏移量
-                start = start - (start % oneMin) + oneMin;
-                end = end - (end % oneMin) + oneMin;
                 mins = ((end - start) / oneMin);
                 break;
             default:
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 f025e51..45273aa 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
@@ -76,31 +76,19 @@
      * @return
      * @throws Exception
      */
-    protected Date getStartTime(ColumnItem columnItem, Date originalTime, Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) {
+    protected Date getStartTime(ColumnItem columnItem, Date originalTime) {
         Date dateTime = new Date();
         Calendar calendar = Calendar.getInstance();
         calendar.setTime(originalTime);
         switch (ModelParamType.getEumByCode(columnItem.getParamType())) {
             case DATAPOINT:
-                ApiPointDTO dataPoint = pointMap.get(columnItem.getParamId());
-                if (dataPoint == null) {
-                    return null;
-                }
-                dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), DataPointFreqEnum.getEumByCode(dataPoint.getMinfreqid()).getValue());
+            case IND:
+            case PLAN:
+                dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), columnItem.getGranularity());
                 break;
             case NORMALITEM:
             case MERGEITEM:
                 dateTime = calendar.getTime();
-                break;
-            case IND:
-                dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), 60);
-                break;
-            case PLAN:
-                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;
@@ -116,23 +104,19 @@
      * @return
      * @throws Exception
      */
-    protected Date getEndTime(ColumnItem columnItem, Date originalTime,Map<String, ApiPointDTO> pointMap, Map<String, ApiPlanItemDTO> planMap) {
+    protected Date getEndTime(ColumnItem columnItem, Date originalTime) {
         Date dateTime = new Date();
         Calendar calendar = Calendar.getInstance();
         calendar.setTime(originalTime);
         switch (ModelParamType.getEumByCode(columnItem.getParamType())) {
             case DATAPOINT:
+            case IND:
+            case PLAN:
                 dateTime = calendar.getTime();
                 break;
             case NORMALITEM:
             case MERGEITEM:
-                dateTime = calculateTime(originalTime, false, columnItem.getDataLength(), 60);
-                break;
-            case IND:
-                dateTime = calendar.getTime();
-                break;
-            case PLAN:
-                dateTime = calendar.getTime();
+                dateTime = calculateTime(originalTime, false, columnItem.getDataLength(), columnItem.getGranularity());
                 break;
             default:
                 break;
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 b3c73a9..acec837 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
@@ -65,9 +65,9 @@
             columnInfo.setDataLength(super.getDataLength(dynamicDataLength, entry.getModelparamportorder(), entry.getDatalength()));
             columnInfo.setModelParamOrder(entry.getModelparamorder());
             columnInfo.setModelParamPortOrder(entry.getModelparamportorder());
-            columnInfo.setStartTime(getStartTime(columnInfo, predictTime, pointMap, planMap));
-            columnInfo.setEndTime(getEndTime(columnInfo, predictTime, pointMap, planMap));
             columnInfo.setGranularity(super.getGranularity(columnInfo, pointMap, planMap));
+            columnInfo.setStartTime(getStartTime(columnInfo, predictTime));
+            columnInfo.setEndTime(getEndTime(columnInfo, predictTime));
 
             //对每一个爪进行数据项归并
             if (curPortOrder != entry.getModelparamportorder()) {

--
Gitblit v1.9.3