com.cloud.platform.common.domain.response.PageQueryResponse Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of platform-common Show documentation
Show all versions of platform-common Show documentation
project for platform-common
The newest version!
package com.cloud.platform.common.domain.response;
import com.cloud.platform.common.exception.BaseExceptionCode;
import lombok.Data;
import java.util.Collections;
import java.util.List;
/**
* @Description:
* @Author: ZhouShuai
* @Date: 2021-06-27 16:26
*/
@Data
public class PageQueryResponse extends BaseResponse> {
private static final long serialVersionUID = -8937008601803151631L;
/**
* 页码
*/
private Integer pageIndex;
/**
* 每页显示数量
*/
private Integer pageSize;
/**
* 总记录条数
*/
private long totalCount;
public PageQueryResponse() {
}
public PageQueryResponse successPage(List model, Integer pageIndex, Integer pageSize, long totalCount) {
this.setSuccess(true);
this.setModel(model);
this.setPageIndex(pageIndex);
this.setPageSize(pageSize);
this.setTotalCount(totalCount);
return this;
}
public static PageQueryResponse createSuccessResult(List model, Integer pageIndex, Integer pageSize, long totalCount) {
PageQueryResponse pageResponse = new PageQueryResponse();
return pageResponse.successPage(model, pageIndex, pageSize, totalCount);
}
public static PageQueryResponse createPageFailResult(BaseExceptionCode errorCode) {
PageQueryResponse pageResponse = new PageQueryResponse();
return (PageQueryResponse) pageResponse.fail(errorCode);
}
/**
* 获取当前页
* @return
*/
public Integer getCurrentPage() {
return this.pageIndex < 1 ? 1 : this.pageIndex;
}
/**
* 是否有下一页
* @return
*/
public boolean hasNext() {
long useCount = (this.getCurrentPage() - 1) * this.getPageSize() + this.getSize();
return this.totalCount > useCount;
}
/**
* 总页数
* @return
*/
public long getTotalPage() {
return this.pageSize == 0 ? 0 : (this.totalCount - 1) / this.pageSize + 1;
}
/**
* 当前查询到的记录数
* @return
*/
private long getSize() {
List page = this.getModel();
return (page == null || page.size() == 0) ? 0 : page.size();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy