package com.jay.monitor.data.server.utils;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.util.JdbcUtils;
import org.junit.Test;

import javax.sql.DataSource;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Module TODO
 * @Description TODO
 * @Author liukaixiong
 * @Date 2020/11/5 13:29
 */
public class SqlUtilsTest {

    public static final long HOUR = 3600 * 1000L;
    public static final long DAY = 24 * 3600 * 1000L;

    @Test
    public void test() throws Exception {
        String sql = "create table jay_monitor_mq_20201105 like jay_monitor_mq;";
        DataSource conn = dataSource();
        JdbcUtils.execute(conn, sql);
//        List<SQLStatement> sqlStatements = SQLUtils.parseStatements(sql, JdbcConstants.MYSQL);
    }

    public DataSource dataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUrl("jdbc:mysql://192.168.0.13:3306/elab_db?useUnicode=true&characterEncoding=gbk&zeroDateTimeBehavior");
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setUsername("root");
        dataSource.setPassword("elab@123");
        return dataSource;
    }

    protected long getTimestamp() {
        long timestamp = System.currentTimeMillis();
        return timestamp / HOUR; // version 2
    }

    protected long getDayTimestamp() {
        long timestamp = System.currentTimeMillis();
        return timestamp / DAY; // version 2
    }

    @Test
    public void testGetTime() {
//        long timestamp = getTimestamp();
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
        Date date = new Date(System.currentTimeMillis());
        System.out.println(sdf.format(date));


        for (int i = 0; i < 5; i++) {
            long timestamp = getTimestamp();
            long dayTimestamp = getDayTimestamp();
            System.out.println(timestamp + "\t" + dayTimestamp);
        }
    }

}