From 1d4ac27e8a9428aff4dd3ba1c9e2bb8b2ed826f7 Mon Sep 17 00:00:00 2001
From: dengzedong <dengzedong@email>
Date: 星期二, 07 一月 2025 18:16:38 +0800
Subject: [PATCH] influxdb查询bug

---
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/influxdb/service/impl/InfluxDBServiceImpl.java |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/influxdb/service/impl/InfluxDBServiceImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/influxdb/service/impl/InfluxDBServiceImpl.java
index a491c35..431a988 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/influxdb/service/impl/InfluxDBServiceImpl.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/influxdb/service/impl/InfluxDBServiceImpl.java
@@ -50,11 +50,13 @@
     public List<InfluxModelResultVO> queryModelResults(InfluxModelResultPOJO pojo, Date startTime, Date endTime) {
         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.toInstant().toString();
+
+        if (startTime.getTime() == endTime.getTime()) {
+            // 如果相等,则engTime加1毫秒,负责influxdb报错(因为influxdb的range函数是左闭右开区间,所以将engTime加一毫秒,才可以查到startTime时间点的数据)
+            endTime.setTime(endTime.getTime() + 1);
         }
-        String stop = endTime.getTime() - calendar.getTime().getTime() + "ms";
+        String stop = endTime.toInstant().toString();
 
         List<InfluxModelResultVO> dataList = new ArrayList<>();
         String measurement = MeasurementUtils.getMeasurement(pojo.getType());

--
Gitblit v1.9.3