Commit 958ab538 by levphon

获取用户下级by用户id

1 parent 799bd47d
......@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.*;
import java.util.Collection;
import java.util.List;
import java.util.Set;
/**
* feign用户服务接口
......@@ -53,25 +54,32 @@ public class FeignUserController implements cn.com.glsx.usercenter.api.feign.Use
}
@Override
@GetMapping(value = "/getSuperiorUserById")
public R<User> getSuperiorUserById(@RequestParam("id") Long id) {
cn.com.glsx.shield.modules.entity.User u = userService.getSuperiorUserById(id);
@GetMapping(value = "/getSuperiorById")
public R<User> getSuperiorById(@RequestParam("id") Long userId) {
cn.com.glsx.shield.modules.entity.User u = userService.getSuperiorUserById(userId);
User user = null;
if (u != null) {
user = UserConverter.INSTANCE.do2foo(u);
user.setMid(id);
user.setMid(userId);
}
return R.ok().data(user);
}
@Override
@PostMapping(value = "/getSuperiorUserByIds")
public R<List<User>> getSuperiorUserByIds(@RequestBody Collection<Long> userIds) {
@PostMapping(value = "/getSuperiorByIds")
public R<List<User>> getSuperiorByIds(@RequestBody Collection<Long> userIds) {
List<User> userList = userService.getSuperiorUserByIds(userIds);
return R.ok().data(userList);
}
@Override
@GetMapping(value = "/getSubordinateById")
public R<Set<Long>> getSubordinateById(@RequestParam("id") Long userId) {
Set<Long> userIdSet = userService.getSubordinateById(userId);
return R.ok().data(userIdSet);
}
@Override
@ApiOperation(value = "系统用户列表查询")
@GetMapping("/findByUser")
public R<List<User>> findByUser(@RequestBody FindUserRequest request) {
......
......@@ -31,6 +31,7 @@ import com.glsx.plat.jwt.base.ComJwtUser;
import com.glsx.plat.jwt.util.JwtUtils;
import com.glsx.plat.web.utils.SessionUtils;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
......@@ -754,58 +755,64 @@ public class UserService {
authUser.setRoles(list);
}
//可见租户
Set<Long> tenantIds = this.getRelationAuthTenantIds(authUser);
Set<Long> tenantIds = this.getRelationAuthTenantIds(user.getId(), roleList.get(0).getId());
//可见根部门(租户)
authUser.setVisibleTenantIds(tenantIds);
//超级管理员无需查询更详细的部门、用户等信息
if (!isSupperAdmin) {
//可见部门
Set<Long> deptIds = this.getRelationAuthDeptIds(authUser);
Set<Long> deptIds = this.getRelationAuthDeptIds(user.getId(), roleList.get(0).getId());
//可见组织(部门)
authUser.setVisibleDeptIds(deptIds);
//可见用户
Set<Long> userIds = this.getRelationAuthUserIds(authUser);
Set<Long> userIds = this.getRelationAuthUserIds(user.getId(), roleList.get(0).getId());
//可见用户
authUser.setVisibleCreatorIds(userIds);
}
return authUser;
}
public Set<Long> getRelationAuthTenantIds(SyntheticUser authUser) {
List<Tenant> deptList = departmentService.getUserRoleTenants(authUser.getUserId(),
authUser.getRoles().get(0).getRoleId());
Set<Long> tenantIds = deptList.stream().map(Tenant::getId).collect(Collectors.toSet());
/**
* 获取用户根据数据权限范围内的可见租户id
*
* @param userId
* @param roleId
* @return
*/
public Set<Long> getRelationAuthTenantIds(Long userId, Long roleId) {
//可见根部门(租户)
authUser.setVisibleTenantIds(tenantIds);
List<Tenant> deptList = departmentService.getUserRoleTenants(userId, roleId);
return tenantIds;
return deptList.stream().map(Tenant::getId).collect(Collectors.toSet());
}
public Set<Long> getRelationAuthDeptIds(SyntheticUser authUser) {
List<Department> deptList = departmentService.getUserRoleDepartments(authUser.getUserId(),
authUser.getRoles().get(0).getRoleId());
Set<Long> deptIds = deptList.stream().map(Department::getId).collect(Collectors.toSet());
/**
* 获取用户根据数据权限范围内的可见部门id
*
* @param userId
* @param roleId
* @return
*/
public Set<Long> getRelationAuthDeptIds(Long userId, Long roleId) {
//可见组织(部门)
authUser.setVisibleDeptIds(deptIds);
List<Department> deptList = departmentService.getUserRoleDepartments(userId, roleId);
return deptIds;
return deptList.stream().map(Department::getId).collect(Collectors.toSet());
}
/**
* 获取用户根据数据权限范围内的可见用户id
*
* @param authUser
* @param userId
* @param roleId
* @return
*/
public Set<Long> getRelationAuthUserIds(SyntheticUser authUser) {
List<User> userList = departmentService.getUserRoleUsers(authUser.getUserId(), authUser.getRoles().get(0).getRoleId());
public Set<Long> getRelationAuthUserIds(Long userId, Long roleId) {
List<User> userList = departmentService.getUserRoleUsers(userId, roleId);
Set<Long> userIds = userList.stream().map(User::getId).collect(Collectors.toSet());
//可见用户
authUser.setVisibleCreatorIds(userIds);
return userIds;
return userList.stream().map(User::getId).collect(Collectors.toSet());
}
/**
......@@ -1000,6 +1007,16 @@ public class UserService {
return userMapper.selectSuperiorUserById(id);
}
public Set<Long> getSubordinateById(Long userId) {
List<Role> roleList = roleService.getUserRoleList(userId);
if (CollectionUtils.isEmpty(roleList)) {
return Sets.newHashSet();
}
return this.getRelationAuthUserIds(userId, roleList.get(0).getId());
}
public List<cn.com.glsx.usercenter.api.dto.response.User> getSuperiorUserByIds(Collection<Long> userIds) {
return userMapper.selectSuperiorUserByIds(userIds);
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!