记得上下班打卡 | git大法好,push需谨慎

Commit f61a4b1f authored by 姜秀龙's avatar 姜秀龙

fix: 手册扩展配置兼容新旧 Redis 缓存

解析海报 JSON 失败时降级为空列表,读取缓存时回源补齐主题色和海报,避免升级后 C 端拿到不完整数据。
Co-authored-by: 's avatarCursor <cursoragent@cursor.com>
parent d56d2d2e
......@@ -174,10 +174,14 @@ public class SweetManualExtConfigServiceImpl implements ISweetManualExtConfigSer
if (StringUtil.isBlank(json)) {
return new ArrayList<>();
}
try {
List<SweetManualPosterTemplateDto> list = JsonUtils.fromJson(json,
new TypeReference<List<SweetManualPosterTemplateDto>>() {
});
return list == null ? new ArrayList<>() : list;
} catch (Exception e) {
return new ArrayList<>();
}
}
private String serializePosterTemplates(List<SweetManualPosterTemplateDto> posters) {
......
......@@ -188,7 +188,7 @@ public class RedisDataUtils {
String redisKey = SweetConstant.REDIS_KEY_SWEET_MANUAL_EXT_CONFIG.concat(manualId);
SweetManualExtConfigDto configDto;
if (content != null) {
configDto = content;
configDto = normalizeExtConfigDto(content);
} else {
SweetManual manual = sweetManualMapper.selectOne(
Wrappers.lambdaQuery(SweetManual.class).eq(SweetManual::getManualId, manualId));
......@@ -202,6 +202,7 @@ public class RedisDataUtils {
configDto.setThemeColor(manual.getThemeColor() == null ? "" : manual.getThemeColor());
configDto.setPosterTemplates(parseManualPosterTemplates(manual.getPosterTemplates()));
}
configDto = normalizeExtConfigDto(configDto);
}
redisUtil.set(redisKey, configDto);
return configDto;
......@@ -213,13 +214,31 @@ public class RedisDataUtils {
if (!(obj instanceof SweetManualExtConfigDto)) {
return setManualExtConfigRedisData(manualId, null);
}
return (SweetManualExtConfigDto) obj;
SweetManualExtConfigDto dto = (SweetManualExtConfigDto) obj;
// 旧缓存没有 posterTemplates:回源 DB,兼容升级前后数据
if (dto.getPosterTemplates() == null) {
return setManualExtConfigRedisData(manualId, null);
}
return normalizeExtConfigDto(dto);
}
public void deleteManualExtConfigRedisData(String manualId) {
redisUtil.del(SweetConstant.REDIS_KEY_SWEET_MANUAL_EXT_CONFIG.concat(manualId));
}
private SweetManualExtConfigDto normalizeExtConfigDto(SweetManualExtConfigDto dto) {
if (dto == null) {
dto = new SweetManualExtConfigDto();
}
if (dto.getThemeColor() == null) {
dto.setThemeColor("");
}
if (dto.getPosterTemplates() == null) {
dto.setPosterTemplates(new ArrayList<>());
}
return dto;
}
private Object parseManualMapGeojson(String geojson) {
if (StringUtil.isBlank(geojson)) {
return null;
......@@ -231,10 +250,15 @@ public class RedisDataUtils {
if (StringUtil.isBlank(json)) {
return new ArrayList<>();
}
try {
List<SweetManualPosterTemplateDto> list = JsonUtils.fromJson(json,
new TypeReference<List<SweetManualPosterTemplateDto>>() {
});
return list == null ? new ArrayList<>() : list;
} catch (Exception e) {
log.warn("解析手册海报模版失败, json={}", json, e);
return new ArrayList<>();
}
}
public List<String> setTagRedisData(String manualId) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment