开发获取用户详情接口.

pull/84/head
chen.ma 3 years ago
parent 135889e8d1
commit 2e4abac7e1

@ -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 {
/**

@ -52,4 +52,12 @@ public interface UserService {
*/
List<String> getUserLikeUsername(String userName);
/**
* .
*
* @param reqDTO
* @return
*/
UserRespDTO getUser(UserReqDTO reqDTO);
}

@ -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;
}
}

@ -48,8 +48,7 @@ public class UserController {
@GetMapping("/info/{username}")
public Result<UserRespDTO> userInfo(@PathVariable("username") String username) {
IPage<UserRespDTO> 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);
}

Loading…
Cancel
Save