Commit 958ab538 by levphon

获取用户下级by用户id

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