package com.inspect.base.core.utils;

import com.inspect.base.core.utils.sql.SqlUtil;
import com.inspect.base.core.web.page.PageDomain;
import com.inspect.base.core.web.page.TableSupport;
import com.github.pagehelper.PageHelper;

public class PageUtils extends PageHelper {
    public static void startPage() {
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) {
            String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
            Boolean reasonable = pageDomain.getReasonable();
            PageHelper.startPage(pageNum, pageSize, orderBy).setReasonable(reasonable);
        }

    }

    public static void clearPage() {
        PageHelper.clearPage();
    }
}
