
package com.jeelowcode.framework.plus.build.build.dql;

import com.jeelowcode.framework.plus.build.ISQLExpression;
import com.jeelowcode.framework.plus.build.buildmodel.SQLInterpretContext;
import com.jeelowcode.framework.plus.build.buildmodel.dql.SqlInfoSelectModel;
import com.jeelowcode.framework.plus.core.dql.select.JeeLowCodeQueryWrapper;
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
import com.jeelowcode.framework.utils.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[]{"*"};
        }
        JeeLowCodeQueryWrapper wrapper=new JeeLowCodeQueryWrapper();
        wrapper.select(columns);

        String sqlSelect = wrapper.getSqlSelect();

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


        return new SqlFormatModel(sql);

    }



}
