package com.backendsys.utils;

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

public class PageUtil {

    private long pageNum;
    private long pageSize;
    private long total;
    private List<List<?>> list;

    /**
     * [Mybatis/XML] 分页的查询写法
     *
     * <resultMap id="total" type="java.lang.Integer">
     *     <result column="total"/>
     * </resultMap>
     * <resultMap id="list" type="java.util.LinkedHashMap">
     *     <id property="id" column="id" jdbcType="BIGINT"></id>
     *     <result property="username" column="username"></result>
     * </resultMap>
     *
     * <select id="queryAll" resultMap="list, total">
     *     SELECT SQL_CALC_FOUND_ROWS * from users
     *         <if test="pageNum != null and pageSize != null">
     *             LIMIT ${(pageNum - 1) * pageSize}, ${pageSize}
     *         </if>;
     *     SELECT FOUND_ROWS() AS total;
     * </select>
     */
    public static Map<String, Object> render(List<List<?>> queryList, long pageNum, long pageSize) {
        Map<String, Object> result = new LinkedHashMap<>();
        result.put("total", queryList.get(1).get(0));
        result.put("pageNum", pageNum);
        result.put("pageSize", pageSize);
        result.put("list", queryList.get(0));
        return result;
    }
    /**
     *
     * [Response] 返回值 (pageNum, pageSize 另外拼接)
     * {
     *     pageNum: 1,
     *     pagesize: 10,
     *     total: 0,
     *     list: []
     * }
     */


}
