package com.m2pool.common.core.web.page;

import com.m2pool.common.core.text.Convert;
import com.m2pool.common.core.utils.ServletUtils;

/**
 * @Description 表格数据处理
 * @Date 2024/6/12 11:32
 * @Author dy
 */
public class TableSupport
{
    /**
     * 当前记录起始索引
     */
    public static final String PAGE_NUM = "pageNum";

    /**
     * 每页显示记录数
     */
    public static final String PAGE_SIZE = "pageSize";

    /**
     * 排序列
     */
    public static final String ORDER_BY_COLUMN = "orderByColumn";

    /**
     * 排序的方向 "desc" 或者 "asc".
     */
    public static final String IS_ASC = "isAsc";

    /**
     * 分页参数合理化
     */
    public static final String REASONABLE = "reasonable";

    /**
     * 封装分页对象
     */
    public static Page getPage()
    {
        Page page = new Page();
        page.setPageNum(Convert.toInt(ServletUtils.getParameter(PAGE_NUM), 1));
        page.setPageSize(Convert.toInt(ServletUtils.getParameter(PAGE_SIZE), 20));
        page.setOrderByColumn(ServletUtils.getParameter(ORDER_BY_COLUMN));
        page.setIsAsc(ServletUtils.getParameter(IS_ASC));
        page.setReasonable(ServletUtils.getParameterToBool(REASONABLE));
        return page;
    }

    public static Page buildPageRequest()
    {
        return getPage();
    }
}
