package com.qiaoba.common.database.entity;

import cn.hutool.http.HttpStatus;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qiaoba.common.base.entity.BasePage;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

/**
 * Mybatis-plus 分页封装对象
 *
 * @author ailanyin
 * @version 1.0
 * @since 2023-04-23 15:37:43
 */
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
@SuppressWarnings("unchecked")
public class TableDataInfo<T> extends BasePage {

    private static final long serialVersionUID = 1L;

    public static <T> TableDataInfo<T> build(IPage<T> page) {
        TableDataInfo<T> rspData = new TableDataInfo<>();
        rspData.setCode(HttpStatus.HTTP_OK);
        rspData.setMsg("查询成功");
        rspData.setRows(page.getRecords());
        rspData.setTotal(page.getTotal());
        return rspData;
    }

}
