|
@@ -0,0 +1,128 @@
|
|
|
+package com.ruoyi.common.core.page;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
|
|
+import lombok.Data;
|
|
|
+import lombok.experimental.Accessors;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Data
|
|
|
+@Accessors(chain = true)
|
|
|
+public class PagePlus<T,K> implements IPage<T> {
|
|
|
+
|
|
|
+ protected List<T> records;
|
|
|
+ protected List<K> recordsVo;
|
|
|
+ protected long total;
|
|
|
+ protected long size;
|
|
|
+ protected long current;
|
|
|
+ protected List<OrderItem> orders;
|
|
|
+ protected boolean optimizeCountSql;
|
|
|
+ protected boolean isSearchCount;
|
|
|
+ protected boolean hitCount;
|
|
|
+ protected String countId;
|
|
|
+ protected Long maxLimit;
|
|
|
+
|
|
|
+ public PagePlus() {
|
|
|
+ this.records = Collections.emptyList();
|
|
|
+ this.recordsVo = Collections.emptyList();
|
|
|
+ this.total = 0L;
|
|
|
+ this.size = 10L;
|
|
|
+ this.current = 1L;
|
|
|
+ this.orders = new ArrayList();
|
|
|
+ this.optimizeCountSql = true;
|
|
|
+ this.isSearchCount = true;
|
|
|
+ this.hitCount = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public PagePlus(long current, long size) {
|
|
|
+ this(current, size, 0L);
|
|
|
+ }
|
|
|
+
|
|
|
+ public PagePlus(long current, long size, long total) {
|
|
|
+ this(current, size, total, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ public PagePlus(long current, long size, boolean isSearchCount) {
|
|
|
+ this(current, size, 0L, isSearchCount);
|
|
|
+ }
|
|
|
+
|
|
|
+ public PagePlus(long current, long size, long total, boolean isSearchCount) {
|
|
|
+ this.records = Collections.emptyList();
|
|
|
+ this.total = 0L;
|
|
|
+ this.size = 10L;
|
|
|
+ this.current = 1L;
|
|
|
+ this.orders = new ArrayList();
|
|
|
+ this.optimizeCountSql = true;
|
|
|
+ this.isSearchCount = true;
|
|
|
+ this.hitCount = false;
|
|
|
+ if (current > 1L) {
|
|
|
+ this.current = current;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.size = size;
|
|
|
+ this.total = total;
|
|
|
+ this.isSearchCount = isSearchCount;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean hasPrevious() {
|
|
|
+ return this.current > 1L;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean hasNext() {
|
|
|
+ return this.current < this.getPages();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void recordsToVo(Class<K> kClass) {
|
|
|
+ this.recordsVo = this.records.stream()
|
|
|
+ .map(any -> BeanUtil.toBean(any, kClass))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String countId() {
|
|
|
+ return this.getCountId();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long maxLimit() {
|
|
|
+ return this.getMaxLimit();
|
|
|
+ }
|
|
|
+
|
|
|
+ public PagePlus<T, K> addOrder(OrderItem... items) {
|
|
|
+ this.orders.addAll(Arrays.asList(items));
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public PagePlus<T, K> addOrder(List<OrderItem> items) {
|
|
|
+ this.orders.addAll(items);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<OrderItem> orders() {
|
|
|
+ return this.getOrders();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean optimizeCountSql() {
|
|
|
+ return this.optimizeCountSql;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean isSearchCount() {
|
|
|
+ return this.total < 0L ? false : this.isSearchCount;
|
|
|
+ }
|
|
|
+
|
|
|
+ public PagePlus<T, K> setSearchCount(boolean isSearchCount) {
|
|
|
+ this.isSearchCount = isSearchCount;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|