From e38716f1fa4cfe37a045d90077681ea07ba7554a Mon Sep 17 00:00:00 2001
From: zhang <zc857179121@qq.com>
Date: 星期四, 29 一月 2026 07:59:29 +0800
Subject: [PATCH] 1

---
 component/pom.xml                                                                                |   24 ++++++
 component/component-Influxdb/src/main/java/com/zy/influxdb/config/InfluxDBAutoConfiguration.java |   23 +++++
 component/component-Influxdb/src/main/java/com/zy/influxdb/service/InfluxDBService.java          |   77 +++++++++++++++++++
 component/component-Influxdb/src/main/resources/META-INF/spring.factories                        |    2 
 zy-acs-gateway/src/main/resources/application.yml                                                |    5 +
 component/component-Influxdb/src/main/java/com/zy/influxdb/config/InfluxDBProperties.java        |   29 +++++++
 zy-acs-gateway/pom.xml                                                                           |    5 +
 pom.xml                                                                                          |    1 
 component/component-Influxdb/pom.xml                                                             |   60 +++++++++++++++
 9 files changed, 226 insertions(+), 0 deletions(-)

diff --git a/component/component-Influxdb/pom.xml b/component/component-Influxdb/pom.xml
new file mode 100644
index 0000000..7bfad2c
--- /dev/null
+++ b/component/component-Influxdb/pom.xml
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>com.zy</groupId>
+        <artifactId>component</artifactId>
+        <version>1.0.0</version>
+    </parent>
+
+    <artifactId>component-Influxdb</artifactId>
+
+    <properties>
+        <!-- Project Properties -->
+        <java.version>1.8</java.version>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+        <!-- Dependency Versions -->
+        <influxdb-java.version>1.7.0</influxdb-java.version>
+        <lombok.version>1.18.20</lombok.version>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.influxdb</groupId>
+            <artifactId>influxdb3-java</artifactId>
+            <version>${influxdb-java.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-devtools</artifactId>
+            <scope>runtime</scope>
+            <optional>true</optional>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-configuration-processor</artifactId>
+            <optional>true</optional>
+        </dependency>
+
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <version>${lombok.version}</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+</project>
\ No newline at end of file
diff --git a/component/component-Influxdb/src/main/java/com/zy/influxdb/config/InfluxDBAutoConfiguration.java b/component/component-Influxdb/src/main/java/com/zy/influxdb/config/InfluxDBAutoConfiguration.java
new file mode 100644
index 0000000..a03e323
--- /dev/null
+++ b/component/component-Influxdb/src/main/java/com/zy/influxdb/config/InfluxDBAutoConfiguration.java
@@ -0,0 +1,23 @@
+package com.zy.influxdb.config;
+
+import com.influxdb.v3.client.InfluxDBClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@ConditionalOnProperty(value = "influxdb3.enabled", havingValue = "true", matchIfMissing = true)
+@EnableConfigurationProperties(InfluxDBProperties.class)
+public class InfluxDBAutoConfiguration {
+
+    private static final Logger logger = LoggerFactory.getLogger(InfluxDBAutoConfiguration.class);
+
+
+    @Bean(destroyMethod = "close")
+    public InfluxDBClient influxDBClient(InfluxDBProperties influxDBProperties) throws Exception{
+        return InfluxDBClient.getInstance(influxDBProperties.getInfluxDbUrl(), influxDBProperties.getToken().toCharArray(), influxDBProperties.getDatabase());
+    }
+}
diff --git a/component/component-Influxdb/src/main/java/com/zy/influxdb/config/InfluxDBProperties.java b/component/component-Influxdb/src/main/java/com/zy/influxdb/config/InfluxDBProperties.java
new file mode 100644
index 0000000..18f3259
--- /dev/null
+++ b/component/component-Influxdb/src/main/java/com/zy/influxdb/config/InfluxDBProperties.java
@@ -0,0 +1,29 @@
+package com.zy.influxdb.config;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+/**
+ * InfluxDB Client Properties
+ */
+@Data
+@ConfigurationProperties(prefix = "influxdb3")
+public class InfluxDBProperties {
+
+    /**
+     * InfluxDB http url
+     */
+    private String url;
+
+    /**
+     * token
+     */
+    private String token;
+
+    /**
+     * database for http
+     */
+    private String database;
+
+
+}
\ No newline at end of file
diff --git a/component/component-Influxdb/src/main/java/com/zy/influxdb/service/InfluxDBService.java b/component/component-Influxdb/src/main/java/com/zy/influxdb/service/InfluxDBService.java
new file mode 100644
index 0000000..c450804
--- /dev/null
+++ b/component/component-Influxdb/src/main/java/com/zy/influxdb/service/InfluxDBService.java
@@ -0,0 +1,77 @@
+package com.zy.influxdb.service;
+
+import com.influxdb.v3.client.InfluxDBClient;
+import com.influxdb.v3.client.Point;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import java.time.Instant;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+
+@Service
+public class InfluxDBService  {
+
+    private static final Logger logger = LoggerFactory.getLogger(InfluxDBService.class);
+
+    private final InfluxDBClient influxDBClient;
+
+    // 鏋勯�犲嚱鏁版敞鍏ュ鎴风
+    public InfluxDBService(InfluxDBClient  influxDBClient  ) {
+        this.influxDBClient =  influxDBClient  ;
+    }
+
+
+    /**
+     * 鍐欏叆鏁版嵁
+     * @param measurement 琛ㄥ悕
+     * @param tags 鏍囩
+     * @param fields 瀛楁
+     */
+    public void writeData(String measurement, Map<String,String> tags,Map<String,Object> fields) {
+        Point point = Point.measurement(measurement)
+                .setTags(tags)
+                .setFields(fields)
+                .setTimestamp(Instant.now().minusSeconds(10));
+        try {
+            influxDBClient.writePoint(point);
+            System.out.println("Data written to the database.");
+        }
+        catch (Exception e) {
+            System.err.println("Failed to write data to the database.");
+            e.printStackTrace();
+        }
+    }
+    /**
+     * 鏌ヨ鏁版嵁
+     * @param sql sql璇彞
+     * @return 鏌ヨ缁撴灉鍒楄〃
+     */
+    public List<Map<String, Object>> queryData(String sql) {
+
+        try {
+            // 鎵ц鏌ヨ
+            Stream<Object[]> query = influxDBClient.query(sql);
+            // 杞崲涓� Map 鍒楄〃锛堜究浜庡悗缁鐞嗭級
+            List<Map<String, Object>> collect = query.map(record -> {
+                        Map<String, Object> map = new LinkedHashMap<>();
+                        for (int i = 0; i < record.length; i += 2) {
+                            map.put((String) record[i], record[i + 1]);
+                        }
+                        return map;
+                    })
+                    .collect(Collectors.toList());
+            return collect;
+        } catch (Exception e) {
+            System.err.println("Failed to query data from the database.");
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+}
diff --git a/component/component-Influxdb/src/main/resources/META-INF/spring.factories b/component/component-Influxdb/src/main/resources/META-INF/spring.factories
new file mode 100644
index 0000000..4273c8f
--- /dev/null
+++ b/component/component-Influxdb/src/main/resources/META-INF/spring.factories
@@ -0,0 +1,2 @@
+com.zy.influxdb.service.InfluxDBService
+
diff --git a/component/pom.xml b/component/pom.xml
new file mode 100644
index 0000000..bd3689e
--- /dev/null
+++ b/component/pom.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>com.zy</groupId>
+        <artifactId>acs</artifactId>
+        <version>1.0.0</version>
+    </parent>
+
+    <artifactId>component</artifactId>
+    <packaging>pom</packaging>
+    <modules>
+        <module>component-Influxdb</module>
+    </modules>
+
+    <properties>
+        <maven.compiler.source>8</maven.compiler.source>
+        <maven.compiler.target>8</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+</project>
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 6604fc9..0219899 100644
--- a/pom.xml
+++ b/pom.xml
@@ -24,6 +24,7 @@
         <module>zy-acs-manager</module>
         <module>zy-acs-fake</module>
         <module>zy-acs-cv</module>
+        <module>component</module>
     </modules>
 
     <properties>
diff --git a/zy-acs-gateway/pom.xml b/zy-acs-gateway/pom.xml
index 7400551..71ff2f1 100644
--- a/zy-acs-gateway/pom.xml
+++ b/zy-acs-gateway/pom.xml
@@ -43,6 +43,11 @@
             <artifactId>acs-common</artifactId>
             <version>1.0.0</version>
         </dependency>
+        <dependency>
+            <groupId>com.zy</groupId>
+            <artifactId>component-Influxdb</artifactId>
+            <version>1.0.0</version>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/zy-acs-gateway/src/main/resources/application.yml b/zy-acs-gateway/src/main/resources/application.yml
index 5f0fe10..98afef8 100644
--- a/zy-acs-gateway/src/main/resources/application.yml
+++ b/zy-acs-gateway/src/main/resources/application.yml
@@ -45,3 +45,8 @@
   rcvbuf: 2097152
   #涓婁笅琛屾棩蹇楁墦鍗�
   printPacLog: true
+
+influxdb3:
+  url: http://localhost:8086
+  token: xltys1995
+  database: rcs_gateway

--
Gitblit v1.9.1