package com.fjhx.base;

import java.io.Serializable;

/**
 * 分页
 * @Author:caozj
 * @DATE:2022/7/12 17:36
 */
public class Pager implements Serializable {

    private static final long serialVersionUID = -4781129496475920388L;

    // 当前页
    private int pageNum;

    // 显示数
    private int pageSize;

    // 总条数
    private int totalCount;

    // 开始
    private int pageStart;

    // 结束
    private int pageEnd;

    // 总页数
    private int totalPage;

    public Pager() {

    }

    /**
     * 分页
     *
     * @param pageNum 当前页
     * @param pageSize    显示数
     */
    public Pager(int pageNum, int pageSize) {
        if (pageNum <= 0) {
            pageNum = 1;
        }
        if (pageSize <= 0) {
            pageSize = 10;
        }

        this.pageNum = pageNum;
        this.pageSize = pageSize;
    }

    public int getpageNum() {
        return pageNum;
    }

    public void setpageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getPageStart() {
        // 分页起始
        if (pageNum > 0) {
            this.pageStart = (pageNum - 1) * pageSize;
        }
        return pageStart;
    }

    public void setPageStart(int pageStart) {
        this.pageStart = pageStart;
    }

    public int getPageEnd() {
        // 分页结束
        this.pageEnd = pageNum * pageSize;
        return pageEnd;
    }

    public void setPageEnd(int pageEnd) {
        this.pageEnd = pageEnd;
    }

    public int getTotalPage() {
        if (pageSize <= 0) {
            return 0;
        }
        // 总页数
        this.totalPage = (totalCount + pageSize - 1) / pageSize;
        return this.totalPage;
    }

    public void setTotalPage(int totalPage) {

    }

    @Override
    public String toString() {
        return "Pager{" +
                "pageNum=" + pageNum +
                ", pageSize=" + pageSize +
                ", totalCount=" + totalCount +
                ", pageStart=" + pageStart +
                ", pageEnd=" + pageEnd +
                ", totalPage=" + totalPage +
                '}';
    }
}
