package com.xjrsoft.module.job;

import cn.hutool.db.Db;
import com.xjrsoft.common.constant.GlobalConstant;
import com.xjrsoft.common.utils.DatasourceUtil;
import com.xjrsoft.common.utils.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

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

@Component
@Slf4j
public class DataSourceTask {
//    /**
//     * 定时刷新动态数据源连接池
//     */
//    @Scheduled(cron = "0 */5 * * * ?")
//    public void RefreshConnectionPool() {
//        System.out.printf("定时刷新动态数据源连接池：%s", DateUtils.format(new Date(), DateUtils.DATE_TIME_PATTERN));
//        DataSource datasource = DatasourceUtil.getDataSource(GlobalConstant.DEFAULT_DATASOURCE_KEY);
//        try {
//            Db use = Db.use(datasource);
//            use.query("select 1");
//        } catch (Exception e) {
//            log.error(e.getMessage(), "定时刷新动态数据源连接池");
//        }
//    }
}
