package com.boyue.mybatisinterceptor.util;

import java.util.List;

import com.boyue.mybatisinterceptor.context.page.PageContextHolder;
import com.boyue.mybatisinterceptor.context.page.model.BoYueTableData;
import com.boyue.mybatisinterceptor.context.page.model.TableInfo;

public class PageUtils {
    public static <E> BoYueTableData toTableInfo(List<E> list) {
        if (list instanceof TableInfo) {
            TableInfo<E> tableInfo = (TableInfo<E>) list;
            BoYueTableData BoYueTableData = new BoYueTableData();
            BoYueTableData.setData(list);
            BoYueTableData.setTotal(tableInfo.getTotal());
            return BoYueTableData;
        }
        BoYueTableData BoYueTableData = new BoYueTableData();
        BoYueTableData.setData(list);
        BoYueTableData.setTotal(-1L);
        return BoYueTableData;

    }

    public static void boyueStartPage() {
        PageContextHolder.startPage();
        PageContextHolder.setPageInfo();
    }

}
