郑永安
2023-06-19 7a6abd05683528032687c75e80e0bd2030a3e46c
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
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
package com.gkhy.safePlatform.account.service.impl;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gkhy.safePlatform.account.entity.schedule.GroupInfoDO;
import com.gkhy.safePlatform.account.entity.schedule.GroupStrategyUserTimeTableInfo;
import com.gkhy.safePlatform.account.entity.schedule.GroupStrategyUserTimeTableInfoDO;
import com.gkhy.safePlatform.account.entity.user.PositionInfoDO;
import com.gkhy.safePlatform.account.enums.*;
import com.gkhy.safePlatform.account.enums.schedule.TimeTypeEnum;
import com.gkhy.safePlatform.account.model.dto.req.AccountAddReqDTO;
import com.gkhy.safePlatform.account.model.dto.req.AccountModReqDTO;
import com.gkhy.safePlatform.account.entity.enterprise.DepartmentInfo;
import com.gkhy.safePlatform.account.entity.user.RoleInfo;
import com.gkhy.safePlatform.account.entity.user.UserInfoDO;
import com.gkhy.safePlatform.account.model.dto.req.AccountPwdForgetReqDTO;
import com.gkhy.safePlatform.account.model.dto.resp.*;
import com.gkhy.safePlatform.account.model.query.AccountQuery;
import com.gkhy.safePlatform.account.model.query.UserScheduleQuery;
import com.gkhy.safePlatform.account.model.query.db.AccountDBQuery;
import com.gkhy.safePlatform.account.model.query.db.UserScheduleDBQuery;
import com.gkhy.safePlatform.account.service.AccountService;
import com.gkhy.safePlatform.account.service.baseService.*;
import com.gkhy.safePlatform.account.entity.user.UserInfo;
import com.gkhy.safePlatform.account.utils.IdCardUtil;
import com.gkhy.safePlatform.account.utils.PasswordUtil;
import com.gkhy.safePlatform.account.utils.RegexUtil;
import com.gkhy.safePlatform.commons.co.ContextCacheUser;
import com.gkhy.safePlatform.commons.enums.E;
import com.gkhy.safePlatform.commons.enums.ResultCodes;
import com.gkhy.safePlatform.commons.enums.UserTypeEnum;
import com.gkhy.safePlatform.commons.exception.AusinessException;
import com.gkhy.safePlatform.commons.exception.BusinessException;
import com.gkhy.safePlatform.commons.query.PageQuery;
import com.gkhy.safePlatform.commons.utils.BeanCopyUtils;
import com.gkhy.safePlatform.commons.utils.StringUtils;
import com.gkhy.safePlatform.commons.vo.SearchResultVO;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.TimeUnit;
 
@Service
public class AccountServiceImpl implements AccountService {
 
    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private RoleInfoService roleInfoService;
    @Autowired
    private PositionInfoService positionInfoService;
    @Autowired
    private DepartmentInfoService departmentInfoService;
    @Autowired
    private GroupInfoService groupInfoService;
    @Autowired
    private GroupMemberInfoService groupMemberInfoService;
    @Autowired
    private GroupStrategyUserTimeTableInfoService groupStrategyUserTimeTableInfoService;
    @Autowired
    private RedissonClient redissonClient;
 
    @Override
    public UserInfo getCurrentUserInfoByUsername(String username) {
        return userInfoService.getUserByUsername(username);
    }
 
    /**
    * @Description: 根据userId 获取用户个人性息
    */
    @Override
    public PersonalDetailRespDTO getPersonalAccountByUserId(Long userId) {
        // 用户
        UserInfo userInfo = userInfoService.getUserByUserId(userId);
        // 角色
        PersonalDetailRoleRespDTO role = null;
        if (userInfo.getRoleId() != null) {
            RoleInfo roleInfo = roleInfoService.getRoleInfoById(userInfo.getRoleId());
            if (roleInfo != null) {
                role = new PersonalDetailRoleRespDTO();
                role.setRoleId(roleInfo.getId());
                role.setRoleCode(roleInfo.getCode());
                role.setRoleName(roleInfo.getName());
                role.setRoleInfo(roleInfo.getInfo());
            }
        }
 
 
        //部门
        PersonalDetailDepRespDTO dep = null;
        if (userInfo.getDepId() != null) {
            DepartmentInfo departmentInfo = departmentInfoService.getDepartmentInfoById(userInfo.getDepId());
            if (departmentInfo != null) {
                dep = new PersonalDetailDepRespDTO();
                dep.setDepId(departmentInfo.getId());
                dep.setDepInfo(departmentInfo.getInfo());
                dep.setDepName(departmentInfo.getName());
                dep.setDepLevel(departmentInfo.getLevel());
                DepartmentLevelEnum levelEnum = DepartmentLevelEnum.parse(departmentInfo.getLevel());
                if (levelEnum != null) {
                    dep.setDepLevelDesc(levelEnum.value);
                }
            }
 
        }
 
        // 获取角色信息
//        roleInfoService.get
        return new PersonalDetailRespDTO(
                userInfo.getUid(),
                userInfo.getUsername(),
                userInfo.getRealName(),
                userInfo.getType(),
                userInfo.getStatus(),
                userInfo.getPhone(),
                userInfo.getEmail(),
                role,
                dep
        );
    }
 
    /**
    * @Description: 新增用户
    */
    @Override
    @Transactional
    public void addAccount(ContextCacheUser currentUser, AccountAddReqDTO accountAddDto) {
 
//        // 身份证判空
//        if (StringUtils.isBlank(accountAddDto.getIdentify())) {
//            throw new AusinessException(E.DATA_PARAM_NULL,"身份证不可为空");
//        }
        // 身份证合法
        String identify = accountAddDto.getIdentify();
        if (StringUtils.isNotBlank(identify)) {
            identify = identify.trim();
            if (!IdCardUtil.strongVerifyIdNumber(identify)) {
                throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"身份证校验非法");
            }
        }
        // 手机校验
        if (StringUtils.isBlank(accountAddDto.getPhone())) {
            throw new AusinessException(E.DATA_PARAM_NULL,"手机号不能为空");
        }
        // 手机规则
        if (!RegexUtil.isMobile(accountAddDto.getPhone().trim())) {
            throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "手机号校验非法");
        }
        if (accountAddDto.getType() == null) {
            throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "用户类型不能为空");
        }
        UserTypeEnum userTypeEnum = UserTypeEnum.parse(accountAddDto.getType());
        if (userTypeEnum == null) {
            throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "用户类型非法");
        }
        // 无法创建type 为1 的管理员类型
        if (userTypeEnum == UserTypeEnum.ADMIN) {
            throw new AusinessException(E.DATA_OPERATION_NO_PERMISSION, "当前用户没有创建该用户类型权限");
        }
//        // 邮箱校验
//        if (StringUtils.isBlank(accountAddDto.getEmail())) {
//            throw new AusinessException(E.DATA_PARAM_NULL,"邮箱不能为空");
//        }
        // 邮箱规则
        String email = accountAddDto.getEmail();
        if (StringUtils.isNotBlank(email)) {
            email = email.trim();
            if (!RegexUtil.isEmail(accountAddDto.getEmail().trim())) {
                throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "邮箱校验非法");
            }
        }
 
        if (StringUtils.isBlank(accountAddDto.getPassword())) {
            throw new BusinessException(ResultCodes.CLIENT_ACCOUNT_PASSWORD_NULL);
        }
        // todo 密码  格式校验
 
        if (accountAddDto.getGender() == null) {
            throw new AusinessException(E.DATA_PARAM_NULL, "性别不可为空");
        }
        if (StringUtils.isBlank(accountAddDto.getRealName())) {
            throw new AusinessException(E.DATA_PARAM_NULL, "真实姓名不可为空");
        }
        if (accountAddDto.getExpireTime() == null) {
            throw new AusinessException(E.DATA_PARAM_NULL, "过期时间不可为空");
        }
        if (accountAddDto.getStatus() == null) {
            throw new AusinessException(E.DATA_PARAM_NULL, "用户状态不可为空");
        }
        if (accountAddDto.getRoleId() == null) {
            throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
        }
        if (accountAddDto.getDepId() == null) {
            throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
        }
        if (accountAddDto.getPositionId() == null) {
            throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
        }
        // 状态区间
        UserStatusEnum userStatus= UserStatusEnum.parse(accountAddDto.getStatus());
        if (userStatus == null) {
            throw new AusinessException(E.DATA_STATUS_NOT_EXIST, "用户状态参数非法");
        }
        // 性别区间
        GenderEnum gender = GenderEnum.parse(accountAddDto.getGender());
        if (gender == null) {
            throw new AusinessException(E.DATA_STATUS_NOT_EXIST, "性别参数非法");
        }
        // 过期时间转换
        Calendar instance = Calendar.getInstance();
        instance.setTime(accountAddDto.getExpireTime());
        instance.set(Calendar.HOUR_OF_DAY,23);
        instance.set(Calendar.MINUTE,59);
        instance.set(Calendar.SECOND,59);
 
        // 手机号重复
        long count;
        count = userInfoService.countByPhone(accountAddDto.getPhone().trim());
        if (count > 0) {
            throw new AusinessException(E.DATA_DATABASE_EXIST, "手机号已被占用");
        }
//        // 身份证重复
//        count = userInfoService.countByIdentify(identify);
//        if (count > 0) {
//            throw new AusinessException(E.DATA_DATABASE_EXIST,"身份证已经存在");
//        }
//        // 邮箱重复
//        count = userInfoService.countByEmail(accountAddDto.getEmail());
//        if (count > 0) {
//            throw new AusinessException(E.DATA_DATABASE_EXIST,"邮箱已经存在");
//        }
 
        // 角色判断
        RoleInfo roleInfo = roleInfoService.getRoleInfoById(accountAddDto.getRoleId());
        if (roleInfo == null) {
            throw new BusinessException(ResultCodes.CLIENT_ROLE_NOT_EXIST);
        }
        if (roleInfo.getStatus() != RoleStatusEnum.ENABLED.getCode()) {
            throw new BusinessException(ResultCodes.CLIENT_ROLE_DISABLED);
        }
        // 部门判断
        DepartmentInfo departmentInfo = departmentInfoService.getDepartmentInfoById(accountAddDto.getDepId());
        if (departmentInfo == null) {
            throw new BusinessException(ResultCodes.CLIENT_DEP_NOT_EXIST);
        }
        if (!departmentInfo.getStatus().equals(DepartmentStatusEnum.ENABLED.getCode())) {
            throw new BusinessException(ResultCodes.CLIENT_DEP_DISABLED);
        }
        if (departmentInfo.getLevel().equals(DepartmentLevelEnum.COMPANY.code)) {
            throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "人员无法从属于总部门");
        }
 
        // 岗位判断
        PositionInfoDO positionInfoDO = positionInfoService.getPositionInfoById(accountAddDto.getPositionId());
        if (positionInfoDO == null) {
            throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "岗位不存在");
        }
        if (!positionInfoDO.getStatus().equals(PositionStatusEnum.ENABLED.getCode())) {
            throw new AusinessException(E.DATA_DATABASE_EXIST_BUT_NOT_VALID, "岗位不存在");
        }
        RLock lock = redissonClient.getLock("LOCK_USER_ADD");
        try {
            lock.lock(3, TimeUnit.SECONDS);
            // username 生成
            String realName = accountAddDto.getRealName().trim();
            count = userInfoService.countByRealName(realName);
            String username = realName;
            if (count > 0) {
                username = username + count;
            }
            // 盐和密码生成
            String salt = PasswordUtil.makeSalt();
            String hash = PasswordUtil.makePassword(accountAddDto.getPassword().trim(), salt);
            // 1.用户新增
            UserInfo userInfo = new UserInfo();
            userInfo.setType(userTypeEnum.getCode());
            userInfo.setSalt(salt);
            userInfo.setHash(hash);
            userInfo.setGender(gender.getCode());
            userInfo.setUsername(username);
            userInfo.setRealName(realName);
            userInfo.setIdentify(identify);
            userInfo.setPhone(accountAddDto.getPhone());
            userInfo.setEmail(email);
            userInfo.setExpireTime(instance.getTime());
            userInfo.setGmtCreate(new Date());
            userInfo.setDepId(accountAddDto.getDepId());
            userInfo.setStatus(userStatus.getCode());
            userInfo.setPhone(accountAddDto.getPhone());
            userInfo.setEmail(accountAddDto.getEmail());
            userInfo.setRoleId(accountAddDto.getRoleId());
            userInfo.setPositionId(accountAddDto.getPositionId());
            userInfoService.saveUserInfo(userInfo);
            lock.unlock();
        }catch (BusinessException e){
            e.printStackTrace();
            throw new BusinessException(e.getCode(),e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(ResultCodes.SERVER_ADD_ERROR);
        }finally {
            if (lock.isLocked()) {
                lock.unlock();
            }
        }
 
 
 
    }
 
 
    /**
    * @Description: 修改账户信息
    */
    @Override
    @Transactional
    public void modAccount(ContextCacheUser currentUser, AccountModReqDTO accountModDto) {
 
        if (accountModDto.getUid() == null) {
            throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
        }
        UserInfo userInfo = userInfoService.getUserByUserId(accountModDto.getUid());
        if (userInfo == null) {
            throw new BusinessException(ResultCodes.CLIENT_ACCOUNT_NOT_EXIST);
        }
        assert userInfo.getStatus() != null;
        UserStatusEnum status = UserStatusEnum.parse(userInfo.getStatus());
        if (status != UserStatusEnum.VALID) {
            throw new BusinessException(ResultCodes.CLIENT_ACCOUNT_NOT_EXIST);
        }
        // 新建更新对象
        UserInfo userEntity = new UserInfo();
        userEntity.setUid(accountModDto.getUid());
 
        // *用户类型
        if (accountModDto.getType() != null) {
            UserTypeEnum userTypeEnum = UserTypeEnum.parse(accountModDto.getType());
            if (userTypeEnum == null) {
                throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "用户类型非法");
            }
            if (userTypeEnum == UserTypeEnum.ADMIN) {
                throw new AusinessException(E.DATA_OPERATION_NO_PERMISSION, "当前用户没有创建该用户类型权限");
            }
            userEntity.setType(userTypeEnum.getCode());
        }
 
        // 真实姓名
        String realName = accountModDto.getRealName();
        if (StringUtils.isNotBlank(realName)
                && !realName.trim().equals(userInfo.getRealName())) {
            userEntity.setRealName(realName.trim());
            long count = userInfoService.countByRealName(realName.trim());
            String username = realName.trim();
            if (count > 0) {
                username = username + count;
            }
            userEntity.setUsername(username);
        }
 
        //身份证校验
        String identify = accountModDto.getIdentify();
        if (StringUtils.isNotBlank(identify)
                && !identify.trim().equals(userInfo.getIdentify())) {
            if (!IdCardUtil.strongVerifyIdNumber(identify.trim())) {
                throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"身份证校验非法");
            }
            UserInfo userByIdentify = userInfoService.getUserInfoByIdentify(identify.trim());
            if (userByIdentify != null && !userByIdentify.getUid().equals(userInfo.getUid())) {
                throw new AusinessException(E.DATA_DATABASE_EXIST,"身份证已经存在");
            }
            userEntity.setIdentify(identify.trim());
        }
 
        // todo 校验密码
        // 检验手机号
        if (StringUtils.isNotBlank(accountModDto.getPhone())
                && !accountModDto.getPhone().trim().equals(userInfo.getPhone())) {
            String phone = accountModDto.getPhone().trim();
            if (!RegexUtil.isMobile(phone)) {
                // 手机校验
                throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "手机校验非法");
            }
            UserInfo userInfoByPhone = userInfoService.getUserInfoByPhone(phone);
            if (userInfoByPhone != null && !userInfoByPhone.getUid().equals(userInfo.getUid())) {
                throw new AusinessException(E.DATA_DATABASE_EXIST, "手机号已被占用");
            }
            userEntity.setPhone(phone);
        }
        // 邮箱
        if (StringUtils.isNotBlank(accountModDto.getEmail())) {
            String email = accountModDto.getEmail().trim();
            if (!RegexUtil.isEmail(email)) {
                throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "邮箱校验非法");
            }
            UserInfo userInfoByEmail = userInfoService.getUserInfoByEmail(email);
            if (userInfoByEmail != null && !userInfoByEmail.getUid().equals(userInfo.getUid())) {
                throw new AusinessException(E.DATA_DATABASE_EXIST, "邮箱已被占用");
            }
            userEntity.setEmail(email);
        }
 
 
        // 部门判断
        if (accountModDto.getDepId() != null) {
            DepartmentInfo departmentInfo = departmentInfoService.getDepartmentInfoById(accountModDto.getDepId());
            if (departmentInfo == null) {
                throw new BusinessException(ResultCodes.CLIENT_DEP_NOT_EXIST);
            }
            if (departmentInfo.getLevel().equals(DepartmentLevelEnum.COMPANY.code)) {
                throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "人员无法从属于总部门");
            }
            userEntity.setDepId(accountModDto.getDepId());
        }
 
        // 角色判断
        if (accountModDto.getRoleId() != null) {
            RoleInfo roleInfo = roleInfoService.getRoleInfoById(accountModDto.getRoleId());
            if (roleInfo == null) {
                throw new BusinessException(ResultCodes.CLIENT_ROLE_NOT_EXIST);
            }
            userEntity.setRoleId(accountModDto.getRoleId());
        }
 
        // 岗位判断
        if (accountModDto.getPositionId() != null) {
            PositionInfoDO positionInfoDO = positionInfoService.getPositionInfoById(accountModDto.getPositionId());
            if (positionInfoDO == null) {
                throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "岗位不存在");
            }
            if (!positionInfoDO.getStatus().equals(PositionStatusEnum.ENABLED.getCode())) {
                throw new AusinessException(E.DATA_DATABASE_EXIST_BUT_NOT_VALID, "岗位不存在");
            }
            userEntity.setPositionId(accountModDto.getPositionId());
        }
 
 
        // 密码
        if (StringUtils.isNotBlank(accountModDto.getPassword())) {
            String password = accountModDto.getPassword().trim();
            // todo 格式校验
            // 重置盐
            String salt = PasswordUtil.makeSalt();
            String hash = PasswordUtil.makePassword(password, salt);
            userEntity.setHash(hash);
            userEntity.setSalt(salt);
        }
 
        // 用户状态
        if (accountModDto.getStatus() != null) {
            // 状态区间
            UserStatusEnum userStatus = UserStatusEnum.parse(accountModDto.getStatus());
            if (userStatus == null) {
                throw new AusinessException(E.DATA_STATUS_NOT_EXIST, "用户状态参数非法");
            }
            userEntity.setStatus(userStatus.getCode() );
        }
        // 过期时间
        if (accountModDto.getExpireTime() != null) {
            Calendar instance = Calendar.getInstance();
            instance.setTime(accountModDto.getExpireTime());
            instance.set(Calendar.HOUR_OF_DAY,23);
            instance.set(Calendar.MINUTE,59);
            instance.set(Calendar.SECOND,59);
            userEntity.setExpireTime(instance.getTime());
        }
        // 性别
        if (accountModDto.getGender() != null) {
            // 性别区间
            GenderEnum gender = GenderEnum.parse(accountModDto.getGender());
            if (gender == null) {
                throw new AusinessException(E.DATA_STATUS_NOT_EXIST, "性别参数非法");
            }
            userEntity.setGender(gender.getCode());
        }
 
 
        userEntity.setGmtModified(new Date());
        userInfoService.updateUserInfo(userEntity);
 
 
    }
 
    @Override
    public SearchResultVO<List<UserDetailRespDTO>> listAccountByPage(Long userId, PageQuery<AccountQuery> pageQuery) {
        ;
        AccountDBQuery accountDBQuery = new AccountDBQuery();
        if (pageQuery.getSearchParams() != null) {
            BeanUtils.copyProperties(pageQuery.getSearchParams(), accountDBQuery);
        }
 
 
        Page<UserInfoDO> page = new Page<>(pageQuery.getPageIndex(), pageQuery.getPageSize());
        List<UserInfoDO> users  = userInfoService.listPage(page,accountDBQuery);
        // 准备工作
        List<UserDetailRespDTO> userDetails = new ArrayList<>(users.size());
        Map<Long, UserDepartmentRespDTO> depPool = new HashMap<>();
        Map<Long, UserRoleRespDTO> rolePool = new HashMap<>();
        Map<Long, UserPositionRespDTO> positionPool = new HashMap<>();
        UserDepartmentRespDTO dep;
        UserRoleRespDTO role;
        UserPositionRespDTO position;
        // 数据整合
        if (users.size() > 0) {
            for (UserInfoDO user : users) {
                UserDetailRespDTO userDetail = new UserDetailRespDTO();
                BeanUtils.copyProperties(user, userDetail);
                // 部门
                if (userDetail.getDepId() != null) {
                    if (!depPool.containsKey(userDetail.getDepId())) {
                        DepartmentInfo depInfo = departmentInfoService.getDepartmentInfoById(userDetail.getDepId());
                        if (depInfo != null ) {
                            dep = new UserDepartmentRespDTO();
                            dep.setDepId(depInfo.getId());
                            dep.setDepName(depInfo.getName());
                            dep.setDepLevel(depInfo.getLevel());
                            depPool.put(dep.getDepId(), dep);
 
                        }
                    }
                    dep = depPool.get(userDetail.getDepId());
                    // 设置部门
                    userDetail.setDepartment(dep);
                }
                // 角色
                if (userDetail.getRoleId() != null) {
                    if (!rolePool.containsKey(userDetail.getRoleId())) {
                    RoleInfo roleInfo = roleInfoService.getById(userDetail.getRoleId());
                        if (roleInfo != null) {
                            role = new UserRoleRespDTO();
                            role.setRoleId(roleInfo.getId());
                            role.setRoleCode(roleInfo.getCode());
                            role.setRoleName(roleInfo.getName());
                            rolePool.put(role.getRoleId(), role);
                        }
                    }
                    role = rolePool.get(userDetail.getRoleId());
                    // 设置角色
                    userDetail.setRole(role);
                }
 
 
                // 岗位
                if (userDetail.getPositionId() != null) {
                    if (!positionPool.containsKey(userDetail.getPositionId())) {
                        PositionInfoDO positionInfoDO = positionInfoService.getPositionInfoById(userDetail.getPositionId());
                        if (positionInfoDO != null) {
                            position = new UserPositionRespDTO();
                            position.setPositionId(positionInfoDO.getId());
                            position.setPositionCode(positionInfoDO.getCode());
                            position.setPositionName(positionInfoDO.getName());
                            positionPool.put(positionInfoDO.getId(), position);
                        }
                    }
                    position = positionPool.get(userDetail.getPositionId());
                    // 设置岗位
                    userDetail.setPosition(position);
                }
 
                userDetails.add(userDetail);
            }
        }
 
        return new SearchResultVO<>(
                true,
                page.getCurrent(),
                page.getSize(),
                page.getPages(),
                page.getTotal(),
                userDetails,
                ResultCodes.OK);
 
    }
 
 
    /**
    * @Description: 获取部门下用户信息
    */
    @Override
    public List<DepUserInfoRespDTO> getDepUserList(Long userId, Long depId) {
        ;
        if (depId == null) {
            throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
        }
        DepartmentInfo departmentInfo = departmentInfoService.getDepartmentInfoById(depId);
        if (departmentInfo == null) {
            throw new BusinessException(ResultCodes.CLIENT_DEP_NOT_EXIST);
        }
        List<UserInfoDO> data = userInfoService.getDepUserList(depId);
        return BeanCopyUtils.copyBeanList(data, DepUserInfoRespDTO.class);
    }
 
    @Override
    @Transactional
    public void delAccount(ContextCacheUser currentUser, Long uid) {
        if (uid == null) {
            throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
        }
        UserInfo userInfo = userInfoService.getUserByUserId(uid);
        if (userInfo == null) {
            throw new BusinessException(ResultCodes.CLIENT_ACCOUNT_NOT_EXIST);
        }
        assert userInfo.getStatus() != null;
        if (!currentUser.getType().equals(UserTypeEnum.ADMIN.getCode())) {
            throw new AusinessException(E.DATA_OPERATION_NO_PERMISSION, "不好意思,当前用户没有删除权限");
        }
        if (currentUser.getType().equals(userInfo.getType())) {
            throw new AusinessException(E.DATA_OPERATION_NO_PERMISSION, "同类型人员不能操作删除");
        }
 
        UserStatusEnum statusEnum = UserStatusEnum.parse(userInfo.getStatus());
        if (statusEnum == UserStatusEnum.ABANDONED) {
            throw new BusinessException(ResultCodes.CLIENT_ACCOUNT_DELETE);
        }
 
        UserInfo user = new UserInfo();
        user.setUid(userInfo.getUid());
        user.setStatus(UserStatusEnum.ABANDONED.getCode());
        user.setGmtModified(new Date());
        userInfoService.updateUserInfo(user);
    }
 
    @Override
    public List<UserTimeTableRespDTO> getUserScheduleInfo(ContextCacheUser currentUser, UserScheduleQuery userScheduleQuery) {
        ;
        if (userScheduleQuery.getStartTime() == null || userScheduleQuery.getEndTime() == null) {
            throw new AusinessException(E.DATA_PARAM_NULL,"时间不能为空");
        }
        if (userScheduleQuery.getStartTime().after(userScheduleQuery.getEndTime())) {
            throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"时间区间非法");
        }
        if (userScheduleQuery.getUid() == null) {
            throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
        }
        UserInfo userInfo = userInfoService.getUserByUserId(userScheduleQuery.getUid());
        if (userInfo == null) {
            throw new BusinessException(ResultCodes.CLIENT_ACCOUNT_NOT_EXIST);
        }
        if (!userInfo.getStatus().equals(UserStatusEnum.VALID.getCode())) {
            throw new AusinessException(E.DATA_DATABASE_EXIST_BUT_NOT_VALID, "用户不存在");
        }
 
        UserScheduleDBQuery userScheduleDBQuery = new UserScheduleDBQuery();
        // 查询对象
        BeanUtils.copyProperties(userScheduleQuery, userScheduleDBQuery);
        List<UserTimeTableRespDTO> result = new ArrayList<>();
        List<GroupStrategyUserTimeTableInfoDO> userTimeTableInfos = groupStrategyUserTimeTableInfoService.getUserTimeTableInfoDOs(userScheduleDBQuery);
 
        if (userTimeTableInfos.size() > 0) {
            TimeTypeEnum typeEnum;
            Map<LocalDate,UserTimeTableRespDTO> dayPool = new HashMap<>();
            GroupStrategyUserTimeTableInfoDO userTimeTableInfo;
            UserTimeTableDetailRespDTO userTimeTableDetailInfo;
            for (int j = 0; j < userTimeTableInfos.size(); j++) {
                userTimeTableInfo = userTimeTableInfos.get(j);
                userTimeTableDetailInfo = new UserTimeTableDetailRespDTO();
                userTimeTableDetailInfo.setStartTime(userTimeTableInfo.getStartTime());
                userTimeTableDetailInfo.setEndTime(userTimeTableInfo.getEndTime());
                userTimeTableDetailInfo.setType(userTimeTableInfo.getType());
                typeEnum = TimeTypeEnum.parse(userTimeTableInfo.getType());
                if (typeEnum != null) {
                    userTimeTableDetailInfo.setTypeDesc(typeEnum.getValue());
                }
 
                // 区分开
                if (!dayPool.containsKey(userTimeTableInfo.getSpecificDate())) {
                    UserTimeTableRespDTO userTimeTableRespDTO = new UserTimeTableRespDTO();
                    userTimeTableRespDTO.setDay(userTimeTableInfo.getSpecificDate());
 
                    userTimeTableRespDTO.setTimeDetails(Collections.singletonList(userTimeTableDetailInfo));
                    dayPool.put(userTimeTableInfo.getSpecificDate(), userTimeTableRespDTO);
                }else{
                    UserTimeTableRespDTO userTimeTableRespDTOS = dayPool.get(userTimeTableInfo.getSpecificDate());
                    userTimeTableRespDTOS.getTimeDetails().add(userTimeTableDetailInfo);
                }
            }
 
            // 整合
            result.addAll(dayPool.values());
        }
 
 
        return result;
    }
 
    @Override
    public UserGroupTimTableRespDTO getUserGroupWorkSchedule(Long uid,LocalDate startTime,LocalDate endTime) {
//        ;
//        // 获取
//        if (uid == null) {
//            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
//        }
//        UserGroupTimTableRespDTO res = new UserGroupTimTableRespDTO();
//        UserInfo userInfo = userInfoService.getUserByUserId(uid);
//        if (userInfo != null) {
//            res.setUid(userInfo.getUid());
//            res.setRealName(userInfo.getRealName());
//            res.setUsername(userInfo.getUsername());
//            res.setPhone(userInfo.getPhone());
//        }
//
//        List<GroupInfoDO> groupInfo = groupMemberInfoService.listGroupInfoByUserId(uid);
//        if (groupInfo != null) {
//            res.setGroupId(groupInfo.getId());
//            res.setGroupName(groupInfo.getName());
//        }
//        LocalDateTime startDateTime = startTime.atStartOfDay();
//        LocalDateTime endDateTime = startTime.atTime(23, 59, 59);
//        List<GroupStrategyUserTimeTableInfoDO> dbData = groupStrategyUserTimeTableInfoService.listUserTimeTable(uid, startDateTime,endDateTime,TimeTypeEnum.WORK.getCode());
//        List<UserTimeTableDetailRespDTO> result = new ArrayList<>(dbData.size());
//        if (dbData.size() > 0) {
//            UserTimeTableDetailRespDTO respDTO;
//            for (GroupStrategyUserTimeTableInfoDO userTimeTableInfoDO : dbData) {
//                respDTO = new UserTimeTableDetailRespDTO();
//                respDTO.setStartTime(userTimeTableInfoDO.getStartTime());
//                respDTO.setEndTime(userTimeTableInfoDO.getEndTime());
//                respDTO.setType(userTimeTableInfoDO.getType());
//                TimeTypeEnum timeTypeEnum = TimeTypeEnum.parse(userTimeTableInfoDO.getType());
//                if (timeTypeEnum != null) {
//                    respDTO.setTypeDesc(timeTypeEnum.getValue());
//                }
//                result.add(respDTO);
//            }
//        }
//        res.setTimeDetails(result);
        return null;
    }
 
    @Override
    public UserInfoRespDTO getUserInfoByUid(Long uid) {
        UserInfo userInfo = userInfoService.getUserByUserId(uid);
        if (userInfo == null) {
            throw new BusinessException(ResultCodes.CLIENT_ACCOUNT_NOT_EXIST);
        }else{
            UserInfoRespDTO result = new UserInfoRespDTO();
            BeanUtils.copyProperties(userInfo, result);
            return result;
        }
 
 
    }
 
    @Override
    public List<UserListRespDTO> getUserList(Long uid) {
        List<UserInfoDO> dbData = userInfoService.listAllUser();
        List<UserListRespDTO> result = new ArrayList<>(dbData.size());
        UserListRespDTO respDTO;
        for (UserInfoDO userInfoDO : dbData) {
            respDTO = new UserListRespDTO();
            respDTO.setUid(userInfoDO.getUid());
            respDTO.setUsername(userInfoDO.getUsername());
            respDTO.setRealName(userInfoDO.getRealName());
            respDTO.setStatus(userInfoDO.getStatus());
            respDTO.setPhone(userInfoDO.getPhone());
            respDTO.setEmail(userInfoDO.getEmail());
            result.add(respDTO);
        }
        return result;
    }
 
    @Override
    public List<UserInfoRespDTO> listUserByUids(List<Long> uids) {
        if (uids != null && uids.size() > 50) {
            throw new BusinessException(ResultCodes.SERVER_SELECT_OVER_SIZE);
        }
        List<UserInfoDO> dbData = userInfoService.listUserByUids(uids);
        List<UserInfoRespDTO> results = new ArrayList<>(dbData.size());
        UserInfoRespDTO respDTO;
        for (UserInfoDO userInfoDO : dbData) {
            respDTO = new UserInfoRespDTO();
            respDTO.setUid(userInfoDO.getUid());
            respDTO.setUuid(userInfoDO.getUuid());
            respDTO.setUsername(userInfoDO.getUsername());
            respDTO.setRealName(userInfoDO.getRealName());
            respDTO.setGender(userInfoDO.getGender());
            respDTO.setType(userInfoDO.getType());
            respDTO.setStatus(userInfoDO.getStatus());
            respDTO.setPhone(userInfoDO.getPhone());
            respDTO.setIdentify(userInfoDO.getIdentify());
            respDTO.setEmail(userInfoDO.getEmail());
            respDTO.setDepId(userInfoDO.getDepId());
            respDTO.setRoleId(userInfoDO.getRoleId());
            respDTO.setPositionId(userInfoDO.getPositionId());
            results.add(respDTO);
        }
 
        return results;
    }
 
    @Override
    public List<UserInfoRespDTO> listUserByRealName(String realName) {
        List<UserInfoDO> dbData = userInfoService.listUserByRealName(realName);
        List<UserInfoRespDTO> result = new ArrayList<>(dbData.size());
        if (dbData.size() > 0) {
            UserInfoRespDTO respDTO;
            for (UserInfoDO userInfoDO : dbData) {
                respDTO = new UserInfoRespDTO();
                respDTO.setUid(userInfoDO.getUid());
                respDTO.setUuid(userInfoDO.getUuid());
                respDTO.setUsername(userInfoDO.getUsername());
                respDTO.setRealName(userInfoDO.getRealName());
                respDTO.setGender(userInfoDO.getGender());
                respDTO.setType(userInfoDO.getType());
                respDTO.setStatus(userInfoDO.getStatus());
                respDTO.setPhone(userInfoDO.getPhone());
                respDTO.setIdentify(userInfoDO.getIdentify());
                respDTO.setEmail(userInfoDO.getEmail());
                respDTO.setDepId(userInfoDO.getDepId());
                respDTO.setRoleId(userInfoDO.getRoleId());
                respDTO.setPositionId(userInfoDO.getPositionId());
                result.add(respDTO);
            }
        }
        return result;
    }
 
    @Override
    public void pwdForget(AccountPwdForgetReqDTO reqDTO) {
        if (StringUtils.isBlank(reqDTO.getRealName())) {
            throw new AusinessException(E.DATA_PARAM_NULL, "姓名不能为空");
        }
        if (StringUtils.isBlank(reqDTO.getIdentify())) {
            throw new AusinessException(E.DATA_PARAM_NULL, "身份证号不能为空");
        }
        if (StringUtils.isBlank(reqDTO.getPhone())) {
            throw new AusinessException(E.DATA_PARAM_NULL, "手机号不能为空");
        }
        if (StringUtils.isBlank(reqDTO.getPassword())) {
            throw new AusinessException(E.DATA_PARAM_NULL, "新密码不能为空");
        }
        if (StringUtils.isBlank(reqDTO.getRePassword())) {
            throw new AusinessException(E.DATA_PARAM_NULL, "新密码确认不能为空");
        }
        // 两次密码填写
        String newPassword = reqDTO.getPassword().trim();
        if (!newPassword.equals(reqDTO.getRePassword().trim())) {
            throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "两次密码填写不一致");
        }
        // 身份证号强校验
        String identify = reqDTO.getIdentify().trim();
        if (!IdCardUtil.strongVerifyIdNumber(identify)) {
            throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "身份证校验非法");
        }
        // 手机号强校验
        String phone = reqDTO.getPhone().trim();
        if (!RegexUtil.isMobile(phone)) {
            throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "手机号校验非法");
        }
        // todo 密码强校验
 
        // 根据身份证获取用户
        UserInfo thisUser = userInfoService.getUserInfoByIdentify(identify);
        if (thisUser == null) {
            throw new BusinessException(ResultCodes.CLIENT_ACCOUNT_NOT_EXIST);
        }
        if (thisUser.getType().equals(UserTypeEnum.ADMIN.getCode())) {
            throw new AusinessException(E.DATA_OPERATION_NO_PERMISSION, "用户不存在");
        }
        // 对比姓名
        if (!thisUser.getRealName().equals(reqDTO.getRealName().trim())) {
            throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "姓名不符合身份证");
        }
        // 对比手机号
        if (!thisUser.getPhone().equals(phone)) {
            throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "手机号不符合身份证所绑定的手机号");
        }
 
        // exc
        // 重置盐
        String salt = PasswordUtil.makeSalt();
        String hash = PasswordUtil.makePassword(newPassword, salt);
        userInfoService.updatePassword(thisUser.getUid(), salt, hash);
    }
 
 
}