You've already forked FrameTour-BE
refactor(scenic): 重构景区相关接口和数据结构
-移除了 ScenicMapper 中的冗余方法 - 更新了 ScenicEntity 和 ScenicRespVO 的字段结构 - 重构了 ScenicRepository 中的缓存逻辑 - 优化了 AppScenicServiceImpl 中的景区详情获取方法
This commit is contained in:
@@ -39,21 +39,22 @@ public class ScenicRepository {
|
||||
private MpNotifyConfigMapper mpNotifyConfigMapper;
|
||||
|
||||
public ScenicEntity getScenic(Long id) {
|
||||
String key = String.format(SCENIC_CACHE_KEY, id);
|
||||
try {
|
||||
ScenicV2DTO scenicDTO = scenicIntegrationService.getScenic(id);
|
||||
ScenicV2WithConfigDTO scenicDTO = scenicIntegrationService.getScenicWithConfig(id);
|
||||
ScenicEntity scenicEntity = convertToScenicEntity(scenicDTO);
|
||||
|
||||
// 请求成功,写入缓存
|
||||
if (scenicEntity != null) {
|
||||
redisTemplate.opsForValue().set(
|
||||
String.format(SCENIC_CACHE_KEY, id),
|
||||
key,
|
||||
JacksonUtil.toJSONString(scenicEntity)
|
||||
);
|
||||
}
|
||||
return scenicEntity;
|
||||
} catch (Exception e) {
|
||||
// 请求失败,尝试从缓存获取历史成功数据
|
||||
String cacheKey = String.format(SCENIC_CACHE_KEY, id);
|
||||
String cacheKey = key;
|
||||
if (redisTemplate.hasKey(cacheKey)) {
|
||||
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(cacheKey), ScenicEntity.class);
|
||||
}
|
||||
@@ -63,6 +64,7 @@ public class ScenicRepository {
|
||||
}
|
||||
|
||||
public ScenicConfigEntity getScenicConfig(Long scenicId) {
|
||||
String key = String.format(SCENIC_CONFIG_CACHE_KEY, scenicId);
|
||||
try {
|
||||
ScenicV2WithConfigDTO scenicWithConfigDTO = scenicIntegrationService.getScenicWithConfig(scenicId);
|
||||
ScenicConfigEntity configEntity = convertToScenicConfigEntity(scenicWithConfigDTO, scenicId);
|
||||
@@ -70,14 +72,14 @@ public class ScenicRepository {
|
||||
// 请求成功,写入缓存
|
||||
if (configEntity != null) {
|
||||
redisTemplate.opsForValue().set(
|
||||
String.format(SCENIC_CONFIG_CACHE_KEY, scenicId),
|
||||
key,
|
||||
JacksonUtil.toJSONString(configEntity)
|
||||
);
|
||||
}
|
||||
return configEntity;
|
||||
} catch (Exception e) {
|
||||
// 请求失败,尝试从缓存获取历史成功数据
|
||||
String cacheKey = String.format(SCENIC_CONFIG_CACHE_KEY, scenicId);
|
||||
String cacheKey = key;
|
||||
if (redisTemplate.hasKey(cacheKey)) {
|
||||
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(cacheKey), ScenicConfigEntity.class);
|
||||
}
|
||||
@@ -174,7 +176,34 @@ public class ScenicRepository {
|
||||
entity.setUpdateTime(new java.util.Date(dto.getUpdateTime()));
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
||||
private ScenicEntity convertToScenicEntity(ScenicV2WithConfigDTO dto) {
|
||||
if (dto == null) {
|
||||
return null;
|
||||
}
|
||||
ScenicEntity entity = new ScenicEntity();
|
||||
entity.setId(Long.parseLong(dto.getId()));
|
||||
entity.setName(dto.getName());
|
||||
entity.setMpId(dto.getMpId());
|
||||
entity.setStatus(dto.getStatus().toString());
|
||||
entity.setCreateTime(new java.util.Date(dto.getCreateTime()));
|
||||
entity.setUpdateTime(new java.util.Date(dto.getUpdateTime()));
|
||||
if (dto.getConfig() != null) {
|
||||
entity.setAddress(ConfigValueUtil.getStringValue(dto.getConfig(), "address"));
|
||||
entity.setArea(ConfigValueUtil.getStringValue(dto.getConfig(), "area"));
|
||||
entity.setCity(ConfigValueUtil.getStringValue(dto.getConfig(), "city"));
|
||||
entity.setProvince(ConfigValueUtil.getStringValue(dto.getConfig(), "province"));
|
||||
entity.setLatitude(ConfigValueUtil.getBigDecimalValue(dto.getConfig(), "latitude"));
|
||||
entity.setLongitude(ConfigValueUtil.getBigDecimalValue(dto.getConfig(), "longitude"));
|
||||
entity.setRadius(ConfigValueUtil.getBigDecimalValue(dto.getConfig(), "radius"));
|
||||
entity.setPhone(ConfigValueUtil.getStringValue(dto.getConfig(), "phone"));
|
||||
entity.setLogoUrl(ConfigValueUtil.getStringValue(dto.getConfig(), "logoUrl"));
|
||||
entity.setCoverUrl(ConfigValueUtil.getStringValue(dto.getConfig(), "coverUrl"));
|
||||
entity.setKfCodeUrl(ConfigValueUtil.getStringValue(dto.getConfig(), "kfCodeUrl"));
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
private ScenicConfigEntity convertToScenicConfigEntity(ScenicV2WithConfigDTO dto, Long scenicId) {
|
||||
if (dto == null || dto.getConfig() == null) {
|
||||
return null;
|
||||
|
Reference in New Issue
Block a user