|
@@ -0,0 +1,120 @@
|
|
|
|
+package com.hrsk.pangu.dto;
|
|
|
|
+
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Collection;
|
|
|
|
+import java.util.Collections;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @author: bianlanzhou
|
|
|
|
+ * @create: 2024-10-21 11:21
|
|
|
|
+ * @description: ANTD页面适配分页响应
|
|
|
|
+ **/
|
|
|
|
+public class AntDPageResponse<T> extends Response {
|
|
|
|
+ private static final long serialVersionUID = 1L;
|
|
|
|
+ private long total = 0L;
|
|
|
|
+ private long pageSize = 10L;
|
|
|
|
+ private long pageIndex = 0L;
|
|
|
|
+ private Collection<T> data;
|
|
|
|
+
|
|
|
|
+ public AntDPageResponse() {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public long getTotal() {
|
|
|
|
+ return this.total;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setTotal(long total) {
|
|
|
|
+ this.total = total;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public long getPageSize() {
|
|
|
|
+ return this.pageSize < 1L ? 1L : this.pageSize;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setPageSize(long pageSize) {
|
|
|
|
+ if (pageSize < 1L) {
|
|
|
|
+ this.pageSize = 1L;
|
|
|
|
+ } else {
|
|
|
|
+ this.pageSize = pageSize;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public long getPageIndex() {
|
|
|
|
+ return this.pageIndex < 1L ? 1L : this.pageIndex;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setPageIndex(long pageIndex) {
|
|
|
|
+ if (pageIndex < 1L) {
|
|
|
|
+ this.pageIndex = 1L;
|
|
|
|
+ } else {
|
|
|
|
+ this.pageIndex = pageIndex;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public List<T> getData() {
|
|
|
|
+ return (List)(null == this.data ? Collections.emptyList() : new ArrayList(this.data));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setData(Collection<T> data) {
|
|
|
|
+ this.data = data;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public long getTotalPages() {
|
|
|
|
+ return this.total % this.pageSize == 0L ? this.total / this.pageSize : this.total / this.pageSize + 1L;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public boolean isEmpty() {
|
|
|
|
+ return this.data == null || this.data.size() == 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public boolean isNotEmpty() {
|
|
|
|
+ return !this.isEmpty();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static AntDPageResponse buildSuccess() {
|
|
|
|
+ AntDPageResponse response = new AntDPageResponse();
|
|
|
|
+ response.setSuccess(true);
|
|
|
|
+ return response;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static AntDPageResponse buildFailure(String errCode, String errMessage) {
|
|
|
|
+ AntDPageResponse response = new AntDPageResponse();
|
|
|
|
+ response.setSuccess(false);
|
|
|
|
+ response.setErrCode(errCode);
|
|
|
|
+ response.setErrMessage(errMessage);
|
|
|
|
+ return response;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static <T> AntDPageResponse<T> of(int pageSize, int pageIndex) {
|
|
|
|
+ AntDPageResponse<T> response = new AntDPageResponse();
|
|
|
|
+ response.setSuccess(true);
|
|
|
|
+ response.setData(Collections.emptyList());
|
|
|
|
+ response.setTotal(0L);
|
|
|
|
+ response.setPageSize((long)pageSize);
|
|
|
|
+ response.setPageIndex((long)pageIndex);
|
|
|
|
+ return response;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static <T> AntDPageResponse<T> of(Collection<T> data, long total, int pageSize, int pageIndex) {
|
|
|
|
+ AntDPageResponse<T> response = new AntDPageResponse();
|
|
|
|
+ response.setSuccess(true);
|
|
|
|
+ response.setData(data);
|
|
|
|
+ response.setTotal(total);
|
|
|
|
+ response.setPageSize((long)pageSize);
|
|
|
|
+ response.setPageIndex((long)pageIndex);
|
|
|
|
+ return response;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static <T> AntDPageResponse<T> of(PageResponse<T> pageResponse) {
|
|
|
|
+ AntDPageResponse<T> response = new AntDPageResponse();
|
|
|
|
+ response.setSuccess(pageResponse.isSuccess());
|
|
|
|
+ response.setData(pageResponse.getData());
|
|
|
|
+ response.setTotal(pageResponse.getTotalCount());
|
|
|
|
+ response.setPageSize(pageResponse.getPageSize());
|
|
|
|
+ response.setPageIndex(pageResponse.getPageIndex());
|
|
|
|
+ return response;
|
|
|
|
+ }
|
|
|
|
+}
|