|
@@ -4,7 +4,6 @@ package com.usky.system.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.ruoyi.common.datascope.annotation.DataScope;
|
|
import com.ruoyi.common.datascope.annotation.DataScope;
|
|
-import com.ruoyi.common.datascope.context.DataScopeContextHolder;
|
|
|
|
import com.usky.common.mybatis.core.AbstractCrudService;
|
|
import com.usky.common.mybatis.core.AbstractCrudService;
|
|
import com.usky.common.security.utils.SecurityUtils;
|
|
import com.usky.common.security.utils.SecurityUtils;
|
|
import com.usky.common.core.exception.BusinessException;
|
|
import com.usky.common.core.exception.BusinessException;
|
|
@@ -13,21 +12,21 @@ import com.usky.common.core.util.StringUtils;
|
|
import com.usky.system.domain.SysDept;
|
|
import com.usky.system.domain.SysDept;
|
|
import com.usky.system.domain.SysRole;
|
|
import com.usky.system.domain.SysRole;
|
|
import com.usky.system.domain.SysUser;
|
|
import com.usky.system.domain.SysUser;
|
|
|
|
+import com.usky.system.domain.SysUserPost;
|
|
import com.usky.system.domain.constants.UserConstants;
|
|
import com.usky.system.domain.constants.UserConstants;
|
|
-import com.usky.system.factory.RemoteLogFallbackFactory;
|
|
|
|
import com.usky.system.mapper.SysDeptMapper;
|
|
import com.usky.system.mapper.SysDeptMapper;
|
|
import com.usky.system.mapper.SysRoleMapper;
|
|
import com.usky.system.mapper.SysRoleMapper;
|
|
|
|
+import com.usky.system.mapper.SysUserPostMapper;
|
|
import com.usky.system.service.ISysDeptService;
|
|
import com.usky.system.service.ISysDeptService;
|
|
|
|
+import com.usky.system.service.vo.TreeNode;
|
|
import com.usky.system.service.vo.TreeSelect;
|
|
import com.usky.system.service.vo.TreeSelect;
|
|
-import org.slf4j.Logger;
|
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
|
|
|
+import com.usky.system.service.vo.UserPostVo;
|
|
|
|
+import org.omg.CORBA.StringHolder;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.Iterator;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Objects;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.function.Function;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@@ -38,14 +37,15 @@ import java.util.stream.Collectors;
|
|
*/
|
|
*/
|
|
@Service
|
|
@Service
|
|
public class SysDeptServiceImpl extends AbstractCrudService<SysDeptMapper, SysDept> implements ISysDeptService {
|
|
public class SysDeptServiceImpl extends AbstractCrudService<SysDeptMapper, SysDept> implements ISysDeptService {
|
|
- private static final Logger log = LoggerFactory.getLogger(SysDeptServiceImpl.class);
|
|
|
|
-
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private SysDeptMapper deptMapper;
|
|
private SysDeptMapper deptMapper;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private SysRoleMapper roleMapper;
|
|
private SysRoleMapper roleMapper;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private SysUserPostMapper sysUserPostMapper;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 查询部门管理数据
|
|
* 查询部门管理数据
|
|
*
|
|
*
|
|
@@ -56,29 +56,78 @@ public class SysDeptServiceImpl extends AbstractCrudService<SysDeptMapper, SysDe
|
|
@DataScope(deptAlias = "d")
|
|
@DataScope(deptAlias = "d")
|
|
public List<SysDept> selectDeptList(SysDept dept) {
|
|
public List<SysDept> selectDeptList(SysDept dept) {
|
|
dept.setTenantId(SecurityUtils.getTenantId());
|
|
dept.setTenantId(SecurityUtils.getTenantId());
|
|
- log.debug(DataScopeContextHolder.getDataScopeSql());
|
|
|
|
return deptMapper.selectDeptList(dept);
|
|
return deptMapper.selectDeptList(dept);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- @DataScope(deptAlias = "d")
|
|
|
|
- public List<SysDept> selectDeptListByLamda(SysDept dept) {
|
|
|
|
- LambdaQueryWrapper<SysDept> deptQuery = Wrappers.lambdaQuery();
|
|
|
|
- deptQuery.eq(SysDept::getDelFlag, 0);
|
|
|
|
- if (dept.getParentId() != null && dept.getParentId() != 0) {
|
|
|
|
- deptQuery.eq(SysDept::getParentId, dept.getParentId());
|
|
|
|
|
|
+ public List<SysDept> deptList(SysDept dept) {
|
|
|
|
+ dept.setTenantId(SecurityUtils.getTenantId());
|
|
|
|
+ return deptMapper.deptList(dept);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<TreeNode> buildDeptUserTreeSelect(List<SysDept> depts, List<SysUser> users) {
|
|
|
|
+ List<Long> userIds = new ArrayList<>();
|
|
|
|
+ for (SysUser user : users){
|
|
|
|
+ userIds.add(user.getUserId());
|
|
}
|
|
}
|
|
- if (StringUtils.isNotBlank(dept.getDeptName())){
|
|
|
|
- deptQuery.like(SysDept::getDeptName, dept.getDeptName());
|
|
|
|
|
|
+ List<UserPostVo> userPost = sysUserPostMapper.getUserPost(userIds);
|
|
|
|
+ Map<Long, String> userIdToPostMap = userPost.stream()
|
|
|
|
+ .collect(Collectors.toMap(UserPostVo::getUserId, UserPostVo::getPostName));
|
|
|
|
+ users.forEach(user -> user.setPost(userIdToPostMap.get(user.getUserId())));
|
|
|
|
+ List<SysDept> deptTrees = buildDeptTree2(depts);
|
|
|
|
+ fillUsersToDepts(deptTrees, users);
|
|
|
|
+ return deptTrees.stream().map(TreeNode::new).collect(Collectors.toList());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void fillUsersToDepts(List<SysDept> depts, List<SysUser> users) {
|
|
|
|
+ for (SysDept dept : depts) {
|
|
|
|
+ if (dept.getChildren() == null || dept.getChildren().isEmpty()) {
|
|
|
|
+ List<SysUser> deptUsers = filterUsersByDept(users, dept.getDeptId());
|
|
|
|
+ if (!deptUsers.isEmpty()) {
|
|
|
|
+ dept.setUsers(deptUsers);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (dept.getChildren() != null) {
|
|
|
|
+ fillUsersToDepts(dept.getChildren(), users);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- if (StringUtils.isNotBlank(dept.getStatus())){
|
|
|
|
- deptQuery.eq(SysDept::getStatus, dept.getStatus());
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<SysUser> filterUsersByDept(List<SysUser> users, Long deptId) {
|
|
|
|
+ return users.stream()
|
|
|
|
+ .filter(user -> user.getDeptId().equals(deptId))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<SysDept> buildDeptTree2(List<SysDept> depts) {
|
|
|
|
+ List<SysDept> returnList = new ArrayList<SysDept>();
|
|
|
|
+ List<Long> tempList = new ArrayList<Long>();
|
|
|
|
+ for (SysDept dept : depts) {
|
|
|
|
+ tempList.add(dept.getDeptId());
|
|
}
|
|
}
|
|
- deptQuery.orderByAsc(SysDept::getParentId, SysDept::getOrderNum)
|
|
|
|
- .apply(DataScopeContextHolder.getDataScopeSql());
|
|
|
|
- log.debug(DataScopeContextHolder.getDataScopeSql());
|
|
|
|
|
|
+ for (Iterator<SysDept> iterator = depts.iterator(); iterator.hasNext(); ) {
|
|
|
|
+ SysDept dept = (SysDept) iterator.next();
|
|
|
|
+ if (!tempList.contains(dept.getParentId())) {
|
|
|
|
+ recursionFn2(depts, dept);
|
|
|
|
+ returnList.add(dept);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (returnList.isEmpty()) {
|
|
|
|
+ returnList = depts;
|
|
|
|
+ }
|
|
|
|
+ return returnList;
|
|
|
|
+ }
|
|
|
|
|
|
- return deptMapper.selectList(deptQuery);
|
|
|
|
|
|
+ private void recursionFn2(List<SysDept> list, SysDept t) {
|
|
|
|
+ List<SysDept> childList = getChildList(list, t);
|
|
|
|
+ t.setChildren(childList);
|
|
|
|
+ for (SysDept tChild : childList) {
|
|
|
|
+ if (hasChild(list, tChild)) {
|
|
|
|
+ recursionFn(list, tChild);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -120,7 +169,7 @@ public class SysDeptServiceImpl extends AbstractCrudService<SysDeptMapper, SysDe
|
|
return deptTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
|
|
return deptTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
|
|
}
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
|
|
|
+/* @Override
|
|
public List<TreeSelect> buildDeptUserTreeSelect(List<SysDept> depts, List<SysUser> users) {
|
|
public List<TreeSelect> buildDeptUserTreeSelect(List<SysDept> depts, List<SysUser> users) {
|
|
List<SysDept> deptTrees = buildDeptTree(depts);
|
|
List<SysDept> deptTrees = buildDeptTree(depts);
|
|
List<TreeSelect> treeSelectList = new ArrayList<>();
|
|
List<TreeSelect> treeSelectList = new ArrayList<>();
|
|
@@ -141,7 +190,7 @@ public class SysDeptServiceImpl extends AbstractCrudService<SysDeptMapper, SysDe
|
|
treeSelectList.add(treeSelect);
|
|
treeSelectList.add(treeSelect);
|
|
}
|
|
}
|
|
return treeSelectList;
|
|
return treeSelectList;
|
|
- }
|
|
|
|
|
|
+ }*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|