com.gitee.fufu669.response.ListResponseLong 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 ListResponseLong extends SimpleResponse {
public static final Long DEFAULT_PAGE_SIZE = 50L;
@ApiModelProperty(value = "总数", example = "1")
private Long count; // 总数
@ApiModelProperty(value = "页大小", example = "20")
private Long limit; // 页大小
@ApiModelProperty(value = "总页数", example = "1")
private Long totalPage; // 总页数
@ApiModelProperty(value = "当前页", example = "1")
private Long page; // 当前页
@ApiModelProperty(value = "当前偏移量", example = "20")
private Long offset; // 当前偏移量
public Long getCount() {
return count;
}
public void setCount(Long count) {
this.count = count;
}
public Long getLimit() {
return limit;
}
public void setLimit(Long limit) {
this.limit = limit;
}
public Long getTotalPage() {
return totalPage;
}
public void setTotalPage(Long totalPage) {
this.totalPage = totalPage;
}
public Long getPage() {
return page;
}
public void setPage(Long page) {
this.page = page;
}
public Long getOffset() {
return offset;
}
public void setOffset(Long offset) {
this.offset = offset;
}
public static ListResponseLong success(List data, Long totalCount, Long page) {
return success(data, totalCount, page, 20L);
}
public static ListResponseLong success(List data, Long totalCount, Long page, Long pageSize) {
ListResponseLong response = new ListResponseLong();
response.setData(data);
response.setStatus(SUCCESS_STATUS);
response.setMessage(SUCCESS_MESSAGE);
if (pageSize == 0)
pageSize = DEFAULT_PAGE_SIZE;
Long totalPage = (long) Math.ceil((double) totalCount / pageSize);
if (page > totalPage)
page = totalPage;
if (page <= 0)
page = 1L;
Long offset = pageSize * (page - 1);
response.setCount(totalCount);
response.setLimit(pageSize);
response.setTotalPage(totalPage);
response.setPage(page);
response.setOffset(offset);
return response;
}
}