package com.qmth.jkserver.base;

import io.swagger.annotations.ApiModelProperty;

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

/**
 * @Description: 分页封装
 * @Param:
 * @return:
 * @Author: wangliang
 * @Date: 2020/8/7
 */
public class BaseListPage<T> implements Serializable {
    @ApiModelProperty(value = "当前第几页(从1开始)")
    private int current;

    @ApiModelProperty(value = "每页条数")
    private int size;

    @ApiModelProperty(value = "总条数")
    private int total;

    @ApiModelProperty(value = "内容列表")
    private List<T> records;

    public BaseListPage(List<T> records, long current, long size, long total) {
        this.current = (int) current;
        this.size = (int) size;
        this.total = (int) total;
        this.records = records;
    }

    public int getCurrent() {
        return current;
    }

    public int getSize() {
        return size;
    }

    public int getTotal() {
        return total;
    }

    public List<T> getRecords() {
        return records;
    }

    /**
     * 总页数
     */
    public int getPages() {
        if (getSize() == 0) {
            return 0;
        }
        int pages = getTotal() / getSize();
        if (getTotal() % getSize() != 0) {
            pages++;
        }
        return pages;
    }
}
