郑永安
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
package com.gkhy.safePlatform.account.service.impl;
 
import com.alibaba.fastjson.JSONArray;
import com.gkhy.safePlatform.account.enums.DepartmentLevelEnum;
import com.gkhy.safePlatform.account.model.dto.req.DepartmentAddReqDTO;
import com.gkhy.safePlatform.account.model.dto.req.DepartmentModReqDTO;
import com.gkhy.safePlatform.account.model.dto.resp.DepRespDTO;
import com.gkhy.safePlatform.account.model.dto.resp.DepartmentRespDTO;
import com.gkhy.safePlatform.account.entity.enterprise.DepartmentInfo;
import com.gkhy.safePlatform.account.entity.enterprise.DepartmentInfoDO;
import com.gkhy.safePlatform.account.enums.DepartmentStatusEnum;
import com.gkhy.safePlatform.account.service.DepartmentService;
import com.gkhy.safePlatform.account.service.RedisService;
import com.gkhy.safePlatform.account.service.baseService.DepartmentInfoService;
import com.gkhy.safePlatform.account.service.baseService.GroupInfoService;
import com.gkhy.safePlatform.account.service.baseService.UserInfoService;
import com.gkhy.safePlatform.account.utils.DepartmentUtil;
import com.gkhy.safePlatform.account.utils.TokenUtil;
import com.gkhy.safePlatform.commons.co.ContextCacheUser;
import com.gkhy.safePlatform.commons.enums.E;
import com.gkhy.safePlatform.commons.enums.RedisKeyEnum;
import com.gkhy.safePlatform.commons.enums.ResultCodes;
import com.gkhy.safePlatform.commons.exception.AusinessException;
import com.gkhy.safePlatform.commons.exception.BusinessException;
import com.gkhy.safePlatform.commons.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.*;
 
@Service("departmentService")
public class DepartmentServiceImpl implements DepartmentService {
 
    @Autowired
    private DepartmentInfoService departmentInfoService;
    @Autowired
    private RedisService redisService;
    @Autowired
    private TokenUtil tokenConfig;
    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private GroupInfoService groupInfoService;
 
    @Override
    public List<DepartmentRespDTO> getDepartmentEnableList() {
        // 获取所有部门
        List<DepartmentInfoDO> allDeps = this.getCacheDepartment();
        // 部门生成树
        return DepartmentUtil.generateMenuTree(allDeps);
    }
 
 
    /**
    * @Description: 新增部门
    */
    @Override
    public void addDepartment(ContextCacheUser currentUser, DepartmentAddReqDTO departmentAddReqDTO) {
 
        if (StringUtils.isBlank(departmentAddReqDTO.getDepName())) {
            throw new AusinessException(E.DATA_PARAM_NULL,"部门名称为空");
        }
        if (departmentAddReqDTO.getDepLevel() == null) {
            throw new AusinessException(E.DATA_PARAM_NULL,"部门等级为空");
        }
        DepartmentLevelEnum levelEnum = DepartmentLevelEnum.parse(departmentAddReqDTO.getDepLevel());
        if (levelEnum == null) {
            throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "部门等级入参非法");
        }
        if (StringUtils.isBlank(departmentAddReqDTO.getDepCode())) {
            throw new AusinessException(E.DATA_PARAM_NULL,"部门编号为空");
        }
        // 部门编号不能超过16位长度
        String depCode = departmentAddReqDTO.getDepCode().trim();
        if (depCode.length() > 16) {
            throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "部门编号长度不宜超过16位");
        }
        // 部门编号是否重复
        DepartmentInfo departmentInfoByCode= departmentInfoService.getDepartmentInfoByCode(depCode);
        if (departmentInfoByCode != null) {
            throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "部门编号已存在");
        }
 
        String name = departmentAddReqDTO.getDepName().trim();
 
        // 根部门等级只能是公司级
        if (departmentAddReqDTO.getParentDepId() == null && levelEnum != DepartmentLevelEnum.COMPANY) {
            throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "根部门等级只能是公司级");
        }
        // 传入父菜单判断是否存在
        if (departmentAddReqDTO.getParentDepId() != null) {
            DepartmentInfo departmentInfo = departmentInfoService.getDepartmentInfoById(departmentAddReqDTO.getParentDepId());
            if (departmentInfo == null) {
                throw new BusinessException(ResultCodes.CLIENT_DEP_NOT_EXIST);
            }
            if (!departmentInfo.getStatus().equals(DepartmentStatusEnum.ENABLED.getCode())) {
                throw new BusinessException(ResultCodes.CLIENT_DEP_NOT_EXIST);
            }
            // 子部门不可以是公司级部门
            if (levelEnum == DepartmentLevelEnum.COMPANY) {
                throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "无法创建公司级部门");
            }
            // 父部门如果level是车间 子部门就必须是车间, 否则 子部门的Level 比父部门level 小(大)
            if (departmentInfo.getLevel().equals(DepartmentLevelEnum.WORKSHOP.code)) {
                levelEnum = DepartmentLevelEnum.WORKSHOP;
            } else if (levelEnum.code < departmentInfo.getLevel()) {
                throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "子部门等级需要在父部门等级之下");
            }
 
        }
 
        // 获取同级目录
        List<DepartmentInfoDO> sameLevelDeps = departmentInfoService.getDepartmentByParentId(departmentAddReqDTO.getParentDepId());
        if (sameLevelDeps.size() > 0) {
            for (DepartmentInfoDO department : sameLevelDeps) {
                // 不能同名
                if (department.getName().equals(name)) {
                    throw new BusinessException(ResultCodes.CLIENT_DEP_NAME_EXIST);
                }
            }
        }
 
        DepartmentInfo departmentInfoDO = departmentInfoService.getDepartmentInfoByName(name);
        if (departmentInfoDO != null) {
            throw new AusinessException(E.DATA_DATABASE_EXIST, "部门名称已经重复,请更改名称方案");
        }
 
        DepartmentInfo departmentInfo = new DepartmentInfo();
        departmentInfo.setInfo(departmentAddReqDTO.getDepInfo());
        departmentInfo.setName(name);
        departmentInfo.setParentId(departmentAddReqDTO.getParentDepId());
        departmentInfo.setGmtCreate(new Date());
        departmentInfo.setStatus(DepartmentStatusEnum.ENABLED.getCode());
        departmentInfo.setLevel(levelEnum.code);
        departmentInfo.setCode(depCode);
        departmentInfoService.saveDepartmentInfo(departmentInfo);
 
        // redis刷新部门
        List<DepartmentInfoDO> allDeps = departmentInfoService.getDepartmentByStatus(DepartmentStatusEnum.ENABLED);
        redisService.setCacheDepAndExpireTime(RedisKeyEnum.AUTH_DEP.getKey(), allDeps, tokenConfig.getExpiration());
    }
 
 
    @Override
    public void modDepartment(ContextCacheUser currentUser, DepartmentModReqDTO departmentModReqDTO) {
 
        if (departmentModReqDTO.getDepId() == null) {
            throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
        }
        if (StringUtils.isBlank(departmentModReqDTO.getDepName())) {
            throw new AusinessException(E.DATA_PARAM_NULL,"部门名称为空");
        }
        if (departmentModReqDTO.getDepLevel() == null) {
            throw new AusinessException(E.DATA_PARAM_NULL,"部门等级为空");
        }
        DepartmentLevelEnum levelEnum = DepartmentLevelEnum.parse(departmentModReqDTO.getDepLevel());
        if (levelEnum == null) {
            throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "部门等级入参非法");
        }
        if (StringUtils.isBlank(departmentModReqDTO.getDepCode())) {
            throw new AusinessException(E.DATA_PARAM_NULL,"部门编号为空");
        }
        String depCode = departmentModReqDTO.getDepCode().trim();
        // 部门编号不能超过16位长度
        if (depCode.length() > 16) {
            throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "部门编号长度不宜超过16位");
        }
        String name = departmentModReqDTO.getDepName().trim();
        // 查找的就是有效的部门
        DepartmentInfo departmentInfo = departmentInfoService.getDepartmentInfoById(departmentModReqDTO.getDepId());
        // 部门是否存在
        if (departmentInfo == null) {
            throw new BusinessException(ResultCodes.CLIENT_DEP_NOT_EXIST);
        }
 
 
        // 部门转移判断
        // 公司级别部门无法转移
        // 存在子部门的部门无法转移
        this.departmentTransferCheck(departmentInfo,departmentModReqDTO);
        // 部门修改判断
 
 
        if (departmentModReqDTO.getParentDepId() == null && levelEnum != DepartmentLevelEnum.COMPANY) {
            throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "根部门等级只能是公司级");
        }
 
        if (departmentModReqDTO.getParentDepId() != null) {
            // 父部门是否存在
            DepartmentInfo department = departmentInfoService.getDepartmentInfoById(departmentModReqDTO.getParentDepId());
            if (department == null) {
                throw new BusinessException(ResultCodes.CLIENT_DEP_NOT_EXIST);
            }
            if (!department.getStatus().equals(DepartmentStatusEnum.ENABLED.getCode())) {
                throw new BusinessException(ResultCodes.CLIENT_DEP_NOT_EXIST);
            }
            if (levelEnum == DepartmentLevelEnum.COMPANY) {
                throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "无法修改为公司级部门");
            }
            // 父部门如果level是车间 子部门就必须是车间, 否则 子部门的Level 比父部门level 小(大)
            if (departmentInfo.getLevel().equals(DepartmentLevelEnum.WORKSHOP.code)) {
                levelEnum = DepartmentLevelEnum.WORKSHOP;
            } else if (levelEnum.code < departmentInfo.getLevel()) {
                throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "子部门等级需要在父部门等级之下");
            }
        }
 
        DepartmentInfo departmentInfoDO = departmentInfoService.getDepartmentInfoByName(name);
        if (departmentInfoDO != null && !departmentInfoDO.getId().equals(departmentModReqDTO.getDepId())) {
            throw new AusinessException(E.DATA_DATABASE_EXIST, "部门名称已经重复,请更改名称方案");
        }
        departmentInfoDO = departmentInfoService.getDepartmentInfoByCode(depCode);
        if (departmentInfoDO != null && !departmentInfoDO.getId().equals(departmentModReqDTO.getDepId())) {
            throw new AusinessException(E.DATA_DATABASE_EXIST, "部门编号已经重复,请更改编号方案");
        }
 
        // 获取同级部门名称
        List<DepartmentInfoDO> sameLevelDeps = departmentInfoService.getDepartmentByParentId(departmentInfo.getParentId());
        // 判断是否重名
        if (sameLevelDeps.size() > 0) {
            for (DepartmentInfoDO dep : sameLevelDeps) {
                // 不是自己的重名
                if (dep.getName().equals(name) && !dep.getId().equals(departmentModReqDTO.getDepId())) {
                    throw new BusinessException(ResultCodes.CLIENT_DEP_NAME_EXIST);
                }
            }
        }
        departmentInfo.setGmtModified(new Date());
        departmentInfo.setName(name);
        departmentInfo.setInfo(departmentModReqDTO.getDepInfo());
        departmentInfo.setParentId(departmentModReqDTO.getParentDepId());
        departmentInfo.setLevel(levelEnum.code);
        departmentInfo.setCode(depCode);
        departmentInfoService.updateDepartmentInfo(departmentInfo);
 
        // redis 刷新部门
        List<DepartmentInfoDO> allDeps = departmentInfoService.getDepartmentByStatus(DepartmentStatusEnum.ENABLED);
        redisService.setCacheDepAndExpireTime(RedisKeyEnum.AUTH_DEP.getKey(), allDeps, tokenConfig.getExpiration());
    }
 
    /**
    * @Description: 判断是否能够部门转移
    * @dbOriginalDep 原始部门数据
    * @targetDep     目标部门修改数据
    */
    private void departmentTransferCheck(DepartmentInfo dbOriginalDep,DepartmentModReqDTO targetDep) {
        if (dbOriginalDep.getParentId() == null && targetDep.getParentDepId() != null) {
            throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "公司级根部门无法进行部门转移");
        }
        // 查询当前修改部门子部门
        List<DepartmentInfoDO> subDepartments = departmentInfoService.getDepartmentByParentId(dbOriginalDep.getId());
        // 子部门如果存在 不能转移
        if (subDepartments.size() > 0) {
            throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "当前部门下存在子部门 无法进行部门转移");
        }
 
    }
 
    @Override
    public void delDepartment(ContextCacheUser currentUser, Long depId) {
        ;
        if (depId == null) {
            throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
        }
        DepartmentInfo department = departmentInfoService.getDepartmentInfoById(depId);
        if (department == null) {
            throw new BusinessException(ResultCodes.CLIENT_DEP_NOT_EXIST);
        }
        assert department.getStatus() != null;
        DepartmentStatusEnum status = DepartmentStatusEnum.parse(department.getStatus());
        if (status != DepartmentStatusEnum.ENABLED) {
            throw new BusinessException(ResultCodes.CLIENT_DEP_NOT_EXIST);
        }
        // 1.判断部门下是否有人员
        long countPerson =  userInfoService.countByDepId(depId);
        if (countPerson > 0L) {
            throw new AusinessException(E.NOT_DELETE, "部门下存在人员");
        }
        // 2.判断部门下是否有子部门
        long countDepartment = departmentInfoService.countByParentDepId(depId);
        if (countDepartment > 0L) {
            throw new AusinessException(E.NOT_DELETE, "部门存在子部门");
        }
 
        // 3.判断部门下是否有班组关系
        boolean existGroup = groupInfoService.isExistGroupMountedByDepartment(depId);
        if (existGroup) {
            throw new AusinessException(E.NOT_DELETE, "部门下存在班组");
        }
        // 4.删除部门
        DepartmentInfo departmentInfo = new DepartmentInfo();
        departmentInfo.setId(department.getId());
        departmentInfo.setStatus(DepartmentStatusEnum.ABANDONED.getCode());
        departmentInfo.setGmtModified(new Date());
        departmentInfoService.updateDepartmentInfo(departmentInfo);
 
        // 5.redis 刷新部门
        List<DepartmentInfoDO> allDeps = departmentInfoService.getDepartmentByStatus(DepartmentStatusEnum.ENABLED);
        redisService.setCacheDepAndExpireTime(RedisKeyEnum.AUTH_DEP.getKey(), allDeps, tokenConfig.getExpiration());
 
    }
 
    @Override
    public DepRespDTO getEnableDepartmentInfoByDepId(Long userId, Long depId) {
        ;
        if (depId == null) {
            throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
        }
        DepRespDTO depRespDTO;
        DepartmentInfo departmentInfo = departmentInfoService.getDepartmentInfoById(depId);
        if (departmentInfo == null) {
            depRespDTO =  null;
        }else{
            depRespDTO = new DepRespDTO();
            depRespDTO.setDepId(departmentInfo.getId());
            depRespDTO.setDepName(departmentInfo.getName());
            depRespDTO.setDepInfo(departmentInfo.getInfo());
            depRespDTO.setStatus(departmentInfo.getStatus());
            depRespDTO.setDepLevel(departmentInfo.getLevel());
            DepartmentLevelEnum levelEnum = DepartmentLevelEnum.parse(departmentInfo.getLevel());
            if (levelEnum != null) {
                depRespDTO.setDepLevelDesc(levelEnum.value);
            }
            DepartmentStatusEnum status = DepartmentStatusEnum.parse(departmentInfo.getStatus());
            if (status != null) {
                depRespDTO.setStatusDesc(status.getValue());
            }
        }
        return depRespDTO;
    }
 
    @Override
    public DepRespDTO getDepartmentInfoByDepId(Long depId) {
        if (depId == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        DepRespDTO depRespDTO = null;
        DepartmentInfo departmentInfo = departmentInfoService.getDepartmentInfoById(depId);
        if (departmentInfo != null) {
            depRespDTO = new DepRespDTO();
            depRespDTO.setDepId(departmentInfo.getId());
            depRespDTO.setDepName(departmentInfo.getName());
            depRespDTO.setDepInfo(departmentInfo.getInfo());
            depRespDTO.setStatus(departmentInfo.getStatus());
            depRespDTO.setDepLevel(departmentInfo.getLevel());
            depRespDTO.setDepCode(departmentInfo.getCode());
            depRespDTO.setParentDepId(departmentInfo.getParentId());
            DepartmentLevelEnum levelEnum = DepartmentLevelEnum.parse(departmentInfo.getLevel());
            if (levelEnum != null) {
                depRespDTO.setDepLevelDesc(levelEnum.value);
            }
            DepartmentStatusEnum status = DepartmentStatusEnum.parse(departmentInfo.getStatus());
            if (status != null) {
                depRespDTO.setStatusDesc(status.getValue());
            }
 
        }
        return depRespDTO;
    }
 
    @Override
    public DepRespDTO getParentDepInfoByDepId(Long depId) {
        DepartmentInfoDO depDO =  departmentInfoService.getParentDepartmentInfoDOByDepId(depId);
        DepRespDTO depRespDTO = null;
        if (depDO != null) {
            depRespDTO = new DepRespDTO();
            depRespDTO.setDepId(depDO.getId());
            depRespDTO.setDepName(depDO.getName());
            depRespDTO.setDepInfo(depDO.getInfo());
            depRespDTO.setDepCode(depDO.getCode());
            depRespDTO.setStatus(depDO.getStatus());
            depRespDTO.setDepLevel(depDO.getLevel());
            DepartmentLevelEnum levelEnum = DepartmentLevelEnum.parse(depDO.getLevel());
            if (levelEnum != null) {
                depRespDTO.setDepLevelDesc(levelEnum.value);
            }
            DepartmentStatusEnum status = DepartmentStatusEnum.parse(depDO.getStatus());
            if (status != null) {
                depRespDTO.setStatusDesc(status.getValue());
            }
        }
        return depRespDTO;
    }
 
    @Override
    public boolean isSelfOrSubDep(Long depId, Long depId1) {
        boolean result;
 
        if (depId.equals(depId1)) {
            result = true;
        }else{
            List<DepartmentInfoDO> allDeps = this.getCacheDepartment();
            result =  DepartmentUtil.isUnderDepartment(depId,depId1,allDeps);
 
        }
 
        return result;
 
 
    }
 
    @Override
    public DepRespDTO getDepartmentInfoByDepName(String depName) {
        DepartmentInfo departmentInfo = departmentInfoService.getDepartmentInfoByName(depName);
        DepRespDTO result = null;
        if (departmentInfo != null) {
            result = new DepRespDTO();
            result.setDepId(departmentInfo.getId());
            result.setDepName(departmentInfo.getName());
            result.setDepInfo(departmentInfo.getInfo());
            result.setStatus(departmentInfo.getStatus());
            result.setDepLevel(departmentInfo.getLevel());
            DepartmentLevelEnum levelEnum = DepartmentLevelEnum.parse(departmentInfo.getLevel());
            if (levelEnum != null) {
                result.setDepLevelDesc(levelEnum.value);
            }
            DepartmentStatusEnum statusEnum = DepartmentStatusEnum.parse(departmentInfo.getStatus());
            if (statusEnum != null) {
                result.setStatusDesc(statusEnum.getValue());
            }
            result.setParentDepId(departmentInfo.getParentId());
        }
 
        return result;
    }
 
    @Override
    public List<Long> listDepAndSubDepIds(Long depId) {
        List<DepartmentInfoDO> allDeps = getCacheDepartment();
        return DepartmentUtil.generateDepIdListByDepId(depId,allDeps);
    }
 
    @Override
    public List<DepRespDTO> listDepAndSubByDepId(Long depId) {
        // 获取所有部门
        List<DepartmentInfoDO> allDeps = this.getCacheDepartment();
        List<DepartmentInfoDO> deps = DepartmentUtil.generateDepListByDepId(depId, allDeps);
        // 转换
        List<DepRespDTO> result = new ArrayList<>(deps.size());
        DepRespDTO respDTO;
        if (deps.size() > 0) {
            for (DepartmentInfoDO dep : deps) {
                respDTO = new DepRespDTO();
                respDTO.setDepId(dep.getId());
                respDTO.setDepName(dep.getName());
                respDTO.setDepInfo(dep.getInfo());
                respDTO.setStatus(dep.getStatus());
                DepartmentStatusEnum statusEnum = DepartmentStatusEnum.parse(dep.getStatus());
                if (statusEnum != null) {
                    respDTO.setStatusDesc(statusEnum.getValue());
                }
                respDTO.setParentDepId(dep.getParentId());
                respDTO.setDepLevel(dep.getLevel());
                DepartmentLevelEnum levelEnum = DepartmentLevelEnum.parse(dep.getLevel());
                if (levelEnum != null) {
                    respDTO.setDepLevelDesc(levelEnum.value);
                }
                result.add(respDTO);
            }
        }
 
        return result;
    }
 
    @Override
    public List<DepRespDTO> listDepByDepIds(List<Long> depIds) {
        List<DepRespDTO> result;
        if (depIds != null && depIds.size() > 0) {
            List<DepartmentInfoDO> allDeps = getCacheDepartment();
            result = new ArrayList<>(depIds.size());
            for (DepartmentInfoDO dep : allDeps) {
                if (depIds.contains(dep.getId())) {
                    DepRespDTO respDTO = new DepRespDTO();
                    respDTO.setDepId(dep.getId());
                    respDTO.setDepName(dep.getName());
                    respDTO.setDepInfo(dep.getInfo());
                    respDTO.setStatus(dep.getStatus());
                    DepartmentStatusEnum statusEnum = DepartmentStatusEnum.parse(dep.getStatus());
                    if (statusEnum != null) {
                        respDTO.setStatusDesc(statusEnum.getValue());
                    }
                    respDTO.setParentDepId(dep.getParentId());
                    respDTO.setDepLevel(dep.getLevel());
                    DepartmentLevelEnum levelEnum = DepartmentLevelEnum.parse(dep.getLevel());
                    if (levelEnum != null) {
                        respDTO.setDepLevelDesc(levelEnum.value);
                    }
                    result.add(respDTO);
                }
            }
        }else{
            result = Collections.emptyList();
        }
 
        return result;
    }
 
    @Override
    public List<DepRespDTO> listSubDepsByDepId(Long depId) {
        List<DepRespDTO> result = new ArrayList<>();
        List<DepartmentInfoDO> deps = getCacheDepartment();
        if (deps.size() > 0 && depId != null) {
            DepRespDTO depRespDTO;
            DepartmentLevelEnum levelEnum;
            DepartmentStatusEnum statusEnum;
            for (DepartmentInfoDO depDo : deps) {
                if (depId.equals(depDo.getParentId())) {
                    depRespDTO = new DepRespDTO();
                    depRespDTO.setDepId(depDo.getId());
                    depRespDTO.setDepName(depDo.getName());
                    depRespDTO.setDepInfo(depDo.getInfo());
                    depRespDTO.setStatus(depDo.getStatus());
                    statusEnum = DepartmentStatusEnum.parse(depDo.getStatus());
                    if (statusEnum != null) {
                        depRespDTO.setStatusDesc(statusEnum.getValue());
                    }
                    depRespDTO.setParentDepId(depDo.getParentId());
                    depRespDTO.setDepLevel(depDo.getLevel());
                    levelEnum = DepartmentLevelEnum.parse(depDo.getLevel());
                    if (levelEnum != null) {
                        depRespDTO.setDepLevelDesc(levelEnum.value);
                    }
                    result.add(depRespDTO);
                }
            }
        }
        return result;
    }
 
 
    /**
    * @Description: 统一调用 缓存获取
    */
    private  List<DepartmentInfoDO> getCacheDepartment(){
        List<DepartmentInfoDO> allDeps;
        // 1.redis获取部门
        String oo = redisService.getCacheDepByKey(RedisKeyEnum.AUTH_DEP.getKey());
        if (oo != null) {
            allDeps = JSONArray.parseArray(oo, DepartmentInfoDO.class);
        }else{
            // 2.mysql获取 && 存入 redis
            // 获取启用部门
            allDeps =  departmentInfoService.getDepartmentByStatus(DepartmentStatusEnum.ENABLED);
            redisService.setCacheDepAndExpireTime(RedisKeyEnum.AUTH_DEP.getKey(), allDeps, tokenConfig.getExpiration());
        }
        return allDeps;
    }
}