From b270a07828a9627f1a42e254a430c9921fec4e95 Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期三, 26 三月 2025 16:14:37 +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/mdk/sample/SampleDataConstructor.java |   52 ++++++++++++++++++++++++----------------------------
 1 files changed, 24 insertions(+), 28 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 5f5befc..9478194 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
@@ -52,8 +52,7 @@
         }
 
         List<DataValueVO> completionDataEntityList = new ArrayList<>();
-        long oneMin = 0L;
-
+        long oneMin = granularity * 1000L;;
         long start = startTime.getTime();
         long end = endTime.getTime();
         long mins = 0L;
@@ -61,44 +60,27 @@
         switch (ModelParamType.getEumByCode(paramType)) {
             case NORMALITEM:
             case MERGEITEM:
-                // 预测值
-                oneMin = granularity * 1000L;
-                start = start - (start % oneMin);
-                end = end - (end % oneMin);
-                mins = ((end - start) / oneMin);
+                // 设置时间偏移量
+                mins = calMins(start, end, granularity);
                 break;
             case DATAPOINT:
             case PLAN:
-                // 测点值
-                oneMin = 1000L * granularity;
                 // 设置时间偏移量
-                start = start - (start % oneMin) + oneMin;
-                end = end - (end % oneMin) + oneMin;
-                mins = ((end - start) / oneMin);
+                mins = calMins(start, end, granularity) + 1;
                 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);
+            case IND_ASCII:
+                // 设置时间偏移量
+                mins = calMins(start, end, granularity) + 1;
                 break;
             default:
                 break;
         }
         Map<Long, Double> sourceDataMap = new HashMap<>(dataEntityList.size());
         for (DataValueVO dataEntity : dataEntityList) {
-            sourceDataMap.put(dataEntity.getDataTime().getTime(), dataEntity.getDataValue());
+            if (null != dataEntity.getDataTime()) {
+                sourceDataMap.put(dataEntity.getDataTime().getTime(), dataEntity.getDataValue());
+            }
         }
 
         //找出缺少项
@@ -129,6 +111,20 @@
         return completionDataEntityList;
     }
 
+    private long calMins(long start, long end, Integer granularity) {
+        long oneMin = granularity * 1000L;
+        // 设置时间偏移量
+        if (granularity >= 24 * 60 * 60) {
+            // 如果时间粒度大于等于一天,因为时区问题,特殊处理,否则时间为8:00,而非0:00
+            start = start - ((start + 8 * 60 * 60 * 1000) % oneMin);
+            end = end - ((end + 8 * 60 * 60 * 1000) % oneMin);
+        } else {
+            start = start - (start % oneMin);
+            end = end - (end % oneMin);
+        }
+        return ((end - start) / oneMin);
+    }
+
     /**
      * getFirstValue
      *

--
Gitblit v1.9.3