feat: 🎸 用户信息查询接口
This commit is contained in:
parent
ec89859f60
commit
960aee1b68
@ -13,12 +13,15 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.jeecg.modules.biz.dto.TeacherInfo;
|
import org.jeecg.modules.biz.dto.TeacherInfo;
|
||||||
import org.jeecg.modules.biz.service.UserBizService;
|
import org.jeecg.modules.biz.service.UserBizService;
|
||||||
|
import org.jeecg.modules.gen.userinfo.entity.UserInfo;
|
||||||
|
import org.jeecg.modules.gen.userinfo.mapper.UserInfoMapper;
|
||||||
import org.jeecg.modules.system.entity.SysUser;
|
import org.jeecg.modules.system.entity.SysUser;
|
||||||
import org.jeecg.modules.system.service.*;
|
import org.jeecg.modules.system.service.*;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
@ -27,6 +30,7 @@ import org.jeecg.common.constant.CommonConstant;
|
|||||||
import org.jeecg.common.system.util.JwtUtil;
|
import org.jeecg.common.system.util.JwtUtil;
|
||||||
import org.jeecg.common.util.PasswordUtil;
|
import org.jeecg.common.util.PasswordUtil;
|
||||||
import org.jeecg.common.util.RedisUtil;
|
import org.jeecg.common.util.RedisUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
@ -44,6 +48,8 @@ public class UserBizController {
|
|||||||
private RedisUtil redisUtil;
|
private RedisUtil redisUtil;
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserBizService userBizService;
|
private UserBizService userBizService;
|
||||||
|
@Autowired
|
||||||
|
private UserInfoMapper userInfoMapper;
|
||||||
|
|
||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
@Operation(summary = "用户登录")
|
@Operation(summary = "用户登录")
|
||||||
@ -60,9 +66,9 @@ public class UserBizController {
|
|||||||
LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
queryWrapper.eq(SysUser::getUsername,username);
|
queryWrapper.eq(SysUser::getUsername,username);
|
||||||
SysUser sysUser = sysUserService.getOne(queryWrapper);
|
SysUser sysUser = sysUserService.getOne(queryWrapper);
|
||||||
result = sysUserService.checkUserIsEffective(sysUser);
|
Result<?> checkResult = sysUserService.checkUserIsEffective(sysUser);
|
||||||
if(!result.isSuccess()) {
|
if(!checkResult.isSuccess()) {
|
||||||
return result;
|
return result.error500(checkResult.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// step.3 校验用户名或密码是否正确
|
// step.3 校验用户名或密码是否正确
|
||||||
@ -130,4 +136,66 @@ public class UserBizController {
|
|||||||
List<TeacherInfo> list = userBizService.queryAllTeachers(categoryId);
|
List<TeacherInfo> list = userBizService.queryAllTeachers(categoryId);
|
||||||
return Result.OK(list);
|
return Result.OK(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/info")
|
||||||
|
@Operation(summary = "查询用户信息")
|
||||||
|
public Result<JSONObject> queryUserInfo(HttpServletRequest request) {
|
||||||
|
try {
|
||||||
|
// 1. 从JWT中获取用户名
|
||||||
|
String username = JwtUtil.getUserNameByToken(request);
|
||||||
|
if (username == null || username.trim().isEmpty()) {
|
||||||
|
return Result.error(401, "用户未登录或token无效");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 根据用户名查询系统用户信息
|
||||||
|
SysUser sysUser = sysUserService.getUserByName(username);
|
||||||
|
if (sysUser == null) {
|
||||||
|
return Result.error(404, "用户不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 查询用户角色
|
||||||
|
List<String> roles = sysUserService.getUserRolesSet(username).stream()
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
// 4. 根据用户ID查询user_info表信息
|
||||||
|
UserInfo userInfo = userInfoMapper.selectOne(
|
||||||
|
new QueryWrapper<UserInfo>().eq("user_id", sysUser.getId())
|
||||||
|
);
|
||||||
|
|
||||||
|
// 5. 构建返回结果
|
||||||
|
JSONObject result = new JSONObject(new LinkedHashMap<>());
|
||||||
|
|
||||||
|
// 基本用户信息
|
||||||
|
JSONObject userBasicInfo = new JSONObject(new LinkedHashMap<>());
|
||||||
|
userBasicInfo.put("id", sysUser.getId());
|
||||||
|
userBasicInfo.put("username", sysUser.getUsername());
|
||||||
|
userBasicInfo.put("realname", sysUser.getRealname());
|
||||||
|
userBasicInfo.put("avatar", sysUser.getAvatar());
|
||||||
|
userBasicInfo.put("phone", sysUser.getPhone());
|
||||||
|
userBasicInfo.put("email", sysUser.getEmail());
|
||||||
|
userBasicInfo.put("sex", sysUser.getSex());
|
||||||
|
userBasicInfo.put("birthday", sysUser.getBirthday());
|
||||||
|
userBasicInfo.put("status", sysUser.getStatus());
|
||||||
|
|
||||||
|
result.put("baseInfo", userBasicInfo);
|
||||||
|
result.put("roles", roles);
|
||||||
|
|
||||||
|
// 扩展用户信息
|
||||||
|
if (userInfo != null) {
|
||||||
|
JSONObject extendedInfo = new JSONObject(new LinkedHashMap<>());
|
||||||
|
extendedInfo.put("major", userInfo.getMajor());
|
||||||
|
extendedInfo.put("college", userInfo.getCollege());
|
||||||
|
extendedInfo.put("education", userInfo.getEducation());
|
||||||
|
extendedInfo.put("title", userInfo.getTitle());
|
||||||
|
extendedInfo.put("tag", userInfo.getTag());
|
||||||
|
extendedInfo.put("sortOrder", userInfo.getSortOrder());
|
||||||
|
result.put("extendedInfo", extendedInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.OK(result);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("查询用户信息失败:" + e.getMessage(), e);
|
||||||
|
return Result.error(500, "查询用户信息失败:" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user