package com.lframework.xingyun.sc.entity;

import io.swagger.annotations.ApiModelProperty;

public class Page<T> {

    @ApiModelProperty("当前页数")
    private int pageNum;

    @ApiModelProperty("总记录数")
    private int total;

    @ApiModelProperty("总页数")
    private int pageTotal;

    @ApiModelProperty("一页记录数")
    private int pageSize;

    @ApiModelProperty("当前页记录数")
    private int size;

    @ApiModelProperty("是否还有下一页")
    private boolean hasNext;

    @ApiModelProperty("数据记录")
    private T data;

    public Page(int pageNum, int total, int pageSize, T data){
        this.pageNum=pageNum;
        this.pageSize=pageSize;
        this.total = total;
        this.data=data;
        int model=total%pageSize;
        boolean bool=model==0;
        int pageTotal=bool?total/pageSize:total/pageSize+1;
        this.pageTotal=pageTotal;
        if(pageTotal>pageNum){
            this.hasNext=true;
            this.size=pageSize;
        }else if(pageTotal==pageNum){
            this.size=bool?pageSize:model;
        }
    }

    public Page(){

    }

    public static Integer getStartNum(Integer pageNum, Integer pageSize){
        return (pageNum-1)*pageSize;
    }

    public static String sqlLimit(Integer pageNum, Integer pageSize){
        Integer startNum=getStartNum(pageNum,pageSize);
        return  "LIMIT "+startNum+","+pageSize;
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        int pageTotal=total%pageSize==0?total/pageSize:total/pageSize+1;
        this.pageTotal=pageTotal;
        if(pageTotal>pageNum){
            hasNext=true;
        }
        this.total = total;
    }

    public int getPageTotal() {
        return pageTotal;
    }

    public void setPageTotal(int pageTotal) {
        this.pageTotal = pageTotal;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public boolean isHasNext() {
        return hasNext;
    }

    public void setHasNext(boolean hasNext) {
        this.hasNext = hasNext;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public int getSize() {
        return size;
    }

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

}
