
package com.lideeyunji.tool.framework.sql.build.build.dql;

import com.lideeyunji.tool.framework.sql.build.ISQLExpression;
import com.lideeyunji.tool.framework.sql.build.buildmodel.SQLInterpretContext;
import com.lideeyunji.tool.framework.sql.build.buildmodel.dql.SqlInfoSelectModel;
import com.lideeyunji.tool.framework.sql.core.dql.select.lideeYunJiQueryWrapper;
import com.lideeyunji.tool.framework.sql.core.model.SqlFormatModel;
import com.lideeyunji.tool.framework.yunji.utils.FuncBase;
import net.sf.jsqlparser.JSQLParserException;

/**
 * 查询相关
 */
public class BuildSelect implements ISQLExpression<SqlFormatModel> {



    @Override
    public SqlFormatModel interpret(SQLInterpretContext context) throws JSQLParserException {
        SqlInfoSelectModel sqlInfo = context.getSelectModel();
        String[] columns = sqlInfo.getColumns();//查询列
        String tableName = sqlInfo.getTableName();//查询表

        if(FuncBase.isEmpty(columns)){
            columns = new String[]{"*"};
        }
        lideeYunJiQueryWrapper wrapper=new lideeYunJiQueryWrapper();
        wrapper.select(columns);

        String sqlSelect = wrapper.getSqlSelect();

        String sql = "select " + sqlSelect + " from " + tableName;


        return new SqlFormatModel(sql);

    }



}
