feat: 添加根据邮箱查询教师信息接口
This commit is contained in:
@ -52,6 +52,7 @@ public class RedisConfig {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("null")
|
||||||
@Bean
|
@Bean
|
||||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
|
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
|
||||||
RedisTemplate<String, Object> template = new RedisTemplate<>();
|
RedisTemplate<String, Object> template = new RedisTemplate<>();
|
||||||
|
@ -102,4 +102,15 @@ public class UserController {
|
|||||||
return new ApiResponse<>(ErrorCode.SYSTEM_ERROR, "获取部门用户列表失败", null);
|
return new ApiResponse<>(ErrorCode.SYSTEM_ERROR, "获取部门用户列表失败", null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/teacher/search")
|
||||||
|
public ApiResponse<User> searchTeacher(@RequestParam String email) {
|
||||||
|
logger.info("收到查询教师信息请求,邮箱: {}", email);
|
||||||
|
try {
|
||||||
|
return userService.findTeacherByEmail(email);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("查询教师信息失败", e);
|
||||||
|
return new ApiResponse<>(ErrorCode.SYSTEM_ERROR, "查询教师信息失败", null);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,4 +172,33 @@ public class UserService implements UserDetailsService {
|
|||||||
logger.info("查询部门用户列表,部门ID: {}", departmentId);
|
logger.info("查询部门用户列表,部门ID: {}", departmentId);
|
||||||
return userRepository.findByDepartmentIdAndNormalStatus(departmentId);
|
return userRepository.findByDepartmentIdAndNormalStatus(departmentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ApiResponse<User> findTeacherByEmail(String email) {
|
||||||
|
if (email == null || email.trim().isEmpty()) {
|
||||||
|
return new ApiResponse<>(ErrorCode.INVALID_PARAM, "邮箱不能为空", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
User user = userRepository.findByEmail(email).orElse(null);
|
||||||
|
if (user == null) {
|
||||||
|
return new ApiResponse<>(ErrorCode.USER_NOT_FOUND, "用户不存在", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证用户是否为教师角色且为课程制作教师岗位
|
||||||
|
if (user.getRoles() != 1) {
|
||||||
|
return new ApiResponse<>(ErrorCode.INVALID_PARAM, "非教师用户", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user.getJobs() != 1) {
|
||||||
|
return new ApiResponse<>(ErrorCode.INVALID_PARAM, "非课程制作教师", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user.getStatus() != 1) {
|
||||||
|
return new ApiResponse<>(ErrorCode.INVALID_PARAM, "用户状态异常", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清除敏感信息
|
||||||
|
user.setPassword(null);
|
||||||
|
|
||||||
|
return ApiResponse.success(user);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user