package com.usky.common.core.influx.config;

import com.usky.common.core.influx.core.InfluxDbUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 *  配置方式：
 * spring:
 *     influx:
 *         url: http://172.16.120.69:8086
 *         password: root
 *         user: root
 *         database: USKTSDB
 */
@Configuration
@Slf4j
public class InfluxDbConfig {

    @Value("${spring.influx.url:''}")
    private String influxDBUrl;

    @Value("${spring.influx.user:''}")
    private String userName;

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

    @Value("${spring.influx.database:''}")
    private String database;

    @Bean
    public InfluxDbUtils influxDbUtils() {
        log.info("influx config info:{},{}",influxDBUrl,database);
        if(influxDBUrl!= null && !influxDBUrl.equals("''") ) {
            log.debug("influx 组件启动");
            return new InfluxDbUtils(userName, password, influxDBUrl, database, "");
        } else {
            log.warn("influx 配置缺失，未启动");
            return new InfluxDbUtils();
        }
    }
}