From 34ba735bfa0d272e063054c7ba0ef6fde65880f4 Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期三, 08 一月 2025 17:37:10 +0800
Subject: [PATCH] point历史值查询增加默认时间

---
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java |   37 ++++++++++++++++++++++++++++++-------
 1 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java
index 64cc9a6..a8d9f0c 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java
@@ -38,7 +38,16 @@
 
     @Override
     public ApiPointDTO getInfoById(String pointId) {
-        return ConvertUtils.sourceToTarget(daPointService.getSimpleInfoById(pointId), ApiPointDTO.class);
+        return daPointService.getSimpleInfoById(pointId);
+    }
+
+    @Override
+    public List<ApiPointDTO> getInfoByIds(Set<String> pointIds) {
+        List<ApiPointDTO> result = new ArrayList<>(pointIds.size());
+        for (String pointId : pointIds) {
+            result.add(daPointService.getSimpleInfoById(pointId));
+        }
+        return result;
     }
 
     @Override
@@ -54,12 +63,16 @@
     @Override
     public Map<String, List<Map<String, Object>>> queryPointsHistoryValue(ApiPointsValueQueryDTO queryDto) {
         Map<String, List<Map<String, Object>>> data = new HashMap<>();
-        if (queryDto.getStart() == null) {
-            queryDto.setStart(new Date());
-        }
+        Calendar calendar = Calendar.getInstance();
+        calendar.set(Calendar.MILLISECOND, 0);
         if (queryDto.getEnd() == null) {
-            queryDto.setEnd(new Date());
+            queryDto.setEnd(calendar.getTime());
         }
+        if (queryDto.getStart() == null) {
+            calendar.add(Calendar.HOUR_OF_DAY, -1);
+            queryDto.setStart(calendar.getTime());
+        }
+
         Map<String, Object> params = new HashMap<>(1);
         params.put("pointNos", queryDto.getPointNos());
         List<DaPointDTO> pointList = daPointService.list(params);
@@ -84,12 +97,21 @@
         pojo.setType(daPointDTO.getDataType());
         Date startTime = queryDto.getStart();
         Date endTime = queryDto.getEnd();
+        Calendar calendar = Calendar.getInstance();
+        calendar.set(Calendar.MILLISECOND, 0);
+        if (endTime == null) {
+            endTime = calendar.getTime();
+        }
+        if (startTime == null) {
+            calendar.add(Calendar.HOUR_OF_DAY, -1);
+            startTime = calendar.getTime();
+        }
         List<Map<String, Object>> list = influxDBService.queryPointValues(pojo, startTime, endTime);
         List<ApiPointValueDTO> pointValueList = new ArrayList<>();
         for (int i = 0; list.size() - i >= 1; i++) {
             ApiPointValueDTO pointValue = new ApiPointValueDTO();
-            pointValue.setDataValue(Double.parseDouble(list.get(i).get(InfluxDBServiceImpl.VALUE).toString()));
-            pointValue.setDataTime(DateUtils.parse(list.get(i).get(InfluxDBServiceImpl.TIME).toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
+            pointValue.setV(Double.parseDouble(list.get(i).get(InfluxDBServiceImpl.VALUE).toString()));
+            pointValue.setT(DateUtils.parse(list.get(i).get(InfluxDBServiceImpl.TIME).toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
             pointValueList.add(pointValue);
         }
         return pointValueList;
@@ -104,6 +126,7 @@
             pointCollector.setValue(wr);
             return true;
         } catch (Exception ex) {
+            ex.printStackTrace();
             return false;
         }
     }

--
Gitblit v1.9.3