package com.hdkj.lt.base.model.request;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * @Description: 在前后端交互时，如果使用mybatis plus的分页对象Page作为控制层请求参数时，未对分页参数进行合法校验，此处是为了重写分页属性，对属性进行合法校验
 * @Author: wenhao
 * @Create: 2022/10/22 12:51
 * @Version: 1.0
 */
@ApiModel(value = "分页查询公共类")
public class PaginationParam<T> extends Page<T> {

    /**
     * 当前页码
     */
    @ApiModelProperty(value = "当前页码", required = true)
    @NotNull(message = "当前页码不能为空")
    @Min(value = 1L, message = "当前页面参数必须大于等于1")
    @Max(value = Long.MAX_VALUE, message = "当前页面参数输入过大")
    @Getter
    public long current;

    /**
     * 每页显示记录数
     */
    @ApiModelProperty(value = "每页显示记录数", required = true)
    @NotNull(message = "每页显示记录数不能为空")
    @Min(value = 1L, message = "每页显示记录数参数必须大于等于1")
    @Max(value = Long.MAX_VALUE, message = "每页显示记录数参数输入过大")
    @Getter
    public long size;

    @Override
    public Page<T> setCurrent(long current) {
        this.current = current;
        return super.setCurrent(current);
    }

    @Override
    public Page<T> setSize(long size) {
        this.size = size;
        return super.setSize(size);
    }

}
