package cn.hnthyy.thmz.vo;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * 分页对象
 */
@Data
public class PageViewVo {
    //默认页
    private   Integer pageIndex=0;
    //默认页面展示数
    private  Integer pageSize=10;
    //总记录数
    private List data;
    //总页数
    private Integer totalPages;
    //总记录数
    private Integer total;
    //剩余数据条数
    private Integer remainder;
    //排序字段
    private String orderByCase;

    public PageViewVo() {

    }

    public PageViewVo(Integer pageIndex, Integer pageSize) {
        if(pageIndex!=null && pageIndex>0){
            this.pageIndex=pageIndex;
        }
        if(pageSize!=null && pageSize>0){
            this.pageSize=pageSize;
        }
    }

    public PageViewVo(Integer pageIndex, Integer pageSize, String orderByCase) {
        if(pageIndex!=null && pageIndex>0){
            this.pageIndex=pageIndex;
        }
        if(pageSize!=null && pageSize>0){
            this.pageSize=pageSize;
        }
        if(StringUtils.isNotBlank(orderByCase)){
            this.orderByCase=orderByCase;
        }
    }

    public void setTotal(int total) {
        this.total = total;
        totalPages= (total+pageSize-1)/pageSize;
        remainder=total-pageSize*(pageIndex+1);
    }
}
