package cn.com.qmth.stmms.ms.commons.utils;

import org.springframework.data.domain.Page;

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

/**
 * 分页
 *
 * @author WANGWEI
 * @date 2018年6月25日
 * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
 * @param <T>
 */
public class PageInfo<T> implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 * 当前页码
	 */
	private long index = 1;

	/**
	 * 每页的数量
	 */
	private long limit = 10;

	/**
	 * 当前页的数量
	 */
	private long size;

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

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

	/**
	 * 结果集
	 */
	private List<T> list;

	/**
	 * 构造函数
	 *
	 */
	public PageInfo() {

	}

	/**
	 * 构造函数
	 *
	 * @param page
	 */
	public PageInfo(Page<T> page) {
		this.total = page.getTotalElements();
		this.pages = page.getTotalPages();
		this.index = page.getNumber();
		this.size = page.getNumberOfElements();
		this.limit = page.getSize();

		this.list = page.getContent();
	}

	/**
	 * 构造函数
	 *
	 * @param page
	 * @param list
	 */
	public PageInfo(Page<?> page, List<T> list) {
		this.total = page.getTotalElements();
		this.pages = page.getTotalPages();
		this.index = page.getNumber();
		this.size = page.getNumberOfElements();
		this.limit = page.getSize();

		this.list = list;
	}

	public long getIndex() {
		return index;
	}

	public void setIndex(long index) {
		this.index = index;
	}

	public long getLimit() {
		return limit;
	}

	public void setLimit(long limit) {
		this.limit = limit;
	}

	public long getSize() {
		return size;
	}

	public void setSize(long size) {
		this.size = size;
	}

	public long getTotal() {
		return total;
	}

	public void setTotal(long total) {
		this.total = total;
	}

	public long getPages() {
		return pages;
	}

	public void setPages(long pages) {
		this.pages = pages;
	}

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}

}
