From f5072463229ec111266c6781d75f7906a8769dc9 Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期一, 17 三月 2025 23:46:40 +0800
Subject: [PATCH] 修复查询不到开始时间数据问题

---
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/PointCollectTaskNet60.java            |    1 +
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/CumulateHandle.java   |    8 ++++----
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/PointCollector.java           |    2 ++
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/influxdb/service/impl/InfluxDBServiceImpl.java |   21 +++++++++++----------
 4 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/influxdb/service/impl/InfluxDBServiceImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/influxdb/service/impl/InfluxDBServiceImpl.java
index ae6045b..efff0f2 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/influxdb/service/impl/InfluxDBServiceImpl.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/influxdb/service/impl/InfluxDBServiceImpl.java
@@ -26,6 +26,7 @@
 import com.influxdb.query.FluxTable;
 import com.influxdb.query.InfluxQLQueryResult;
 import lombok.extern.slf4j.Slf4j;
+
 import javax.annotation.Resource;
 
 import org.springframework.beans.factory.annotation.Autowired;
@@ -124,7 +125,7 @@
         }
         if (!CollectionUtils.isEmpty(tagValues)) {
             tagValues.forEach(item -> {
-                log.info("bucket==="+ influxDBInstance.getBucket() + ",org===" + influxDBInstance.org);
+                log.info("bucket===" + influxDBInstance.getBucket() + ",org===" + influxDBInstance.org);
                 writeApi.writeMeasurement(influxDBInstance.getBucket(), influxDBInstance.org, WritePrecision.MS, item);
             });
         }
@@ -144,8 +145,8 @@
         calendar.set(Calendar.MILLISECOND, 0);
         // String start = startTime.getTime() - calendar.getTime().getTime() + "ms";
         String start = startTime.getTime() - calendar.getTime().getTime() - pas_ms + "ms";
-        if (endTime==null){
-            endTime= new Date();
+        if (endTime == null) {
+            endTime = new Date();
         }
         String stop = endTime.getTime() - calendar.getTime().getTime() + "ms";
 
@@ -239,7 +240,7 @@
         List<Map<String, Object>> list = data.get(queryDto.getTagIds().get(0));
 
         //导出
-        try{
+        try {
             String sheetTitle = "采集数据";
             String[] title = new String[]{"值", "时间"};
             ExcelUtil.exportPointValue(sheetTitle, title, new ArrayList<>(list), response);
@@ -277,7 +278,7 @@
 
         //提取list
         List<Map<String, Object>> list = data.get(queryDto.getPointNos().get(0));
-        for(Map<String, Object> map : list){
+        for (Map<String, Object> map : list) {
             PointValueExportVO dto = new PointValueExportVO();
             dto.setDatatime(map.get("time").toString());
             dto.setDatavalue(map.get("value").toString());
@@ -316,7 +317,7 @@
         if (influxQLQueryApi == null) {
             influxQLQueryApi = influxDBInstance.getClient().getInfluxQLQueryApi();
         }
-        long utcMillis = startTime.getTime() -rawOffset;
+        long utcMillis = startTime.getTime() - rawOffset;
         String utsStart = DateUtils.format(new Date(utcMillis), DateUtils.FORMAT_YEAR_MONTH_DAY);
         log.info("utsStart=" + utsStart);
         String measurement = PointValueUtils.getMeasurement(point.getType());
@@ -325,7 +326,7 @@
         sql.append(measurement);
         sql.append(" WHERE point = '");
         sql.append(point.getPoint());
-        sql.append("' AND time >= '" + utsStart +"'");
+        sql.append("' AND time >= '" + utsStart + "'");
         InfluxQLQueryResult data = influxQLQueryApi.query(new InfluxQLQuery(sql.toString(), influxDBInstance.getBucket()));
         if (data == null) {
             return null;
@@ -352,9 +353,9 @@
         Map<String, List<Map<String, Object>>> result = new HashMap<>();
         Calendar calendar = Calendar.getInstance();
         calendar.set(Calendar.MILLISECOND, 0);
-        String start = startTime.getTime() - calendar.getTime().getTime() + "ms";
-        if (endTime==null){
-            endTime= new Date();
+        String start = (startTime.getTime() - calendar.getTime().getTime() - pas_ms) + "ms";
+        if (endTime == null) {
+            endTime = new Date();
         }
         String stop = endTime.getTime() - calendar.getTime().getTime() + "ms";
 
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/PointCollectTaskNet60.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/PointCollectTaskNet60.java
index ff21b63..0d775a7 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/PointCollectTaskNet60.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/PointCollectTaskNet60.java
@@ -34,6 +34,7 @@
         logger.info("CollectTaskNet60定时任务正在执行,参数为:{}", params);
         try {
             Calendar calendar = Calendar.getInstance();
+            calendar.set(Calendar.SECOND, 0);
             calendar.set(Calendar.MILLISECOND, 0);
             pointCollector.collect(calendar.getTime(), NET);
             logger.info("PointCollectTaskNet60定时任务完成时间:" + LocalDateTime.now());
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/PointCollector.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/PointCollector.java
index 3bba8de..0c4839a 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/PointCollector.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/PointCollector.java
@@ -86,6 +86,7 @@
      */
     public void collect(Date collectTime, String minfreq) {
         try {
+            log.info("collectTime=" + collectTime.getTime());
             Map<String, Object> dataMap = new HashMap<>();
             List<InfluxPointValuePOJO> pointValues = new ArrayList<>();
             // 记录点位状态
@@ -108,6 +109,7 @@
             pointValues.addAll(cumulateHandle.handle(collectTime, pointCumulateList, listGood, listBad));
 
             log.info("存入时序库");
+            log.info("pointValueTimestamp=" + (pointValues.get(0) == null ? 0 : pointValues.get(0).getTimestamp().getNano()));
             influxDBService.asyncWritePointValues(pointValues);
 
             log.info("存入缓存");
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 05e28d2..fd28d31 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
@@ -43,7 +43,7 @@
     @Autowired
     private RedisTemplate<String, Object> redisTemplate;
 
-    public List<InfluxPointValuePOJO> handle(Date collectTime, List<DaPointDTO> dtos,List<String> listGood,List<String> listBad) {
+    public List<InfluxPointValuePOJO> handle(Date collectTime, List<DaPointDTO> dtos, List<String> listGood, List<String> listBad) {
         List<InfluxPointValuePOJO> result = new ArrayList<>();
         try {
             log.info("累计点处理开始");
@@ -52,7 +52,7 @@
             }
             dtos.forEach(dto -> {
                 try {
-                    Object value = singleCompute(dto, collectTime,listGood,listBad);
+                    Object value = singleCompute(dto, collectTime, listGood, listBad);
                     InfluxPointValuePOJO pojo = GenInfluxPointValueUtils.getByPoint(dto, value);
                     pojo.setTimestamp(collectTime.toInstant());
                     result.add(pojo);
@@ -90,10 +90,10 @@
     }
 
     private Object singleCompute(DaPointDTO dto, Date collectTime) {
-        return singleCompute(dto,collectTime,null,null);
+        return singleCompute(dto, collectTime, null, null);
     }
 
-    private Object singleCompute(DaPointDTO dto, Date collectTime,List<String> listGood,List<String> listBad) {
+    private Object singleCompute(DaPointDTO dto, Date collectTime, List<String> listGood, List<String> listBad) {
         ApiPointDTO pointDTO = dataPointApi.getInfoByNo(dto.getMomentPoint());
         if (pointDTO == null) {
             if (listBad != null) {

--
Gitblit v1.9.3