|
@@ -0,0 +1,78 @@
|
|
|
+package com.fjhx.mail.service.message.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.fjhx.common.constant.SourceConstant;
|
|
|
+import com.fjhx.mail.service.message.InfoService;
|
|
|
+import com.ruoyi.common.core.domain.entity.SysDept;
|
|
|
+import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
|
+import com.ruoyi.system.service.ISysDeptService;
|
|
|
+import com.ruoyi.system.service.ISysUserService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class InfoServiceImpl implements InfoService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysDeptService sysDeptService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysUserService sysUserService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<SysUser> getUserList() {
|
|
|
+
|
|
|
+ DynamicDataSourceContextHolder.push(SourceConstant.BASE);
|
|
|
+
|
|
|
+ Long userId = SecurityUtils.getUserId();
|
|
|
+
|
|
|
+ List<SysDept> sysDeptList = sysDeptService.list(Wrappers.<SysDept>lambdaQuery()
|
|
|
+ .and(q -> q.eq(SysDept::getDirectorId, userId).or().eq(SysDept::getLeaderId, userId)));
|
|
|
+
|
|
|
+ if (sysDeptList.size() == 0) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<Long> deptSet = new HashSet<>();
|
|
|
+ List<SysDept> list = sysDeptService.list();
|
|
|
+ Map<Long, List<SysDept>> parentDeptMap = list.stream().collect(Collectors.groupingBy(SysDept::getParentId));
|
|
|
+
|
|
|
+ for (SysDept sysDept : sysDeptList) {
|
|
|
+ Long deptId = sysDept.getDeptId();
|
|
|
+
|
|
|
+ if (Objects.equals(sysDept.getDirectorId(), userId)) {
|
|
|
+ subordinateDeptId(deptId, deptSet, parentDeptMap);
|
|
|
+ } else {
|
|
|
+ deptSet.add(deptId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<SysUser> sysUserList = sysUserService.list(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getDeptId, deptSet));
|
|
|
+
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
+ return sysUserList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void subordinateDeptId(Long deptId, Set<Long> deptSet, Map<Long, List<SysDept>> parentDeptMap) {
|
|
|
+ deptSet.add(deptId);
|
|
|
+
|
|
|
+ // 获取子部门
|
|
|
+ List<SysDept> sysDeptList = parentDeptMap.get(deptId);
|
|
|
+ if (ObjectUtil.isEmpty(sysDeptList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (SysDept sysDept : sysDeptList) {
|
|
|
+ subordinateDeptId(sysDept.getDeptId(), deptSet, parentDeptMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|