package com.qmth.boot.mybatis.query;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qmth.boot.core.collection.PageResult;

/**
 * 分页排序查询基类，默认分页20条
 *
 * @param <T>
 */
public class BaseQuery<T> extends Page<T> {

    private static final long serialVersionUID = -1065595998785067382L;

    public BaseQuery() {
        super(1, 20);
    }

    public BaseQuery(long pageNumber, long pageSize) {
        super(pageNumber, pageSize);
    }

    public void setPageNumber(long pageNumber) {
        setCurrent(pageNumber);
    }

    public long getPageNumber() {
        return getCurrent();
    }

    public void setPageSize(long pageSize) {
        setSize(pageSize);
    }

    public long getPageSize() {
        return getSize();
    }

    public PageResult<T> toPageResult() {
        PageResult<T> result = new PageResult<>();
        result.setResult(getRecords());
        result.setPageNumber(getPageNumber());
        result.setPageSize(getPageSize());
        result.setTotalCount(getTotal());
        result.setPageCount(getPages());
        return result;
    }
}
