RemoteUserService add getUserById方法 (项目中有需要 通过内部获取 user基础信息的需求)

This commit is contained in:
duandazhi 2021-09-07 10:14:37 +08:00
parent 17ff3db1b2
commit 1b2521712c
3 changed files with 34 additions and 9 deletions

View File

@ -1,11 +1,7 @@
package com.ruoyi.system.api; package com.ruoyi.system.api;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import com.ruoyi.common.core.constant.SecurityConstants; import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.constant.ServiceNameConstants; import com.ruoyi.common.core.constant.ServiceNameConstants;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.R;
@ -15,7 +11,7 @@ import com.ruoyi.system.api.model.LoginUser;
/** /**
* 用户服务 * 用户服务
* *
* @author ruoyi * @author ruoyi
*/ */
@FeignClient(contextId = "remoteUserService", value = ServiceNameConstants.SYSTEM_SERVICE, fallbackFactory = RemoteUserFallbackFactory.class) @FeignClient(contextId = "remoteUserService", value = ServiceNameConstants.SYSTEM_SERVICE, fallbackFactory = RemoteUserFallbackFactory.class)
@ -40,4 +36,14 @@ public interface RemoteUserService
*/ */
@PostMapping("/user/register") @PostMapping("/user/register")
public R<Boolean> registerUserInfo(@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); public R<Boolean> registerUserInfo(@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
/**
* 根据userId获取用户信息
* @param userId 用户id必填
* @param source 可选header参数 取值{@link SecurityConstants#INNER}
* @return 用户基础信息
*/
@GetMapping(value = "/user/getUserById")
public R<SysUser> getUserById(@RequestParam(value = "userId") Long userId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
} }

View File

@ -11,7 +11,7 @@ import com.ruoyi.system.api.model.LoginUser;
/** /**
* 用户服务降级处理 * 用户服务降级处理
* *
* @author ruoyi * @author ruoyi
*/ */
@Component @Component
@ -36,6 +36,12 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
{ {
return R.fail("注册用户失败:" + throwable.getMessage()); return R.fail("注册用户失败:" + throwable.getMessage());
} }
@Override
public R<SysUser> getUserById(Long userId, String source)
{
return R.fail("获取用户信息失败:" + throwable.getMessage());
}
}; };
} }
} }

View File

@ -40,7 +40,7 @@ import com.ruoyi.system.service.ISysUserService;
/** /**
* 用户信息 * 用户信息
* *
* @author ruoyi * @author ruoyi
*/ */
@RestController @RestController
@ -147,7 +147,7 @@ public class SysUserController extends BaseController
/** /**
* 获取用户信息 * 获取用户信息
* *
* @return 用户信息 * @return 用户信息
*/ */
@GetMapping("getInfo") @GetMapping("getInfo")
@ -303,4 +303,17 @@ public class SysUserController extends BaseController
userService.insertUserAuth(userId, roleIds); userService.insertUserAuth(userId, roleIds);
return success(); return success();
} }
/**
* 根据用户编号获取用户基础信息(不包含权限信息不含授权用于内部调用)
*/
@InnerAuth
@GetMapping(value = "getUserById")
public R<SysUser> getUserById(Long userId)
{
if (userId == null) {
return R.fail("getUserById:getUserId不能为空!");
}
return R.ok(userService.selectUserById(userId), "获取用户信息成功");
}
} }