/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights reserved. <a>http://www.crunii.com</a>
 */
package com.crunii.micro.common.dto;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

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

/**
 * @author 田平 create 2017年4月24日下午3:07:34
 */
@Setter
@Getter
@ToString
@ApiModel(description = "分页响应对象")
public class PageRsp<T> implements Serializable {

	private static final long serialVersionUID = 1L;
	@ApiModelProperty(value = "页码")
	private int pageNo;
	@ApiModelProperty(value = "页大小")
	private int pageSize;
	@ApiModelProperty(value = "list结果集")
	private List<T> result;
	@ApiModelProperty(value = "总记录数")
	private long totalNum;
	/**
	 * 手机端专用属性
	 */
	@ApiModelProperty(value = "是否由下一页")
	private boolean hasNext;

	public void next() {
		this.hasNext = pageNo * pageSize < this.totalNum ? true : false;
	}

	public PageRsp() {
		result = Collections.emptyList();
	}

	public PageRsp(int pageNo, int pageSize, int total, List<T> list) {
		this.pageNo = pageNo;
		this.pageSize = pageSize;
		this.totalNum = total;
		this.result = list;
		next();
	}
}
