package cn.reghao.autodop.dmaster.util.db;

import lombok.Data;
import org.springframework.data.domain.Page;

import java.util.List;

/**
 * 分页列表
 *
 * @author reghao
 * @date 2020-03-05 17:39:53
 */
@Data
public class PageList<T> {
    // 每页大小
    private int pageSize;
    // 总数量
    private long totalSize;
    // 总页数
    private int totalPages;
    // 是否最后一页
    private boolean hasNext;
    private List<T> list;

    public static <T> PageList<T> pageList(Page<T> page) {
        PageList<T> pageList = new PageList<>();
        pageList.setPageSize(page.getSize());
        pageList.setTotalSize(page.getTotalElements());
        pageList.setTotalPages(page.getTotalPages());
        pageList.setHasNext(page.hasNext());
        pageList.setList(page.getContent());
        return pageList;
    }

    public static <T> PageList<T> emptyPageList(Page page) {
        PageList<T> pageList = new PageList<>();
        pageList.setPageSize(page.getSize());
        pageList.setTotalSize(page.getTotalElements());
        pageList.setTotalPages(page.getTotalPages());
        pageList.setHasNext(page.hasNext());
        return pageList;
    }
}
