package com.copy.trade.entity.base;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;

@ApiModel
@Slf4j
@Data
public class BaseQueryForm<P> extends BaseForm {
    /**
     * 分页查询的参数，当前页数
     */
    @ApiModelProperty(value = "第几页",example = "1")
    private long currentPage = 1;
    /**
     * 分页查询的参数，当前页面每页显示的数量
     */
    @ApiModelProperty(value = "每页多少条",example = "10")
    private long pageSize = 10;

    /**
     * Form转化为Param
     *
     * @param clazz
     * @return
     */
    public P toParam(Class<P> clazz) {
        P p = BeanUtils.instantiateClass(clazz);
        BeanUtils.copyProperties(this, p);
        return p;
    }

    /**
     * 从form中获取page参数，用于分页查询参数
     *
     * @return
     */
    @ApiModelProperty(value = "从form中获取page参数" ,hidden=true)
    public Page newFormPage() {
        return new Page(this.getCurrentPage(), this.getPageSize());
    }

}
