From c7ec0ceff9cf30cabbd8d071c1ef75d20d04548f Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期二, 01 四月 2025 17:33:28 +0800
Subject: [PATCH] Day频率数据采集时分秒置0 getByMin

---
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/CumulateHandle.java         |    2 +-
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/ConstantHandle.java         |    3 ++-
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java          |    5 +++--
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/utils/GenInfluxPointValueUtils.java |   27 +++++++++++++++++++++++++++
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/CalculateHandle.java        |    3 ++-
 5 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/CalculateHandle.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/CalculateHandle.java
index 8b1376a..22b0cbd 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/CalculateHandle.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/CalculateHandle.java
@@ -6,6 +6,7 @@
 import com.iailab.module.data.common.enums.DataTypeEnum;
 import com.iailab.module.data.common.enums.JsErrorCode;
 import com.iailab.module.data.common.utils.JavaScriptHandler;
+import com.iailab.module.data.enums.DataPointFreqEnum;
 import com.iailab.module.data.point.collection.PointCollector;
 import com.iailab.module.data.point.collection.utils.GenInfluxPointValueUtils;
 import com.iailab.module.data.point.dto.DaPointDTO;
@@ -67,7 +68,7 @@
                     BigDecimal coefficient = dto.getUnittransfactor() == null ? BigDecimal.ONE : dto.getUnittransfactor();
                     BigDecimal calValue = new BigDecimal(rawValue.toString()).multiply(coefficient);
                     InfluxPointValuePOJO pojo = GenInfluxPointValueUtils.getByPoint(dto, calValue);
-                    pojo.setTimestamp(collectTime.toInstant());
+                    pojo.setTimestamp(GenInfluxPointValueUtils.getByMin(collectTime, DataPointFreqEnum.getEumByCode(dto.getMinfreqid())));
                     result.add(pojo);
                 } catch (Exception ex) {
                     ex.printStackTrace();
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/ConstantHandle.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/ConstantHandle.java
index 8aed10c..28f2758 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/ConstantHandle.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/ConstantHandle.java
@@ -1,5 +1,6 @@
 package com.iailab.module.data.point.collection.handler;
 
+import com.iailab.module.data.enums.DataPointFreqEnum;
 import com.iailab.module.data.point.collection.utils.GenInfluxPointValueUtils;
 import com.iailab.module.data.point.dto.DaPointDTO;
 import com.iailab.module.data.point.service.DaPointService;
@@ -33,7 +34,7 @@
         }
         dtos.forEach(dto -> {
             InfluxPointValuePOJO pojo = GenInfluxPointValueUtils.getByPoint(dto);
-            pojo.setTimestamp(collectTime.toInstant());
+            pojo.setTimestamp(GenInfluxPointValueUtils.getByMin(collectTime, DataPointFreqEnum.getEumByCode(dto.getMinfreqid())));
             dataMap.put(dto.getPointNo(), dto.getDefaultValue());
             result.add(pojo);
             listGood.add(dto.getPointNo());
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/CumulateHandle.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/CumulateHandle.java
index fd28d31..c6fb0f2 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/CumulateHandle.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/CumulateHandle.java
@@ -54,7 +54,7 @@
                 try {
                     Object value = singleCompute(dto, collectTime, listGood, listBad);
                     InfluxPointValuePOJO pojo = GenInfluxPointValueUtils.getByPoint(dto, value);
-                    pojo.setTimestamp(collectTime.toInstant());
+                    pojo.setTimestamp(GenInfluxPointValueUtils.getByMin(collectTime, DataPointFreqEnum.getEumByCode(dto.getMinfreqid())));
                     result.add(pojo);
                 } catch (Exception ex) {
                     ex.printStackTrace();
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java
index c03f5ef..9fbd7ee 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java
@@ -14,6 +14,7 @@
 import com.iailab.module.data.channel.kio.collector.KingIOCollector;
 import com.iailab.module.data.channel.modbus.collector.ModBusCollector;
 import com.iailab.module.data.channel.opcua.collector.OpcUaCollector;
+import com.iailab.module.data.enums.DataPointFreqEnum;
 import com.iailab.module.data.point.collection.PointCollector;
 import com.iailab.module.data.point.collection.utils.GenInfluxPointValueUtils;
 import com.iailab.module.data.point.common.PointDataTypeEnum;
@@ -158,13 +159,13 @@
                 if (tagValues.containsKey(tagId)) {
                     Object value = handleData(dto, tagValues.get(tagId));
                     InfluxPointValuePOJO pojo = GenInfluxPointValueUtils.getByPoint(dto, value);
-                    pojo.setTimestamp(collectTime.toInstant());
+                    pojo.setTimestamp(GenInfluxPointValueUtils.getByMin(collectTime, DataPointFreqEnum.getEumByCode(dto.getMinfreqid())));
                     dataMap.put(dto.getPointNo(), value);
                     result.add(pojo);
                     listGood.add(dto.getPointNo());
                 } else {
                     InfluxPointValuePOJO pojo = GenInfluxPointValueUtils.getByPoint(dto, CommonConstant.BAD_VALUE);
-                    pojo.setTimestamp(collectTime.toInstant());
+                    pojo.setTimestamp(GenInfluxPointValueUtils.getByMin(collectTime, DataPointFreqEnum.getEumByCode(dto.getMinfreqid())));
                     result.add(pojo);
                     listBad.add(dto.getPointNo());
                     log.info("值异常!TagId=" + tagId);
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/utils/GenInfluxPointValueUtils.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/utils/GenInfluxPointValueUtils.java
index 36d6dd1..dc8f888 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/utils/GenInfluxPointValueUtils.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/utils/GenInfluxPointValueUtils.java
@@ -1,8 +1,13 @@
 package com.iailab.module.data.point.collection.utils;
 
 import com.iailab.module.data.common.enums.DataTypeEnum;
+import com.iailab.module.data.enums.DataPointFreqEnum;
 import com.iailab.module.data.point.dto.DaPointDTO;
 import com.iailab.module.data.influxdb.pojo.*;
+
+import java.time.Instant;
+import java.util.Calendar;
+import java.util.Date;
 
 /**
  * @author PanZhibao
@@ -69,4 +74,26 @@
             return new InfluxPointValueStrPOJO();
         }
     }
+
+    public static Instant getByMin(Date collectTime, DataPointFreqEnum freqEnum) {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(collectTime);
+        switch (freqEnum) {
+            case NET_1MIN:
+                cal.set(Calendar.SECOND, 0);
+                break;
+            case NET_1H:
+                cal.set(Calendar.SECOND, 0);
+                cal.set(Calendar.MINUTE, 0);
+                break;
+            case NET_Day:
+                cal.set(Calendar.SECOND, 0);
+                cal.set(Calendar.MINUTE, 0);
+                cal.set(Calendar.HOUR_OF_DAY, 0);
+                break;
+            default:
+                break;
+        }
+        return cal.getTime().toInstant();
+    }
 }

--
Gitblit v1.9.3