feat: 添加根据邮箱查询教师信息接口

This commit is contained in:
huertian 2025-01-03 14:35:59 +08:00
parent 6dd845cdd7
commit 3c40fca9b3
3 changed files with 45 additions and 4 deletions

View File

@ -52,6 +52,7 @@ public class RedisConfig {
.build();
}
@SuppressWarnings("null")
@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, Object> template = new RedisTemplate<>();
@ -59,15 +60,15 @@ public class RedisConfig {
// 使用 GenericJackson2JsonRedisSerializer 进行序列化
GenericJackson2JsonRedisSerializer jackson2JsonRedisSerializer = new GenericJackson2JsonRedisSerializer();
// 设置 key 的序列化方式
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());
// 设置 value 的序列化方式
template.setValueSerializer(jackson2JsonRedisSerializer);
template.setHashValueSerializer(jackson2JsonRedisSerializer);
template.afterPropertiesSet();
// 测试连接
@ -77,7 +78,7 @@ public class RedisConfig {
} catch (Exception e) {
logger.error("Redis连接测试失败: {}", e.getMessage(), e);
}
return template;
}
}

View File

@ -102,4 +102,15 @@ public class UserController {
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);
}
}
}

View File

@ -172,4 +172,33 @@ public class UserService implements UserDetailsService {
logger.info("查询部门用户列表部门ID: {}", 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);
}
}