package com.friday.custody.utils;

import com.friday.custody.exception.RRException;
import com.friday.custody.req.BasicQueryReq;
import com.friday.custody.enums.RetCodeEnum;

import java.util.HashMap;
import java.util.Map;

public class PageUtil {

    public static Map<String, Object> getPageParams(BasicQueryReq dto) {
        Map<String, Object> pageParams = new HashMap<>();
        //页数，大于0，初始默认1
        Integer pageNo = dto.getPageNo();
        if (pageNo == null || pageNo < 1) {
            pageNo = 1;
        }
        //每页显示条数，大于0，初始默认100，最大不得超过500
        Integer pageSize =  dto.getPageSize();
        if (pageSize == null || pageSize < 0) {
            pageSize = 100;
        } else if (pageSize > 500) {
            throw new RRException(RetCodeEnum.PARAM_ERROR.getCode(),"每页查询条数不得超过500！");
        }
        pageParams.put("page", pageNo + "");
        pageParams.put("limit", pageSize + "");
        return pageParams;
    }
}
