mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
用户赋角色、角色配用户添加组织id参数,添加根据角色id查询用户列表接口
This commit is contained in:
+2
-2
@@ -75,9 +75,9 @@ public class PostController {
|
||||
|
||||
@GetMapping(value = {"/list-all-simple", "simple-list"})
|
||||
@Operation(summary = "获取岗位全列表", description = "只包含被开启的岗位,主要用于前端的下拉选项")
|
||||
public CommonResult<List<PostSimpleRespVO>> getSimplePostList() {
|
||||
public CommonResult<List<PostSimpleRespVO>> getSimplePostList(@RequestParam(value = "organId", required = false) Long organId) {
|
||||
// 获得岗位列表,只要开启状态的
|
||||
List<PostDO> list = postService.getPostList(null, Collections.singleton(CommonStatusEnum.ENABLE.getStatus()));
|
||||
List<PostDO> list = postService.getPostList(null, Collections.singleton(CommonStatusEnum.ENABLE.getStatus()), organId);
|
||||
// 排序后,返回给前端
|
||||
list.sort(Comparator.comparing(PostDO::getSort));
|
||||
return success(BeanUtils.toBean(list, PostSimpleRespVO.class));
|
||||
|
||||
+13
-2
@@ -76,8 +76,9 @@ public class PermissionController {
|
||||
reqVO.getMenuIds().removeIf(menuId -> !CollUtil.contains(menuIds, menuId));
|
||||
});
|
||||
}
|
||||
Long organId = reqVO.getOrganId() == null? OrganContextHolder.getOrganId(): reqVO.getOrganId();
|
||||
// 执行菜单的分配
|
||||
permissionService.assignRoleMenu(reqVO.getRoleId(), reqVO.getMenuIds());
|
||||
permissionService.assignRoleMenu(reqVO.getRoleId(), reqVO.getMenuIds(), organId);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@@ -101,7 +102,8 @@ public class PermissionController {
|
||||
@PostMapping("/assign-user-role")
|
||||
@PreAuthorize("@ss.hasPermission('system:permission:assign-user-role')")
|
||||
public CommonResult<Boolean> assignUserRole(@Validated @RequestBody PermissionAssignUserRoleReqVO reqVO) {
|
||||
permissionService.assignUserRole(reqVO.getUserId(), reqVO.getRoleIds(),OrganContextHolder.getOrganId());
|
||||
Long organId = reqVO.getOrganId() == null ? OrganContextHolder.getOrganId() : reqVO.getOrganId();
|
||||
permissionService.assignUserRole(reqVO.getUserId(), reqVO.getRoleIds(), organId);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@@ -124,4 +126,13 @@ public class PermissionController {
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "获得拥有角色的用户列表")
|
||||
@Parameter(name = "roleId", description = "角色id", required = true)
|
||||
@GetMapping("/list-role-users")
|
||||
@PreAuthorize("@ss.hasPermission('system:permission:assign-user-role')")
|
||||
public CommonResult<Set<Long>> listRoleUsers(@RequestParam("roleId") Long roleId, @RequestParam(value = "organId", required = false) Long organId) {
|
||||
return success(permissionService.getListRoleUsers(roleId, organId));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
@@ -18,4 +18,7 @@ public class PermissionAssignRoleMenuReqVO {
|
||||
@Schema(description = "菜单编号列表", example = "1,3,5")
|
||||
private Set<Long> menuIds = Collections.emptySet(); // 兜底
|
||||
|
||||
@Schema(description = "组织id")
|
||||
private Long organId;
|
||||
|
||||
}
|
||||
|
||||
+3
@@ -18,4 +18,7 @@ public class PermissionAssignUserRoleReqVO {
|
||||
@Schema(description = "角色编号列表", example = "1,3,5")
|
||||
private Set<Long> roleIds = Collections.emptySet(); // 兜底
|
||||
|
||||
@Schema(description = "组织id")
|
||||
private Long organId;
|
||||
|
||||
}
|
||||
|
||||
+3
-2
@@ -126,8 +126,9 @@ public class UserController {
|
||||
|
||||
@GetMapping({"/list-all-simple", "/simple-list"})
|
||||
@Operation(summary = "获取用户精简信息列表", description = "只包含被开启的用户,主要用于前端的下拉选项")
|
||||
public CommonResult<List<UserSimpleRespVO>> getSimpleUserList() {
|
||||
List<AdminUserDO> list = userService.getUserListByStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
public CommonResult<List<UserSimpleRespVO>> getSimpleUserList( @RequestParam(value = "organId", required = false) Long organId,
|
||||
@RequestParam(value = "deptId", required = false) Long deptId) {
|
||||
List<AdminUserDO> list = userService.getUserListByStatus(CommonStatusEnum.ENABLE.getStatus(), organId, deptId);
|
||||
// 拼接数据
|
||||
Map<Long, DeptDO> deptMap = deptService.getDeptMap(
|
||||
convertList(list, AdminUserDO::getDeptId));
|
||||
|
||||
+2
-1
@@ -17,8 +17,9 @@ import java.util.Objects;
|
||||
@Mapper
|
||||
public interface PostMapper extends BaseMapperX<PostDO> {
|
||||
|
||||
default List<PostDO> selectList(Collection<Long> ids, Collection<Integer> statuses) {
|
||||
default List<PostDO> selectList(Collection<Long> ids, Collection<Integer> statuses, Long organId) {
|
||||
return selectList(new LambdaQueryWrapperX<PostDO>()
|
||||
.eqIfPresent(PostDO::getOrganId, organId)
|
||||
.inIfPresent(PostDO::getId, ids)
|
||||
.inIfPresent(PostDO::getStatus, statuses));
|
||||
}
|
||||
|
||||
+6
-2
@@ -62,8 +62,12 @@ public interface AdminUserMapper extends BaseMapperX<AdminUserDO> {
|
||||
return selectList(new LambdaQueryWrapperX<AdminUserDO>().like(AdminUserDO::getNickname, nickname));
|
||||
}
|
||||
|
||||
default List<AdminUserDO> selectListByStatus(Integer status) {
|
||||
return selectList(AdminUserDO::getStatus, status);
|
||||
default List<AdminUserDO> selectListByStatus(Integer status, Long organId, Long deptId) {
|
||||
return selectList(new LambdaQueryWrapperX<AdminUserDO>()
|
||||
.eqIfPresent(AdminUserDO::getOrganId, organId)
|
||||
.eqIfPresent(AdminUserDO::getDeptId, deptId)
|
||||
.eq(AdminUserDO::getStatus, status));
|
||||
// return selectList(AdminUserDO::getStatus, status);
|
||||
}
|
||||
|
||||
default List<AdminUserDO> selectListByDeptIds(Collection<Long> deptIds) {
|
||||
|
||||
+3
-1
@@ -54,7 +54,9 @@ public interface PostService {
|
||||
* @return 部门列表
|
||||
*/
|
||||
List<PostDO> getPostList(@Nullable Collection<Long> ids,
|
||||
@Nullable Collection<Integer> statuses);
|
||||
@Nullable Collection<Integer> statuses,
|
||||
Long organId
|
||||
);
|
||||
|
||||
/**
|
||||
* 获得岗位分页列表
|
||||
|
||||
+2
-2
@@ -118,8 +118,8 @@ public class PostServiceImpl implements PostService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PostDO> getPostList(Collection<Long> ids, Collection<Integer> statuses) {
|
||||
return postMapper.selectList(ids, statuses);
|
||||
public List<PostDO> getPostList(Collection<Long> ids, Collection<Integer> statuses, Long organId) {
|
||||
return postMapper.selectList(ids, statuses, organId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-3
@@ -174,7 +174,7 @@ public class OrganServiceImpl implements OrganService {
|
||||
.setSort(0).setRemark("系统自动生成").setOrganId(organId);
|
||||
Long roleId = roleService.createRole(reqVO, RoleTypeEnum.SYSTEM.getType());
|
||||
// 分配权限
|
||||
permissionService.assignRoleMenu(roleId, tenantPackage.getMenuIds());
|
||||
permissionService.assignRoleMenu(roleId, tenantPackage.getMenuIds(), organId);
|
||||
return roleId;
|
||||
}
|
||||
|
||||
@@ -249,14 +249,14 @@ public class OrganServiceImpl implements OrganService {
|
||||
roles.forEach(role -> {
|
||||
// 如果是组织管理员,重新分配其权限为组织套餐的权限
|
||||
if (Objects.equals(role.getCode(), RoleCodeEnum.TENANT_ADMIN.getCode())) {
|
||||
permissionService.assignRoleMenu(role.getId(), menuIds);
|
||||
permissionService.assignRoleMenu(role.getId(), menuIds, organId);
|
||||
log.info("[updateTenantRoleMenu][组织管理员({}/{}) 的权限修改为({})]", role.getId(), role.getOrganId(), menuIds);
|
||||
return;
|
||||
}
|
||||
// 如果是其他角色,则去掉超过套餐的权限
|
||||
Set<Long> roleMenuIds = permissionService.getRoleMenuListByRoleId(role.getId());
|
||||
roleMenuIds = CollUtil.intersectionDistinct(roleMenuIds, menuIds);
|
||||
permissionService.assignRoleMenu(role.getId(), roleMenuIds);
|
||||
permissionService.assignRoleMenu(role.getId(), roleMenuIds, organId);
|
||||
log.info("[updateTenantRoleMenu][角色({}/{}) 的权限修改为({})]", role.getId(), role.getOrganId(), roleMenuIds);
|
||||
});
|
||||
});
|
||||
|
||||
+8
-1
@@ -43,7 +43,7 @@ public interface PermissionService {
|
||||
* @param roleId 角色编号
|
||||
* @param menuIds 菜单编号集合
|
||||
*/
|
||||
void assignRoleMenu(Long roleId, Set<Long> menuIds);
|
||||
void assignRoleMenu(Long roleId, Set<Long> menuIds, Long organId);
|
||||
|
||||
/**
|
||||
* 处理角色删除时,删除关联授权数据
|
||||
@@ -156,4 +156,11 @@ public interface PermissionService {
|
||||
Set<Long> getRoleMenuListByRoleId2(Set<Long> roleIds);
|
||||
|
||||
void bathAssignUserRole(List<PermissionAssignUserRoleReqVO> listReqVO);
|
||||
|
||||
/**
|
||||
* 获得拥有角色的用户列表
|
||||
* @param roleId
|
||||
* @return
|
||||
*/
|
||||
Set<Long> getListRoleUsers(Long roleId, Long organId);
|
||||
}
|
||||
|
||||
+21
-2
@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.cf.imes.framework.common.enums.CommonStatusEnum;
|
||||
import com.cf.imes.framework.common.util.collection.CollectionUtils;
|
||||
import com.cf.imes.framework.datapermission.core.annotation.DataPermission;
|
||||
@@ -39,6 +40,7 @@ import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static com.cf.imes.framework.common.util.collection.CollectionUtils.convertSet;
|
||||
@@ -146,7 +148,7 @@ public class PermissionServiceImpl implements PermissionService {
|
||||
@DSTransactional // 多数据源,使用 @DSTransactional 保证本地事务,以及数据源的切换
|
||||
@CacheEvict(value = RedisKeyConstants.MENU_ROLE_ID_LIST,
|
||||
allEntries = true) // allEntries 清空所有缓存,主要一次更新涉及到的 menuIds 较多,反倒批量会更快
|
||||
public void assignRoleMenu(Long roleId, Set<Long> menuIds) {
|
||||
public void assignRoleMenu(Long roleId, Set<Long> menuIds, Long organId) {
|
||||
// 获得角色拥有菜单编号
|
||||
Set<Long> dbMenuIds = null;
|
||||
if (Objects.equals(roleId, ORGAN_ADMIN_ROLE_ID) || Objects.equals(roleId, ORGAN_STAFF_ROLE_ID)) {
|
||||
@@ -167,6 +169,8 @@ public class PermissionServiceImpl implements PermissionService {
|
||||
entity.setMenuId(menuId);
|
||||
if (Objects.equals(roleId, ORGAN_ADMIN_ROLE_ID) || Objects.equals(roleId, ORGAN_STAFF_ROLE_ID)) {
|
||||
entity.setOrganId(0L);
|
||||
}else {
|
||||
entity.setOrganId(organId);
|
||||
}
|
||||
return entity;
|
||||
};
|
||||
@@ -238,12 +242,27 @@ public class PermissionServiceImpl implements PermissionService {
|
||||
@Override
|
||||
@DSTransactional
|
||||
public void bathAssignUserRole(List<PermissionAssignUserRoleReqVO> listReqVO) {
|
||||
Long organId = OrganContextHolder.getOrganId();
|
||||
Long contextOrganId = OrganContextHolder.getOrganId();
|
||||
listReqVO.forEach(e->{
|
||||
Long organId = e.getOrganId() ==null ? contextOrganId : e.getOrganId();
|
||||
assignUserRole(e.getUserId(), e.getRoleIds(), organId);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Long> getListRoleUsers(Long roleId, Long organId) {
|
||||
List<UserRoleDO> userRoleDOS = userRoleMapper.selectList(new LambdaQueryWrapperX<UserRoleDO>()
|
||||
.eqIfPresent(UserRoleDO::getOrganId, organId)
|
||||
.eq(UserRoleDO::getRoleId, roleId)
|
||||
.select(UserRoleDO::getUserId)
|
||||
);
|
||||
if(CollUtil.isEmpty(userRoleDOS)) {
|
||||
return new HashSet<>();
|
||||
}
|
||||
return userRoleDOS.stream().map(UserRoleDO::getUserId).collect(Collectors.toSet());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = RedisKeyConstants.MENU_ROLE_ID_LIST, key = "#menuId")
|
||||
public Set<Long> getMenuRoleIdListByMenuIdFromCache(Long menuId) {
|
||||
|
||||
+1
-1
@@ -206,7 +206,7 @@ public interface AdminUserService {
|
||||
* @param status 状态
|
||||
* @return 用户们
|
||||
*/
|
||||
List<AdminUserDO> getUserListByStatus(Integer status);
|
||||
List<AdminUserDO> getUserListByStatus(Integer status, Long organId, Long deptId);
|
||||
|
||||
/**
|
||||
* 判断密码是否匹配
|
||||
|
||||
+2
-2
@@ -489,8 +489,8 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AdminUserDO> getUserListByStatus(Integer status) {
|
||||
return userMapper.selectListByStatus(status);
|
||||
public List<AdminUserDO> getUserListByStatus(Integer status, Long organId, Long deptId) {
|
||||
return userMapper.selectListByStatus(status, organId, deptId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -710,7 +710,7 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest {
|
||||
Integer status = CommonStatusEnum.DISABLE.getStatus();
|
||||
|
||||
// 调用
|
||||
List<AdminUserDO> result = userService.getUserListByStatus(status);
|
||||
List<AdminUserDO> result = userService.getUserListByStatus(status, 1L);
|
||||
// 断言
|
||||
assertEquals(1, result.size());
|
||||
assertEquals(user, result.get(0));
|
||||
|
||||
Reference in New Issue
Block a user