package com.github.wxiaoqi.security.common.util;


import cn.hutool.core.bean.BeanUtil;
import com.github.wxiaoqi.security.common.vo.PageParam;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 查询参数
 */
public class Query extends LinkedHashMap<String, Object> {
	private static final long serialVersionUID = 1L;
	//当前页码
    private int page = 1;
    //每页条数
    private int limit = 10;

    public Query(Map<String, Object> params){
        this.putAll(params);
        //分页参数
        if(params.get("page")!=null) {
            this.page = Integer.parseInt(params.get("page").toString());
        }
        if(params.get("limit")!=null) {
            this.limit = Integer.parseInt(params.get("limit").toString());
        }
        this.remove("page");
        this.remove("limit");
    }

    /**
     * zjw新增
     * @param pageParam
     */
    public Query(PageParam pageParam){
        this.putAll(BeanUtil.beanToMap(pageParam));
        //分页参数
        if(pageParam.getPage() != null) {
            this.page = pageParam.getPage();
        }
        if(pageParam.getLimit() != null) {
            this.limit = pageParam.getLimit();
        }
        this.remove("page");
        this.remove("limit");
    }


    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }

    public LinkedHashMap<String, Object> getSuper() {
        return this;
    }
}
