com.gitee.fufu669.response.AlphaListResponse Maven / Gradle / Ivy
package com.gitee.fufu669.response;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.List;
/** @author wangfupeng */
@ApiModel("列表返回")
public class AlphaListResponse extends AlphaSimpleResponse {
public static final int DEFAULT_PAGE_SIZE = 50;
@ApiModelProperty(value = "总数", example = "1")
private Integer total; // 总数
@ApiModelProperty(value = "页大小", example = "20")
private Integer pageSize; // 页大小
@ApiModelProperty(value = "总页数", example = "1")
private Integer totalPage; // 总页数
@ApiModelProperty(value = "当前页", example = "1")
private Integer page; // 当前页
@ApiModelProperty(value = "当前偏移量", example = "20")
private Integer offset; // 当前偏移量
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
public Integer getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
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 AlphaListResponse success(List data, int totalCount, int page) {
return success(data, totalCount, page, 20);
}
public static AlphaListResponse success(List data, int totalCount, int page, int pageSize) {
AlphaListResponse response = new AlphaListResponse();
response.setData(data);
response.setCode(SUCCESS_STATUS);
response.setMsg(SUCCESS_MESSAGE);
if (pageSize == 0)
pageSize = DEFAULT_PAGE_SIZE;
int totalPage = (int) Math.ceil((double) totalCount / pageSize);
if (page > totalPage)
page = totalPage;
if (page <= 0)
page = 1;
int offset = pageSize * (page - 1);
response.setTotal(totalCount);
response.setPageSize(pageSize);
response.setTotalPage(totalPage);
response.setPage(page);
response.setOffset(offset);
return response;
}
}