package com.pannk.mms.common.base;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * Created by wolf on 20-11-20.
 */
@Data
public class PageData<T> implements Serializable {


    private static final long serialVersionUID = -8171781651062157031L;

    /**
     * 总记录数
     */
    private long total;

    /**
     * 分页大小
     */
    private long pageSize;

    /**
     * 总页数
     */
    private long totalPage;

    /**
     * 当前页
     */
    private long curPage;

    private List<T> list;

    public PageData(long total, long pageSize, long curPage, List<T> list) {
        this.total = total;
        this.pageSize = pageSize;
        this.curPage = curPage;
        this.list = list;
        this.totalPage = (long) Math.ceil((double)total/pageSize);
    }

    public PageData(IPage<T> page){
        this.list = page.getRecords();
        this.total = page.getTotal();
        this.pageSize = page.getSize();
        this.curPage = page.getCurrent();
        this.totalPage = page.getPages();
    }
}
