diff --git a/hippo4j-auth/src/main/java/cn/hippo4j/auth/model/biz/user/UserReqDTO.java b/hippo4j-auth/src/main/java/cn/hippo4j/auth/model/biz/user/UserReqDTO.java index 82b602cd..b84529d7 100644 --- a/hippo4j-auth/src/main/java/cn/hippo4j/auth/model/biz/user/UserReqDTO.java +++ b/hippo4j-auth/src/main/java/cn/hippo4j/auth/model/biz/user/UserReqDTO.java @@ -2,6 +2,7 @@ package cn.hippo4j.auth.model.biz.user; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import lombok.Data; +import lombok.experimental.Accessors; /** * User req dto. @@ -10,6 +11,7 @@ import lombok.Data; * @date 2021/11/11 20:30 */ @Data +@Accessors(chain = true) public class UserReqDTO extends Page { /** diff --git a/hippo4j-auth/src/main/java/cn/hippo4j/auth/service/UserService.java b/hippo4j-auth/src/main/java/cn/hippo4j/auth/service/UserService.java index 9e92ffa2..bbbffba5 100644 --- a/hippo4j-auth/src/main/java/cn/hippo4j/auth/service/UserService.java +++ b/hippo4j-auth/src/main/java/cn/hippo4j/auth/service/UserService.java @@ -52,4 +52,12 @@ public interface UserService { */ List getUserLikeUsername(String userName); + /** + * 获取用户详情. + * + * @param reqDTO + * @return + */ + UserRespDTO getUser(UserReqDTO reqDTO); + } diff --git a/hippo4j-auth/src/main/java/cn/hippo4j/auth/service/impl/UserServiceImpl.java b/hippo4j-auth/src/main/java/cn/hippo4j/auth/service/impl/UserServiceImpl.java index d8f5b0fc..6b0470fa 100644 --- a/hippo4j-auth/src/main/java/cn/hippo4j/auth/service/impl/UserServiceImpl.java +++ b/hippo4j-auth/src/main/java/cn/hippo4j/auth/service/impl/UserServiceImpl.java @@ -8,8 +8,10 @@ import cn.hippo4j.auth.model.biz.user.UserRespDTO; import cn.hippo4j.auth.service.RoleService; import cn.hippo4j.auth.service.UserService; import cn.hippo4j.common.toolkit.StringUtil; +import cn.hippo4j.common.web.exception.ServiceException; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -19,6 +21,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; /** @@ -92,4 +95,15 @@ public class UserServiceImpl implements UserService { return userNames; } + @Override + public UserRespDTO getUser(UserReqDTO reqDTO) { + Wrapper queryWrapper = Wrappers.lambdaQuery(UserInfo.class).eq(UserInfo::getUserName, reqDTO.getUserName()); + UserInfo userInfo = userMapper.selectOne(queryWrapper); + + UserRespDTO respUser = Optional.ofNullable(userInfo) + .map(each -> BeanUtil.toBean(each, UserRespDTO.class)) + .orElseThrow(() -> new ServiceException("查询无此用户, 可以尝试清空缓存或退出登录.")); + return respUser; + } + } diff --git a/hippo4j-console/src/main/java/cn/hippo4j/console/controller/UserController.java b/hippo4j-console/src/main/java/cn/hippo4j/console/controller/UserController.java index e87d98e8..04091505 100644 --- a/hippo4j-console/src/main/java/cn/hippo4j/console/controller/UserController.java +++ b/hippo4j-console/src/main/java/cn/hippo4j/console/controller/UserController.java @@ -48,8 +48,7 @@ public class UserController { @GetMapping("/info/{username}") public Result userInfo(@PathVariable("username") String username) { - IPage listUser = userService.listUser(new UserQueryPageReqDTO().setUserName(username)); - UserRespDTO userRespDTO = listUser.getRecords().get(0); + UserRespDTO userRespDTO = userService.getUser(new UserReqDTO().setUserName(username)); return Results.success(userRespDTO); }