
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.SqlInfoGroupModel;
import com.lideeyunji.tool.framework.sql.core.dql.select.lideeYunJiQueryWrapper;
import com.lideeyunji.tool.framework.sql.core.model.SqlFormatModel;
import net.sf.jsqlparser.JSQLParserException;

import java.util.Arrays;

/**
 * group  by
 */
public class BuildGroupBy implements ISQLExpression<SqlFormatModel>  {



    @Override
    public SqlFormatModel interpret(SQLInterpretContext context) throws JSQLParserException {

        SqlInfoGroupModel sqlInfo = context.getGroupModel();
        String[] columns = sqlInfo.getColumns();

        lideeYunJiQueryWrapper wrapper=new lideeYunJiQueryWrapper();
        wrapper.groupBy(Arrays.asList(columns));
        String groupByStr = wrapper.getCustomSqlSegment();

        return new SqlFormatModel(groupByStr);
    }



}
