diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 58593ed..e0ca8ae 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -2,6 +2,7 @@ + @@ -9,6 +10,7 @@ + @@ -16,6 +18,7 @@ + @@ -25,7 +28,9 @@ + + diff --git a/.idea/encodings.xml b/.idea/encodings.xml index cbf76af..7d30db4 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -4,7 +4,9 @@ + + diff --git a/base-commons/common-core/src/main/java/com/evotech/hd/common/core/entity/BaseEntity.java b/base-commons/common-core/src/main/java/com/evotech/hd/common/core/entity/BaseEntity.java index 8d9e06d..b1f6020 100644 --- a/base-commons/common-core/src/main/java/com/evotech/hd/common/core/entity/BaseEntity.java +++ b/base-commons/common-core/src/main/java/com/evotech/hd/common/core/entity/BaseEntity.java @@ -8,8 +8,6 @@ import com.baomidou.mybatisplus.annotation.TableId; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.v3.oas.annotations.Hidden; import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.media.Schema.RequiredMode; -import jakarta.validation.constraints.Min; import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; @@ -32,6 +30,7 @@ public class BaseEntity implements Serializable { @Hidden private Integer pkId; + @Schema(description = "创建人", hidden = true) @TableField(fill = FieldFill.INSERT) private String creater; diff --git a/base-commons/common-influxdb/pom.xml b/base-commons/common-influxdb/pom.xml new file mode 100644 index 0000000..08fd216 --- /dev/null +++ b/base-commons/common-influxdb/pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + + com.evotech.hd + base-commons + 1.0.0-SNAPSHOT + + common-influxdb + + + + + com.influxdb + influxdb-client-java + 6.6.0 + + + + + + + + org.springframework + spring-context + + + org.projectlombok + lombok + provided + + + org.springframework.boot + spring-boot + + + + + \ No newline at end of file diff --git a/base-commons/common-influxdb/src/main/java/com/evotech/hd/influxdb/config/InfluxdbProperty.java b/base-commons/common-influxdb/src/main/java/com/evotech/hd/influxdb/config/InfluxdbProperty.java new file mode 100644 index 0000000..0a392c6 --- /dev/null +++ b/base-commons/common-influxdb/src/main/java/com/evotech/hd/influxdb/config/InfluxdbProperty.java @@ -0,0 +1,90 @@ +package com.evotech.hd.influxdb.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +/** + * 类 + * + * @ClassName:InfluxdbPropertys + * @date: 2025年04月26日 13:30 + * @author: andy.shi + * @contact: 17330188597 + * @remark: 开发人员联系方式 1042025947@qq.com/微信同步 + */ +@Data +@Component +@ConfigurationProperties(prefix = "influxdb", ignoreUnknownFields = true) +public class InfluxdbProperty { + + static String url; + + static String name; + + static String password; + + static String token; + + static String org; + + static String bucket; + + static Boolean gzip; + + public static String getUrl() { + return url; + } + + public void setUrl(String url) { + InfluxdbProperty.url = url; + } + + public static String getName() { + return name; + } + + public void setName(String name) { + InfluxdbProperty.name = name; + } + + public static String getPassword() { + return password; + } + + public void setPassword(String password) { + InfluxdbProperty.password = password; + } + + public static String getToken() { + return token; + } + + public void setToken(String token) { + InfluxdbProperty.token = token; + } + + public static String getBucket() { + return bucket; + } + + public void setBucket(String bucket) { + InfluxdbProperty.bucket = bucket; + } + + public static Boolean getGzip() { + return gzip; + } + + public void setGzip(Boolean gzip) { + InfluxdbProperty.gzip = gzip; + } + + public static String getOrg() { + return org; + } + + public void setOrg(String org) { + InfluxdbProperty.org = org; + } +} diff --git a/base-commons/common-influxdb/src/main/java/com/evotech/hd/influxdb/config/MyInfluxDBConfiguration.java b/base-commons/common-influxdb/src/main/java/com/evotech/hd/influxdb/config/MyInfluxDBConfiguration.java new file mode 100644 index 0000000..359d44e --- /dev/null +++ b/base-commons/common-influxdb/src/main/java/com/evotech/hd/influxdb/config/MyInfluxDBConfiguration.java @@ -0,0 +1,42 @@ +package com.evotech.hd.influxdb.config; + +import com.influxdb.client.InfluxDBClient; +import com.influxdb.client.InfluxDBClientFactory; +import com.influxdb.client.InfluxQLQueryApi; +import com.influxdb.client.WriteApi; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * influxdb的bean + * + * @ClassName:MyInfluxDBConfiguration + * @date: 2025年04月26日 14:26 + * @author: andy.shi + * @contact: 17330188597 + * @remark: 开发人员联系方式 1042025947@qq.com/微信同步 + */ +@Configuration +@EnableConfigurationProperties +public class MyInfluxDBConfiguration { + + @Bean + public InfluxDBClient influxDBClient(){ + InfluxDBClient client = InfluxDBClientFactory.create(InfluxdbProperty.getUrl(), InfluxdbProperty.getToken().toCharArray()); + if(InfluxdbProperty.getGzip()){ + client.enableGzip(); + } + return client; + } + + @Bean + public WriteApi writeApiBlocking(final InfluxDBClient influxDBClient){ + return influxDBClient.getWriteApi(); + } + + @Bean + public InfluxQLQueryApi influxQLQueryApi(final InfluxDBClient influxDBClient){ + return influxDBClient.getInfluxQLQueryApi(); + } +} diff --git a/base-commons/common-influxdb/src/main/java/com/evotech/hd/influxdb/service/InfluxDbService.java b/base-commons/common-influxdb/src/main/java/com/evotech/hd/influxdb/service/InfluxDbService.java new file mode 100644 index 0000000..3502e10 --- /dev/null +++ b/base-commons/common-influxdb/src/main/java/com/evotech/hd/influxdb/service/InfluxDbService.java @@ -0,0 +1,38 @@ +//package com.evotech.hd.influxdb.service; +// +//import com.evotech.hd.influxdb.config.InfluxdbProperty; +//import com.influxdb.client.InfluxDBClient; +//import com.influxdb.client.InfluxDBClientFactory; +//import com.influxdb.client.WriteApiBlocking; +//import org.springframework.beans.factory.DisposableBean; +//import org.springframework.stereotype.Service; +///** +// * influxdb 数据库链接类 +// * +// * @ClassName:InfluxDbService +// * @date: 2025年04月26日 13:21 +// * @author: andy.shi +// * @contact: 17330188597 +// * @remark: 开发人员联系方式 1042025947@qq.com/微信同步 +// */ +//@Service +//public class InfluxDbService implements DisposableBean { +// /*** +// * 单例 饿汉式(线程安全) +// * 简单,天生线程安全,实例在类加载时就完成了初始化。 +// */ +// private static InfluxDBClient client = InfluxDBClientFactory.create(InfluxdbProperty.getUrl(), InfluxdbProperty.getName(),InfluxdbProperty.getPassword().toCharArray()); +// +// +// public static void write(){ +// WriteApiBlocking writeApi = client.getWriteApiBlocking(); +// writeApi.writePoint("","",com.influxdb.client.write.Point.measurement("")); +// } +// +// @Override +// public void destroy() throws Exception { +// if(client != null){ +// client.close(); +// } +// } +//} diff --git a/base-commons/common-influxdb/src/main/java/com/evotech/hd/influxdb/util/BeanUtil.java b/base-commons/common-influxdb/src/main/java/com/evotech/hd/influxdb/util/BeanUtil.java new file mode 100644 index 0000000..9710cf7 --- /dev/null +++ b/base-commons/common-influxdb/src/main/java/com/evotech/hd/influxdb/util/BeanUtil.java @@ -0,0 +1,48 @@ +package com.evotech.hd.influxdb.util; + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + +/** + * 类 + * + * @ClassName:BeanUtil + * @date: 2025年04月26日 14:41 + * @author: andy.shi + * @contact: 17330188597 + * @remark: 开发人员联系方式 1042025947@qq.com/微信同步 + */ +@Component +public class BeanUtil implements ApplicationContextAware { + + private static ApplicationContext applicationContext = null; + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + setGlobalApplicationContext(applicationContext); + } + + private synchronized static void setGlobalApplicationContext(ApplicationContext applicationContext) { + if(BeanUtil.applicationContext == null){ + BeanUtil.applicationContext = applicationContext; + } + } + + private static ApplicationContext getApplicationContext() { + return applicationContext; + } + + public static Object getBean(String name) { + return getApplicationContext().getBean(name); + } + + public static T getBean(Class clazz) { + T b = null; + try { + b=getApplicationContext().getBean(clazz); + } catch (BeansException e) { + } + return b; + } +} diff --git a/base-commons/common-influxdb/src/main/java/com/evotech/hd/influxdb/util/InfluxDBUtils.java b/base-commons/common-influxdb/src/main/java/com/evotech/hd/influxdb/util/InfluxDBUtils.java new file mode 100644 index 0000000..44f554d --- /dev/null +++ b/base-commons/common-influxdb/src/main/java/com/evotech/hd/influxdb/util/InfluxDBUtils.java @@ -0,0 +1,63 @@ +package com.evotech.hd.influxdb.util; + +import com.evotech.hd.influxdb.config.InfluxdbProperty; +import com.influxdb.client.InfluxDBClient; +import com.influxdb.client.InfluxDBClientFactory; +import com.influxdb.client.WriteApi; +import com.influxdb.client.domain.WritePrecision; +import org.springframework.util.CollectionUtils; + +import java.util.Iterator; +import java.util.Map; + +/** + * 数据数据库的工具类 + * @ClassName:InfluxDBUtils + * @date: 2025年04月26日 14:36 + * @author: andy.shi + * @contact: 17330188597 + * @remark: 开发人员联系方式 1042025947@qq.com/微信同步 + */ + +public class InfluxDBUtils { + + + public static int insert(String tableName, Map tags, Map values){ + WriteApi writeApi = BeanUtil.getBean(WriteApi.class); + InfluxDBClient client = InfluxDBClientFactory.create(InfluxdbProperty.getUrl(), InfluxdbProperty.getToken().toCharArray()); + com.influxdb.client.write.Point point = com.influxdb.client.write.Point.measurement(tableName) + .time(System.currentTimeMillis(), WritePrecision.NS); + + if(!CollectionUtils.isEmpty(tags)){ + Iterator iterator = tags.keySet().iterator(); + while (iterator.hasNext()){ + String key = iterator.next(); + point = point.addTag(key, tags.get(key)); + } + } + + if(!CollectionUtils.isEmpty(values)){ +// point = point.addFields(values); + Iterator iterator = values.keySet().iterator(); + while (iterator.hasNext()){ + String key = iterator.next(); + Object value = values.get(key); + if (value instanceof Boolean) { + point = point.addField(key, (Boolean)value); + } else if (value instanceof Long) { + point = point.addField(key, (Long)value); + } else if (value instanceof Double) { + point = point.addField(key, (Double)value); + } else if (value instanceof String) { + point = point.addField(key, (String)value); + } + } + } + client.getWriteApiBlocking().writePoint(InfluxdbProperty.getBucket(),InfluxdbProperty.getOrg(),point); + writeApi.flush(); + return 1; + } + + + +} diff --git a/cloud-manage-server/pom.xml b/cloud-manage-server/pom.xml index 9a9d654..56f2489 100644 --- a/cloud-manage-server/pom.xml +++ b/cloud-manage-server/pom.xml @@ -31,6 +31,11 @@ common-permission 1.0.0-SNAPSHOT + + com.evotech.hd + common-influxdb + 1.0.0-SNAPSHOT + org.springframework.cloud @@ -90,7 +95,8 @@ fastjson 1.2.58 - + + ${project.artifactId} diff --git a/cloud-manage-server/src/main/java/com/evotech/hd/cloud/controller/test/TestController.java b/cloud-manage-server/src/main/java/com/evotech/hd/cloud/controller/test/TestController.java index f52f7a2..581740d 100644 --- a/cloud-manage-server/src/main/java/com/evotech/hd/cloud/controller/test/TestController.java +++ b/cloud-manage-server/src/main/java/com/evotech/hd/cloud/controller/test/TestController.java @@ -16,6 +16,7 @@ import com.evotech.hd.common.core.entity.cloud.BatteryStation; import com.evotech.hd.common.core.entity.cloud.OrderSwapBattery; import com.evotech.hd.common.core.entity.cloud.OrderSwapBatteryPre; import com.evotech.hd.common.core.utils.Collections; +import com.evotech.hd.influxdb.util.InfluxDBUtils; import jakarta.annotation.Resource; import org.springframework.web.bind.annotation.*; @@ -42,6 +43,15 @@ public class TestController { @Resource private SwapOrderBasicFeeComponent orderBasicFeeComponent; + @GetMapping("/influxdb") + public Result influxdb() { + + InfluxDBUtils.insert("test", Collections.asMap("t","test"), Collections.asMap("name","张三","age",12,"sax","男")); + return new Result().success("1"); + } + + + @GetMapping("/station") public Result list() { System.out.println("======>>开始......"); diff --git a/cloud-manage-server/src/main/java/com/evotech/hd/cloud/mqtt/config/MqttConnectInit.java b/cloud-manage-server/src/main/java/com/evotech/hd/cloud/mqtt/config/MqttConnectInit.java index e7a57fa..14998bf 100644 --- a/cloud-manage-server/src/main/java/com/evotech/hd/cloud/mqtt/config/MqttConnectInit.java +++ b/cloud-manage-server/src/main/java/com/evotech/hd/cloud/mqtt/config/MqttConnectInit.java @@ -12,14 +12,13 @@ import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.core.annotation.Order; -import org.springframework.stereotype.Component; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Date; import java.util.concurrent.ConcurrentHashMap; -@Component +//@Component @Order(value = 20) @Slf4j public class MqttConnectInit implements ApplicationRunner { diff --git a/cloud-manage-server/src/main/resources/application.yml b/cloud-manage-server/src/main/resources/application.yml index 733a9cc..704e108 100644 --- a/cloud-manage-server/src/main/resources/application.yml +++ b/cloud-manage-server/src/main/resources/application.yml @@ -23,6 +23,7 @@ spring: - nacos:yt-common.properties?refreshEnabled=true - nacos:cloud-server.yaml?refreshEnabled=true - nacos:yt-redis.yaml?refreshEnabled=true + - nacos:yt-influxdb.yml?refreshEnabled=true cloud: nacos: serverAddr: 192.168.5.213:8848 diff --git a/cloud-manage-server/src/test/java/com/evotech/hd/cloud/AesDecryTest.java b/cloud-manage-server/src/test/java/com/evotech/hd/cloud/AesDecryTest.java index df2f44d..3b85a93 100644 --- a/cloud-manage-server/src/test/java/com/evotech/hd/cloud/AesDecryTest.java +++ b/cloud-manage-server/src/test/java/com/evotech/hd/cloud/AesDecryTest.java @@ -6,6 +6,7 @@ public class AesDecryTest { public static void main(String[] args) { +// HttpUtils System.out.println(new BCryptPasswordEncoder().encode("123456")); // String key = "94kl35k25d3t2rk2"; // String iv = "k394kf44lf1pyq8k"; diff --git a/pom.xml b/pom.xml index 0f408a6..841f45c 100644 --- a/pom.xml +++ b/pom.xml @@ -164,5 +164,6 @@ resource-server wechat-server admin-server - + base-commons/common-influxdb + \ No newline at end of file