Quellcode durchsuchen

调整 PageScroll 滚动查询

reghao vor 1 Woche
Ursprung
Commit
f95e423014

+ 21 - 49
common/src/main/java/cn/reghao/tnb/common/db/PageScroll.java

@@ -11,16 +11,16 @@ import java.util.List;
 public class PageScroll<T> implements Serializable {
     private static final long serialVersionUID = 1L;
 
-    // 当前页
-    private final int pageNumber;
     // 每页大小
     private final int pageSize;
     // 总记录数量
     private final int totalSize;
-    // 是否最后一页
-    private final boolean hasNext;
     private final String prevId;
+    // 是否第一页
+    private final boolean hasPrev;
     private final String nextId;
+    // 是否最后一页
+    private final boolean hasNext;
     // 当前页元素
     private final List<T> list;
 
@@ -28,74 +28,42 @@ public class PageScroll<T> implements Serializable {
         return new PageScroll<>();
     }
 
-    public static <T> PageScroll<T> pageList(String prevId, String nextId, List<T> list) {
-        return new PageScroll<>(0, 0, 0, prevId, nextId, list);
-    }
-
-    public static <T> PageScroll<T> pageList(int total, String prevId, String nextId, List<T> list) {
-        return new PageScroll<>(0, 0, total, prevId, nextId, list);
-    }
-
-    public static <T> PageScroll<T> pageList(int pageNumber, int pageSize, int total, List<T> list) {
-        return new PageScroll<>(pageNumber, pageSize, total, list);
+    public static <T> PageScroll<T> pageList(int pageSize, int total, String prevId, String nextId, List<T> list) {
+        return new PageScroll<>(pageSize, total, prevId, nextId, list);
     }
 
-    public static <T> PageScroll<T> pageList(int pageNumber, int pageSize, int total, String lastId, List<T> list) {
-        return new PageScroll<>(pageNumber, pageSize, total, lastId, list);
+    public static <T> PageScroll<T> pageList(int pageSize, int total, String prevId, boolean hasPrev, String nextId, boolean hasNext, List<T> list) {
+        return new PageScroll<>(pageSize, total, prevId, hasPrev, nextId, hasNext, list);
     }
 
     private PageScroll() {
-        this.pageNumber = 1;
         this.pageSize = 10;
         this.totalSize = 0;
         this.list = Collections.emptyList();
+        this.hasPrev = false;
         this.hasNext = false;
         this.prevId = "0";
         this.nextId = "0";
     }
 
-    private PageScroll(int pageNumber, int pageSize, int totalSize, List<T> list) {
-        this.pageNumber = pageNumber;
-        this.pageSize = pageSize;
-        this.totalSize = totalSize;
-        this.list = list;
-        this.hasNext = (totalSize - pageSize*pageNumber > 0);
-        this.prevId = "0";
-        this.nextId = "0";
-    }
-
-    private PageScroll(int pageNumber, int pageSize, int totalSize, String lastId, List<T> list) {
-        this.pageNumber = pageNumber;
+    private PageScroll(int pageSize, int totalSize, String prevId, boolean hasPrev, String nextId, boolean hasNext, List<T> list) {
         this.pageSize = pageSize;
         this.totalSize = totalSize;
         this.list = list;
-        this.hasNext = (totalSize - pageSize*pageNumber > 0);
-        this.prevId = "0";
-        this.nextId = lastId;
+        this.prevId = prevId;
+        this.hasPrev = hasPrev;
+        this.nextId = nextId;
+        this.hasNext = false;
     }
 
-    private PageScroll(int pageNumber, int pageSize, int totalSize, String prevId, String lastId, List<T> list) {
-        this.pageNumber = pageNumber;
+    private PageScroll(int pageSize, int totalSize, String prevId, String nextId, List<T> list) {
         this.pageSize = pageSize;
         this.totalSize = totalSize;
         this.list = list;
-        this.hasNext = (totalSize - pageSize*pageNumber > 0);
         this.prevId = prevId;
-        this.nextId = lastId;
-    }
-
-    private PageScroll(int pageNumber, int pageSize) {
-        this.pageNumber = pageNumber;
-        this.pageSize = pageSize;
-        this.totalSize = 0;
-        this.list = Collections.emptyList();
+        this.hasPrev = false;
+        this.nextId = nextId;
         this.hasNext = false;
-        this.prevId = "0";
-        this.nextId = "0";
-    }
-
-    public int getPageNumber() {
-        return pageNumber;
     }
 
     public int getPageSize() {
@@ -106,6 +74,10 @@ public class PageScroll<T> implements Serializable {
         return totalSize;
     }
 
+    public boolean hasPrev() {
+        return hasNext;
+    }
+
     public boolean hasNext() {
         return hasNext;
     }

+ 1 - 1
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/service/PlayService.java

@@ -190,6 +190,6 @@ public class PlayService {
             nextId1 = 0;
         }
 
-        return PageScroll.pageList(total, String.valueOf(nextId), String.valueOf(nextId1), list1);
+        return PageScroll.pageList(pageSize, total, nextId+"", nextId1+"", list1);
     }
 }

+ 1 - 1
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/service/VideoQueryService.java

@@ -77,7 +77,7 @@ public class VideoQueryService {
                 .map(videoPostCard -> videoPostQuery.getVideoCard(videoPostCard, true))
                 .collect(Collectors.toList());
         nextIdStr = list.get(list.size()-1).getVideoId();
-        return PageScroll.pageList(0, nextIdStr, nextIdStr, list1);
+        return PageScroll.pageList(pageSize, 0, nextIdStr, nextIdStr, list1);
     }
 
     public List<BannerVideoVO> getBannerVideos() {