You've already forked FrameTour-BE
refactor(basic): 重构景区相关接口调用
- 移除 Redis 缓存操作,改为直接调用 ScenicIntegrationService- 新增 convertToScenicEntity 和 convertToScenicConfigEntity 方法进行数据转换 - 优化异常处理,fallback 到数据库查询
This commit is contained in:
@@ -9,6 +9,12 @@ import com.ycwl.basic.model.pc.mp.MpNotifyConfigEntity;
|
||||
import com.ycwl.basic.model.pc.mp.ScenicMpNotifyVO;
|
||||
import com.ycwl.basic.model.pc.scenic.entity.ScenicConfigEntity;
|
||||
import com.ycwl.basic.model.pc.scenic.entity.ScenicEntity;
|
||||
import com.ycwl.basic.integration.scenic.service.ScenicIntegrationService;
|
||||
import com.ycwl.basic.integration.scenic.dto.scenic.ScenicV2DTO;
|
||||
import com.ycwl.basic.integration.scenic.dto.scenic.ScenicV2WithConfigDTO;
|
||||
import com.ycwl.basic.facebody.enums.FaceBodyAdapterType;
|
||||
import com.ycwl.basic.pay.enums.PayAdapterType;
|
||||
import com.ycwl.basic.storage.enums.StorageType;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -23,6 +29,8 @@ public class ScenicRepository {
|
||||
private MpConfigMapper mpConfigMapper;
|
||||
@Autowired
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
@Autowired
|
||||
private ScenicIntegrationService scenicIntegrationService;
|
||||
|
||||
public static final String SCENIC_CACHE_KEY = "scenic:%s";
|
||||
public static final String SCENIC_FULL_CACHE_KEY = "scenic:f%s";
|
||||
@@ -33,25 +41,21 @@ public class ScenicRepository {
|
||||
private MpNotifyConfigMapper mpNotifyConfigMapper;
|
||||
|
||||
public ScenicEntity getScenic(Long id) {
|
||||
if (redisTemplate.hasKey(String.format(SCENIC_CACHE_KEY, id))) {
|
||||
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(SCENIC_CACHE_KEY, id)), ScenicEntity.class);
|
||||
try {
|
||||
ScenicV2DTO scenicDTO = scenicIntegrationService.getScenic(id);
|
||||
return convertToScenicEntity(scenicDTO);
|
||||
} catch (Exception e) {
|
||||
return scenicMapper.get(id);
|
||||
}
|
||||
ScenicEntity scenic = scenicMapper.get(id);
|
||||
if (scenic != null) {
|
||||
redisTemplate.opsForValue().set(String.format(SCENIC_CACHE_KEY, id), JacksonUtil.toJSONString(scenic));
|
||||
}
|
||||
return scenic;
|
||||
}
|
||||
|
||||
public ScenicConfigEntity getScenicConfig(Long scenicId) {
|
||||
if (redisTemplate.hasKey(String.format(SCENIC_CONFIG_CACHE_KEY, scenicId))) {
|
||||
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(String.format(SCENIC_CONFIG_CACHE_KEY, scenicId)), ScenicConfigEntity.class);
|
||||
try {
|
||||
ScenicV2WithConfigDTO scenicWithConfigDTO = scenicIntegrationService.getScenicWithConfig(scenicId);
|
||||
return convertToScenicConfigEntity(scenicWithConfigDTO, scenicId);
|
||||
} catch (Exception e) {
|
||||
return scenicMapper.getConfig(scenicId);
|
||||
}
|
||||
ScenicConfigEntity scenicConfig = scenicMapper.getConfig(scenicId);
|
||||
if (scenicConfig != null) {
|
||||
redisTemplate.opsForValue().set(String.format(SCENIC_CONFIG_CACHE_KEY, scenicId), JacksonUtil.toJSONString(scenicConfig));
|
||||
}
|
||||
return scenicConfig;
|
||||
}
|
||||
|
||||
public MpConfigEntity getScenicMpConfig(Long scenicId) {
|
||||
@@ -129,4 +133,134 @@ public class ScenicRepository {
|
||||
redisTemplate.delete(String.format(SCENIC_MP_NOTIFY_CACHE_KEY, scenicId));
|
||||
}
|
||||
|
||||
private ScenicEntity convertToScenicEntity(ScenicV2DTO 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()));
|
||||
return entity;
|
||||
}
|
||||
|
||||
private ScenicConfigEntity convertToScenicConfigEntity(ScenicV2WithConfigDTO dto, Long scenicId) {
|
||||
if (dto == null || dto.getConfig() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ScenicConfigEntity entity = new ScenicConfigEntity();
|
||||
entity.setScenicId(scenicId);
|
||||
|
||||
java.util.Map<String, Object> config = dto.getConfig();
|
||||
|
||||
entity.setBookRoutine(getIntValue(config, "book_routine"));
|
||||
entity.setForceFinishTime(getIntValue(config, "force_finish_time"));
|
||||
entity.setTourTime(getIntValue(config, "tour_time"));
|
||||
entity.setSampleStoreDay(getIntValue(config, "sample_store_day"));
|
||||
entity.setFaceStoreDay(getIntValue(config, "face_store_day"));
|
||||
entity.setVideoStoreDay(getIntValue(config, "video_store_day"));
|
||||
entity.setAllFree(getIntValue(config, "all_free"));
|
||||
entity.setDisableSourceVideo(getIntValue(config, "disable_source_video"));
|
||||
entity.setDisableSourceImage(getIntValue(config, "disable_source_image"));
|
||||
entity.setTemplateNewVideoType(getIntValue(config, "template_new_video_type"));
|
||||
entity.setAntiScreenRecordType(getIntValue(config, "anti_screen_record_type"));
|
||||
entity.setVideoSourceStoreDay(getIntValue(config, "video_source_store_day"));
|
||||
entity.setImageSourceStoreDay(getIntValue(config, "image_source_store_day"));
|
||||
entity.setUserSourceExpireDay(getIntValue(config, "user_source_expire_day"));
|
||||
entity.setFaceDetectHelperThreshold(getIntValue(config, "face_detect_helper_threshold"));
|
||||
entity.setPhotoFreeNum(getIntValue(config, "photo_free_num"));
|
||||
entity.setVideoFreeNum(getIntValue(config, "video_free_num"));
|
||||
entity.setVoucherEnable(getIntValue(config, "voucher_enable"));
|
||||
|
||||
entity.setFaceScoreThreshold(getFloatValue(config, "face_score_threshold"));
|
||||
entity.setBrokerDirectRate(getBigDecimalValue(config, "broker_direct_rate"));
|
||||
|
||||
entity.setWatermarkType(getStringValue(config, "watermark_type"));
|
||||
entity.setWatermarkScenicText(getStringValue(config, "watermark_scenic_text"));
|
||||
entity.setWatermarkDtFormat(getStringValue(config, "watermark_dt_format"));
|
||||
entity.setImageSourcePackHint(getStringValue(config, "image_source_pack_hint"));
|
||||
entity.setVideoSourcePackHint(getStringValue(config, "video_source_pack_hint"));
|
||||
entity.setExtraNotificationTime(getStringValue(config, "extra_notification_time"));
|
||||
|
||||
entity.setStoreType(getEnumValue(config, "store_type", StorageType.class));
|
||||
entity.setStoreConfigJson(getStringValue(config, "store_config_json"));
|
||||
entity.setTmpStoreType(getEnumValue(config, "tmp_store_type", StorageType.class));
|
||||
entity.setTmpStoreConfigJson(getStringValue(config, "tmp_store_config_json"));
|
||||
entity.setLocalStoreType(getEnumValue(config, "local_store_type", StorageType.class));
|
||||
entity.setLocalStoreConfigJson(getStringValue(config, "local_store_config_json"));
|
||||
|
||||
entity.setFaceType(getEnumValue(config, "face_type", FaceBodyAdapterType.class));
|
||||
entity.setFaceConfigJson(getStringValue(config, "face_config_json"));
|
||||
|
||||
entity.setPayType(getEnumValue(config, "pay_type", PayAdapterType.class));
|
||||
entity.setPayConfigJson(getStringValue(config, "pay_config_json"));
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
private Integer getIntValue(java.util.Map<String, Object> config, String key) {
|
||||
Object value = config.get(key);
|
||||
if (value == null) return null;
|
||||
if (value instanceof Integer) return (Integer) value;
|
||||
if (value instanceof String) {
|
||||
try {
|
||||
return Integer.parseInt((String) value);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Float getFloatValue(java.util.Map<String, Object> config, String key) {
|
||||
Object value = config.get(key);
|
||||
if (value == null) return null;
|
||||
if (value instanceof Float) return (Float) value;
|
||||
if (value instanceof Double) return ((Double) value).floatValue();
|
||||
if (value instanceof String) {
|
||||
try {
|
||||
return Float.parseFloat((String) value);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private java.math.BigDecimal getBigDecimalValue(java.util.Map<String, Object> config, String key) {
|
||||
Object value = config.get(key);
|
||||
if (value == null) return null;
|
||||
if (value instanceof java.math.BigDecimal) return (java.math.BigDecimal) value;
|
||||
if (value instanceof String) {
|
||||
try {
|
||||
return new java.math.BigDecimal((String) value);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (value instanceof Number) {
|
||||
return new java.math.BigDecimal(value.toString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getStringValue(java.util.Map<String, Object> config, String key) {
|
||||
Object value = config.get(key);
|
||||
return value != null ? value.toString() : null;
|
||||
}
|
||||
|
||||
private <T extends Enum<T>> T getEnumValue(java.util.Map<String, Object> config, String key, Class<T> enumClass) {
|
||||
Object value = config.get(key);
|
||||
if (value == null) return null;
|
||||
try {
|
||||
return Enum.valueOf(enumClass, value.toString());
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user