ludc
2023-04-12 d7a83f1396425c4e47da9b95f287b26cd5bb3344
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
package com.vci.ubcs.com.vci.starter.web.pagemodel;
 
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
 
//package com.vci.starter.web.pagemodel;
 
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
 
public class PageHelper implements Serializable {
    private static final long serialVersionUID = -588765760880887850L;
    private int page;
    private String sort;
    private String order;
    private int start = 0;
    private int limit = 25;
    private boolean queryTotal = true;
    private String ordersql;
    private String nick;
    public final String asc = "asc";
    public final String desc = "desc";
    private Set<String> unNickField = new HashSet();
 
    public PageHelper() {
    }
 
    public PageHelper(int limit) {
        this.limit = limit;
        this.page = 1;
    }
 
    public PageHelper(int limit, boolean queryTotal) {
        this.limit = limit;
        this.queryTotal = queryTotal;
    }
 
    public PageHelper(String sort) {
        this.sort = sort;
        this.limit = -1;
        this.order = "asc";
    }
 
    public PageHelper(String sort, String order) {
        this.sort = sort;
        this.limit = -1;
        this.order = order;
    }
 
    public PageHelper(int limit, String sort, String order) {
        this.limit = limit;
        this.sort = sort;
        this.order = order;
    }
 
    public PageHelper(int limit, int page, String sort, String order) {
        this.limit = limit;
        this.page = page;
        this.sort = sort;
        this.order = order;
    }
 
    public int getPage() {
        return this.page;
    }
 
    public void setPage(int page) {
        this.page = page;
        if (page > 0 && this.limit > 0) {
            this.start = (this.page - 1) * this.limit;
        }
 
    }
 
    public void setSort(String sort) {
        this.sort = sort;
    }
 
    public String getOrder() {
        return this.order;
    }
 
    public void setOrder(String order) {
        this.order = order;
    }
 
    public int getStart() {
        return this.limit <= 0 ? 0 : (this.page - 1) * this.limit + 1;
    }
 
    public boolean isQueryTotal() {
        return this.queryTotal;
    }
 
    public void setQueryTotal(boolean queryTotal) {
        this.queryTotal = queryTotal;
    }
 
    public int getLimit() {
        return this.limit;
    }
 
    public void setLimit(int limit) {
        this.limit = limit;
        if (this.page > 0 && this.limit > 0) {
            this.start = (this.page - 1) * this.limit + 1;
        }
 
    }
 
    public void addSort(String sort, String order) {
        this.setSort(StringUtils.isBlank(this.getSort()) ? sort : this.getSort() + "," + sort);
        this.setOrder(StringUtils.isBlank(this.getOrder()) ? order : this.getOrder() + "," + order);
    }
 
    public void addAsc(String field) {
        this.addSort(field, "asc");
    }
 
    public void addDefaultAsc(String field) {
        if (StringUtils.isBlank(this.getSort()) && StringUtils.isBlank(this.getOrder())) {
            this.addAsc(field);
        }
 
    }
 
    public void addDefaultDesc(String field) {
        if (StringUtils.isBlank(this.getSort()) && StringUtils.isBlank(this.getOrder())) {
            this.addDesc(field);
        }
 
    }
 
    public void addDesc(String field) {
        this.addSort(field, "desc");
    }
 
    public String getSort() {
        return this.sort;
    }
 
    public void setStart(int start) {
        this.start = start;
    }
 
    public String getOrdersql() {
        if ((this.ordersql == null || this.ordersql.trim().length() == 0) && this.sort != null && this.sort.trim().length() > 0 && this.order != null && this.order.trim().length() > 0) {
            if (this.sort.indexOf(",") > -1) {
                String[] sortArray = this.sort.split(",");
                String[] orderArray = this.order.split(",");
                StringBuilder sb = new StringBuilder();
 
                for(int i = 0; i < sortArray.length; ++i) {
                    if (StringUtils.isNotBlank(sortArray[i]) && orderArray.length > i && StringUtils.isNotBlank(orderArray[i])) {
                        if (sortArray[i].indexOf(".") < 0 && !this.unNickField.contains(sortArray[i].toLowerCase())) {
                            sb.append(StringUtils.isBlank(this.getNick()) ? "" : this.getNick() + ".");
                        }
 
                        sb.append(sortArray[i].toLowerCase());
                        sb.append(" ");
                        sb.append(orderArray[i]);
                        sb.append(",");
                    }
                }
 
                this.ordersql = " order by " + sb.toString();
                if (this.ordersql.endsWith(",")) {
                    this.ordersql = this.ordersql.substring(0, this.ordersql.length() - 1);
                }
            } else {
                this.ordersql = " order by " + this.sort + " " + this.order;
            }
        }
 
        return this.ordersql;
    }
 
    public String getOrderSql(String nick) {
        if ((this.ordersql == null || this.ordersql.trim().length() == 0) && this.sort != null && this.sort.trim().length() > 0 && this.order != null && this.order.trim().length() > 0) {
            if (this.sort.indexOf(",") > -1) {
                String[] sortArray = this.sort.split(",");
                String[] orderArray = this.order.split(",");
                StringBuilder sb = new StringBuilder();
 
                for(int i = 0; i < sortArray.length; ++i) {
                    if (StringUtils.isNotBlank(sortArray[i]) && orderArray.length > i && StringUtils.isNotBlank(orderArray[i])) {
                        if (sortArray[i].indexOf(".") < 0) {
                            sb.append(StringUtils.isBlank(nick) ? "" : nick + ".");
                        }
 
                        sb.append(sortArray[i].toLowerCase());
                        sb.append(" ");
                        sb.append(orderArray[i]);
                        sb.append(",");
                    }
                }
 
                this.ordersql = " order by " + sb.toString();
                if (this.ordersql.endsWith(",")) {
                    this.ordersql = this.ordersql.substring(0, this.ordersql.length() - 1);
                }
            } else {
                this.ordersql = " order by " + nick + "." + this.sort + " " + this.order;
            }
        }
 
        return this.ordersql;
    }
 
    public String getNick() {
        return this.nick;
    }
 
    public void setNick(String nick) {
        this.nick = nick;
    }
 
    public void setOrdersql(String ordersql) {
        this.ordersql = ordersql;
    }
 
    @Override
    public String toString() {
        return "PageHelper{page=" + this.page + ", sort='" + this.sort + '\'' + ", order='" + this.order + '\'' + ", start=" + this.start + ", limit=" + this.limit + ", queryTotal=" + this.queryTotal + ", ordersql='" + this.ordersql + '\'' + ", nick='" + this.nick + '\'' + ", asc='" + "asc" + '\'' + ", desc='" + "desc" + '\'' + ", unNickField=" + this.unNickField + '}';
    }
 
    public Set<String> getUnNickField() {
        return this.unNickField;
    }
 
    public void setUnNickField(Set<String> unNickField) {
        this.unNickField = unNickField;
    }
}