All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gitee.fufu669.response.ListResponseLongCount Maven / Gradle / Ivy

There is a newer version: 6.666.66021
Show newest version
package com.gitee.fufu669.response;


import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.List;

/** @author wangfupeng */
@ApiModel("列表返回")
public class ListResponseLongCount extends SimpleResponse {

    public static final Integer DEFAULT_PAGE_SIZE = 50;

    @ApiModelProperty(value = "总数", example = "1")
    private Long count; // 总数

    @ApiModelProperty(value = "页大小", example = "20")
    private Integer limit; // 页大小

    @ApiModelProperty(value = "总页数", example = "1")
    private Integer totalPage; // 总页数

    @ApiModelProperty(value = "当前页", example = "1")
    private Integer page; // 当前页

    @ApiModelProperty(value = "当前偏移量", example = "20")
    private Integer offset; // 当前偏移量

    public Long getCount() {
        return count;
    }

    public void setCount(Long count) {
        this.count = count;
    }

    public Integer getLimit() {
        return limit;
    }

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

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public Integer getPage() {
        return page;
    }

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

    public Integer getOffset() {
        return offset;
    }

    public void setOffset(Integer offset) {
        this.offset = offset;
    }

    public static  ListResponseLongCount success(List data, Long totalCount, Integer page) {
        return success(data, totalCount, page, 20);
    }

    public static  ListResponseLongCount success(List data, Long totalCount, Integer page, Integer pageSize) {
        ListResponseLongCount response = new ListResponseLongCount();
        response.setData(data);
        response.setStatus(SUCCESS_STATUS);
        response.setMessage(SUCCESS_MESSAGE);

        if (pageSize == 0)
            pageSize = DEFAULT_PAGE_SIZE;

        Integer totalPage = (int) Math.ceil((double) totalCount / pageSize);

        if (page > totalPage)
            page = totalPage;
        if (page <= 0)
            page = 1;

        Integer offset = pageSize * (page - 1);
        response.setCount(totalCount);
        response.setLimit(pageSize);
        response.setTotalPage(totalPage);
        response.setPage(page);
        response.setOffset(offset);
        return response;
    }

}








© 2015 - 2024 Weber Informatics LLC | Privacy Policy