package com.flossom.common.core.utils;

import com.flossom.common.core.web.page.PageDomain;
import com.flossom.common.core.web.page.TableSupport;
import com.github.pagehelper.PageHelper;
import com.flossom.common.core.utils.sql.SqlUtil;

/**
 * 分页工具类
 *
 * @author flossom
 */
public class PageUtils extends PageHelper
{
    /**
     * 设置请求分页数据
     */
    public static Integer startPage()
    {
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
        Boolean reasonable = pageDomain.getReasonable();
        PageHelper.startPage(pageNum, pageSize, orderBy).setReasonable(reasonable);
        return pageNum;
    }

    /**
     * 清理分页的线程变量
     */
    public static void clearPage()
    {
        PageHelper.clearPage();
    }
}
