Wrappers.java
8.94 KB
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
package com.huaheng.common.utils;
import com.baomidou.mybatisplus.core.conditions.ISqlSegment;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.huaheng.common.utils.security.ShiroUtils;
import java.util.Collections;
import java.util.Map;
/**
* @BelongsProject: wms_wuhangelinmei
* @BelongsPackage: com.huaheng.common.utils
* @Author: zhouhong
* @CreateTime: 2022-07-13 16:14
* @Description: TODO
* @Version: 1.0
*/
public class Wrappers {
/**
* true查询所有 false按照登录仓库查询
*/
private static boolean dataAllByWarehouse=false;
private static String warehouselist=null;
/**
* 空的 EmptyWrapper
*/
private static final QueryWrapper<?> emptyWrapper = new Wrappers.EmptyWrapper<>();
private Wrappers() {
// ignore
}
public static void setWarehouseList(String str){
warehouselist=str;
}
public static void initWarehouseList(){
warehouselist=null;
}
public static void setWarehouseFindAll(boolean tag){
dataAllByWarehouse=tag;
}
public static void initWarehouseFindAll(){
if(dataAllByWarehouse){
dataAllByWarehouse=false;
}
}
/**
* 获取 QueryWrapper<T>
*
* @param <T> 实体类泛型
* @return QueryWrapper<T>
*/
public static <T> QueryWrapper<T> query() {
return new QueryWrapper<>();
}
/**
* 获取 QueryWrapper<T>
*
* @param entity 实体类
* @param <T> 实体类泛型
* @return QueryWrapper<T>
*/
public static <T> QueryWrapper<T> query(T entity) {
return new QueryWrapper<>(entity);
}
/**
* 获取 LambdaQueryWrapper<T>
* 1.默认查询当前登录仓库数据,未登录则查询所有
* 2.dataAllByWarehouse默认为false,查询当前仓库数据,为true时,查询所有仓库数据
* 3.dataAllByWarehouse用完要设为false,不影响后面的查询
* 4.也可以指定查询哪几个仓库warehouselist,如:"CS0001,CS0002"
* @param <T> 实体类泛型
* @return LambdaQueryWrapper<T>
*/
/* 也可以指定查询哪几个仓库warehouselist,如:"CS0001,CS0002"
if(StringUtils.isNotEmpty(warehouselist)){
String[] str_spplit=warehouselist.split(",");
wrapper.in("warehouseCode",str_spplit);
}else{
wrapper.eq("warehouseCode", ShiroUtils.getWarehouseCode());
}*/
public static <T> LambdaQueryWrapper<T> lambdaQuery() {
QueryWrapper<T> wrapper=new QueryWrapper<>();
if(ShiroUtils.getUser()!=null){
if (!dataAllByWarehouse){
wrapper.eq("warehouseCode", ShiroUtils.getWarehouseCode());
}
}
initWarehouseFindAll();
LambdaQueryWrapper<T> result=wrapper.lambda();
return result;
}
/**
* 1.表没有warehouseCode字段的用该方法
* 2.查询所有仓库数据
* 获取 LambdaQueryWrapper<T>
* @param <T> 实体类泛型
* @return LambdaQueryWrapper<T>
*/
public static <T> LambdaQueryWrapper<T> lambdaQueryNoWarehouse() {
return new LambdaQueryWrapper<>();
}
/**
* 获取 LambdaQueryWrapper<T>
*
* @param entity 实体类
* @param <T> 实体类泛型
* @return LambdaQueryWrapper<T>
*/
public static <T> LambdaQueryWrapper<T> lambdaQuery(T entity) {
QueryWrapper<T> wrapper=new QueryWrapper<>(entity);
if(ShiroUtils.getUser()!=null){
if (!dataAllByWarehouse){
wrapper.eq("warehouseCode", ShiroUtils.getWarehouseCode());
}
}
initWarehouseFindAll();
LambdaQueryWrapper<T> result=wrapper.lambda();
return result;
}
/**
* 获取 LambdaQueryWrapper<T>
*
* @param entity 实体类
* @param <T> 实体类泛型
* @return LambdaQueryWrapper<T>
*/
public static <T> LambdaQueryWrapper<T> lambdaQueryNoWarehouse(T entity) {
return new LambdaQueryWrapper<>(entity);
}
/**
* 获取 UpdateWrapper<T>
*
* @param <T> 实体类泛型
* @return UpdateWrapper<T>
*/
public static <T> UpdateWrapper<T> update() {
return new UpdateWrapper<>();
}
/**
* 获取 UpdateWrapper<T>
*
* @param entity 实体类
* @param <T> 实体类泛型
* @return UpdateWrapper<T>
*/
public static <T> UpdateWrapper<T> update(T entity) {
return new UpdateWrapper<>(entity);
}
/**
* 获取 LambdaUpdateWrapper<T>
*
* @param <T> 实体类泛型
* @return LambdaUpdateWrapper<T>
*/
public static <T> LambdaUpdateWrapper<T> lambdaUpdate() {
UpdateWrapper<T> wrapper=new UpdateWrapper<>();
if(ShiroUtils.getUser()!=null){
wrapper.eq("warehouseCode", ShiroUtils.getWarehouseCode());
}
LambdaUpdateWrapper<T> result=wrapper.lambda();
return result;
}
/**
* 获取 LambdaUpdateWrapper<T>
*
* @param <T> 实体类泛型
* @return LambdaUpdateWrapper<T>
*/
public static <T> LambdaUpdateWrapper<T> lambdaUpdateNoWarehouse() {
return new LambdaUpdateWrapper<>();
}
/**
* 获取 LambdaUpdateWrapper<T>
*
* @param entity 实体类
* @param <T> 实体类泛型
* @return LambdaUpdateWrapper<T>
*/
public static <T> LambdaUpdateWrapper<T> lambdaUpdate(T entity) {
UpdateWrapper<T> wrapper=new UpdateWrapper<>(entity);
if(ShiroUtils.getUser()!=null){
wrapper.eq("warehouseCode", ShiroUtils.getWarehouseCode());
}
LambdaUpdateWrapper<T> result=wrapper.lambda();
return result;
}
/**
* 获取 LambdaUpdateWrapper<T>
*
* @param entity 实体类
* @param <T> 实体类泛型
* @return LambdaUpdateWrapper<T>
*/
public static <T> LambdaUpdateWrapper<T> lambdaUpdateNoWarehouse(T entity) {
return new LambdaUpdateWrapper<>(entity);
}
/**
* 获取 EmptyWrapper<T>
*
* @param <T> 任意泛型
* @return EmptyWrapper<T>
* @see Wrappers.EmptyWrapper
*/
@SuppressWarnings("unchecked")
public static <T> QueryWrapper<T> emptyWrapper() {
return (QueryWrapper<T>) emptyWrapper;
}
/**
* 一个空的QueryWrapper子类该类不包含任何条件
*
* @param <T>
* @see com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
*/
private static class EmptyWrapper<T> extends QueryWrapper<T> {
private static final long serialVersionUID = -2515957613998092272L;
@Override
public T getEntity() {
return null;
}
@Override
public Wrappers.EmptyWrapper<T> setEntity(T entity) {
throw new UnsupportedOperationException();
}
@Override
public String getSqlSelect() {
return null;
}
@Override
public MergeSegments getExpression() {
return null;
}
@Override
public boolean isEmptyOfWhere() {
return true;
}
@Override
public boolean isEmptyOfNormal() {
return true;
}
@Override
public boolean nonEmptyOfEntity() {
return !isEmptyOfEntity();
}
@Override
public boolean isEmptyOfEntity() {
return true;
}
@Override
protected void initEntityClass() {
}
@Override
protected Class<T> getCheckEntityClass() {
throw new UnsupportedOperationException();
}
@Override
public Wrappers.EmptyWrapper<T> last(boolean condition, String lastSql) {
throw new UnsupportedOperationException();
}
@Override
protected Wrappers.EmptyWrapper<T> doIt(boolean condition, ISqlSegment... sqlSegments) {
throw new UnsupportedOperationException();
}
@Override
public String getSqlSegment() {
return null;
}
@Override
public Map<String, Object> getParamNameValuePairs() {
return Collections.emptyMap();
}
@Override
protected String columnsToString(String... columns) {
return null;
}
@Override
protected String columnToString(String column) {
return null;
}
@Override
protected Wrappers.EmptyWrapper<T> instance() {
throw new UnsupportedOperationException();
}
}
}