package com.ai.da.common.response;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * @ClassName PageResponse
 * @Description 分页响应
 * @Author dwjian
 * @Date 2020/1/13 0:26
 */
@Data
@NoArgsConstructor
@ApiModel("分页响应结果")
public class PageBaseResponse<T> {
    @ApiModelProperty("页码")
    private long page;
    @ApiModelProperty("每页数量")
    private long size;
    @ApiModelProperty("总页数")
    private long pages;
    @ApiModelProperty("总条数")
    private long total;
    @ApiModelProperty("结果集")
    private List<T> content;


    public PageBaseResponse(List<T> list, long page, long size, long total, long pages) {
        this.page = page;
        this.size = size;
        this.total = total;
        this.pages = pages;
        this.content = list;
    }

    public static <T> PageBaseResponse<T> success(IPage<T> page) {
        return new PageBaseResponse<>(page.getRecords(), page.getCurrent(), page.getSize(), page.getTotal(), page.getPages());
    }
}
