package cn.hmsoft.jdbc.entity;

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

/***********************
 * 分页实体类，用来处理前台分页
 * @author zxq
 * @create 2019-05-05 09:45:20
 * @version 2.0.0
 * @email: revisit@126.com
 * @Company: www.hmsoft.cn
 */
public class Pager implements Serializable {
	private static final long serialVersionUID = -8579213169783425537L;
	// 开始位置，
	private int start;
	// 显示的条数
	private int limit;
	// 符合条件的结果集
	private List<?> records;
	// 总条数
	private int total;
	// 总页数
	private int count = 0;
	// 当前页面
	private int index = 0;
	// 存放其他参数
	private Map<String,Object> param;

	public Pager(List<?> records, int total, int start, int limit) {
		this.records = records;
		this.total = total;
		this.start = start;
		this.limit = limit;
		// 计算在总页数
		if (limit > 0) {
			int value = total % limit;
			if (value == 0)
				count = total / limit;
			else
				count = total / limit + 1;

			value = start % limit;
			if (value == 0)
				index = start / limit;
			else
				index = start / limit + 1;

		}

	}

	public Pager() {
	}

	public Pager(List<?> records) {
		this.records = records;
		this.total = records == null ? 0 : records.size();
		this.start = 1;
		this.limit = records == null ? 0 : records.size();
		count = 1;
		index = 0;
	}

	public int getStart() {
		return start;
	}

	public int getLimit() {
		return limit;
	}

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

	public void setRecords(List<?> records) {
		this.records = records;
	}

	public int getTotal() {
		return total;
	}

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

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public int getIndex() {
		return index;
	}

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

	public Map<String, Object> getParam() {
		return param;
	}

	public void setParam(Map<String, Object> param) {
		this.param = param;
	}

}
