mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
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
/*
 * Copyright (c) 2011-2020, baomidou (jobob@qq.com). <p> Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy of the License at <p>
 * https://www.apache.org/licenses/LICENSE-2.0 <p> Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language governing permissions and limitations under the
 * License.
 */
package com.panzhihua.common.model.vos;
 
import static java.util.stream.Collectors.toList;
 
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
 
/**
 * 分页 Page 对象接口
 *
 * @author
 * @since
 */
public class IPageVO<T> implements Serializable {
 
    /**
     * 获取排序信息,排序的字段和正反序
     *
     * @return 排序信息
     */
    List<Object> orders() {
        return null;
    }
 
    /**
     * KEY/VALUE 条件
     *
     * @return ignore
     * @deprecated 3.4.0 @2020-06-30
     */
    @Deprecated
    Map<Object, Object> condition() {
        return null;
    }
 
    /**
     * 自动优化 COUNT SQL【 默认:true 】
     *
     * @return true 是 / false 否
     */
    boolean optimizeCountSql() {
        return true;
    }
 
    /**
     * 进行 count 查询 【 默认: true 】
     *
     * @return true 是 / false 否
     */
    boolean isSearchCount() {
        return true;
    }
 
    /**
     * 计算当前分页偏移量
     */
    long offset() {
        long current = getCurrent();
        if (current <= 1L) {
            return 0L;
        }
        return (current - 1) * getSize();
    }
 
    /**
     * 最大每页分页数限制,优先级高于分页插件内的 maxLimit
     *
     * @since 3.4.0 @2020-07-17
     */
    Long maxLimit() {
        return null;
    }
 
    /**
     * 当前分页总页数
     */
    long getPages() {
        if (getSize() == 0) {
            return 0L;
        }
        long pages = getTotal() / getSize();
        if (getTotal() % getSize() != 0) {
            pages++;
        }
        return pages;
    }
 
    /**
     * 内部什么也不干
     * <p>
     * 只是为了 json 反序列化时不报错
     * </p>
     */
    IPageVO<T> setPages(long pages) {
        // to do nothing
        return this;
    }
 
    /**
     * 设置是否命中count缓存
     *
     * @param hit
     *            是否命中
     * @since 3.3.1
     * @deprecated 3.4.0 @2020-06-30 缓存遵循mybatis的一或二缓
     */
    @Deprecated
    void hitCount(boolean hit) {
 
    }
 
    /**
     * 是否命中count缓存
     *
     * @return 是否命中count缓存
     * @since 3.3.1
     * @deprecated 3.4.0 @2020-06-30 缓存遵循mybatis的一或二缓
     */
    @Deprecated
    boolean isHitCount() {
        return false;
    }
 
    /**
     * 分页记录列表
     *
     * @return 分页对象记录列表
     */
    List<T> getRecords() {
        return null;
    }
 
    /**
     * 设置分页记录列表
     */
    IPageVO<T> setRecords(List<T> records) {
        return null;
    }
 
    /**
     * 当前满足条件总行数
     *
     * @return 总条数
     */
    long getTotal() {
        return 0l;
    }
 
    /**
     * 设置当前满足条件总行数
     */
    IPageVO<T> setTotal(long total) {
        return null;
    }
 
    /**
     * 获取每页显示条数
     *
     * @return 每页显示条数
     */
    long getSize() {
        return 0;
    }
 
    /**
     * 设置每页显示条数
     */
    IPageVO<T> setSize(long size) {
        return null;
    }
 
    /**
     * 当前页
     *
     * @return 当前页
     */
    long getCurrent() {
        return 0l;
    }
 
    /**
     * 设置当前页
     */
    IPageVO<T> setCurrent(long current) {
        return null;
    }
 
    /**
     * IPageVO 的泛型转换
     *
     * @param mapper
     *            转换函数
     * @param <R>
     *            转换后的泛型
     * @return 转换泛型后的 IPageVO
     */
    @SuppressWarnings("unchecked")
    <R> IPageVO<R> convert(Function<? super T, ? extends R> mapper) {
        List<R> collect = this.getRecords().stream().map(mapper).collect(toList());
        return ((IPageVO<R>)this).setRecords(collect);
    }
 
    /**
     * 老分页插件不支持
     * <p>
     * MappedStatement 的 id
     *
     * @return id
     * @since 3.4.0 @2020-06-19
     */
    String countId() {
        return null;
    }
 
}