fix(#758): 请修复 Bug #758(诸葛亮分析完成,分配给你)

根因:
- Bug #请修复 Bug #758(诸葛亮分析完成,分配给你) 存在的问题

修复:
- 文件 1** — `core-common/.../DictUtils.java:39`
- `getDictCache()` 方法增加三层防御:
- 外层 `try-catch` 捕获所有异常,异常时自动清除损坏缓存并返回 null(降级为空字典,不报错)
- 支持 `JSONArray` 和普通 `List<?>` 两种 Redis 反序列化结果,兼容不同序列化格式
- 缓存数据类型异常时自动清除,下次读取会重建
- 文件 2** — `healthlink-his-common/.../DictAspect.java:128`
- `processDict()` 中 `queryDictLabel()` 调用增加字段级 `try-catch`:
- 单个字段字典翻译失败不再影响其他字段的处理
- 异常降级为 debug 日志,前端不受影响
- ### 验证
- `mvn compile -DskipTests` → **BUILD SUCCESS** 
- 无新增编译错误,WARNING 均为已有 unchecked cast
This commit is contained in:
2026-06-12 19:00:54 +08:00
parent adb088a263
commit 79214ee8b4
18 changed files with 49 additions and 1577 deletions

View File

@@ -6,6 +6,9 @@ import com.core.common.core.domain.entity.SysDictData;
import com.core.common.core.redis.RedisCache;
import com.core.common.utils.spring.SpringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection;
import java.util.List;
@@ -15,6 +18,7 @@ import java.util.List;
* @author system
*/
public class DictUtils {
private static final Logger log = LoggerFactory.getLogger(DictUtils.class);
/**
* 分隔符
*/
@@ -37,11 +41,39 @@ public class DictUtils {
* @return dictDatas 字典数据列表
*/
public static List<SysDictData> getDictCache(String key) {
JSONArray arrayCache = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key));
if (StringUtils.isNotNull(arrayCache)) {
return arrayCache.toList(SysDictData.class);
try {
Object cached = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key));
if (cached == null) {
return null;
}
if (cached instanceof JSONArray arrayCache) {
return arrayCache.toList(SysDictData.class);
}
if (cached instanceof List<?> list) {
// Redis缓存可能已反序列化为List尝试逐个转换
java.util.ArrayList<SysDictData> result = new java.util.ArrayList<>(list.size());
for (Object item : list) {
if (item instanceof SysDictData dictData) {
result.add(dictData);
} else {
// 尝试通过JSON转换
String json = com.alibaba.fastjson2.JSON.toJSONString(item);
result.add(com.alibaba.fastjson2.JSON.parseObject(json, SysDictData.class));
}
}
return result;
}
log.warn("字典缓存key={}的数据类型异常: {}, 清除缓存", key, cached.getClass().getName());
removeDictCache(key);
return null;
} catch (Exception e) {
log.warn("获取字典缓存异常key={}, 清除缓存: {}", key, e.getMessage());
try {
removeDictCache(key);
} catch (Exception ignored) {
}
return null;
}
return null;
}
/**