按 userKey 获取用户信息

  1. public Optional<BizUser> findByUserKey(String userKey) {
  2. R<GetUserByUserKeyResponse> r = bizUserClient.getUserByUserKey(userKey);
  3. if (r.isSuccess()) {
  4. return Optional.of(r.getData().getBizUser());
  5. }
  6. if (r.getCode() == FeignCodes.DataNotExist) {
  7. return Optional.empty();
  8. }
  9. throw new RuntimeException("查询用户信息出错");
  10. }

用户信息接口 BizUserClient

按用户获取所属组织机构信息

  1. /**
  2. * 返回用户所属的组织机构信息
  3. * 用户可属于多个组织
  4. *
  5. * @param userId 用户ID
  6. * @return 组织机构信息
  7. */
  8. @GetMapping(value = "/b/user/{userId}/organizations")
  9. R<ListUserOrganizationResponse> listUserOrganization(@PathVariable("userId") Long userId);

按用户获取所属组织机构信息(带子级)

  1. /**
  2. * 返回用户所属的组织机构信息(含子级)
  3. * 用户可属于多个组织
  4. *
  5. * @param userId 用户ID
  6. * @return 组织机构信息
  7. */
  8. @GetMapping(value = "/b/user/{userId}/organizations/hierarchy")
  9. R<ListUserOrganizationHierarchyResponse> listUserOrganizationHierarchy(@PathVariable("userId") Long userId);

批量查询多个用户所属的组织机构信息

    /**
     * 批量查询多个用户所属的组织机构信息
     * 用户可属于多个组织
     *
     * @param userIds 用户ID数组
     * @return 多个用户所属的组织机构信息
     */
    @GetMapping(value = "/b/user/batchFindUserOrganizations")
    R<BatchListUserOrganizationResponse> batchListUserOrganization(@RequestParam("userIds") Long[] userIds);

为用户分配一个组织

    /**
     * 为用户分配一个组织
     *
     * @param userId         用户编码
     * @param organizationId 组织机构编码
     * @return 分配成功
     */
    @PostMapping(value = "/b/user/{userId}/organization/assign")
    R<Void> assignOrganization(@PathVariable("userId") Long userId,
                               @RequestParam("organizationId") Long organizationId);

验证访问权限

    /**
     * 验证访问权限
     *
     * @param userId        用户编码
     * @param permissionKey 权限标识
     * @return 无权限抛出异常
     */
    @PostMapping(value = "/b/user/{userId}/checkPermission")
    R<Void> checkPermission(@PathVariable("userId") Long userId,
                            @RequestParam("permissionKey") String permissionKey);

验证权限和数据范围

    /**
     * 验证权限和数据范围
     *
     * @param userId        用户编码
     * @param permissionKey 权限标识
     * @param scopeType     数据范围类型
     * @param scopeKey      数据范围标识
     * @return 无权限抛出异常
     */
    @PostMapping(value = "/b/user/{userId}/checkPermissionWithScope")
    R<Void> checkPermissionWithScope(@PathVariable("userId") Long userId,
                                     @RequestParam("permissionKey") String permissionKey,
                                     @RequestParam("scopeType") String scopeType,
                                     @RequestParam("scopeKey") String scopeKey);

分组列表用户数据范围权限

    /**
     * 分组列表用户数据范围权限
     *
     * @param userId 用户编码
     * @return 分组数据范围列表
     */
    @GetMapping(value = "/b/user/{userId}/scopes")
    R<ListUserScopeResponse> listUserScope(@PathVariable("userId") Long userId);

批量为用户重新分配数据权限

    /**
     * 批量为用户重新分配数据权限
     *
     * @param userId    用户编码
     * @param scopeType 数据范围类型
     * @param scopeKeys 数据范围标识列表
     * @return 分配成功
     */
    @PostMapping(value = "/b/user/{userId}/scope/{scopeType}/batchReassign")
    R<Void> batchReassignScope(@PathVariable("userId") Long userId,
                               @PathVariable("scopeType") String scopeType,
                               @RequestParam("scopeKeys") String[] scopeKeys);

批量为用户重新分配角色

    /**
     * 批量为用户重新分配角色
     *
     * @param userId  用户编码
     * @param roleIds 角色编码列表
     * @return 分配成功
     */
    @PostMapping(value = "/b/user/{userId}/role/batchReassign")
    R<Void> batchReassignRole(@PathVariable("userId") Long userId,
                              @RequestParam("roleIds") Long[] roleIds);

列表用户角色

    /**
     * 列表用户角色
     *
     * @param userId 用户角色
     * @return 角色列表
     */
    @GetMapping(value = "/b/user/{userId}/roles")
    R<ListUserRoleResponse> listRole(@PathVariable("userId") Long userId);

列表用户拥有的菜单和资源

    /**
     * 列表用户拥有的菜单和资源
     *
     * @param userId 用户编码
     * @return 菜单和资源列表
     */
    @GetMapping(value = "/b/user/{userId}/menuAndResource")
    R<ListUserMenuAndResourceResponse> listMenuAndResource(@PathVariable("userId") Long userId);

组织机构接口 BizOrganizationClient

获取指定组织机构的层级信息

    /**
     * 按组织编码获取层级信息,包含祖先节点和子节点列表
     * 祖先节点为逐级向上返回
     *
     * @param organizationId 组织编码
     * @return 层级信息
     */
    @GetMapping(value = "/b/organization/{organizationId}/hierarchy")
    R<ListOrganizationHierarchyResponse> listHierarchy(@PathVariable("organizationId") Long organizationId);

按组织机构编码获取信息

    /**
     * 按组织机构编码获取信息
     *
     * @param organizationId 组织机构编码
     * @return 组织机构信息
     */
    @GetMapping(value = "/b/organization/{organizationId}")
    R<GetOrganizationByIdResponse> getById(@PathVariable("organizationId") Long organizationId);

角色接口 BizRoleClient

新建角色

    /**
     * 新建角色
     *
     * @param request 角色信息
     * @return 新建成功后的角色信息
     */
    @PostMapping(value = "/b/role/create")
    R<CreateRoleResponse> create(@RequestBody CreateRoleRequest request);