Browse Source

修改获取用户信息,改为从token中获取

tags/v1.0.0^2
wanjing 1 year ago
parent
commit
b719f0f045
4 changed files with 8 additions and 48 deletions
  1. +3
    -4
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/UserController.java
  2. +1
    -1
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/user/IUserService.java
  3. +2
    -2
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/user/UserServiceImpl.java
  4. +2
    -41
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/user/query/QueryUserInfoByIdService.java

+ 3
- 4
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/UserController.java View File

@@ -41,12 +41,11 @@ public class UserController {
/**
* 获取用户详情
*
* @param username
* @return
*/
@GetMapping("/info/{username}")
public JsonResult getUserInfo(@PathVariable("username") String username) {
return userService.getUserInfo(username);
@GetMapping("/info")
public JsonResult getUserInfo() {
return userService.getUserInfo();
}

/**

+ 1
- 1
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/user/IUserService.java View File

@@ -34,7 +34,7 @@ public interface IUserService {
* @param username
* @return
*/
JsonResult getUserInfo(String username);
JsonResult getUserInfo();

/**
* 添加用户

+ 2
- 2
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/user/UserServiceImpl.java View File

@@ -80,8 +80,8 @@ public class UserServiceImpl implements IUserService {
* @return
*/
@Override
public JsonResult getUserInfo(String username) {
return queryUserInfoByIdService.getUserInfo(username);
public JsonResult getUserInfo() {
return queryUserInfoByIdService.getUserInfo();
}

/**

+ 2
- 41
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/user/query/QueryUserInfoByIdService.java View File

@@ -6,14 +6,11 @@ import com.tuoheng.admin.conver.UserConverMapper;
import com.tuoheng.admin.entity.Dept;
import com.tuoheng.admin.entity.Role;
import com.tuoheng.admin.entity.User;
import com.tuoheng.admin.enums.code.user.QueryUserInfoByIdCodeEnum;
import com.tuoheng.admin.mapper.DeptMapper;
import com.tuoheng.admin.mapper.RoleMapper;
import com.tuoheng.admin.mapper.UserMapper;
import com.tuoheng.admin.utils.CurrentUserUtil;
import com.tuoheng.admin.vo.user.UserInfoVo;
import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -29,9 +26,6 @@ import org.springframework.stereotype.Service;
@Service
public class QueryUserInfoByIdService {

@Autowired
private UserMapper userMapper;

@Autowired
private DeptMapper deptMapper;

@@ -43,16 +37,9 @@ public class QueryUserInfoByIdService {
*
* @return
*/
public JsonResult getUserInfo(String username) {
public JsonResult getUserInfo() {
log.info("进入根据用户名查询用户信息业务");
JsonResult result = this.check(username);
if (0 != result.getCode()) {
log.info("根据用户名查询用户信息业务:校验失败:{}", result.getMsg());
return result;
}

User user = (User) result.getData();

User user = CurrentUserUtil.getUserInfo();
UserInfoVo userInfoVo = UserConverMapper.INSTANCE.fromUserToUserInfoVo(user);
Dept dept = deptMapper.selectOne(new LambdaQueryWrapper<Dept>()
.eq(Dept::getId, userInfoVo.getDeptId())
@@ -60,7 +47,6 @@ public class QueryUserInfoByIdService {
if (ObjectUtil.isNotNull(dept)) {
userInfoVo.setDeptName(dept.getName());
}

Role role = roleMapper.selectOne(new LambdaQueryWrapper<Role>()
.eq(Role::getId, userInfoVo.getRoleId())
.eq(Role::getMark, 1));
@@ -69,29 +55,4 @@ public class QueryUserInfoByIdService {
}
return JsonResult.success(userInfoVo);
}

/**
* 检查参数
*
* @param username
* @return
*/
private JsonResult check(String username) {
if (StringUtils.isEmpty(username)) {
return JsonResult.error(QueryUserInfoByIdCodeEnum.USERNAME_ID_IS_NULL.getCode(), QueryUserInfoByIdCodeEnum.USERNAME_ID_IS_NULL.getMsg());
}
User user = userMapper.selectOne(new LambdaQueryWrapper<User>()
.eq(User::getUsername, username)
.eq(User::getMark, 1));

if (ObjectUtil.isNull(user)) {
return JsonResult.error(QueryUserInfoByIdCodeEnum.USER_IS_NOT_EXIST.getCode(), QueryUserInfoByIdCodeEnum.USER_IS_NOT_EXIST.getMsg());
}

if (!user.getTenantId().equals(CurrentUserUtil.getTenantId())) {
return JsonResult.error(QueryUserInfoByIdCodeEnum.NON_TENANT_USER.getCode(), QueryUserInfoByIdCodeEnum.NON_TENANT_USER.getMsg());
}
return JsonResult.success(user);
}

}

Loading…
Cancel
Save