提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.framework.mybatis.core.query; |
H |
2 |
|
|
3 |
import cn.hutool.core.util.ArrayUtil; |
|
4 |
import cn.hutool.core.util.ObjectUtil; |
|
5 |
import com.iailab.framework.common.util.collection.ArrayUtils; |
|
6 |
import com.baomidou.mybatisplus.core.toolkit.support.SFunction; |
|
7 |
import com.github.yulichang.toolkit.MPJWrappers; |
|
8 |
import com.github.yulichang.wrapper.MPJLambdaWrapper; |
|
9 |
import org.springframework.util.StringUtils; |
|
10 |
|
|
11 |
import java.util.Collection; |
|
12 |
import java.util.function.Consumer; |
|
13 |
|
|
14 |
/** |
|
15 |
* 拓展 MyBatis Plus Join QueryWrapper 类,主要增加如下功能: |
|
16 |
* <p> |
|
17 |
* 1. 拼接条件的方法,增加 xxxIfPresent 方法,用于判断值不存在的时候,不要拼接到条件中。 |
|
18 |
* |
|
19 |
* @param <T> 数据类型 |
|
20 |
*/ |
|
21 |
public class MPJLambdaWrapperX<T> extends MPJLambdaWrapper<T> { |
|
22 |
|
|
23 |
public MPJLambdaWrapperX<T> likeIfPresent(SFunction<T, ?> column, String val) { |
|
24 |
MPJWrappers.lambdaJoin().like(column, val); |
|
25 |
if (StringUtils.hasText(val)) { |
|
26 |
return (MPJLambdaWrapperX<T>) super.like(column, val); |
|
27 |
} |
|
28 |
return this; |
|
29 |
} |
|
30 |
|
|
31 |
public MPJLambdaWrapperX<T> inIfPresent(SFunction<T, ?> column, Collection<?> values) { |
|
32 |
if (ObjectUtil.isAllNotEmpty(values) && !ArrayUtil.isEmpty(values)) { |
|
33 |
return (MPJLambdaWrapperX<T>) super.in(column, values); |
|
34 |
} |
|
35 |
return this; |
|
36 |
} |
|
37 |
|
|
38 |
public MPJLambdaWrapperX<T> inIfPresent(SFunction<T, ?> column, Object... values) { |
|
39 |
if (ObjectUtil.isAllNotEmpty(values) && !ArrayUtil.isEmpty(values)) { |
|
40 |
return (MPJLambdaWrapperX<T>) super.in(column, values); |
|
41 |
} |
|
42 |
return this; |
|
43 |
} |
|
44 |
|
|
45 |
public MPJLambdaWrapperX<T> eqIfPresent(SFunction<T, ?> column, Object val) { |
|
46 |
if (ObjectUtil.isNotEmpty(val)) { |
|
47 |
return (MPJLambdaWrapperX<T>) super.eq(column, val); |
|
48 |
} |
|
49 |
return this; |
|
50 |
} |
|
51 |
|
|
52 |
public MPJLambdaWrapperX<T> neIfPresent(SFunction<T, ?> column, Object val) { |
|
53 |
if (ObjectUtil.isNotEmpty(val)) { |
|
54 |
return (MPJLambdaWrapperX<T>) super.ne(column, val); |
|
55 |
} |
|
56 |
return this; |
|
57 |
} |
|
58 |
|
|
59 |
public MPJLambdaWrapperX<T> gtIfPresent(SFunction<T, ?> column, Object val) { |
|
60 |
if (val != null) { |
|
61 |
return (MPJLambdaWrapperX<T>) super.gt(column, val); |
|
62 |
} |
|
63 |
return this; |
|
64 |
} |
|
65 |
|
|
66 |
public MPJLambdaWrapperX<T> geIfPresent(SFunction<T, ?> column, Object val) { |
|
67 |
if (val != null) { |
|
68 |
return (MPJLambdaWrapperX<T>) super.ge(column, val); |
|
69 |
} |
|
70 |
return this; |
|
71 |
} |
|
72 |
|
|
73 |
public MPJLambdaWrapperX<T> ltIfPresent(SFunction<T, ?> column, Object val) { |
|
74 |
if (val != null) { |
|
75 |
return (MPJLambdaWrapperX<T>) super.lt(column, val); |
|
76 |
} |
|
77 |
return this; |
|
78 |
} |
|
79 |
|
|
80 |
public MPJLambdaWrapperX<T> leIfPresent(SFunction<T, ?> column, Object val) { |
|
81 |
if (val != null) { |
|
82 |
return (MPJLambdaWrapperX<T>) super.le(column, val); |
|
83 |
} |
|
84 |
return this; |
|
85 |
} |
|
86 |
|
|
87 |
public MPJLambdaWrapperX<T> betweenIfPresent(SFunction<T, ?> column, Object val1, Object val2) { |
|
88 |
if (val1 != null && val2 != null) { |
|
89 |
return (MPJLambdaWrapperX<T>) super.between(column, val1, val2); |
|
90 |
} |
|
91 |
if (val1 != null) { |
|
92 |
return (MPJLambdaWrapperX<T>) ge(column, val1); |
|
93 |
} |
|
94 |
if (val2 != null) { |
|
95 |
return (MPJLambdaWrapperX<T>) le(column, val2); |
|
96 |
} |
|
97 |
return this; |
|
98 |
} |
|
99 |
|
|
100 |
public MPJLambdaWrapperX<T> betweenIfPresent(SFunction<T, ?> column, Object[] values) { |
|
101 |
Object val1 = ArrayUtils.get(values, 0); |
|
102 |
Object val2 = ArrayUtils.get(values, 1); |
|
103 |
return betweenIfPresent(column, val1, val2); |
|
104 |
} |
|
105 |
|
|
106 |
// ========== 重写父类方法,方便链式调用 ========== |
|
107 |
|
|
108 |
@Override |
|
109 |
public <X> MPJLambdaWrapperX<T> eq(boolean condition, SFunction<X, ?> column, Object val) { |
|
110 |
super.eq(condition, column, val); |
|
111 |
return this; |
|
112 |
} |
|
113 |
|
|
114 |
@Override |
|
115 |
public <X> MPJLambdaWrapperX<T> eq(SFunction<X, ?> column, Object val) { |
|
116 |
super.eq(column, val); |
|
117 |
return this; |
|
118 |
} |
|
119 |
|
|
120 |
@Override |
|
121 |
public <X> MPJLambdaWrapperX<T> orderByDesc(SFunction<X, ?> column) { |
|
122 |
//noinspection unchecked |
|
123 |
super.orderByDesc(true, column); |
|
124 |
return this; |
|
125 |
} |
|
126 |
|
|
127 |
@Override |
|
128 |
public MPJLambdaWrapperX<T> last(String lastSql) { |
|
129 |
super.last(lastSql); |
|
130 |
return this; |
|
131 |
} |
|
132 |
|
|
133 |
@Override |
|
134 |
public <X> MPJLambdaWrapperX<T> in(SFunction<X, ?> column, Collection<?> coll) { |
|
135 |
super.in(column, coll); |
|
136 |
return this; |
|
137 |
} |
|
138 |
|
|
139 |
@Override |
|
140 |
public MPJLambdaWrapperX<T> selectAll(Class<?> clazz) { |
|
141 |
super.selectAll(clazz); |
|
142 |
return this; |
|
143 |
} |
|
144 |
|
|
145 |
@Override |
|
146 |
public MPJLambdaWrapperX<T> selectAll(Class<?> clazz, String prefix) { |
|
147 |
super.selectAll(clazz, prefix); |
|
148 |
return this; |
|
149 |
} |
|
150 |
|
|
151 |
@Override |
|
152 |
public <S> MPJLambdaWrapperX<T> selectAs(SFunction<S, ?> column, String alias) { |
|
153 |
super.selectAs(column, alias); |
|
154 |
return this; |
|
155 |
} |
|
156 |
|
|
157 |
@Override |
|
158 |
public <E> MPJLambdaWrapperX<T> selectAs(String column, SFunction<E, ?> alias) { |
|
159 |
super.selectAs(column, alias); |
|
160 |
return this; |
|
161 |
} |
|
162 |
|
|
163 |
@Override |
|
164 |
public <S, X> MPJLambdaWrapperX<T> selectAs(SFunction<S, ?> column, SFunction<X, ?> alias) { |
|
165 |
super.selectAs(column, alias); |
|
166 |
return this; |
|
167 |
} |
|
168 |
|
|
169 |
@Override |
|
170 |
public <E, X> MPJLambdaWrapperX<T> selectAs(String index, SFunction<E, ?> column, SFunction<X, ?> alias) { |
|
171 |
super.selectAs(index, column, alias); |
|
172 |
return this; |
|
173 |
} |
|
174 |
|
|
175 |
@Override |
|
176 |
public <E> MPJLambdaWrapperX<T> selectAsClass(Class<E> source, Class<?> tag) { |
|
177 |
super.selectAsClass(source, tag); |
|
178 |
return this; |
|
179 |
} |
|
180 |
|
|
181 |
@Override |
|
182 |
public <E, F> MPJLambdaWrapperX<T> selectSub(Class<E> clazz, Consumer<MPJLambdaWrapper<E>> consumer, SFunction<F, ?> alias) { |
|
183 |
super.selectSub(clazz, consumer, alias); |
|
184 |
return this; |
|
185 |
} |
|
186 |
|
|
187 |
@Override |
|
188 |
public <E, F> MPJLambdaWrapperX<T> selectSub(Class<E> clazz, String st, Consumer<MPJLambdaWrapper<E>> consumer, SFunction<F, ?> alias) { |
|
189 |
super.selectSub(clazz, st, consumer, alias); |
|
190 |
return this; |
|
191 |
} |
|
192 |
|
|
193 |
@Override |
|
194 |
public <S> MPJLambdaWrapperX<T> selectCount(SFunction<S, ?> column) { |
|
195 |
super.selectCount(column); |
|
196 |
return this; |
|
197 |
} |
|
198 |
|
|
199 |
@Override |
|
200 |
public MPJLambdaWrapperX<T> selectCount(Object column, String alias) { |
|
201 |
super.selectCount(column, alias); |
|
202 |
return this; |
|
203 |
} |
|
204 |
|
|
205 |
@Override |
|
206 |
public <X> MPJLambdaWrapperX<T> selectCount(Object column, SFunction<X, ?> alias) { |
|
207 |
super.selectCount(column, alias); |
|
208 |
return this; |
|
209 |
} |
|
210 |
|
|
211 |
@Override |
|
212 |
public <S, X> MPJLambdaWrapperX<T> selectCount(SFunction<S, ?> column, String alias) { |
|
213 |
super.selectCount(column, alias); |
|
214 |
return this; |
|
215 |
} |
|
216 |
|
|
217 |
@Override |
|
218 |
public <S, X> MPJLambdaWrapperX<T> selectCount(SFunction<S, ?> column, SFunction<X, ?> alias) { |
|
219 |
super.selectCount(column, alias); |
|
220 |
return this; |
|
221 |
} |
|
222 |
|
|
223 |
@Override |
|
224 |
public <S> MPJLambdaWrapperX<T> selectSum(SFunction<S, ?> column) { |
|
225 |
super.selectSum(column); |
|
226 |
return this; |
|
227 |
} |
|
228 |
|
|
229 |
@Override |
|
230 |
public <S, X> MPJLambdaWrapperX<T> selectSum(SFunction<S, ?> column, String alias) { |
|
231 |
super.selectSum(column, alias); |
|
232 |
return this; |
|
233 |
} |
|
234 |
|
|
235 |
@Override |
|
236 |
public <S, X> MPJLambdaWrapperX<T> selectSum(SFunction<S, ?> column, SFunction<X, ?> alias) { |
|
237 |
super.selectSum(column, alias); |
|
238 |
return this; |
|
239 |
} |
|
240 |
|
|
241 |
@Override |
|
242 |
public <S> MPJLambdaWrapperX<T> selectMax(SFunction<S, ?> column) { |
|
243 |
super.selectMax(column); |
|
244 |
return this; |
|
245 |
} |
|
246 |
|
|
247 |
@Override |
|
248 |
public <S, X> MPJLambdaWrapperX<T> selectMax(SFunction<S, ?> column, String alias) { |
|
249 |
super.selectMax(column, alias); |
|
250 |
return this; |
|
251 |
} |
|
252 |
|
|
253 |
@Override |
|
254 |
public <S, X> MPJLambdaWrapperX<T> selectMax(SFunction<S, ?> column, SFunction<X, ?> alias) { |
|
255 |
super.selectMax(column, alias); |
|
256 |
return this; |
|
257 |
} |
|
258 |
|
|
259 |
@Override |
|
260 |
public <S> MPJLambdaWrapperX<T> selectMin(SFunction<S, ?> column) { |
|
261 |
super.selectMin(column); |
|
262 |
return this; |
|
263 |
} |
|
264 |
|
|
265 |
@Override |
|
266 |
public <S, X> MPJLambdaWrapperX<T> selectMin(SFunction<S, ?> column, String alias) { |
|
267 |
super.selectMin(column, alias); |
|
268 |
return this; |
|
269 |
} |
|
270 |
|
|
271 |
@Override |
|
272 |
public <S, X> MPJLambdaWrapperX<T> selectMin(SFunction<S, ?> column, SFunction<X, ?> alias) { |
|
273 |
super.selectMin(column, alias); |
|
274 |
return this; |
|
275 |
} |
|
276 |
|
|
277 |
@Override |
|
278 |
public <S> MPJLambdaWrapperX<T> selectAvg(SFunction<S, ?> column) { |
|
279 |
super.selectAvg(column); |
|
280 |
return this; |
|
281 |
} |
|
282 |
|
|
283 |
@Override |
|
284 |
public <S, X> MPJLambdaWrapperX<T> selectAvg(SFunction<S, ?> column, String alias) { |
|
285 |
super.selectAvg(column, alias); |
|
286 |
return this; |
|
287 |
} |
|
288 |
|
|
289 |
@Override |
|
290 |
public <S, X> MPJLambdaWrapperX<T> selectAvg(SFunction<S, ?> column, SFunction<X, ?> alias) { |
|
291 |
super.selectAvg(column, alias); |
|
292 |
return this; |
|
293 |
} |
|
294 |
|
|
295 |
@Override |
|
296 |
public <S> MPJLambdaWrapperX<T> selectLen(SFunction<S, ?> column) { |
|
297 |
super.selectLen(column); |
|
298 |
return this; |
|
299 |
} |
|
300 |
|
|
301 |
@Override |
|
302 |
public <S, X> MPJLambdaWrapperX<T> selectLen(SFunction<S, ?> column, String alias) { |
|
303 |
super.selectLen(column, alias); |
|
304 |
return this; |
|
305 |
} |
|
306 |
|
|
307 |
@Override |
|
308 |
public <S, X> MPJLambdaWrapperX<T> selectLen(SFunction<S, ?> column, SFunction<X, ?> alias) { |
|
309 |
super.selectLen(column, alias); |
|
310 |
return this; |
|
311 |
} |
|
312 |
|
|
313 |
} |