package com.yzt.airconditionersystem.util;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.yzt.airconditionersystem.vo.BasePageVo;
import com.yzt.airconditionersystem.result.Result;

/**
 * @author TzZach
 * @since 2022-04-15 17:00
 */
public class BasePageVoUtil {

    /**
     * 基于MybatisPlus的分页信息封装
     * @param pageInfo
     * @return
     */
    public static BasePageVo getPageVo(Page<? extends Object> pageInfo) {
        BasePageVo basePageVo = new BasePageVo();
        basePageVo.setCode(Result.SUCCESS_CODE);
        basePageVo.setLimit(pageInfo.getSize());
        basePageVo.setPage(pageInfo.getCurrent());
        basePageVo.setData(pageInfo.getRecords());
        basePageVo.setCount(pageInfo.getTotal());
        return basePageVo;
    }

    /**
     * 基于PageHelper的分页信息封装
     * @param pageInfo
     * @return
     */
    public static BasePageVo getPageVo(PageInfo<? extends Object> pageInfo) {
        BasePageVo basePageVo = new BasePageVo();
        basePageVo.setCode(Result.SUCCESS_CODE);
        basePageVo.setLimit((long) pageInfo.getPageSize());
        basePageVo.setPage((long) pageInfo.getPageNum());
        basePageVo.setData(pageInfo.getList());
        basePageVo.setCount(pageInfo.getTotal());
        return basePageVo;
    }
}
