微调
This commit is contained in:
@@ -5,6 +5,7 @@ import com.njcn.influx.core.InfluxExecutor;
|
||||
import com.njcn.influx.utils.InfluxDbUtils;
|
||||
import lombok.Data;
|
||||
import org.influxdb.InfluxDB;
|
||||
import org.influxdb.InfluxDBFactory;
|
||||
import org.influxdb.impl.InfluxDBMapper;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
@@ -42,12 +43,14 @@ public class InfluxDbConfig {
|
||||
|
||||
@Bean(name = "influxDbMapper")
|
||||
public InfluxDBMapper influxDbMapper(InfluxDB influxDb) {
|
||||
influxDb = InfluxDBFactory.connect(url, user, password,InfluxDbUtils.client);
|
||||
influxDb.setLogLevel(InfluxDB.LogLevel.BASIC);
|
||||
return new InfluxDBMapper(influxDb);
|
||||
}
|
||||
|
||||
@Bean(name = "influxDbExecutor")
|
||||
public InfluxExecutor executor(InfluxDB influxDb, InfluxDBMapper influxDbMapper) {
|
||||
influxDb = InfluxDBFactory.connect(url, user, password,InfluxDbUtils.client);
|
||||
return new InfluxExecutor(influxDb, influxDbMapper,database);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ import java.util.concurrent.TimeUnit;
|
||||
@Slf4j
|
||||
@Data
|
||||
public class InfluxDbUtils {
|
||||
static OkHttpClient.Builder client = new OkHttpClient.Builder()
|
||||
public static OkHttpClient.Builder client = new OkHttpClient.Builder()
|
||||
.connectTimeout(1000, TimeUnit.SECONDS)
|
||||
.readTimeout(1000, TimeUnit.SECONDS)
|
||||
.writeTimeout(1000, TimeUnit.SECONDS);
|
||||
@@ -45,15 +45,25 @@ public class InfluxDbUtils {
|
||||
.appendZoneOrOffsetId()
|
||||
.toFormatter();
|
||||
|
||||
/**用户名*/
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String username;
|
||||
/**密码*/
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
/**链接地址*/
|
||||
/**
|
||||
* 链接地址
|
||||
*/
|
||||
private String openurl;
|
||||
/**数据库*/
|
||||
/**
|
||||
* 数据库
|
||||
*/
|
||||
private String dbName;
|
||||
/**保留策略*/
|
||||
/**
|
||||
* 保留策略
|
||||
*/
|
||||
private String retentionPolicy;
|
||||
|
||||
private InfluxDB influxDB;
|
||||
@@ -92,8 +102,6 @@ public class InfluxDbUtils {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 创建数据库
|
||||
*
|
||||
@@ -153,7 +161,7 @@ public class InfluxDbUtils {
|
||||
|
||||
/**
|
||||
* 创建默认的保留策略
|
||||
*
|
||||
* <p>
|
||||
* 策略名:hour,保存天数:30天,保存副本数量:1,设为默认保留策略
|
||||
*/
|
||||
public void createDefaultRetentionPolicy() {
|
||||
@@ -192,7 +200,6 @@ public class InfluxDbUtils {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 批量写入测点
|
||||
*
|
||||
@@ -264,12 +271,11 @@ public class InfluxDbUtils {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//单条查询语句封装
|
||||
|
||||
/**
|
||||
* 查询结果封装到map
|
||||
*
|
||||
* @param commond 单条sql语句
|
||||
* @return 查询结果
|
||||
*/
|
||||
@@ -373,5 +379,4 @@ public class InfluxDbUtils {
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.njcn.influx.utils;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2023年07月24日 13:33
|
||||
*/
|
||||
@Component
|
||||
public class InstantDateDeserializer extends StdDeserializer<Instant> {
|
||||
|
||||
|
||||
public InstantDateDeserializer() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
|
||||
protected InstantDateDeserializer(Class<?> vc) {
|
||||
super(vc);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Instant deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
|
||||
String text = p.getValueAsString();
|
||||
return InstantUtil.dateToInstant(DateUtil.parse(text,DatePattern.NORM_DATETIME_PATTERN));
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,9 @@ import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
@@ -31,4 +33,15 @@ public class InstantUtil {
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
* 将date转为instant 处理8小时误差
|
||||
* @author hongawen
|
||||
* @date 2023/7/20 15:58
|
||||
* @param date 日期
|
||||
* @return Instant
|
||||
*/
|
||||
public static Instant dateToInstant(Date date){
|
||||
return date.toInstant().plusMillis(TimeUnit.HOURS.toMillis(8));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user