ny
昨天 b6f169fe43a2b13f351aefc152374fc7f0bc8cb7
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
package jnpf.permission.mapper;
 
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import jnpf.base.Pagination;
import jnpf.base.mapper.SuperMapper;
import jnpf.permission.entity.UserEntity;
import jnpf.permission.model.rolerelaiton.RoleRelationPage;
import jnpf.permission.model.user.UserSystemCountModel;
import jnpf.permission.model.user.page.PageUser;
import jnpf.permission.model.user.page.PaginationUser;
import jnpf.util.StringUtil;
import jnpf.util.UserProvider;
import org.apache.ibatis.annotations.Param;
 
import java.util.*;
 
import static jnpf.util.Constants.ADMIN_KEY;
 
 
/**
 * 用户信息
 *
 * @author JNPF开发平台组
 * @version V3.1.0
 * @copyright 引迈信息技术有限公司
 * @date 2019年9月26日 上午9:18
 */
public interface UserMapper extends SuperMapper<UserEntity> {
    /**
     * 获取用户id
     *
     * @return
     */
    List<String> getListId();
 
    /**
     * 通过组织id获取用户信息
     *
     * @param orgIdList
     * @param gender
     * @return
     */
    List<String> query(@Param("orgIdList") List<String> orgIdList, @Param("account") String account, @Param("dbSchema") String dbSchema, @Param("enabledMark") Integer enabledMark, @Param("gender") String gender);
 
    /**
     * 通过组织id获取用户信息
     *
     * @param orgIdList
     * @param gender
     * @return
     */
    Long count(@Param("orgIdList") List<String> orgIdList, @Param("account") String account, @Param("dbSchema") String dbSchema, @Param("enabledMark") Integer enabledMark, @Param("gender") String gender);
 
    default List<UserEntity> getList(boolean filterEnabledMark) {
        QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
        if (filterEnabledMark) {
            queryWrapper.lambda().ne(UserEntity::getEnabledMark, 0);
        }
        queryWrapper.lambda().ne(UserEntity::getAccount, ADMIN_KEY);
        queryWrapper.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime);
        return this.selectList(queryWrapper);
    }
 
    default List<UserEntity> getUserNameList(List<String> idList) {
        if (idList.size() > 0) {
            QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().select(UserEntity::getId, UserEntity::getRealName, UserEntity::getEnabledMark).in(UserEntity::getId, idList);
            return this.selectList(queryWrapper);
        }
        return new ArrayList<>();
    }
 
    default List<UserEntity> getUserNameList(Set<String> idList) {
        if (idList.size() > 0) {
            QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().select(UserEntity::getId, UserEntity::getRealName, UserEntity::getAccount).in(UserEntity::getId, idList);
            return this.selectList(queryWrapper);
        }
        return new ArrayList<>();
    }
 
    default Map<String, Object> getUserMap() {
        QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().select(UserEntity::getId, UserEntity::getRealName, UserEntity::getAccount);
        Map<String, Object> userMap = new HashMap<>();
        this.selectList(queryWrapper).stream().forEach(user -> userMap.put(user.getId(), user.getRealName() + "/" + user.getAccount()));
        return userMap;
    }
 
    default Map<String, Object> getUserNameAndIdMap() {
        QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().select(UserEntity::getId, UserEntity::getRealName, UserEntity::getAccount);
        Map<String, Object> userMap = new HashMap<>();
        this.selectList(queryWrapper).stream().forEach(user -> userMap.put(user.getRealName() + "/" + user.getAccount(), user.getId()));
        return userMap;
    }
 
    default Map<String, Object> getUserNameAndIdMap(boolean enabledMark) {
        QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
        if (enabledMark) {
            queryWrapper.lambda().ne(UserEntity::getEnabledMark, 0);
        }
        queryWrapper.lambda().select(UserEntity::getId, UserEntity::getRealName, UserEntity::getAccount);
        Map<String, Object> userMap = new HashMap<>();
        this.selectList(queryWrapper).stream().forEach(user -> userMap.put(user.getRealName() + "/" + user.getAccount(), user.getId()));
        return userMap;
    }
 
    default UserEntity getByRealName(String realName) {
        UserEntity userEntity = new UserEntity();
        QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(UserEntity::getRealName, realName);
        queryWrapper.lambda().select(UserEntity::getId);
        List<UserEntity> list = this.selectList(queryWrapper);
        if (list.size() > 0) {
            userEntity = list.get(0);
        }
        return userEntity;
    }
 
    default UserEntity getByRealName(String realName, String account) {
        UserEntity userEntity = new UserEntity();
        QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(UserEntity::getRealName, realName);
        queryWrapper.lambda().eq(UserEntity::getAccount, account);
        queryWrapper.lambda().select(UserEntity::getId);
        List<UserEntity> list = this.selectList(queryWrapper);
        if (list.size() > 0) {
            userEntity = list.get(0);
        }
        return userEntity;
    }
 
    default List<UserEntity> getAdminList() {
        QueryWrapper<UserEntity> query = new QueryWrapper<>();
        query.lambda().eq(UserEntity::getIsAdministrator, 1);
        query.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime);
        return selectList(query);
    }
 
    default List<UserEntity> getList(PageUser pagination, Boolean filterCurrentUser) {
        // 定义变量判断是否需要使用修改时间倒序
        boolean filterLastTime = false;
        QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
        if (filterCurrentUser) {
            String userId = UserProvider.getUser().getUserId();
            queryWrapper.lambda().ne(UserEntity::getId, userId);
        }
        queryWrapper.lambda().ne(UserEntity::getEnabledMark, 0);
        //关键字(账户、姓名、手机)
        if (!StringUtil.isEmpty(pagination.getKeyword())) {
            filterLastTime = true;
            queryWrapper.lambda().and(
                    t -> t.like(UserEntity::getAccount, pagination.getKeyword())
                            .or().like(UserEntity::getRealName, pagination.getKeyword())
                            .or().like(UserEntity::getMobilePhone, pagination.getKeyword())
            );
        }
        if (CollectionUtil.isNotEmpty(pagination.getIdList())) {
            List<List<String>> partition = Lists.partition(pagination.getIdList(), 1000);
            queryWrapper.lambda().and(t -> {
                for (List<String> list : partition) {
                    t.in(UserEntity::getId, list).or();
                }
            });
        }
        //排序
        queryWrapper.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime);
        if (filterLastTime) {
            queryWrapper.lambda().orderByDesc(UserEntity::getLastModifyTime);
        }
        Page<UserEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
        IPage<UserEntity> iPage = this.selectPage(page, queryWrapper);
        return pagination.setData(iPage.getRecords(), iPage.getTotal());
    }
 
    default List<UserEntity> getUserPage(Pagination pagination) {
        QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().ne(UserEntity::getEnabledMark, 0);
        if (StringUtil.isNotEmpty(pagination.getKeyword())) {
            //通过关键字查询
            queryWrapper.lambda().and(
                    t -> t.like(UserEntity::getAccount, pagination.getKeyword())
                            .or().like(UserEntity::getRealName, pagination.getKeyword())
                            .or().like(UserEntity::getMobilePhone, pagination.getKeyword())
            );
        }
        queryWrapper.lambda().ne(UserEntity::getEnabledMark, 0);
        queryWrapper.lambda().select(UserEntity::getId, UserEntity::getAccount, UserEntity::getRealName, UserEntity::getGender, UserEntity::getEnabledMark);
        Page<UserEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
        IPage<UserEntity> iPage = this.selectPage(page, queryWrapper);
        return iPage.getRecords();
    }
 
    default List<UserEntity> getListByManagerId(String managerId, String keyword) {
        QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(UserEntity::getManagerId, managerId);
        // 通过关键字查询
        if (StringUtil.isNotEmpty(keyword)) {
            queryWrapper.lambda().and(
                    t -> t.like(UserEntity::getAccount, keyword)
                            .or().like(UserEntity::getRealName, keyword)
            );
        }
        // 只查询正常的用户
        queryWrapper.lambda().ne(UserEntity::getEnabledMark, 0);
        queryWrapper.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime);
        return this.selectList(queryWrapper);
    }
 
    default UserEntity getInfo(String id) {
        return this.selectById(id);
    }
 
    default UserEntity getUserByAccount(String account) {
        QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(UserEntity::getAccount, account);
        return this.selectOne(queryWrapper);
    }
 
    default UserEntity getUserByMobile(String mobile) {
        QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(UserEntity::getMobilePhone, mobile);
        List<UserEntity> list = this.selectList(queryWrapper);
        return CollectionUtil.isNotEmpty(list) ? list.get(0) : null;
    }
 
    default boolean isExistByAccount(String account) {
        QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(UserEntity::getAccount, account);
        List<UserEntity> list = this.selectList(queryWrapper);
        if (CollectionUtil.isNotEmpty(list)) {
            return true;
        }
        return false;
    }
 
 
    default List<UserEntity> getUserName(List<String> id) {
        return getUserName(id, false);
    }
 
    /**
     * 查询用户名称
     *
     * @param id 主键值
     * @return
     */
    default List<UserEntity> getUserName(List<String> id, boolean filterEnabledMark) {
        List<UserEntity> list = new ArrayList<>();
        // 达梦数据库无法null值入参
        id.removeAll(Collections.singleton(null));
        if (id.size() > 0) {
            QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().in(UserEntity::getId, id);
            if (filterEnabledMark) {
                queryWrapper.lambda().ne(UserEntity::getEnabledMark, 0);
            }
            list = this.selectList(queryWrapper);
        }
        return list;
    }
 
    default List<UserEntity> getListByUserIds(List<String> id) {
        List<UserEntity> list = new ArrayList<>();
        // 达梦数据库无法null值入参
        id.removeAll(Collections.singleton(null));
        if (id.size() > 0) {
            QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().in(UserEntity::getId, id);
            list = this.selectList(queryWrapper);
        }
        return list;
    }
 
    default List<UserEntity> getUserList(List<String> id) {
        List<UserEntity> list = new ArrayList<>();
        // 达梦数据库无法null值入参
        id.removeAll(Collections.singleton(null));
        if (id.size() > 0) {
            QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().in(UserEntity::getId, id);
            queryWrapper.lambda().ne(UserEntity::getEnabledMark, 0);
            list = this.selectList(queryWrapper);
        }
        return list;
    }
 
    default UserEntity getUserEntity(String account) {
        QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(UserEntity::getAccount, account);
        return this.selectOne(queryWrapper);
    }
 
    default void update(UserEntity entity, String type) {
        UpdateWrapper<UserEntity> wrapper = new UpdateWrapper<>();
        if ("Position".equals(type)) {
            wrapper.lambda().set(UserEntity::getPositionId, entity.getPositionId());
        } else {
            wrapper.lambda().set(UserEntity::getRoleId, entity.getRoleId());
        }
        wrapper.lambda().eq(UserEntity::getId, entity.getId());
        this.update(wrapper);
    }
 
    default void updateLastTime(UserEntity entity, String type) {
        UpdateWrapper<UserEntity> wrapper = new UpdateWrapper<>();
        if ("Position".equals(type)) {
            wrapper.lambda().set(UserEntity::getPositionId, entity.getPositionId());
        } else {
            wrapper.lambda().set(UserEntity::getRoleId, entity.getRoleId());
        }
        wrapper.lambda().set(UserEntity::getLastModifyTime, new Date());
        wrapper.lambda().set(UserEntity::getLastModifyUserId, entity.getLastModifyUserId());
        wrapper.lambda().eq(UserEntity::getId, entity.getId());
        this.update(wrapper);
    }
 
    default List<UserEntity> getUserName(List<String> id, Pagination pagination) {
        List<UserEntity> list = new ArrayList<>();
        id.removeAll(Collections.singleton(null));
        if (id.size() > 0) {
            QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
            if (!StringUtil.isEmpty(pagination.getKeyword())) {
                queryWrapper.lambda().and(
                        t -> t.like(UserEntity::getRealName, pagination.getKeyword())
                                .or().like(UserEntity::getAccount, pagination.getKeyword())
                );
            }
            queryWrapper.lambda().in(UserEntity::getId, id);
            queryWrapper.lambda().ne(UserEntity::getEnabledMark, 0);
            queryWrapper.lambda().select(UserEntity::getId, UserEntity::getRealName, UserEntity::getAccount,
                    UserEntity::getGender, UserEntity::getHeadIcon, UserEntity::getMobilePhone);
            Page<UserEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
            IPage<UserEntity> iPage = this.selectPage(page, queryWrapper);
            return pagination.setData(iPage.getRecords(), iPage.getTotal());
        }
        return pagination.setData(list, list.size());
    }
 
    default List<UserEntity> getUserNames(List<String> id, PaginationUser pagination, Boolean flag, Boolean enabledMark) {
        List<UserEntity> list = new ArrayList<>();
        id.removeAll(Collections.singleton(null));
        if (id.size() > 0) {
            QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
            if (!StringUtil.isEmpty(pagination.getKeyword())) {
                queryWrapper.lambda().and(
                        t -> t.like(UserEntity::getRealName, pagination.getKeyword())
                                .or().like(UserEntity::getAccount, pagination.getKeyword())
                                .or().like(UserEntity::getMobilePhone, pagination.getKeyword())
                );
            }
            List<List<String>> lists = Lists.partition(id, 1000);
            queryWrapper.lambda().and(t -> {
                for (List<String> userId : lists) {
                    t.or().in(UserEntity::getId, userId);
                }
            });
            if (flag) {
                queryWrapper.lambda().ne(UserEntity::getId, UserProvider.getUser().getUserId());
            }
            if (enabledMark) {
                queryWrapper.lambda().ne(UserEntity::getEnabledMark, 0);
            }
            if (StringUtil.isNotEmpty(pagination.getGender())) {
                queryWrapper.lambda().eq(UserEntity::getGender, pagination.getGender());
            }
            queryWrapper.lambda().orderByDesc(UserEntity::getCreatorTime);
//            queryWrapper.lambda().select(UserEntity::getId, UserEntity::getRealName, UserEntity::getAccount,
//                    UserEntity::getGender, UserEntity::getMobilePhone);
            if (ObjectUtil.isEmpty(pagination) || Objects.equals(pagination.getDataType(), 1)) {
                return this.selectList(queryWrapper);
            }
            Page<UserEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
            IPage<UserEntity> iPage = this.selectPage(page, queryWrapper);
            return pagination.setData(iPage.getRecords(), iPage.getTotal());
        }
        return ObjectUtil.isEmpty(pagination) ? new ArrayList<>() : pagination.setData(list, list.size());
    }
 
    default List<UserEntity> getUserAccount(List<String> ids) {
        List<UserEntity> list = new ArrayList<>();
        if (!ids.isEmpty()) {
            QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().in(UserEntity::getAccount, ids);
            list = this.selectList(queryWrapper);
        }
        return list;
    }
 
    default void updateStand(List<String> ids, int standing) {
        List<UserEntity> userName = getUserName(new ArrayList<>(ids), false);
        for (UserEntity user : userName) {
            String positionId = user.getPositionId();
            String organizeId = user.getOrganizeId();
            String id = user.getId();
            UpdateWrapper<UserEntity> wrapper = new UpdateWrapper<>();
            wrapper.lambda().eq(UserEntity::getId, id);
            wrapper.lambda().set(UserEntity::getOrganizeId, organizeId);
            wrapper.lambda().set(UserEntity::getPositionId, positionId);
            update(wrapper);
        }
        if (!ids.isEmpty()) {
            UpdateWrapper<UserEntity> pcWrapper = new UpdateWrapper<>();
            pcWrapper.lambda().in(UserEntity::getId, ids);
            pcWrapper.lambda().eq(UserEntity::getStanding, standing);
            pcWrapper.lambda().set(UserEntity::getStanding, 3);
            update(pcWrapper);
            UpdateWrapper<UserEntity> appWrapper = new UpdateWrapper<>();
            appWrapper.lambda().in(UserEntity::getId, ids);
            appWrapper.lambda().eq(UserEntity::getAppStanding, standing);
            appWrapper.lambda().set(UserEntity::getAppStanding, 3);
            update(appWrapper);
        }
    }
 
    default List<UserEntity> getPageByIds(RoleRelationPage pagination) {
        QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().select(UserEntity::getId, UserEntity::getAccount, UserEntity::getRealName, UserEntity::getGender,
                UserEntity::getMobilePhone, UserEntity::getEnabledMark);
        boolean flag = false;
        //关键字(账户、姓名、手机)
        if (!StringUtil.isEmpty(pagination.getKeyword())) {
            flag = true;
            queryWrapper.lambda().and(
                    t -> t.like(UserEntity::getAccount, pagination.getKeyword())
                            .or().like(UserEntity::getRealName, pagination.getKeyword())
                            .or().like(UserEntity::getMobilePhone, pagination.getKeyword())
            );
        }
 
        List<List<String>> lists = Lists.partition(pagination.getIdList(), 1000);
        queryWrapper.lambda().and(t -> {
            for (List<String> item : lists) {
                t.in(UserEntity::getId, item).or();
            }
        });
        queryWrapper.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime);
        if (flag) {
            queryWrapper.lambda().orderByDesc(UserEntity::getLastModifyTime);
            return this.selectList(queryWrapper);
        }
        Page<UserEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
        IPage<UserEntity> iPage = this.selectPage(page, queryWrapper);
        return pagination.setData(iPage.getRecords(), iPage.getTotal());
    }
 
    default List<UserEntity> pageUser(UserSystemCountModel userSystemCountModel) {
        if (CollectionUtil.isEmpty(userSystemCountModel.getCollect())) {
            return Collections.emptyList();
        }
        QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
        if (userSystemCountModel.isFilter()) {
            queryWrapper.lambda().ne(UserEntity::getEnabledMark, 0);
        }
        if (!StringUtil.isEmpty(userSystemCountModel.getPagination().getKeyword())) {
            queryWrapper.lambda().and(
                    t -> t.like(UserEntity::getAccount, userSystemCountModel.getPagination().getKeyword())
                            .or().like(UserEntity::getRealName, userSystemCountModel.getPagination().getKeyword())
                            .or().like(UserEntity::getMobilePhone, userSystemCountModel.getPagination().getKeyword())
            );
        }
        if (CollectionUtil.isNotEmpty(userSystemCountModel.getCollect())) {
            queryWrapper.lambda().in(UserEntity::getId, userSystemCountModel.getCollect());
        }
 
        long count = this.selectCount(queryWrapper);
        queryWrapper.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime);
        Page<UserEntity> page = new Page<>(userSystemCountModel.getPagination().getCurrentPage()
                , userSystemCountModel.getPagination().getPageSize(), count, false);
        page.setOptimizeCountSql(true);
        Page<UserEntity> userEntityPage = this.selectPage(page, queryWrapper);
        List<UserEntity> entities = userSystemCountModel.getPagination().setData(userEntityPage.getRecords(), page.getTotal());
        return entities;
    }
}