You've already forked FrameTour-BE
refactor(basic): 重构景区配置管理逻辑
- 移除 AppOrderV2Controller 中的价格缓存逻辑 - 修正 VoucherServiceImpl 中的购买数量计算方式- 重构 ScenicRepository 中的景区配置获取逻辑 -增加 ScenicConfigManager 的扁平化配置和驼峰转换功能
This commit is contained in:
@@ -76,14 +76,14 @@ public class AppOrderV2Controller {
|
|||||||
Long scenicId = face.getScenicId();
|
Long scenicId = face.getScenicId();
|
||||||
|
|
||||||
// 先尝试从Redis缓存获取价格计算结果
|
// 先尝试从Redis缓存获取价格计算结果
|
||||||
PriceCalculationResult cachedResult = priceCacheService.getCachedPriceResult(
|
// PriceCalculationResult cachedResult = priceCacheService.getCachedPriceResult(
|
||||||
currentUserId, scenicId, request.getProducts());
|
// currentUserId, scenicId, request.getProducts());
|
||||||
|
//
|
||||||
if (cachedResult != null) {
|
// if (cachedResult != null) {
|
||||||
log.info("命中价格缓存: userId={}, scenicId={}, finalAmount={}",
|
// log.info("命中价格缓存: userId={}, scenicId={}, finalAmount={}",
|
||||||
currentUserId, scenicId, cachedResult.getFinalAmount());
|
// currentUserId, scenicId, cachedResult.getFinalAmount());
|
||||||
return ApiResponse.success(cachedResult);
|
// return ApiResponse.success(cachedResult);
|
||||||
}
|
// }
|
||||||
|
|
||||||
// 转换为标准价格计算请求
|
// 转换为标准价格计算请求
|
||||||
PriceCalculationRequest standardRequest = request.toStandardRequest(currentUserId, scenicId);
|
PriceCalculationRequest standardRequest = request.toStandardRequest(currentUserId, scenicId);
|
||||||
|
@@ -310,7 +310,7 @@ public class VoucherServiceImpl implements IVoucherService {
|
|||||||
// 在实际应用中可能需要更复杂的计算逻辑
|
// 在实际应用中可能需要更复杂的计算逻辑
|
||||||
BigDecimal totalAmount = BigDecimal.ZERO;
|
BigDecimal totalAmount = BigDecimal.ZERO;
|
||||||
for (ProductItem item : applicableItems) {
|
for (ProductItem item : applicableItems) {
|
||||||
BigDecimal itemAmount = item.getUnitPrice().multiply(BigDecimal.valueOf(item.getQuantity()));
|
BigDecimal itemAmount = item.getUnitPrice().multiply(BigDecimal.valueOf(item.getPurchaseCount()));
|
||||||
totalAmount = totalAmount.add(itemAmount);
|
totalAmount = totalAmount.add(itemAmount);
|
||||||
}
|
}
|
||||||
return totalAmount;
|
return totalAmount;
|
||||||
|
@@ -97,28 +97,71 @@ public class ScenicRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ScenicConfigEntity getScenicConfig(Long scenicId) {
|
public ScenicConfigEntity getScenicConfig(Long scenicId) {
|
||||||
String key = String.format(SCENIC_CONFIG_CACHE_KEY, scenicId);
|
ScenicConfigManager scenicConfigManager = getScenicConfigManager(scenicId);
|
||||||
try {
|
ScenicConfigEntity config = new ScenicConfigEntity();
|
||||||
ScenicV2WithConfigDTO scenicWithConfigDTO = scenicIntegrationService.getScenicWithConfig(scenicId);
|
|
||||||
ScenicConfigEntity configEntity = convertToScenicConfigEntity(scenicWithConfigDTO, scenicId);
|
// 基础配置
|
||||||
|
config.setScenicId(scenicId);
|
||||||
// 请求成功,写入缓存
|
|
||||||
if (configEntity != null) {
|
// 业务流程配置
|
||||||
redisTemplate.opsForValue().set(
|
config.setBookRoutine(scenicConfigManager.getInteger("book_routine"));
|
||||||
key,
|
config.setForceFinishTime(scenicConfigManager.getInteger("force_finish_time"));
|
||||||
JacksonUtil.toJSONString(configEntity)
|
config.setTourTime(scenicConfigManager.getInteger("tour_time"));
|
||||||
);
|
|
||||||
}
|
// 存储时间配置
|
||||||
return configEntity;
|
config.setSampleStoreDay(scenicConfigManager.getInteger("sample_store_day"));
|
||||||
} catch (Exception e) {
|
config.setFaceStoreDay(scenicConfigManager.getInteger("face_store_day"));
|
||||||
// 请求失败,尝试从缓存获取历史成功数据
|
config.setVideoStoreDay(scenicConfigManager.getInteger("video_store_day"));
|
||||||
String cacheKey = key;
|
config.setVideoSourceStoreDay(scenicConfigManager.getInteger("video_source_store_day"));
|
||||||
if (redisTemplate.hasKey(cacheKey)) {
|
config.setImageSourceStoreDay(scenicConfigManager.getInteger("image_source_store_day"));
|
||||||
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(cacheKey), ScenicConfigEntity.class);
|
config.setUserSourceExpireDay(scenicConfigManager.getInteger("user_source_expire_day"));
|
||||||
}
|
|
||||||
// 缓存也没有,返回null
|
// 功能开关配置
|
||||||
return null;
|
config.setAllFree(scenicConfigManager.getBoolean("all_free"));
|
||||||
}
|
config.setDisableSourceVideo(scenicConfigManager.getBoolean("disable_source_video"));
|
||||||
|
config.setDisableSourceImage(scenicConfigManager.getBoolean("disable_source_image"));
|
||||||
|
config.setVoucherEnable(scenicConfigManager.getBoolean("voucher_enable"));
|
||||||
|
|
||||||
|
// 模板和防录屏配置
|
||||||
|
config.setTemplateNewVideoType(scenicConfigManager.getInteger("template_new_video_type"));
|
||||||
|
config.setAntiScreenRecordType(scenicConfigManager.getInteger("anti_screen_record_type"));
|
||||||
|
|
||||||
|
// 人脸识别配置
|
||||||
|
config.setFaceScoreThreshold(scenicConfigManager.getFloat("face_score_threshold"));
|
||||||
|
config.setFaceDetectHelperThreshold(scenicConfigManager.getInteger("face_detect_helper_threshold"));
|
||||||
|
config.setFaceType(scenicConfigManager.getEnum("face_type", FaceBodyAdapterType.class));
|
||||||
|
config.setFaceConfigJson(scenicConfigManager.getString("face_config_json"));
|
||||||
|
|
||||||
|
// 存储配置
|
||||||
|
config.setStoreType(scenicConfigManager.getEnum("store_type", StorageType.class));
|
||||||
|
config.setStoreConfigJson(scenicConfigManager.getString("store_config_json"));
|
||||||
|
config.setTmpStoreType(scenicConfigManager.getEnum("tmp_store_type", StorageType.class));
|
||||||
|
config.setTmpStoreConfigJson(scenicConfigManager.getString("tmp_store_config_json"));
|
||||||
|
config.setLocalStoreType(scenicConfigManager.getEnum("local_store_type", StorageType.class));
|
||||||
|
config.setLocalStoreConfigJson(scenicConfigManager.getString("local_store_config_json"));
|
||||||
|
|
||||||
|
// 支付配置
|
||||||
|
config.setPayType(scenicConfigManager.getEnum("pay_type", PayAdapterType.class));
|
||||||
|
config.setPayConfigJson(scenicConfigManager.getString("pay_config_json"));
|
||||||
|
|
||||||
|
// 推客配置
|
||||||
|
config.setBrokerDirectRate(scenicConfigManager.getBigDecimal("broker_direct_rate"));
|
||||||
|
|
||||||
|
// 水印配置
|
||||||
|
config.setWatermarkType(scenicConfigManager.getString("watermark_type"));
|
||||||
|
config.setWatermarkScenicText(scenicConfigManager.getString("watermark_scenic_text"));
|
||||||
|
config.setWatermarkDtFormat(scenicConfigManager.getString("watermark_dt_format"));
|
||||||
|
|
||||||
|
// 提示信息配置
|
||||||
|
config.setImageSourcePackHint(scenicConfigManager.getString("image_source_pack_hint"));
|
||||||
|
config.setVideoSourcePackHint(scenicConfigManager.getString("video_source_pack_hint"));
|
||||||
|
config.setExtraNotificationTime(scenicConfigManager.getString("extra_notification_time"));
|
||||||
|
|
||||||
|
// 免费数量配置
|
||||||
|
config.setPhotoFreeNum(scenicConfigManager.getInteger("photo_free_num"));
|
||||||
|
config.setVideoFreeNum(scenicConfigManager.getInteger("video_free_num"));
|
||||||
|
|
||||||
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MpConfigEntity getScenicMpConfig(Long scenicId) {
|
public MpConfigEntity getScenicMpConfig(Long scenicId) {
|
||||||
|
@@ -366,6 +366,65 @@ public class ScenicConfigManager {
|
|||||||
return new ScenicConfigManager(subsetMap);
|
return new ScenicConfigManager(subsetMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将配置转换为扁平化的Map,键名转换为驼峰形式
|
||||||
|
*
|
||||||
|
* @return 扁平化的配置Map,键为驼峰形式
|
||||||
|
*/
|
||||||
|
public Map<String, Object> toFlatConfig() {
|
||||||
|
Map<String, Object> flatConfig = new HashMap<>();
|
||||||
|
|
||||||
|
for (Map.Entry<String, Object> entry : configMap.entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
Object value = entry.getValue();
|
||||||
|
|
||||||
|
if (key != null) {
|
||||||
|
String camelCaseKey = toCamelCase(key);
|
||||||
|
flatConfig.put(camelCaseKey, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return flatConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将字符串转换为驼峰形式
|
||||||
|
* 支持下划线、短横线、点号分隔的字符串转换
|
||||||
|
*
|
||||||
|
* @param str 原始字符串
|
||||||
|
* @return 驼峰形式的字符串
|
||||||
|
*/
|
||||||
|
private String toCamelCase(String str) {
|
||||||
|
if (str == null || str.isEmpty()) {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 支持下划线、短横线、点号作为分隔符
|
||||||
|
String[] parts = str.split("[_\\-.]");
|
||||||
|
|
||||||
|
if (parts.length <= 1) {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder camelCase = new StringBuilder();
|
||||||
|
|
||||||
|
// 第一部分保持原样(全小写)
|
||||||
|
camelCase.append(parts[0].toLowerCase());
|
||||||
|
|
||||||
|
// 后续部分首字母大写
|
||||||
|
for (int i = 1; i < parts.length; i++) {
|
||||||
|
String part = parts[i];
|
||||||
|
if (!part.isEmpty()) {
|
||||||
|
camelCase.append(Character.toUpperCase(part.charAt(0)));
|
||||||
|
if (part.length() > 1) {
|
||||||
|
camelCase.append(part.substring(1).toLowerCase());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return camelCase.toString();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ScenicConfigManager{" +
|
return "ScenicConfigManager{" +
|
||||||
|
Reference in New Issue
Block a user