|
7 | 7 | import club.boyuan.official.mapper.ResumeFieldValueMapper; |
8 | 8 | import club.boyuan.official.service.IResumeFieldDefinitionService; |
9 | 9 | import lombok.AllArgsConstructor; |
10 | | -import org.apache.ibatis.session.ExecutorType; |
11 | 10 | import org.apache.ibatis.session.SqlSession; |
12 | 11 | import org.apache.ibatis.session.SqlSessionFactory; |
13 | 12 | import org.slf4j.Logger; |
|
17 | 16 |
|
18 | 17 | import java.time.LocalDateTime; |
19 | 18 | import java.util.List; |
| 19 | +import java.util.Map; |
20 | 20 | import java.util.concurrent.TimeUnit; |
21 | 21 |
|
22 | 22 | @Service |
@@ -47,14 +47,22 @@ public ResumeFieldDefinition getFieldDefinitionById(Integer fieldId) { |
47 | 47 | try { |
48 | 48 | // 尝试从Redis缓存中获取数据 |
49 | 49 | String cacheKey = "field_definition:" + fieldId; |
50 | | - ResumeFieldDefinition cachedDefinition = (ResumeFieldDefinition) redisTemplate.opsForValue().get(cacheKey); |
| 50 | + Object cachedObject = redisTemplate.opsForValue().get(cacheKey); |
51 | 51 |
|
52 | | - if (cachedDefinition != null) { |
53 | | - logger.debug("从Redis缓存中获取到字段定义,字段ID: {}", fieldId); |
54 | | - return cachedDefinition; |
| 52 | + if (cachedObject != null) { |
| 53 | + // 检查缓存对象类型并进行适当转换 |
| 54 | + if (cachedObject instanceof ResumeFieldDefinition) { |
| 55 | + logger.debug("从Redis缓存中获取到字段定义,字段ID: {}", fieldId); |
| 56 | + return (ResumeFieldDefinition) cachedObject; |
| 57 | + } else if (cachedObject instanceof Map) { |
| 58 | + // 如果是Map类型,尝试手动转换 |
| 59 | + logger.debug("从Redis缓存中获取到字段定义Map,字段ID: {}", fieldId); |
| 60 | + // 由于复杂的类型转换可能出错,我们选择直接从数据库查询 |
| 61 | + logger.debug("缓存中对象类型不匹配,将从数据库重新查询"); |
| 62 | + } |
55 | 63 | } |
56 | 64 |
|
57 | | - // 缓存未命中,从数据库查询 |
| 65 | + // 缓存未命中或类型不匹配,从数据库查询 |
58 | 66 | ResumeFieldDefinition definition = resumeFieldDefinitionMapper.findById(fieldId); |
59 | 67 |
|
60 | 68 | // 将查询结果存入Redis缓存,设置过期时间为1小时 |
@@ -106,7 +114,7 @@ public ResumeFieldDefinition updateFieldDefinition(ResumeFieldDefinition fieldDe |
106 | 114 | @Override |
107 | 115 | public List<ResumeFieldDefinition> batchUpdateFieldDefinitions(List<ResumeFieldDefinition> fieldDefinitions) { |
108 | 116 | logger.info("批量更新简历字段定义,字段数量: {}", fieldDefinitions.size()); |
109 | | - try (SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH)) { |
| 117 | + try (SqlSession sqlSession = sqlSessionFactory.openSession()) { |
110 | 118 | ResumeFieldDefinitionMapper batchMapper = sqlSession.getMapper(ResumeFieldDefinitionMapper.class); |
111 | 119 |
|
112 | 120 | // 批量更新字段定义 |
|
0 commit comments