ソースを参照

fix dto 适配pageHelper插件

bianlz 1 ヶ月 前
コミット
33f6b13290

+ 28 - 50
pangu-component/pangu-component-dto/src/main/java/com/hrsk/pangu/dto/PageResponse.java

@@ -9,82 +9,61 @@ import java.util.List;
  * @author: bianlanzhou
  * @create: 2024-08-05 17:20
  * @description: copy from https://github.com/alibaba/COLA/tree/COLA4.3.2?tab=readme-ov-file
+ *               适配了pageHelper
  **/
 public class PageResponse<T> extends Response {
 
     private static final long serialVersionUID = 1L;
-
-    private int totalCount = 0;
-
-    private int pageSize = 1;
-
-    private int pageIndex = 1;
-
+    private long totalCount = 0L;
+    private long pageSize = 1L;
+    private long pageIndex = 1L;
     private Collection<T> data;
 
-    public int getTotalCount() {
-        return totalCount;
+    public PageResponse() {
     }
 
-    public void setTotalCount(int totalCount) {
+    public long getTotalCount() {
+        return this.totalCount;
+    }
+
+    public void setTotalCount(long totalCount) {
         this.totalCount = totalCount;
     }
 
-    public int getPageSize() {
-        if (pageSize < 1) {
-            return 1;
-        }
-        return pageSize;
+    public long getPageSize() {
+        return Math.max(this.pageSize, 1L);
     }
 
-    public void setPageSize(int pageSize) {
-        if (pageSize < 1) {
-            this.pageSize = 1;
-        } else {
-            this.pageSize = pageSize;
-        }
+    public void setPageSize(long pageSize) {
+        this.pageSize = Math.max(pageSize, 1L);
     }
 
-    public int getPageIndex() {
-        if (pageIndex < 1) {
-            return 1;
-        }
-        return pageIndex;
+    public long getPageIndex() {
+        return Math.max(this.pageIndex, 1L);
     }
 
-    public void setPageIndex(int pageIndex) {
-        if (pageIndex < 1) {
-            this.pageIndex = 1;
-        } else {
-            this.pageIndex = pageIndex;
-        }
+    public void setPageIndex(long pageIndex) {
+        this.pageIndex = Math.max(pageIndex, 1L);
     }
 
     public List<T> getData() {
-        if (null == data) {
-            return Collections.emptyList();
-        }
-        if (data instanceof List) {
-            return (List<T>) data;
-        }
-        return new ArrayList<>(data);
+        return (List)(this.data == null ? Collections.emptyList() : new ArrayList(this.data));
     }
 
     public void setData(Collection<T> data) {
         this.data = data;
     }
 
-    public int getTotalPages() {
-        return this.totalCount % this.pageSize == 0 ? this.totalCount
-            / this.pageSize : (this.totalCount / this.pageSize) + 1;
+    public long getTotalPages() {
+        return this.totalCount % this.pageSize == 0L ? this.totalCount / this.pageSize : this.totalCount / this.pageSize + 1L;
     }
 
     public boolean isEmpty() {
-        return data == null || data.isEmpty();
+        return this.data == null || this.data.size() == 0;
     }
 
     public boolean isNotEmpty() {
-        return !isEmpty();
+        return !this.isEmpty();
     }
 
     public static PageResponse buildSuccess() {
@@ -101,18 +80,18 @@ public class PageResponse<T> extends Response {
         return response;
     }
 
-    public static <T> PageResponse<T> of(int pageSize, int pageIndex) {
-        PageResponse<T> response = new PageResponse<>();
+    public static <T> PageResponse<T> of(long pageSize, long pageIndex) {
+        PageResponse<T> response = new PageResponse();
         response.setSuccess(true);
         response.setData(Collections.emptyList());
-        response.setTotalCount(0);
+        response.setTotalCount(0L);
         response.setPageSize(pageSize);
         response.setPageIndex(pageIndex);
         return response;
     }
 
-    public static <T> PageResponse<T> of(Collection<T> data, int totalCount, int pageSize, int pageIndex) {
-        PageResponse<T> response = new PageResponse<>();
+    public static <T> PageResponse<T> of(Collection<T> data, long totalCount, long pageSize, long pageIndex) {
+        PageResponse<T> response = new PageResponse();
         response.setSuccess(true);
         response.setData(data);
         response.setTotalCount(totalCount);
@@ -120,5 +99,4 @@ public class PageResponse<T> extends Response {
         response.setPageIndex(pageIndex);
         return response;
     }
-
 }