package cn.config;

import org.influxdb.InfluxDB;
import org.influxdb.InfluxDBFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import cn.component.influxdb.InfluxDbUtil;

import java.util.concurrent.TimeUnit;

/** @Author BJTU
 * @Description Influxdb配置类
 */
@Configuration
public class InfluxDBConfig {

    @Value("${spring.influx.url}")
    private String openurl;

    @Value("${spring.influx.user}")
    private String username;

    @Value("${spring.influx.password}")
    private String password;

    @Value("${spring.influx.database}")
    private String database;
    
    @Value("${spring.influx.retentionPolicy}")
    private String retentionPolicy = "";
        
    @Bean
    public void initInfluxDB()
    {
        InfluxDB influxDB = InfluxDBFactory.connect(openurl, username, password);
        influxDB.enableBatch(5,60, TimeUnit.MILLISECONDS);
        influxDB.setDatabase(database);
        InfluxDbUtil.setParam(database,retentionPolicy, influxDB);
    }
    
}
