package com.jy.framework.mybatis.join;

import com.baomidou.mybatisplus.core.toolkit.StringPool;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
public class OrderBy extends AbstractSql {

    /**
     * 排序方式 （ asc desc ）
     */
    private final String orderType;

    /**
     * 查询列
     */
    private final AbstractSql abstractSql;

    private boolean exist = true;

    public OrderBy exist(boolean exist) {
        this.exist = exist;
        return this;
    }

    @Override
    protected String format() {
        if (exist) {
            return abstractSql.format() + orderType;
        }
        return StringPool.EMPTY;
    }

}
