From 9671fa60b69a5b749bfbd989f0aa281aa284dde6 Mon Sep 17 00:00:00 2001
From: zhang <zc857179121@qq.com>
Date: 星期四, 12 三月 2026 16:50:57 +0800
Subject: [PATCH] 1

---
 zy-acs-hex/src/main/java/com/zy/acs/hex/controller/DeviceLogController.java |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 51 insertions(+), 8 deletions(-)

diff --git a/zy-acs-hex/src/main/java/com/zy/acs/hex/controller/DeviceLogController.java b/zy-acs-hex/src/main/java/com/zy/acs/hex/controller/DeviceLogController.java
index 047b845..8a8e6b2 100644
--- a/zy-acs-hex/src/main/java/com/zy/acs/hex/controller/DeviceLogController.java
+++ b/zy-acs-hex/src/main/java/com/zy/acs/hex/controller/DeviceLogController.java
@@ -1,16 +1,20 @@
 package com.zy.acs.hex.controller;
 
-import com.zy.acs.common.domain.mq.DeviceMessage;
+import com.influxdb.v3.client.PointValues;
 import com.zy.acs.framework.common.R;
+import com.zy.acs.hex.domain.DeviceLog;
 import com.zy.component.influxdb.service.InfluxDBService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.bind.annotation.*;
 
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Stream;
 
 @RestController
 @Slf4j
@@ -28,10 +32,49 @@
      */
     @GetMapping(value = "/query")
     @ResponseBody
-    public R query() {
-        List<DeviceMessage> deviceMessages = influxDBService.queryPoints("select * from device order by time desc limit 10", DeviceMessage.class);
-        return R.ok(deviceMessages);
+    public R query(@RequestParam(required = false, defaultValue = "device") String measurement,
+                   @RequestParam(required = false) Map<String, Object> conditions,
+                   @RequestParam(required = false, defaultValue = "100") Integer limit,
+                   @RequestParam(required = false, defaultValue = "time") String orderBy,
+                   @RequestParam(required = false, defaultValue = "DESC") String orderDirection) {
+        return R.ok(getData(measurement, conditions, limit, orderBy, orderDirection));
     }
 
 
+    /**
+     * 閫氱敤鏌ヨ鏂规硶锛屾敮鎸佸姩鎬佹潯浠�
+     */
+    private List<DeviceLog> getData(String measurement, Map<String, Object> conditions,int limit, String orderBy, String orderDirection) {
+        // 鏋勫缓鏌ヨ璇彞
+        StringBuilder sqlBuilder = new StringBuilder("SELECT * FROM ").append(measurement).append(" WHERE 1=1");
+        Map<String, Object> params = new HashMap<>();
+
+        // 鍔ㄦ�佹坊鍔犳潯浠�
+        if (conditions != null && !conditions.isEmpty()) {
+            if (conditions.get("startTime") != null) {
+                if (conditions.get("startTime") != null) {
+                    sqlBuilder.append(" AND ").append("time").append(" >= :").append("startTime");
+                    params.put("startTime", conditions.get("startTime"));
+                }
+            }else if (conditions.get("endTime") != null) {
+                if (conditions.get("endTime") != null) {
+                    sqlBuilder.append(" AND ").append("time").append(" <= :").append("endTime");
+                    params.put("endTime", conditions.get("endTime"));
+                }
+            }else {
+                conditions.forEach((key, value) -> {
+                    if (value != null) {
+                        sqlBuilder.append(" AND ").append(key).append(" = :").append(key);
+                        params.put(key, value);
+                    }
+                });
+            }
+        }
+        // 娣诲姞鎺掑簭鍜岄檺鍒�
+        sqlBuilder.append(" ORDER BY ").append(orderBy).append(" ").append(orderDirection);
+        sqlBuilder.append(" LIMIT :limit");
+        params.put("limit", limit);
+        return influxDBService.queryPoints(sqlBuilder.toString(),params, DeviceLog.class);
+    }
+
 }

--
Gitblit v1.9.1