yangys
2024-04-04 ed4a5236bab800094be4a8378f5098eebe3de6ac
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
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
package com.qianwen.smartman.modules.system.service.impl;
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
 
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.qianwen.core.log.exception.ServiceException;
import com.qianwen.core.mp.base.BaseServiceImpl;
import com.qianwen.core.mp.support.Condition;
import com.qianwen.core.mp.support.Query;
import com.qianwen.core.redis.cache.BladeRedis;
import com.qianwen.core.secure.BladeUser;
import com.qianwen.core.secure.utils.AuthUtil;
import com.qianwen.core.tenant.BladeTenantProperties;
import com.qianwen.core.tool.jackson.JsonUtil;
import com.qianwen.core.tool.support.Kv;
import com.qianwen.core.tool.utils.BeanUtil;
import com.qianwen.core.tool.utils.DateUtil;
import com.qianwen.core.tool.utils.DesUtil;
import com.qianwen.core.tool.utils.DigestUtil;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.core.tool.utils.ObjectUtil;
import com.qianwen.core.tool.utils.StringUtil;
import com.qianwen.smartman.common.cache.CacheNames;
import com.qianwen.smartman.common.cache.DictCache;
import com.qianwen.smartman.common.cache.ParamCache;
import com.qianwen.smartman.common.cache.SysCache;
import com.qianwen.smartman.common.cache.UserCache;
import com.qianwen.smartman.common.constant.CommonConstant;
import com.qianwen.smartman.common.constant.DncConstant;
import com.qianwen.smartman.common.constant.TenantConstant;
import com.qianwen.smartman.common.constant.UserConstant;
import com.qianwen.smartman.common.enums.DictEnum;
import com.qianwen.smartman.common.utils.Lambda;
import com.qianwen.smartman.modules.auth.enums.UserEnum;
import com.qianwen.smartman.modules.cps.entity.Employee;
import com.qianwen.smartman.modules.cps.service.IEmployeeService;
import com.qianwen.smartman.modules.notify.dto.NotifyUserDTO;
import com.qianwen.smartman.modules.sync.constant.DingConstant;
import com.qianwen.smartman.modules.sync.constant.OuterAppConfigConstant;
import com.qianwen.smartman.modules.sync.constant.QyWechatConstant;
import com.qianwen.smartman.modules.sync.entity.OuterAppConfig;
import com.qianwen.smartman.modules.sync.service.IOuterAppConfigService;
import com.qianwen.smartman.modules.system.entity.Tenant;
import com.qianwen.smartman.modules.system.entity.User;
import com.qianwen.smartman.modules.system.entity.UserApp;
import com.qianwen.smartman.modules.system.entity.UserDept;
import com.qianwen.smartman.modules.system.entity.UserInfo;
import com.qianwen.smartman.modules.system.entity.UserOauth;
import com.qianwen.smartman.modules.system.entity.UserOther;
import com.qianwen.smartman.modules.system.entity.UserWeb;
import com.qianwen.smartman.modules.system.excel.UserExcel;
import com.qianwen.smartman.modules.system.mapper.UserMapper;
import com.qianwen.smartman.modules.system.service.IRoleService;
import com.qianwen.smartman.modules.system.service.IUserDeptService;
import com.qianwen.smartman.modules.system.service.IUserOauthService;
import com.qianwen.smartman.modules.system.service.IUserService;
import com.qianwen.smartman.modules.system.service.IWorkbenchService;
import com.qianwen.smartman.modules.system.vo.QuCreAccBackMessageVO;
import com.qianwen.smartman.modules.system.vo.QuCreAccBackUserVO;
import com.qianwen.smartman.modules.system.vo.QuickCreationAccountVO;
import com.qianwen.smartman.modules.system.vo.QuickCreationUserVO;
import com.qianwen.smartman.modules.system.vo.UserAccountVO;
import com.qianwen.smartman.modules.system.vo.UserVO;
import com.qianwen.smartman.modules.system.wrapper.UserWrapper;
 
import cn.hutool.core.convert.Convert;
 
@Service
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/system/service/impl/UserServiceImpl.class */
public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implements IUserService {
    private static final String GUEST_NAME = "guest";
    private final IUserDeptService userDeptService;
    private final IUserOauthService userOauthService;
    private final IRoleService roleService;
    private final BladeTenantProperties tenantProperties;
    private final BladeRedis bladeRedis;
    private final IEmployeeService employeeService;
    private final IWorkbenchService workbenchService;
    private final IOuterAppConfigService outerAppConfigService;
 
    public UserServiceImpl(final IUserDeptService userDeptService, final IUserOauthService userOauthService, final IRoleService roleService, final BladeTenantProperties tenantProperties, final BladeRedis bladeRedis, final IEmployeeService employeeService, final IWorkbenchService workbenchService, final IOuterAppConfigService outerAppConfigService) {
        this.userDeptService = userDeptService;
        this.userOauthService = userOauthService;
        this.roleService = roleService;
        this.tenantProperties = tenantProperties;
        this.bladeRedis = bladeRedis;
        this.employeeService = employeeService;
        this.workbenchService = workbenchService;
        this.outerAppConfigService = outerAppConfigService;
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    @Transactional(rollbackFor = {Exception.class})
    public boolean submit(User user) {
        if (StringUtil.isBlank(user.getTenantId())) {
            user.setTenantId("000000");
        }
        String tenantId = user.getTenantId();
        Tenant tenant = SysCache.getTenant(tenantId);
        if (Func.isNotEmpty(tenant)) {
            Integer accountNumber = tenant.getAccountNumber();
            if (this.tenantProperties.getLicense().booleanValue()) {
                String licenseKey = tenant.getLicenseKey();
                String decrypt = DesUtil.decryptFormHex(licenseKey, TenantConstant.DES_KEY);
                accountNumber = ((Tenant) JsonUtil.parse(decrypt, Tenant.class)).getAccountNumber();
            }
            
            Long tenantCount = this.baseMapper.selectCount(Wrappers.<User>query().lambda().eq(User::getTenantId, tenantId));
            /*
            Long tenantCount = ((UserMapper) this.baseMapper).selectCount((Wrapper) Wrappers.query().lambda().eq((v0) -> {
                return v0.getTenantId();
            }, tenantId));*/
            if (accountNumber != null && accountNumber.intValue() > 0 && accountNumber.intValue() <= tenantCount.longValue()) {
                throw new ServiceException("当前租户已到最大账号额度!");
            }
        }
        String securityLevelSetting = ParamCache.getValue("account.passwordModifySecurityLevel");
        Integer securityLevel = (Integer) Convert.convert(Integer.class, securityLevelSetting, 0);
        Boolean isAdd = false;
        if (user.getId() == null) {
            if (!meetSecurityLevel(securityLevel.intValue(), user.getPassword())) {
                throw new ServiceException("密码强度校验不通过,密码强度等级:" + securityLevel);
            }
            if (Func.isNotEmpty(user.getPassword())) {
                user.setPassword(DigestUtil.encrypt(user.getPassword()));
            }
            isAdd = true;
        }
        Long userCount = this.baseMapper.selectCount(Wrappers.<User>query().lambda().eq(User::getTenantId, tenantId).eq(User::getAccount, user.getAccount()));
        /*
        Long userCount = ((UserMapper) this.baseMapper).selectCount((Wrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> {
            return v0.getTenantId();
        }, tenantId)).eq((v0) -> {
            return v0.getAccount();
        }, user.getAccount()));*/
        if (userCount.longValue() > 0 && Func.isEmpty(user.getId())) {
            throw new ServiceException(StringUtil.format("当前用户 [{}] 已存在!", new Object[]{user.getAccount()}));
        }
        Long oldEmployeeId = null;
        if (user.getId() != null) {
            User userParam = new User();
            userParam.setId(user.getId());
            User currentUser = detail(userParam);
            oldEmployeeId = currentUser.getEmployeeId();
        }
        Boolean flag = Boolean.valueOf(saveOrUpdate(user) && submitUserDept(user));
        if (isAdd.booleanValue()) {
            this.workbenchService.initWorkbench(user.getId(), user.getRealName());
        }
        return flag.booleanValue() && this.employeeService.changeUserId(user.getEmployeeId(), oldEmployeeId, user.getId()).booleanValue();
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    @Transactional(rollbackFor = {Exception.class})
    public boolean updateUser(User user) {
        String tenantId = user.getTenantId();
        Long userCount = this.baseMapper.selectCount(
                Wrappers.<User>query().lambda()
                .eq(User::getTenantId, tenantId)
                .eq(User::getAccount, user.getAccount())
                .notIn(User::getId, new Object[] { user.getId() }));
        /*
        Long userCount = ((UserMapper) this.baseMapper).selectCount((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> {
            return v0.getTenantId();
        }, tenantId)).eq((v0) -> {
            return v0.getAccount();
        }, user.getAccount())).notIn((v0) -> {
            return v0.getId();
        }, new Object[]{user.getId()}));*/
        if (userCount.longValue() > 0) {
            throw new ServiceException(StringUtil.format("当前用户 [{}] 已存在!", new Object[]{user.getAccount()}));
        }
        return updateUserInfo(user) && submitUserDept(user);
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    public boolean updateUserInfo(User user) {
        user.setPassword(null);
        return updateById(user);
    }
 
    private boolean submitUserDept(User user) {
        List<Long> deptIdList = Func.toLongList(user.getDeptId());
        List<UserDept> userDeptList = new ArrayList<>();
        deptIdList.forEach(deptId -> {
            UserDept userDept = new UserDept();
            userDept.setUserId(user.getId());
            userDept.setDeptId(deptId);
            userDeptList.add(userDept);
        });
        this.userDeptService.remove(Wrappers.<UserDept>update().lambda().eq(UserDept::getUserId, user.getId()));
        /*
        this.userDeptService.remove((Wrapper) Wrappers.update().lambda().eq((v0) -> {
            return v0.getUserId();
        }, user.getId()));*/
        return this.userDeptService.saveBatch(userDeptList);
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    public IPage<User> selectUserPage(IPage<User> page, User user, Long deptId, String tenantId) {
        List<Long> deptIdList = SysCache.getDeptChildIds(deptId);
        return page.setRecords(((UserMapper) this.baseMapper).selectUserPage(page, user, deptIdList, tenantId));
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    public IPage<UserVO> selectUserSearch(UserVO user, Query query) {
        LambdaQueryWrapper<User> queryWrapper = Wrappers.<User>query().lambda();
        if (StringUtil.isNotBlank(user.getAccount())) {
            queryWrapper.likeRight((v0) -> {
                return v0.getAccount();
            }, user.getAccount());
        }
        if (StringUtil.isNotBlank(user.getDeptName())) {
            String deptIds = SysCache.getDeptIdsByFuzzy(AuthUtil.getTenantId(), user.getDeptName());
            if (StringUtil.isNotBlank(deptIds)) {
                queryWrapper.and(wrapper -> {
                    List<String> ids = Func.toStrList(deptIds);
                    ids.forEach(id -> {
                        LambdaQueryWrapper lambdaQueryWrapper = wrapper.like((v0) -> {
                            return v0.getDeptId();
                        }, id).or();
                    });
                });
            }
        }
        if (StringUtil.isNotBlank(user.getPostName())) {
            String postIds = SysCache.getPostIdsByFuzzy(AuthUtil.getTenantId(), user.getPostName());
            if (StringUtil.isNotBlank(postIds)) {
                queryWrapper.and(wrapper2 -> {
                    List<String> ids = Func.toStrList(postIds);
                    ids.forEach(id -> {
                        LambdaQueryWrapper lambdaQueryWrapper = wrapper2.like((v0) -> {
                            return v0.getPostId();
                        }, id).or();
                    });
                });
            }
        }
        IPage<User> pages = page(Condition.getPage(query), queryWrapper);
        return UserWrapper.build().pageVO(pages);
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    public User userByAccount(String tenantId, String account) {
        return this.baseMapper.selectOne(Wrappers.<User>query().lambda().eq(User::getTenantId, tenantId)
                .eq(User::getAccount, account).eq(User::getIsDeleted, 0));
        /*
        return (User) ((UserMapper) this.baseMapper).selectOne((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> {
            return v0.getTenantId();
        }, tenantId)).eq((v0) -> {
            return v0.getAccount();
        }, account)).eq((v0) -> {
            return v0.getIsDeleted();
        }, 0));*/
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    public UserInfo userInfo(Long userId) {
        User user = (User) ((UserMapper) this.baseMapper).selectById(userId);
        return buildUserInfo(user);
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    public UserInfo userInfo(String tenantId, String account, String password) {
        User user = ((UserMapper) this.baseMapper).getUser(tenantId, account, password);
        return buildUserInfo(user);
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    public UserInfo userInfo(String tenantId, String account, String password, UserEnum userEnum) {
        User user = ((UserMapper) this.baseMapper).getUser(tenantId, account, password);
        return buildUserInfo(user, userEnum);
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    public UserInfo buildUserInfo(User user) {
        return buildUserInfo(user, UserEnum.WEB);
    }
 
    private UserInfo buildUserInfo(User user, UserEnum userEnum) {
        if (ObjectUtil.isEmpty(user)) {
            return null;
        }
        UserInfo userInfo = new UserInfo();
        userInfo.setUser(user);
        if (Func.isNotEmpty(user)) {
            List<String> roleAlias = this.roleService.getRoleAliases(user.getRoleId());
            userInfo.setRoles(roleAlias);
        }
        Kv detail = Kv.create().set("type", userEnum.getName());
        if (userEnum == UserEnum.WEB) {
            UserWeb userWeb = new UserWeb();
            UserWeb query = userWeb.selectOne(Wrappers.<UserWeb>lambdaQuery().eq(UserWeb::getUserId, user.getId()));
            /*
            UserWeb query = (UserWeb) userWeb.selectOne((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
                return v0.getUserId();
            }, user.getId()));*/
            if (ObjectUtil.isNotEmpty(query)) {
                detail.set("ext", query.getUserExt());
            }
        } else if (userEnum == UserEnum.APP) {
            UserApp userApp = new UserApp();
            UserApp query = userApp.selectOne(Wrappers.<UserApp>lambdaQuery().eq(UserApp::getUserId, user.getId()));
            /*                
            UserApp query2 = (UserApp) userApp.selectOne((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
                return v0.getUserId();
            }, user.getId()));*/
            if (ObjectUtil.isNotEmpty(query)) {
                detail.set("ext", query.getUserExt());
            }
        } else {
            UserOther userOther = new UserOther();
            UserOther query = (UserOther)userOther.selectOne(Wrappers.<UserOther>lambdaQuery().eq(UserOther::getUserId, user.getId()));
            /*
            UserOther query3 = (UserOther) userOther.selectOne((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
                return v0.getUserId();
            }, user.getId()));*/
            if (ObjectUtil.isNotEmpty(query)) {
                detail.set("ext", query.getUserExt());
            }
        }
        userInfo.setDetail(detail);
        return userInfo;
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    @Transactional(rollbackFor = {Exception.class})
    public UserInfo userInfo(UserOauth userOauth) {
        UserInfo userInfo;
        UserOauth uo = this.userOauthService.getOne(Wrappers.<UserOauth>query().lambda()
                .eq(UserOauth::getUuid, userOauth.getUuid())
                .eq(UserOauth::getSource, userOauth.getSource()));
        /*
        UserOauth uo = (UserOauth) this.userOauthService.getOne((Wrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> {
            return v0.getUuid();
        }, userOauth.getUuid())).eq((v0) -> {
            return v0.getSource();
        }, userOauth.getSource()));*/
        if (Func.isNotEmpty(uo) && Func.isNotEmpty(uo.getUserId())) {
            userOauth.setId(uo.getId());
            this.userOauthService.updateById(userOauth);
            userInfo = userInfo(uo.getUserId());
            userInfo.setOauthId(Func.toStr(uo.getId()));
        } else {
            userInfo = new UserInfo();
            if (Func.isEmpty(uo)) {
                this.userOauthService.save(userOauth);
                userInfo.setOauthId(Func.toStr(userOauth.getId()));
            } else {
                userOauth.setId(uo.getId());
                this.userOauthService.updateById(userOauth);
                userInfo.setOauthId(Func.toStr(uo.getId()));
            }
            User user = new User();
            user.setAccount(userOauth.getUsername());
            user.setTenantId(userOauth.getTenantId());
            userInfo.setUser(user);
            userInfo.setRoles(Collections.singletonList(GUEST_NAME));
        }
        return userInfo;
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    public boolean grant(String userIds, String roleIds) {
        User user = new User();
        user.setRoleId(roleIds);
        return update(user, Wrappers.<User>update().lambda().in(User::getId, Func.toLongList(userIds)));
        /*
        return update(user, (Wrapper) Wrappers.update().lambda().in((v0) -> {
            return v0.getId();
        }, Func.toLongList(userIds)));*/
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    public boolean resetPassword(String userIds) {
        User user = new User();
        user.setPassword(DigestUtil.encrypt(ParamCache.getValue(CommonConstant.DEFAULT_PARAM_PASSWORD)));
        user.setUpdateTime(DateUtil.now());
        user.setPwdUpdateDate(null);
        return update(user, Wrappers.<User>update().lambda().in(User::getId, Func.toLongList(userIds)));
        /*
        return update(user, (Wrapper) Wrappers.update().lambda().in((v0) -> {
            return v0.getId();
        }, Func.toLongList(userIds)));*/
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    public boolean updatePassword(Long userId, String oldPassword, String newPassword, String newPassword1) {
        User user = (User) getById(userId);
        if (!newPassword.equals(newPassword1)) {
            throw new ServiceException("请输入正确的确认密码!");
        }
        if (!user.getPassword().equals(DigestUtil.encrypt(oldPassword))) {
            throw new ServiceException("原密码不正确!");
        }
        if (oldPassword.equals(newPassword)) {
            throw new ServiceException("新密码不能与原密码相同!");
        }
        String securityLevelSetting = ParamCache.getValue("account.passwordModifySecurityLevel");
        Integer securityLevel = (Integer) Convert.convert(Integer.class, securityLevelSetting, 0);
        if (!meetSecurityLevel(securityLevel.intValue(), newPassword)) {
            throw new ServiceException("密码强度校验不通过,密码强度等级:" + securityLevel);
        }
        return update(
                Wrappers.<User>update().lambda()
                .set(User::getPassword, DigestUtil.encrypt(newPassword))
                .set(User::getPwdUpdateDate, DateUtil.now())
                .eq(User::getId, userId));
        /*
        return update((Wrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) Wrappers.update().lambda().set((v0) -> {
            return v0.getPassword();
        }, DigestUtil.encrypt(newPassword))).set((v0) -> {
            return v0.getPwdUpdateDate();
        }, DateUtil.now())).eq((v0) -> {
            return v0.getId();
        }, userId));*/
    }
 
    private boolean meetSecurityLevel(int level, String password) {
        Boolean result;
        String passwordLengthRegx = ParamCache.getValue("account.passwordModifyLength");
        String levelZero = "^[a-zA-Z0-9\\W]" + passwordLengthRegx + "$";
        String levelOne = "^(?![a-z]+$)(?![A-Z]+$)(?![0-9]+$)(?![\\W]+$)[a-zA-Z0-9\\W]" + passwordLengthRegx + "$";
        String levelTwo = "^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\\W]+$)(?![a-z0-9]+$)(?![a-z\\W]+$)(?![0-9\\W]+$)[a-zA-Z0-9\\W]" + passwordLengthRegx + "$";
        String levelThree = "^(?![A-Za-z0-9]+$)(?![a-z0-9\\W]+$)(?![A-Za-z\\W]+$)(?![A-Z0-9\\W]+$)[a-zA-Z0-9\\W]" + passwordLengthRegx + "$";
        switch (level) {
            case 1:
                result = Boolean.valueOf(password.matches(levelOne));
                break;
            case 2:
                result = Boolean.valueOf(password.matches(levelTwo));
                break;
            case 3:
                result = Boolean.valueOf(password.matches(levelThree));
                break;
            default:
                result = Boolean.valueOf(password.matches(levelZero));
                break;
        }
        return result.booleanValue();
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    @Transactional(rollbackFor = {Exception.class})
    public boolean removeUser(String userIds) {
        Long[] ids = Func.toLongArray(userIds);
        if (Func.contains(ids, AuthUtil.getUserId())) {
            throw new ServiceException("不能删除本账号!");
        }
        this.employeeService.updateUserIdIsNull(Func.toStrList(userIds));
        this.userDeptService.remove(Lambda.in(UserDept::getUserId, (Object[])ids));
        /*
        this.userDeptService.remove(Lambda.in((v0) -> {
            return v0.getUserId();
        }, ids));*/
        return deleteLogic(Func.toLongList(userIds));
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    @Transactional(rollbackFor = {Exception.class})
    public void importUser(List<UserExcel> data, Boolean isCovered) {
        data.forEach(userExcel -> {
            User oldUser;
            User user = (User) Objects.requireNonNull(BeanUtil.copy(userExcel, User.class));
            if (Func.isEmpty(user.getAccount())) {
                return;
            }
            user.setUserType(Integer.valueOf(Func.toInt(DictCache.getKey(DictEnum.USER_TYPE, userExcel.getUserTypeName()), 1)));
            user.setDeptId(SysCache.getDeptIds("000000", userExcel.getDeptName()));
            user.setPostId(SysCache.getPostIds("000000", userExcel.getPostName()));
            user.setRoleId(SysCache.getRoleIds("000000", userExcel.getRoleName()));
            if (!AuthUtil.isAdministrator() || StringUtil.isBlank(user.getTenantId())) {
                user.setTenantId(AuthUtil.getTenantId());
            }
            if (isCovered.booleanValue() && (oldUser = UserCache.getUser("000000", userExcel.getAccount())) != null && oldUser.getId() != null) {
                user.setId(oldUser.getId());
                updateUser(user);
                return;
            }
            String initPassword = DigestUtil.encrypt(ParamCache.getValue(CommonConstant.DEFAULT_PARAM_PASSWORD));
            user.setPassword(initPassword);
            submit(user);
        });
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    public List<UserExcel> exportUser(Wrapper<User> queryWrapper) {
        List<UserExcel> userList = ((UserMapper) this.baseMapper).exportUser(queryWrapper);
        userList.forEach(user -> {
            user.setUserTypeName(DictCache.getValue(DictEnum.USER_TYPE, user.getUserType()));
            user.setRoleName(StringUtil.join(SysCache.getRoleNames(user.getRoleId())));
            user.setDeptName(StringUtil.join(SysCache.getDeptNames(user.getDeptId())));
            user.setPostName(StringUtil.join(SysCache.getPostNames(user.getPostId())));
        });
        return userList;
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    @Transactional(rollbackFor = {Exception.class})
    public boolean registerGuest(User user, Long oauthId) {
        Tenant tenant = SysCache.getTenant(user.getTenantId());
        if (tenant == null || tenant.getId() == null) {
            throw new ServiceException("租户信息错误!");
        }
        UserOauth userOauth = (UserOauth) this.userOauthService.getById(oauthId);
        if (userOauth == null || userOauth.getId() == null) {
            throw new ServiceException("第三方登陆信息错误!");
        }
        user.setRealName(user.getRealName());
        user.setAvatar(userOauth.getAvatar());
        user.setRoleId(DncConstant.DNC_DEFAULT_PARENT_ID);
        user.setDeptId(DncConstant.DNC_DEFAULT_PARENT_ID);
        user.setPostId(DncConstant.DNC_DEFAULT_PARENT_ID);
        boolean userTemp = submit(user);
        userOauth.setUserId(user.getId());
        userOauth.setTenantId(user.getTenantId());
        boolean oauthTemp = this.userOauthService.updateById(userOauth);
        return userTemp && oauthTemp;
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    public boolean updatePlatform(Long userId, Integer userType, String userExt) {
        if (userType.equals(Integer.valueOf(UserEnum.WEB.getCategory()))) {
            UserWeb userWeb = new UserWeb();
            
            UserWeb query = userWeb.selectOne(Wrappers.<UserWeb>lambdaQuery().eq(UserWeb::getUserId, userId));
            /*
            UserWeb query = (UserWeb) userWeb.selectOne((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
                return v0.getUserId();
            }, userId));*/
            if (ObjectUtil.isNotEmpty(query)) {
                userWeb.setId(query.getId());
            }
            userWeb.setUserId(userId);
            userWeb.setUserExt(userExt);
            return userWeb.insertOrUpdate();
        } else if (userType.equals(Integer.valueOf(UserEnum.APP.getCategory()))) {
            UserApp userApp = new UserApp();
            UserApp userApp1 = userApp.selectOne(Wrappers.<UserApp>lambdaQuery().eq(UserApp::getUserId, userId));
            /*
            UserApp query2 = (UserApp) userApp.selectOne((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
                return v0.getUserId();
            }, userId));*/
            if (ObjectUtil.isNotEmpty(userApp1)) {
                userApp.setId(userApp1.getId());
            }
            userApp.setUserId(userId);
            userApp.setUserExt(userExt);
            return userApp.insertOrUpdate();
        } else {
            UserOther userOther = new UserOther();
            UserOther query = userOther.selectOne(Wrappers.<UserOther>lambdaQuery().eq(UserOther::getUserId, userId));
            /*
            UserOther query3 = (UserOther) userOther.selectOne((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
                return v0.getUserId();
            }, userId));*/
            if (ObjectUtil.isNotEmpty(query)) {
                userOther.setId(query.getId());
            }
            userOther.setUserId(userId);
            userOther.setUserExt(userExt);
            return userOther.insertOrUpdate();
        }
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    public UserVO platformDetail(User user) {
        User detail = (User) ((UserMapper) this.baseMapper).selectOne(Condition.getQueryWrapper(user));
        UserVO userVO = UserWrapper.build().entityVO(detail);
        if (userVO.getUserType().equals(Integer.valueOf(UserEnum.WEB.getCategory()))) {
            UserWeb userWeb = new UserWeb();
            UserWeb query = userWeb.selectOne(Wrappers.<UserWeb>lambdaQuery().eq(UserWeb::getUserId, user.getId()));
            /*
            UserWeb query = (UserWeb) userWeb.selectOne((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
                return v0.getUserId();
            }, user.getId()));*/
            if (ObjectUtil.isNotEmpty(query)) {
                userVO.setUserExt(query.getUserExt());
            }
        } else if (userVO.getUserType().equals(Integer.valueOf(UserEnum.APP.getCategory()))) {
            UserApp userApp = new UserApp();
            UserApp query = userApp.selectOne(Wrappers.<UserApp>lambdaQuery().eq(UserApp::getUserId, user.getId()));
            /*
            UserApp query2 = (UserApp) userApp.selectOne((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
                return v0.getUserId();
            }, user.getId()));*/
            if (ObjectUtil.isNotEmpty(query)) {
                userVO.setUserExt(query.getUserExt());
            }
        } else {
            UserOther userOther = new UserOther();
            UserOther query = userOther.selectOne(Wrappers.<UserOther>lambdaQuery().eq(UserOther::getUserId, user.getId()));
            /*
            UserOther query3 = (UserOther) userOther.selectOne((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
                return v0.getUserId();
            }, user.getId()));*/
            if (ObjectUtil.isNotEmpty(query)) {
                userVO.setUserExt(query.getUserExt());
            }
        }
        return userVO;
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    public boolean enable(Long id, boolean enable) {
        Integer value = Integer.valueOf(enable ? 1 : 0);
        return update(Wrappers.<User>update().lambda().set(User::getStatus, value).eq(User::getId, id));
        /*
        return update((Wrapper) ((LambdaUpdateWrapper) Wrappers.update().lambda().set((v0) -> {
            return v0.getStatus();
        }, value)).eq((v0) -> {
            return v0.getId();
        }, id));*/
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    public boolean unlock(Long id) {
        User user = (User) ((UserMapper) this.baseMapper).selectById(id);
        String cacheKey = CacheNames.tenantKey(AuthUtil.getTenantId(), CacheNames.USER_FAIL_KEY, user.getAccount());
        if (this.bladeRedis.del(cacheKey).booleanValue()) {
            return true;
        }
        throw new ServiceException("用户不处于锁定状态,无需解锁");
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    public List<User> selectRoleUserList(String roleId) {
        List<User> users = this.baseMapper.selectList(Lambda.<User>create().findIn(User::getRoleId, roleId, "/"));
        /*
        List<User> users = ((UserMapper) this.baseMapper).selectList(Lambda.create().findIn((v0) -> {
            return v0.getRoleId();
        }, roleId, "/"));*/
        return users;
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    public Boolean roleBindUsers(String roleId, List<Long> userIds) {
        StringBuilder stringBuilder = new StringBuilder(roleId);
        List<User> userList = list(new QueryWrapper<User>().lambda().in(User::getId, userIds));
        /*
        List<User> userList = list((Wrapper) new QueryWrapper().lambda().in((v0) -> {
            return v0.getId();
        }, userIds));*/
        if (Func.isNotEmpty(userList)) {
            userList.forEach(user -> {
                String newRoleId = Optional.ofNullable(user.getRoleId()).map(id -> {
                    return !id.contains(roleId) ? stringBuilder.append(",").append(id).toString() : id;
                }).orElse(roleId);
                user.setRoleId(newRoleId);
            });
            updateBatchById(userList);
        }
        return Boolean.TRUE;
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    public Boolean roleRemoveUsers(String roleId, List<Long> ids) {
        List<User> userList = list(new QueryWrapper<User>().lambda().in(User::getId, ids));
        /*
        List<User> userList = list((Wrapper) new QueryWrapper().lambda().in((v0) -> {
            return v0.getId();
        }, ids));*/
        if (Func.isNotEmpty(userList)) {
            userList.forEach(user -> {
                String newRoleId = Stream.of(user.getRoleId().split(",")).filter(str -> {
                    return !str.equals(roleId);
                }).collect(Collectors.joining(","));
                user.setRoleId(Func.isEmpty(newRoleId) ? null : newRoleId);
            });
            updateBatchById(userList);
        }
        return Boolean.TRUE;
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    public List<UserAccountVO> getUnbindAccountList(Long userId, String tel) {
        return ((UserMapper) this.baseMapper).getUnbindAccountList(userId, tel);
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    public Boolean checkUserIsBindEmployee(String userIds) {
        return this.employeeService.checkUserIsBindEmployee(userIds);
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    public UserVO detail(User user) {
        User detail = (User) getOne(Condition.getQueryWrapper(user));
        UserVO result = UserWrapper.build().entityVO(detail);
        Employee employee = this.employeeService.getByUserId(detail.getId());
        if (employee != null) {
            result.setEmployeeId(employee.getId());
            result.setEmployeeName(employee.getName());
            result.setEmployeeCode(employee.getCode());
        }
        return result;
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    public UserVO info(BladeUser user) {
        User detail = (User) getById(user.getUserId());
        UserVO result = UserWrapper.build().entityVO(detail);
        Employee employee = this.employeeService.getByUserId(detail.getId());
        if (employee != null) {
            result.setEmployeeId(employee.getId());
            result.setEmployeeName(employee.getName());
            List<UserOauth> userOauths = this.userOauthService.list(Wrappers.<UserOauth>lambdaQuery().eq(UserOauth::getUserId, employee.getId())
                    .in(UserOauth::getSource, Arrays.asList(new String[] { "DINGTALK_WEB", "WECHAT_ENTERPRISE_WEB" })));
            /*
            List<UserOauth> userOauths = this.userOauthService.list((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
                return v0.getUserId();
            }, employee.getId())).in((v0) -> {
                return v0.getSource();
            }, Arrays.asList(DingConstant.DING_AUTH_KEY, QyWechatConstant.QY_SOURCE)));*/
            if (Func.isNotEmpty(userOauths)) {
                userOauths.forEach(o -> {
                    if (o.getSource().equals(DingConstant.DING_AUTH_KEY)) {
                        result.setBindDingFlag(true);
                    } else if (o.getSource().equals(QyWechatConstant.QY_SOURCE)) {
                        result.setBindQyWechatFlag(true);
                    }
                });
            }
        }
        OuterAppConfig outerAppConfigDing = this.outerAppConfigService.getAppConfig(OuterAppConfigConstant.DING);
        OuterAppConfig outerAppConfigQy = this.outerAppConfigService.getAppConfig(OuterAppConfigConstant.QY_WECHAT);
        if (Func.isNotEmpty(outerAppConfigDing) && outerAppConfigDing.getStatus().equals(CommonConstant.ENABLE)) {
            result.setDingStatus(true);
        }
        if (Func.isNotEmpty(outerAppConfigQy) && outerAppConfigQy.getStatus().equals(CommonConstant.ENABLE)) {
            result.setWxStatus(true);
        }
        return result;
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    public List<NotifyUserDTO> getNotifySubscriberList(List<String> userIds) {
        return list(Wrappers.<User>lambdaQuery().in(User::getId, userIds)
                .select(User::getId, User::getPhone, User::getEmail )).stream()
              .map(user -> new NotifyUserDTO(user.getId(), user.getEmail(), user.getPhone(), this.userOauthService.getUserMiniUuid(user.getId())))
              .collect(Collectors.toList());
        /*
        return (List) list(((LambdaQueryWrapper) Wrappers.lambdaQuery().in((v0) -> {
            return v0.getId();
        }, userIds)).select(new SFunction[]{(v0) -> {
            return v0.getId();
        }, (v0) -> {
            return v0.getPhone();
        }, (v0) -> {
            return v0.getEmail();
        }})).stream().map(user -> {
            return new NotifyUserDTO(user.getId(), user.getEmail(), user.getPhone(), this.userOauthService.getUserMiniUuid(user.getId()));
        }).collect(Collectors.toList());*/
    }
 
    @Override // org.springblade.modules.system.service.IUserService
    @Transactional(rollbackFor = {Exception.class})
    public QuCreAccBackMessageVO batchCreateAccount(QuickCreationAccountVO quickCreationAccountVO) {
        QuCreAccBackMessageVO quCreAccBackMessageVO = new QuCreAccBackMessageVO();
        List<Employee> employeeList = this.employeeService.list();
        Map<String, Employee> employeeMap = employeeList.stream().filter(s -> {
            return Func.isNotEmpty(s.getUserId());
        }).collect(Collectors.toMap((v0) -> {
            return v0.getUserId();
        }, Function.identity()));
        List<User> userList = list();
        List<QuickCreationUserVO> quickCreationUsers = quickCreationAccountVO.getQuickCreationUsers();
        if (Func.isEmpty(quickCreationUsers)) {
            quCreAccBackMessageVO.setSuccessNums(Integer.valueOf(Integer.parseInt("0")));
            quCreAccBackMessageVO.setFailNums(Integer.valueOf(Integer.parseInt("0")));
            return quCreAccBackMessageVO;
        }
        List<String> accounts = quickCreationUsers.stream().map((v0) -> {
            return v0.getAccount();
        }).collect(Collectors.toList());
        String initPassword = ParamCache.getValue(CommonConstant.DEFAULT_PARAM_PASSWORD);
        String deptIds = quickCreationAccountVO.getDeptId();
        String roleIds = quickCreationAccountVO.getRoleId();
        if (Func.isNotEmpty(userList)) {
            List<QuCreAccBackUserVO> list = new ArrayList<>();
            List<User> alreadyExistsUsers = userList.stream().filter(user -> {
                return accounts.contains(user.getAccount());
            }).collect(Collectors.toList());
            if (Func.isNotEmpty(alreadyExistsUsers)) {
                alreadyExistsUsers.forEach(user2 -> {
                    Employee employee = (Employee) employeeMap.get(String.valueOf(user2.getId()));
                    List<String> deptName = SysCache.getDeptNames(user2.getDeptId());
                    QuCreAccBackUserVO existsUser = new QuCreAccBackUserVO();
                    if (employee != null) {
                        existsUser.setAccount(employee.getJobNumber());
                    }
                    existsUser.setAccountUser(user2.getAccount()).setRealName(user2.getRealName()).setEmail(user2.getEmail()).setPhone(user2.getPhone()).setDeptName(Func.join(deptName)).setFailReason(UserConstant.ACCOUNT_REPEAT);
                    list.add(existsUser);
                });
            }
            if (Func.isNotEmpty(list)) {
                List<String> exitsAccounts = list.stream().map((v0) -> {
                    return v0.getAccountUser();
                }).collect(Collectors.toList());
                quCreAccBackMessageVO.setFailNums(Integer.valueOf(list.size()));
                quCreAccBackMessageVO.setFailList(list);
                quickCreationUsers = quickCreationUsers.stream().filter(s2 -> {
                    return !exitsAccounts.contains(s2.getAccount());
                }).collect(Collectors.toList());
            }
        }
        if (Func.isNotEmpty(quickCreationUsers)) {
            quickCreationUsers.forEach(user3 -> {
                User createUser = new User();
                createUser.setRealName(user3.getUsername());
                createUser.setAccount(user3.getAccount());
                createUser.setDeptId(deptIds);
                createUser.setRoleId(roleIds);
                createUser.setPassword(initPassword);
                createUser.setEmployeeId(Long.valueOf(Func.toLong(user3.getEmployeeId())));
                submit(createUser);
            });
            quCreAccBackMessageVO.setSuccessNums(Integer.valueOf(quickCreationUsers.size()));
        }
        return quCreAccBackMessageVO;
    }
}