package com.liang.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.validation.Valid;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

@Getter
@Setter
@NoArgsConstructor
@ApiModel
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Page<T> implements Serializable {
    private static final long serialVersionUID = -880132266597087829L;

    /**
     * 包装Page对象
     *
     * @param list
     */
    public Page(List<? extends T> list) {
        PageInfo<? extends T> page = new PageInfo<>(list);
        this.total = page.getTotal();
        this.pageNum = page.getPageNum();
        this.pageSize = page.getPageSize();
        this.rows = page.getList();
    }

    /**
     * 包装Page对象
     *
     * @param list
     */
    public Page(List<? extends T> list, Map<String,Object> other) {
        PageInfo<? extends T> page = new PageInfo<>(list);
        this.total = page.getTotal();
        this.pageNum = page.getPageNum();
        this.pageSize = page.getPageSize();
        this.rows = page.getList();
        this.other = other;
    }
    //当前页
    @ApiModelProperty(value = "当前页数",required = true)
    private int pageNum =1;
    //每页的数量
    @ApiModelProperty(value = "每页显示数",required = true)
    private int pageSize = 10;

    private long total = 0;

    /**
     * 列表查询入参实体类
     */
    @ApiModelProperty(value = "列表查询返回附加数据实体类",dataType = "java.util.HashMap",hidden = true)
    private Map<String,Object> other;
    /**
     * 列表查询入参实体类
     */
    @ApiModelProperty(value = "列表查询入参实体类")
    @Valid
    private transient T data;
    @ApiModelProperty(hidden = true)
    private  List<? extends T> rows;
}
