Helius
2021-06-29 5252d1396e21a16774be699a5ba1c8d39c14a22e
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
233
234
235
236
237
238
239
240
package com.xzx.gc.util;
 
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
public class PageQuery<T> implements Serializable {
    private static final long serialVersionUID = -7523359884334787081L;
    public static final String pageFlag = "_page";
    public static final Boolean pageObj;
    public static long DEFAULT_PAGE_SIZE;
    protected List<T> list;
    protected Object paras;
    protected String orderBy;
    protected long pageNumber;
    protected long pageSize;
    protected long totalPage;
    protected long totalRow;
    private transient PageQuery.ParasBuilder parasBuilder;
 
    public PageQuery() {
        this(1L, (Object)null);
    }
 
    public PageQuery(long pageNumber) {
        this(pageNumber, (Object)null);
    }
 
    public PageQuery(long pageNumber, long pageSize) {
        this(pageNumber, (Object)null);
        this.pageSize = pageSize;
    }
 
    public PageQuery(long pageNumber, long pageSize, Object paras) {
        this(pageNumber, paras);
        this.pageSize = pageSize;
    }
 
    public PageQuery(long pageNumber, Object paras) {
        this.pageSize = DEFAULT_PAGE_SIZE;
        this.totalRow = -1L;
        this.parasBuilder = new PageQuery.ParasBuilder();
        this.pageNumber = pageNumber;
        this.paras = paras;
    }
 
    public PageQuery(long pageNumber, Object paras, String userDefinedOrderBy) {
        this.pageSize = DEFAULT_PAGE_SIZE;
        this.totalRow = -1L;
        this.parasBuilder = new PageQuery.ParasBuilder();
        this.pageNumber = pageNumber;
        this.paras = paras;
        this.orderBy = userDefinedOrderBy;
    }
 
    public PageQuery(long pageNumber, Object paras, long totalRow) {
        this(pageNumber, paras);
        this.totalRow = totalRow;
    }
 
    public PageQuery(long pageNumber, Object paras, String userDefinedOrderBy, long totalRow) {
        this.pageSize = DEFAULT_PAGE_SIZE;
        this.totalRow = -1L;
        this.parasBuilder = new PageQuery.ParasBuilder();
        this.pageNumber = pageNumber;
        this.paras = paras;
        this.orderBy = userDefinedOrderBy;
        this.totalRow = totalRow;
    }
 
    public PageQuery(long pageNumber, Object paras, long totalRow, long pageSize) {
        this(pageNumber, paras);
        this.totalRow = totalRow;
        this.pageSize = pageSize;
    }
 
    public List<T> getList() {
        return this.list;
    }
 
    public void setList(List list) {
        this.list = list;
    }
 
    public long getPageNumber() {
        return this.pageNumber;
    }
 
    public void setPageNumber(long pageNumber) {
        this.pageNumber = pageNumber;
    }
 
    public long getPageSize() {
        return this.pageSize;
    }
 
    public void setPageSize(long pageSize) {
        this.pageSize = pageSize;
    }
 
    public long getTotalPage() {
        this.calcTotalPage();
        return this.totalPage;
    }
 
    public long getTotalRow() {
        return this.totalRow;
    }
 
    public void setTotalRow(long totalRow) {
        this.totalRow = totalRow;
    }
 
    public boolean isFirstPage() {
        return this.pageNumber == 1L;
    }
 
    public boolean isLastPage() {
        this.calcTotalPage();
        return this.pageNumber == this.totalPage;
    }
 
    public Object getParas() {
        return this.paras;
    }
 
    public void setParas(Object paras) {
        this.parasBuilder.setRoot(paras);
        this.paras = this.parasBuilder.build();
    }
 
    public void setPara(String key, Object value) {
        this.parasBuilder.set(key, value);
        this.paras = this.parasBuilder.build();
    }
 
    public String getOrderBy() {
        return this.orderBy;
    }
 
    public void setOrderBy(String orderBy) {
        this.orderBy = orderBy;
    }
 
    public PageQuery.ParasBuilder parasBuilder() {
        return this.parasBuilder;
    }
 
    private void calcTotalPage() {
        if (this.totalRow == 0L) {
            this.totalPage = 1L;
        } else if (this.totalRow % this.pageSize == 0L) {
            this.totalPage = this.totalRow / this.pageSize;
        } else {
            this.totalPage = this.totalRow / this.pageSize + 1L;
        }
 
    }
 
    @Override
    public int hashCode() {
        boolean prime = true;
        int result = 1;
        result = 31 * result + (this.orderBy == null ? 0 : this.orderBy.hashCode());
        result = 31 * result + (int)(this.pageNumber ^ this.pageNumber >>> 32);
        result = 31 * result + (int)(this.pageSize ^ this.pageSize >>> 32);
        result = 31 * result + (this.paras == null ? 0 : this.paras.hashCode());
        return result;
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        } else if (obj == null) {
            return false;
        } else if (this.getClass() != obj.getClass()) {
            return false;
        } else {
            PageQuery other = (PageQuery)obj;
            if (this.orderBy == null) {
                if (other.orderBy != null) {
                    return false;
                }
            } else if (!this.orderBy.equals(other.orderBy)) {
                return false;
            }
 
            if (this.pageNumber != other.pageNumber) {
                return false;
            } else if (this.pageSize != other.pageSize) {
                return false;
            } else if (this.paras == null) {
                return other.paras == null;
            } else {
                return this.paras.equals(other.paras);
            }
        }
    }
 
    static {
        pageObj = Boolean.TRUE;
        DEFAULT_PAGE_SIZE = 20L;
    }
 
    public static class ParasBuilder {
        private Object root;
        private Map map = null;
 
        public ParasBuilder() {
        }
 
        public Object build() {
            if (this.map != null && this.root != null) {
                this.map.put("_root", this.root);
                return this.map;
            } else if (this.map == null && this.root != null) {
                return this.root;
            } else {
                return this.map != null && this.root == null ? this.map : null;
            }
        }
 
        public Object getRoot() {
            return this.root;
        }
 
        public void setRoot(Object o) {
            this.root = o;
        }
 
        public void set(String key, Object value) {
            if (this.map == null) {
                this.map = new HashMap();
            }
 
            this.map.put(key, value);
        }
    }
}