package com.tofly.common.oauth.util;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author tuonbed
 * @date 2020/3/19  10:39
 */
@Component
public class ToflyDataTypeConstant {

    @Autowired
    private DruidDataSource druidDataSource;

    public String getDataType(){
        return druidDataSource.getDbType();
    }

    public String getNowTimeSql(){
        String dataType=getDataType();
        switch (dataType){
            case "oracle":
                return "sysdate";
            case "mysql":
                return "now()";
            default:
                return "";
        }
    }

    public String limitSql(int end,int start){
        String dataType=getDataType();
        switch (dataType){
            case "oracle":
                return " and rownum <= "+end+" and rownum>"+start;
            case "mysql":
                return "limit "+start+","+end;
            default:
                return "";
        }
    }
}
