You've already forked FrameTour-BE
feat(pricing): 添加全局配置查询功能并优化价格计算逻辑
- 在PriceProductConfigMapper中新增selectGlobalByProductTypeAndId方法,用于查询全局配置(排除景区级配置) - 在PriceTierConfigMapper中新增selectGlobalByProductTypeAndQuantity方法,用于查询全局阶梯价格配置 - 移除价格计算服务中的default配置兜底逻辑,简化价格计算流程 - 更新ProductConfigServiceImpl中的配置查询逻辑,使用新的全局配置查询方法替代原有查询方式 - 优化配置查找顺序,提高全局配置的优先级和查询效率
This commit is contained in:
@@ -34,6 +34,12 @@ public interface PriceProductConfigMapper extends BaseMapper<PriceProductConfig>
|
|||||||
@Select("SELECT * FROM price_product_config WHERE product_type = #{productType} AND product_id = #{productId} AND is_active = 1")
|
@Select("SELECT * FROM price_product_config WHERE product_type = #{productType} AND product_id = #{productId} AND is_active = 1")
|
||||||
PriceProductConfig selectByProductTypeAndId(String productType, String productId);
|
PriceProductConfig selectByProductTypeAndId(String productType, String productId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据商品类型和商品ID查询全局配置(排除景区级配置)
|
||||||
|
*/
|
||||||
|
@Select("SELECT * FROM price_product_config WHERE product_type = #{productType} AND product_id = #{productId} AND (scenic_id IS NULL OR scenic_id = '') AND is_active = 1")
|
||||||
|
PriceProductConfig selectGlobalByProductTypeAndId(String productType, String productId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据商品类型、商品ID和景区ID查询配置(支持景区维度)
|
* 根据商品类型、商品ID和景区ID查询配置(支持景区维度)
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -27,6 +27,17 @@ public interface PriceTierConfigMapper extends BaseMapper<PriceTierConfig> {
|
|||||||
@Param("productId") String productId,
|
@Param("productId") String productId,
|
||||||
@Param("quantity") Integer quantity);
|
@Param("quantity") Integer quantity);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据商品类型、商品ID和数量查询全局匹配的阶梯价格(排除景区级配置)
|
||||||
|
*/
|
||||||
|
@Select("SELECT * FROM price_tier_config WHERE product_type = #{productType} " +
|
||||||
|
"AND product_id = #{productId} AND (scenic_id IS NULL OR scenic_id = '') " +
|
||||||
|
"AND #{quantity} >= min_quantity AND #{quantity} <= max_quantity " +
|
||||||
|
"AND is_active = 1 ORDER BY sort_order ASC LIMIT 1")
|
||||||
|
PriceTierConfig selectGlobalByProductTypeAndQuantity(@Param("productType") String productType,
|
||||||
|
@Param("productId") String productId,
|
||||||
|
@Param("quantity") Integer quantity);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据商品类型、商品ID、数量和景区ID查询匹配的阶梯价格(支持景区维度)
|
* 根据商品类型、商品ID、数量和景区ID查询匹配的阶梯价格(支持景区维度)
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -401,29 +401,10 @@ public class PriceCalculationServiceImpl implements IPriceCalculationService {
|
|||||||
log.warn("未找到具体商品配置: productType={}, productId={}, scenicId={}, 尝试使用通用配置",
|
log.warn("未找到具体商品配置: productType={}, productId={}, scenicId={}, 尝试使用通用配置",
|
||||||
productType, productId, scenicId);
|
productType, productId, scenicId);
|
||||||
|
|
||||||
// 兜底:使用default配置(带景区ID)
|
|
||||||
try {
|
|
||||||
PriceProductConfig defaultConfig = productConfigService.getProductConfig(productType.getCode(), "default", scenicId);
|
|
||||||
if (defaultConfig != null) {
|
|
||||||
actualPrice = defaultConfig.getBasePrice();
|
|
||||||
originalPrice = defaultConfig.getOriginalPrice();
|
|
||||||
|
|
||||||
if (isQuantityBasedPricing(capability)) {
|
|
||||||
actualPrice = actualPrice.multiply(BigDecimal.valueOf(product.getQuantity()));
|
|
||||||
if (originalPrice != null) {
|
|
||||||
originalPrice = originalPrice.multiply(BigDecimal.valueOf(product.getQuantity()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new PriceCalculationException("无法找到default配置");
|
|
||||||
}
|
|
||||||
} catch (Exception defaultEx) {
|
|
||||||
log.warn("未找到default配置: productType={}, scenicId={}", productType.getCode(), scenicId);
|
|
||||||
|
|
||||||
// 最后兜底:使用通用配置(向后兼容)
|
// 最后兜底:使用通用配置(向后兼容)
|
||||||
List<PriceProductConfig> configs = productConfigService.getProductConfig(productType.getCode());
|
List<PriceProductConfig> configs = productConfigService.getProductConfig(productType.getCode());
|
||||||
if (!configs.isEmpty()) {
|
if (!configs.isEmpty()) {
|
||||||
PriceProductConfig baseConfig = configs.getFirst(); // 使用第一个配置作为默认
|
PriceProductConfig baseConfig = configs.getFirst();
|
||||||
actualPrice = baseConfig.getBasePrice();
|
actualPrice = baseConfig.getBasePrice();
|
||||||
originalPrice = baseConfig.getOriginalPrice();
|
originalPrice = baseConfig.getOriginalPrice();
|
||||||
|
|
||||||
@@ -438,7 +419,6 @@ public class PriceCalculationServiceImpl implements IPriceCalculationService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return new ProductPriceInfo(actualPrice, originalPrice);
|
return new ProductPriceInfo(actualPrice, originalPrice);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ public class ProductConfigServiceImpl implements IProductConfigService {
|
|||||||
|
|
||||||
// 3. 全局+商品ID (兜底)
|
// 3. 全局+商品ID (兜底)
|
||||||
try {
|
try {
|
||||||
config = productConfigMapper.selectByProductTypeAndId(productType, productId);
|
config = productConfigMapper.selectGlobalByProductTypeAndId(productType, productId);
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
log.debug("使用全局商品配置: productType={}, productId={}", productType, productId);
|
log.debug("使用全局商品配置: productType={}, productId={}", productType, productId);
|
||||||
return config;
|
return config;
|
||||||
@@ -108,7 +108,7 @@ public class ProductConfigServiceImpl implements IProductConfigService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 4. 全局+默认 (最后兜底)
|
// 4. 全局+默认 (最后兜底)
|
||||||
config = productConfigMapper.selectByProductTypeAndId(productType, "default");
|
config = productConfigMapper.selectGlobalByProductTypeAndId(productType, "default");
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
log.debug("使用全局默认配置: productType={}", productType);
|
log.debug("使用全局默认配置: productType={}", productType);
|
||||||
return config;
|
return config;
|
||||||
@@ -152,7 +152,7 @@ public class ProductConfigServiceImpl implements IProductConfigService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 3. 全局+商品ID (兜底)
|
// 3. 全局+商品ID (兜底)
|
||||||
config = tierConfigMapper.selectByProductTypeAndQuantity(productType, productId, quantity);
|
config = tierConfigMapper.selectGlobalByProductTypeAndQuantity(productType, productId, quantity);
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
log.debug("使用全局阶梯定价: productType={}, productId={}, quantity={}",
|
log.debug("使用全局阶梯定价: productType={}, productId={}, quantity={}",
|
||||||
productType, productId, quantity);
|
productType, productId, quantity);
|
||||||
@@ -160,7 +160,7 @@ public class ProductConfigServiceImpl implements IProductConfigService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 4. 全局+默认 (最后兜底)
|
// 4. 全局+默认 (最后兜底)
|
||||||
config = tierConfigMapper.selectByProductTypeAndQuantity(productType, "default", quantity);
|
config = tierConfigMapper.selectGlobalByProductTypeAndQuantity(productType, "default", quantity);
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
log.debug("使用全局默认阶梯定价: productType={}, quantity={}", productType, quantity);
|
log.debug("使用全局默认阶梯定价: productType={}, quantity={}", productType, quantity);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user