疯狂的狮子li
2021-05-20 7076deb2b6da9ab0a8b599c61150ec2bd5a926f8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package com.ruoyi.common.core.page;
 
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;
 
@Data
@Accessors(chain = true)
public class PagePlus<T,K> implements IPage<T> {
 
    /**
     * domain实体列表
     */
    private List<T> records = Collections.emptyList();
 
    /**
     * vo实体列表
     */
    private List<K> recordsVo = Collections.emptyList();
 
    /**
     * 总数
     */
    private long total = 0L;
 
    /**
     * 页长度
     */
    private long size = 10L;
 
    /**
     * 当前页
     */
    private long current = 1L;
 
    /**
     * 排序字段信息
     */
    private List<OrderItem> orders = new ArrayList<>();
 
    /**
     * 自动优化 COUNT SQL
     */
    private boolean optimizeCountSql = true;
 
    /**
     * 是否进行 count 查询
     */
    private boolean isSearchCount = true;
 
    /**
     * 是否命中count缓存
     */
    private boolean hitCount = false;
 
    /**
     * countId
     */
    private String countId;
 
    /**
     * 最大limit
     */
    private Long maxLimit;
 
    public PagePlus() {
    }
 
    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) {
        if (current > 1L) {
            this.current = current;
        }
        this.size = size;
        this.total = total;
        this.isSearchCount = isSearchCount;
    }
 
    @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 && this.isSearchCount;
    }
 
    public PagePlus<T, K> setSearchCount(boolean isSearchCount) {
        this.isSearchCount = isSearchCount;
        return this;
    }
 
}