Newer
Older
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
package com.cesgroup.bdc.util;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import java.util.Collections;
import java.util.List;
/**
* cui简单分页模型
*
* @author: shen.shaohua
* @since: 2019/7/15 13:58
*/
public class CuiPage<T> implements IPage<T> {
private static final long serialVersionUID = 3680640738282033255L;
/**
* 查询数据列表
*/
private List<T> records = Collections.emptyList();
/**
* 总数
*/
private long total = 0;
/**
* 每页显示条数,默认 10
*/
private long size = 10;
/**
* 当前页
*/
private long current = 1;
/**
* SQL 排序 ASC 数组
*/
private String[] ascs;
/**
* SQL 排序 DESC 数组
*/
private String[] descs;
/**
* 自动优化 COUNT SQL
*/
private boolean optimizeCountSql = true;
/**
* 是否进行 count 查询
*/
private boolean isSearchCount = true;
public CuiPage() {
}
/**
* 分页构造函数
*
* @param current 当前页
* @param size 每页显示条数
*/
public CuiPage(long current, long size) {
this(current, size, 0);
}
public CuiPage(long current, long size, long total) {
this(current, size, total, true);
}
public CuiPage(long current, long size, boolean isSearchCount) {
this(current, size, 0, isSearchCount);
}
public CuiPage(long current, long size, long total, boolean isSearchCount) {
if (current > 1) {
this.current = current;
}
this.size = size;
this.total = total;
this.isSearchCount = isSearchCount;
}
/**
* P_pageNumber 当前页
*
* @param current
* @return
*/
public CuiPage<T> setP_pageNumber(long current) {
this.current = current;
return this;
}
/**
* P_pagesize 每页条数
*
* @param size
* @return
*/
public CuiPage<T> setP_pagesize(long size) {
this.size = size;
return this;
}
/**
* 是否存在上一页
*
* @return true / false
*/
public boolean hasPrevious() {
return this.current > 1;
}
/**
* 是否存在下一页
*
* @return true / false
*/
public boolean hasNext() {
return this.current < this.getPages();
}
@Override
public List<T> getRecords() {
return this.records;
}
@Override
public CuiPage<T> setRecords(List<T> records) {
this.records = records;
return this;
}
@Override
public long getTotal() {
return this.total;
}
@Override
public CuiPage<T> setTotal(long total) {
this.total = total;
return this;
}
@Override
public long getSize() {
return this.size;
}
@Override
public CuiPage<T> setSize(long size) {
this.size = size;
return this;
}
@Override
public long getCurrent() {
return this.current;
}
@Override
public CuiPage<T> setCurrent(long current) {
this.current = current;
return this;
}
@Override
public String[] ascs() {
return ascs;
}
public CuiPage<T> setAscs(List<String> ascs) {
if (CollectionUtils.isNotEmpty(ascs)) {
this.ascs = ascs.toArray(new String[0]);
}
return this;
}
/**
* 升序
*
* @param ascs 多个升序字段
*/
public CuiPage<T> setAsc(String... ascs) {
this.ascs = ascs;
return this;
}
@Override
public String[] descs() {
return descs;
}
public CuiPage<T> setDescs(List<String> descs) {
if (CollectionUtils.isNotEmpty(descs)) {
this.descs = descs.toArray(new String[0]);
}
return this;
}
/**
* 降序
*
* @param descs 多个降序字段
*/
public CuiPage<T> setDesc(String... descs) {
this.descs = descs;
return this;
}
@Override
public boolean optimizeCountSql() {
return optimizeCountSql;
}
@Override
public boolean isSearchCount() {
if (total < 0) {
return false;
}
return isSearchCount;
}
public CuiPage<T> setSearchCount(boolean isSearchCount) {
this.isSearchCount = isSearchCount;
return this;
}
public CuiPage<T> setOptimizeCountSql(boolean optimizeCountSql) {
this.optimizeCountSql = optimizeCountSql;
return this;
}
}