Commit f5e6c9bc authored by wdy's avatar wdy

Merge branch 'dev' of http://gitlab.91isoft.com:90/wangfei/vehicle-quality-review into wangdingyi

parents 4de9ba8b 50d0b217
...@@ -90,7 +90,7 @@ public class SysUserController extends BaseController ...@@ -90,7 +90,7 @@ public class SysUserController extends BaseController
role.setRoleName(request.getRoleName()); role.setRoleName(request.getRoleName());
List<SysRole> roleList = roleService.selectRoleList(role); List<SysRole> roleList = roleService.selectRoleList(role);
if (CollUtil.isNotEmpty(roleList)) { if (CollUtil.isNotEmpty(roleList)) {
List<SysUser> list = userService.selectUserListByRoleId(roleList.get(0).getRoleId()); List<SysUser> list = userService.selectUserByRoleInDept(roleList.get(0).getRoleId());
return R.ok(list); return R.ok(list);
} else { } else {
return R.fail("角色不存在"); return R.fail("角色不存在");
......
...@@ -219,4 +219,10 @@ public interface ISysUserService ...@@ -219,4 +219,10 @@ public interface ISysUserService
*/ */
public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName); public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName);
/**
* 通过角色ID查询在同部门下的所有用户
* @param roleId
* @return
*/
List<SysUser> selectUserByRoleInDept(Long roleId);
} }
...@@ -4,6 +4,9 @@ import java.util.ArrayList; ...@@ -4,6 +4,9 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.validation.Validator; import javax.validation.Validator;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.system.mapper.*;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -22,11 +25,6 @@ import com.ruoyi.common.utils.spring.SpringUtils; ...@@ -22,11 +25,6 @@ import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.system.domain.SysPost; import com.ruoyi.system.domain.SysPost;
import com.ruoyi.system.domain.SysUserPost; import com.ruoyi.system.domain.SysUserPost;
import com.ruoyi.system.domain.SysUserRole; import com.ruoyi.system.domain.SysUserRole;
import com.ruoyi.system.mapper.SysPostMapper;
import com.ruoyi.system.mapper.SysRoleMapper;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.mapper.SysUserPostMapper;
import com.ruoyi.system.mapper.SysUserRoleMapper;
import com.ruoyi.system.service.ISysConfigService; import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.system.service.ISysUserService; import com.ruoyi.system.service.ISysUserService;
...@@ -61,6 +59,9 @@ public class SysUserServiceImpl implements ISysUserService ...@@ -61,6 +59,9 @@ public class SysUserServiceImpl implements ISysUserService
@Autowired @Autowired
protected Validator validator; protected Validator validator;
@Autowired
private SysDeptMapper sysDeptMapper;
@Override @Override
public List<SysUser> selectUserListByRoleId(Long roleId) { public List<SysUser> selectUserListByRoleId(Long roleId) {
return userMapper.selectUserListByRoleId(roleId); return userMapper.selectUserListByRoleId(roleId);
...@@ -552,4 +553,46 @@ public class SysUserServiceImpl implements ISysUserService ...@@ -552,4 +553,46 @@ public class SysUserServiceImpl implements ISysUserService
} }
return successMsg.toString(); return successMsg.toString();
} }
/**
* 通过角色ID查询在同部门下的所有用户
* @param roleId
* @return
*/
@Override
public List<SysUser> selectUserByRoleInDept(Long roleId) {
List<SysUser> list = new ArrayList<>();
// 获取当前登陆用户的部门
Long deptId = SecurityUtils.getDeptId();
// 获取当前角色下的所有用户
List<SysUser> userList = selectUserListByRoleId(roleId);
// 查询出当前用户所在部门以及所有子部门
List<SysDept> deptList = sysDeptMapper.selectDeptList(new SysDept());
List<Long> userListInDept = new ArrayList<>();
userListInDept.add(deptId);
getAllDeptId(deptList, deptId, userListInDept);
for (SysUser user : userList) {
if (userListInDept.contains(user.getDeptId())) {
list.add(user);
}
}
return list;
}
/**
* 递归
* 查询出当前用户所在部门以及所有子部门
* @param deptList 传入的部门集合
* @param deptId 查询需要的部门ID
* @param userListInDept 存入的指定部门集合
*/
private void getAllDeptId(List<SysDept> deptList, Long deptId, List<Long> userListInDept) {
deptList.stream()
.filter(dept -> dept.getParentId().equals(deptId))
.forEach(dept -> {
userListInDept.add(dept.getDeptId());
getAllDeptId(deptList, dept.getDeptId(), userListInDept);
});
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment