diff --git a/src/main/java/com/ycwl/basic/pricing/controller/PricingConfigController.java b/src/main/java/com/ycwl/basic/pricing/controller/PricingConfigController.java index 8b98ad8..35d9d6b 100644 --- a/src/main/java/com/ycwl/basic/pricing/controller/PricingConfigController.java +++ b/src/main/java/com/ycwl/basic/pricing/controller/PricingConfigController.java @@ -26,61 +26,6 @@ public class PricingConfigController { private final IPriceBundleService bundleService; private final IPricingManagementService managementService; - /** - * 获取所有商品配置 - */ - @GetMapping("/products") - public ApiResponse> getProductConfigs() { - List configs = productConfigService.getActiveProductConfigs(); - return ApiResponse.success(configs); - } - - /** - * 根据商品类型获取阶梯配置 - */ - @GetMapping("/tiers/{productType}") - public ApiResponse> getTierConfigs(@PathVariable String productType) { - List configs = productConfigService.getTierConfigs(productType); - return ApiResponse.success(configs); - } - - /** - * 根据商品类型和商品ID获取阶梯配置 - */ - @GetMapping("/tiers/{productType}/{productId}") - public ApiResponse> getTierConfigs(@PathVariable String productType, - @PathVariable String productId) { - List configs = productConfigService.getTierConfigs(productType, productId); - return ApiResponse.success(configs); - } - - /** - * 根据商品类型和商品ID获取具体配置 - */ - @GetMapping("/products/{productType}/{productId}") - public ApiResponse getProductConfig(@PathVariable String productType, - @PathVariable String productId) { - PriceProductConfig config = productConfigService.getProductConfig(productType, productId); - return ApiResponse.success(config); - } - - /** - * 获取所有阶梯配置 - */ - @GetMapping("/tiers") - public ApiResponse> getAllTierConfigs() { - log.info("获取所有阶梯定价配置"); - return ApiResponse.success(List.of()); - } - - /** - * 获取所有一口价配置 - */ - @GetMapping("/bundles") - public ApiResponse> getBundleConfigs() { - List configs = bundleService.getActiveBundles(); - return ApiResponse.success(configs); - } // ==================== 配置管理API(手动处理时间) ==================== @@ -146,4 +91,121 @@ public class PricingConfigController { boolean success = managementService.updateBundleConfig(config); return ApiResponse.success(success); } + + // ==================== 启用/禁用API ==================== + + /** + * 启用/禁用商品配置 + */ + @PutMapping("/products/{id}/status") + public ApiResponse updateProductConfigStatus(@PathVariable Long id, @RequestParam Boolean isActive) { + log.info("修改商品配置状态: id={}, isActive={}", id, isActive); + boolean success = managementService.updateProductConfigStatus(id, isActive); + return ApiResponse.success(success); + } + + /** + * 启用/禁用阶梯配置 + */ + @PutMapping("/tiers/{id}/status") + public ApiResponse updateTierConfigStatus(@PathVariable Long id, @RequestParam Boolean isActive) { + log.info("修改阶梯配置状态: id={}, isActive={}", id, isActive); + boolean success = managementService.updateTierConfigStatus(id, isActive); + return ApiResponse.success(success); + } + + /** + * 启用/禁用一口价配置 + */ + @PutMapping("/bundles/{id}/status") + public ApiResponse updateBundleConfigStatus(@PathVariable Long id, @RequestParam Boolean isActive) { + log.info("修改一口价配置状态: id={}, isActive={}", id, isActive); + boolean success = managementService.updateBundleConfigStatus(id, isActive); + return ApiResponse.success(success); + } + + // ==================== 删除API ==================== + + /** + * 删除商品配置 + */ + @DeleteMapping("/products/{id}") + public ApiResponse deleteProductConfig(@PathVariable Long id) { + log.info("删除商品配置: id={}", id); + boolean success = managementService.deleteProductConfig(id); + return ApiResponse.success(success); + } + + /** + * 删除阶梯配置 + */ + @DeleteMapping("/tiers/{id}") + public ApiResponse deleteTierConfig(@PathVariable Long id) { + log.info("删除阶梯配置: id={}", id); + boolean success = managementService.deleteTierConfig(id); + return ApiResponse.success(success); + } + + /** + * 删除一口价配置 + */ + @DeleteMapping("/bundles/{id}") + public ApiResponse deleteBundleConfig(@PathVariable Long id) { + log.info("删除一口价配置: id={}", id); + boolean success = managementService.deleteBundleConfig(id); + return ApiResponse.success(success); + } + + // ==================== 管理端接口(包含禁用的配置) ==================== + + /** + * 管理端:获取所有商品配置(包含禁用的) + */ + @GetMapping("/admin/products") + public ApiResponse> getAllProductConfigsForAdmin() { + log.info("管理端获取所有商品配置"); + List configs = productConfigService.getAllProductConfigsForAdmin(); + return ApiResponse.success(configs); + } + + /** + * 管理端:获取所有阶梯配置(包含禁用的) + */ + @GetMapping("/admin/tiers") + public ApiResponse> getAllTierConfigsForAdmin() { + log.info("管理端获取所有阶梯配置"); + List configs = productConfigService.getAllTierConfigsForAdmin(); + return ApiResponse.success(configs); + } + + /** + * 管理端:根据商品类型获取阶梯配置(包含禁用的) + */ + @GetMapping("/admin/tiers/{productType}") + public ApiResponse> getTierConfigsForAdmin(@PathVariable String productType) { + log.info("管理端根据商品类型获取阶梯配置: {}", productType); + List configs = productConfigService.getTierConfigsForAdmin(productType); + return ApiResponse.success(configs); + } + + /** + * 管理端:根据商品类型和商品ID获取阶梯配置(包含禁用的) + */ + @GetMapping("/admin/tiers/{productType}/{productId}") + public ApiResponse> getTierConfigsForAdmin(@PathVariable String productType, + @PathVariable String productId) { + log.info("管理端根据商品类型和ID获取阶梯配置: {}, {}", productType, productId); + List configs = productConfigService.getTierConfigsForAdmin(productType, productId); + return ApiResponse.success(configs); + } + + /** + * 管理端:获取所有一口价配置(包含禁用的) + */ + @GetMapping("/admin/bundles") + public ApiResponse> getAllBundleConfigsForAdmin() { + log.info("管理端获取所有一口价配置"); + List configs = bundleService.getAllBundlesForAdmin(); + return ApiResponse.success(configs); + } } \ No newline at end of file diff --git a/src/main/java/com/ycwl/basic/pricing/entity/PriceBundleConfig.java b/src/main/java/com/ycwl/basic/pricing/entity/PriceBundleConfig.java index f7457dd..0d1ec9f 100644 --- a/src/main/java/com/ycwl/basic/pricing/entity/PriceBundleConfig.java +++ b/src/main/java/com/ycwl/basic/pricing/entity/PriceBundleConfig.java @@ -19,6 +19,11 @@ public class PriceBundleConfig extends BaseEntity { */ private String bundleName; + /** + * 景区ID + */ + private String scenicId; + /** * 套餐价格 */ diff --git a/src/main/java/com/ycwl/basic/pricing/entity/PriceProductConfig.java b/src/main/java/com/ycwl/basic/pricing/entity/PriceProductConfig.java index 5bc37d7..8fec5d8 100644 --- a/src/main/java/com/ycwl/basic/pricing/entity/PriceProductConfig.java +++ b/src/main/java/com/ycwl/basic/pricing/entity/PriceProductConfig.java @@ -24,6 +24,11 @@ public class PriceProductConfig extends BaseEntity { */ private String productId; + /** + * 景区ID:用于前端搜索和编辑时正确显示景区内容 + */ + private String scenicId; + /** * 商品名称 */ diff --git a/src/main/java/com/ycwl/basic/pricing/entity/PriceTierConfig.java b/src/main/java/com/ycwl/basic/pricing/entity/PriceTierConfig.java index 31711b7..4c76593 100644 --- a/src/main/java/com/ycwl/basic/pricing/entity/PriceTierConfig.java +++ b/src/main/java/com/ycwl/basic/pricing/entity/PriceTierConfig.java @@ -25,9 +25,9 @@ public class PriceTierConfig extends BaseEntity { private String productId; /** - * 商品子类型 + * 景区ID:用于前端搜索和编辑时正确显示景区内容 */ - private String productSubType; + private String scenicId; /** * 最小数量 diff --git a/src/main/java/com/ycwl/basic/pricing/enums/ProductType.java b/src/main/java/com/ycwl/basic/pricing/enums/ProductType.java index c90bab2..bc3aa78 100644 --- a/src/main/java/com/ycwl/basic/pricing/enums/ProductType.java +++ b/src/main/java/com/ycwl/basic/pricing/enums/ProductType.java @@ -10,11 +10,11 @@ import lombok.Getter; @AllArgsConstructor public enum ProductType { - VLOG_VIDEO("vlog_video", "Vlog视频"), - RECORDING_SET("recording_set", "录像集"), - PHOTO_SET("photo_set", "照相集"), - PHOTO_PRINT("photo_print", "照片打印"), - MACHINE_PRINT("machine_print", "一体机打印"); + VLOG_VIDEO("VLOG_VIDEO", "Vlog视频"), + RECORDING_SET("RECORDING_SET", "录像集"), + PHOTO_SET("PHOTO_SET", "照相集"), + PHOTO_PRINT("PHOTO_PRINT", "照片打印"), + MACHINE_PRINT("MACHINE_PRINT", "一体机打印"); private final String code; private final String description; diff --git a/src/main/java/com/ycwl/basic/pricing/mapper/PriceBundleConfigMapper.java b/src/main/java/com/ycwl/basic/pricing/mapper/PriceBundleConfigMapper.java index 3f7f48f..08a7199 100644 --- a/src/main/java/com/ycwl/basic/pricing/mapper/PriceBundleConfigMapper.java +++ b/src/main/java/com/ycwl/basic/pricing/mapper/PriceBundleConfigMapper.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.ycwl.basic.pricing.entity.PriceBundleConfig; import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Update; @@ -27,20 +28,34 @@ public interface PriceBundleConfigMapper extends BaseMapper { @Select("SELECT * FROM price_bundle_config WHERE id = #{id} AND is_active = 1") PriceBundleConfig selectActiveBundleById(Long id); + // ==================== 管理端接口(包含禁用的配置) ==================== + + /** + * 查询所有一口价配置(包含禁用的)- 管理端使用 + */ + @Select("SELECT * FROM price_bundle_config ORDER BY is_active DESC, bundle_name ASC") + List selectAllBundlesForAdmin(); + /** * 插入一口价配置 */ - @Insert("INSERT INTO price_bundle_config (bundle_name, bundle_price, included_products, excluded_products, " + + @Insert("INSERT INTO price_bundle_config (bundle_name, scenic_id, bundle_price, included_products, excluded_products, " + "description, is_active, created_time, updated_time) VALUES " + - "(#{bundleName}, #{bundlePrice}, #{includedProducts}, #{excludedProducts}, " + + "(#{bundleName}, #{scenicId}, #{bundlePrice}, #{includedProducts}, #{excludedProducts}, " + "#{description}, #{isActive}, NOW(), NOW())") int insertBundleConfig(PriceBundleConfig config); /** * 更新一口价配置 */ - @Update("UPDATE price_bundle_config SET bundle_name = #{bundleName}, bundle_price = #{bundlePrice}, " + + @Update("UPDATE price_bundle_config SET bundle_name = #{bundleName}, scenic_id = #{scenicId}, bundle_price = #{bundlePrice}, " + "included_products = #{includedProducts}, excluded_products = #{excludedProducts}, " + "description = #{description}, is_active = #{isActive}, updated_time = NOW() WHERE id = #{id}") int updateBundleConfig(PriceBundleConfig config); + + /** + * 更新一口价配置状态 + */ + @Update("UPDATE price_bundle_config SET is_active = #{isActive}, updated_time = NOW() WHERE id = #{id}") + int updateBundleConfigStatus(@Param("id") Long id, @Param("isActive") Boolean isActive); } \ No newline at end of file diff --git a/src/main/java/com/ycwl/basic/pricing/mapper/PriceProductConfigMapper.java b/src/main/java/com/ycwl/basic/pricing/mapper/PriceProductConfigMapper.java index 907e650..0f77fcb 100644 --- a/src/main/java/com/ycwl/basic/pricing/mapper/PriceProductConfigMapper.java +++ b/src/main/java/com/ycwl/basic/pricing/mapper/PriceProductConfigMapper.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.ycwl.basic.pricing.entity.PriceProductConfig; import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Update; @@ -33,17 +34,37 @@ public interface PriceProductConfigMapper extends BaseMapper @Select("SELECT * FROM price_product_config WHERE product_type = #{productType} AND product_id = #{productId} AND is_active = 1") PriceProductConfig selectByProductTypeAndId(String productType, String productId); + // ==================== 管理端接口(包含禁用的配置) ==================== + + /** + * 查询所有商品配置(包含禁用的)- 管理端使用 + */ + @Select("SELECT * FROM price_product_config ORDER BY product_type ASC, is_active DESC, product_id ASC") + List selectAllConfigsForAdmin(); + + /** + * 根据商品类型查询所有配置(包含禁用的)- 管理端使用 + */ + @Select("SELECT * FROM price_product_config WHERE product_type = #{productType} ORDER BY is_active DESC, product_id ASC") + List selectByProductTypeForAdmin(@Param("productType") String productType); + /** * 插入商品价格配置 */ - @Insert("INSERT INTO price_product_config (product_type, product_id, product_name, base_price, original_price, unit, is_active, created_time, updated_time) " + - "VALUES (#{productType}, #{productId}, #{productName}, #{basePrice}, #{originalPrice}, #{unit}, #{isActive}, NOW(), NOW())") + @Insert("INSERT INTO price_product_config (product_type, product_id, scenic_id, product_name, base_price, original_price, unit, is_active, created_time, updated_time) " + + "VALUES (#{productType}, #{productId}, #{scenicId}, #{productName}, #{basePrice}, #{originalPrice}, #{unit}, #{isActive}, NOW(), NOW())") int insertProductConfig(PriceProductConfig config); /** * 更新商品价格配置 */ - @Update("UPDATE price_product_config SET product_id = #{productId}, product_name = #{productName}, base_price = #{basePrice}, " + + @Update("UPDATE price_product_config SET product_id = #{productId}, scenic_id = #{scenicId}, product_name = #{productName}, base_price = #{basePrice}, " + "original_price = #{originalPrice}, unit = #{unit}, is_active = #{isActive}, updated_time = NOW() WHERE id = #{id}") int updateProductConfig(PriceProductConfig config); + + /** + * 更新商品配置状态 + */ + @Update("UPDATE price_product_config SET is_active = #{isActive}, updated_time = NOW() WHERE id = #{id}") + int updateProductConfigStatus(@Param("id") Long id, @Param("isActive") Boolean isActive); } \ No newline at end of file diff --git a/src/main/java/com/ycwl/basic/pricing/mapper/PriceTierConfigMapper.java b/src/main/java/com/ycwl/basic/pricing/mapper/PriceTierConfigMapper.java index e1f6a72..5421f65 100644 --- a/src/main/java/com/ycwl/basic/pricing/mapper/PriceTierConfigMapper.java +++ b/src/main/java/com/ycwl/basic/pricing/mapper/PriceTierConfigMapper.java @@ -21,12 +21,10 @@ public interface PriceTierConfigMapper extends BaseMapper { */ @Select("SELECT * FROM price_tier_config WHERE product_type = #{productType} " + "AND product_id = #{productId} " + - "AND (product_sub_type = #{productSubType} OR product_sub_type IS NULL) " + "AND #{quantity} >= min_quantity AND #{quantity} <= max_quantity " + "AND is_active = 1 ORDER BY sort_order ASC LIMIT 1") PriceTierConfig selectByProductTypeAndQuantity(@Param("productType") String productType, @Param("productId") String productId, - @Param("productSubType") String productSubType, @Param("quantity") Integer quantity); /** @@ -44,28 +42,56 @@ public interface PriceTierConfigMapper extends BaseMapper { List selectByProductTypeAndId(@Param("productType") String productType, @Param("productId") String productId); + /** - * 根据商品类型和子类型查询阶梯配置 + * 查询所有启用的阶梯配置 + */ + @Select("SELECT * FROM price_tier_config WHERE is_active = 1 ORDER BY product_type ASC, sort_order ASC") + List selectAllActiveConfigs(); + + // ==================== 管理端接口(包含禁用的配置) ==================== + + /** + * 查询所有阶梯配置(包含禁用的)- 管理端使用 + */ + @Select("SELECT * FROM price_tier_config ORDER BY product_type ASC, is_active DESC, sort_order ASC") + List selectAllConfigsForAdmin(); + + /** + * 根据商品类型查询所有阶梯配置(包含禁用的)- 管理端使用 */ @Select("SELECT * FROM price_tier_config WHERE product_type = #{productType} " + - "AND product_sub_type = #{productSubType} AND is_active = 1 ORDER BY sort_order ASC") - List selectByProductTypeAndSubType(@Param("productType") String productType, - @Param("productSubType") String productSubType); + "ORDER BY is_active DESC, sort_order ASC") + List selectByProductTypeForAdmin(@Param("productType") String productType); + + /** + * 根据商品类型和商品ID查询所有阶梯配置(包含禁用的)- 管理端使用 + */ + @Select("SELECT * FROM price_tier_config WHERE product_type = #{productType} " + + "AND product_id = #{productId} ORDER BY is_active DESC, sort_order ASC") + List selectByProductTypeAndIdForAdmin(@Param("productType") String productType, + @Param("productId") String productId); /** * 插入阶梯定价配置 */ - @Insert("INSERT INTO price_tier_config (product_type, product_id, product_sub_type, min_quantity, max_quantity, price, " + + @Insert("INSERT INTO price_tier_config (product_type, product_id, scenic_id, min_quantity, max_quantity, price, " + "original_price, unit, sort_order, is_active, created_time, updated_time) VALUES " + - "(#{productType}, #{productId}, #{productSubType}, #{minQuantity}, #{maxQuantity}, #{price}, " + + "(#{productType}, #{productId}, #{scenicId}, #{minQuantity}, #{maxQuantity}, #{price}, " + "#{originalPrice}, #{unit}, #{sortOrder}, #{isActive}, NOW(), NOW())") int insertTierConfig(PriceTierConfig config); /** * 更新阶梯定价配置 */ - @Update("UPDATE price_tier_config SET product_id = #{productId}, product_sub_type = #{productSubType}, min_quantity = #{minQuantity}, " + + @Update("UPDATE price_tier_config SET product_id = #{productId}, scenic_id = #{scenicId}, min_quantity = #{minQuantity}, " + "max_quantity = #{maxQuantity}, price = #{price}, original_price = #{originalPrice}, unit = #{unit}, sort_order = #{sortOrder}, " + "is_active = #{isActive}, updated_time = NOW() WHERE id = #{id}") int updateTierConfig(PriceTierConfig config); + + /** + * 更新阶梯配置状态 + */ + @Update("UPDATE price_tier_config SET is_active = #{isActive}, updated_time = NOW() WHERE id = #{id}") + int updateTierConfigStatus(@Param("id") Long id, @Param("isActive") Boolean isActive); } \ No newline at end of file diff --git a/src/main/java/com/ycwl/basic/pricing/service/IPriceBundleService.java b/src/main/java/com/ycwl/basic/pricing/service/IPriceBundleService.java index 0e7ae09..2e66341 100644 --- a/src/main/java/com/ycwl/basic/pricing/service/IPriceBundleService.java +++ b/src/main/java/com/ycwl/basic/pricing/service/IPriceBundleService.java @@ -33,4 +33,13 @@ public interface IPriceBundleService { * @return 一口价配置列表 */ List getActiveBundles(); + + // ==================== 管理端接口(包含禁用的配置) ==================== + + /** + * 获取所有一口价配置(包含禁用的)- 管理端使用 + * + * @return 一口价配置列表 + */ + List getAllBundlesForAdmin(); } \ No newline at end of file diff --git a/src/main/java/com/ycwl/basic/pricing/service/IPricingManagementService.java b/src/main/java/com/ycwl/basic/pricing/service/IPricingManagementService.java index bcb9f29..a37de38 100644 --- a/src/main/java/com/ycwl/basic/pricing/service/IPricingManagementService.java +++ b/src/main/java/com/ycwl/basic/pricing/service/IPricingManagementService.java @@ -56,4 +56,38 @@ public interface IPricingManagementService { * 更新一口价配置 */ boolean updateBundleConfig(PriceBundleConfig config); + + // ==================== 状态管理 ==================== + + /** + * 更新商品配置状态 + */ + boolean updateProductConfigStatus(Long id, Boolean isActive); + + /** + * 更新阶梯配置状态 + */ + boolean updateTierConfigStatus(Long id, Boolean isActive); + + /** + * 更新一口价配置状态 + */ + boolean updateBundleConfigStatus(Long id, Boolean isActive); + + // ==================== 删除操作 ==================== + + /** + * 删除商品配置 + */ + boolean deleteProductConfig(Long id); + + /** + * 删除阶梯配置 + */ + boolean deleteTierConfig(Long id); + + /** + * 删除一口价配置 + */ + boolean deleteBundleConfig(Long id); } \ No newline at end of file diff --git a/src/main/java/com/ycwl/basic/pricing/service/IProductConfigService.java b/src/main/java/com/ycwl/basic/pricing/service/IProductConfigService.java index cd7ab96..11a31b8 100644 --- a/src/main/java/com/ycwl/basic/pricing/service/IProductConfigService.java +++ b/src/main/java/com/ycwl/basic/pricing/service/IProductConfigService.java @@ -32,22 +32,10 @@ public interface IProductConfigService { * * @param productType 商品类型 * @param productId 具体商品ID - * @param productSubType 商品子类型 * @param quantity 数量 * @return 阶梯价格配置 */ - PriceTierConfig getTierConfig(String productType, String productId, String productSubType, Integer quantity); - - /** - * 根据商品类型和数量获取阶梯价格配置(兼容旧接口) - * - * @param productType 商品类型 - * @param productSubType 商品子类型 - * @param quantity 数量 - * @return 阶梯价格配置 - */ - @Deprecated - PriceTierConfig getTierConfig(String productType, String productSubType, Integer quantity); + PriceTierConfig getTierConfig(String productType, String productId, Integer quantity); /** * 获取所有启用的商品配置 @@ -72,4 +60,44 @@ public interface IProductConfigService { * @return 阶梯配置列表 */ List getTierConfigs(String productType, String productId); + + /** + * 获取所有启用的阶梯配置 + * + * @return 阶梯配置列表 + */ + List getAllTierConfigs(); + + // ==================== 管理端接口(包含禁用的配置) ==================== + + /** + * 获取所有商品配置(包含禁用的)- 管理端使用 + * + * @return 商品配置列表 + */ + List getAllProductConfigsForAdmin(); + + /** + * 获取所有阶梯配置(包含禁用的)- 管理端使用 + * + * @return 阶梯配置列表 + */ + List getAllTierConfigsForAdmin(); + + /** + * 根据商品类型获取所有阶梯配置(包含禁用的)- 管理端使用 + * + * @param productType 商品类型 + * @return 阶梯配置列表 + */ + List getTierConfigsForAdmin(String productType); + + /** + * 根据商品类型和商品ID获取所有阶梯配置(包含禁用的)- 管理端使用 + * + * @param productType 商品类型 + * @param productId 具体商品ID + * @return 阶梯配置列表 + */ + List getTierConfigsForAdmin(String productType, String productId); } \ No newline at end of file diff --git a/src/main/java/com/ycwl/basic/pricing/service/impl/PriceBundleServiceImpl.java b/src/main/java/com/ycwl/basic/pricing/service/impl/PriceBundleServiceImpl.java index 2baa997..f0ba3eb 100644 --- a/src/main/java/com/ycwl/basic/pricing/service/impl/PriceBundleServiceImpl.java +++ b/src/main/java/com/ycwl/basic/pricing/service/impl/PriceBundleServiceImpl.java @@ -9,7 +9,7 @@ import com.ycwl.basic.pricing.mapper.PriceBundleConfigMapper; import com.ycwl.basic.pricing.service.IPriceBundleService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.cache.annotation.Cacheable; +//import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import java.math.BigDecimal; @@ -71,11 +71,18 @@ public class PriceBundleServiceImpl implements IPriceBundleService { } @Override - @Cacheable(value = "active-bundles") +// @Cacheable(value = "active-bundles") public List getActiveBundles() { return bundleConfigMapper.selectActiveBundles(); } + // ==================== 管理端接口(包含禁用的配置) ==================== + + @Override + public List getAllBundlesForAdmin() { + return bundleConfigMapper.selectAllBundlesForAdmin(); + } + private boolean isProductsMatchBundle(Set productTypes, PriceBundleConfig bundle) { try { List includedProducts = objectMapper.readValue( diff --git a/src/main/java/com/ycwl/basic/pricing/service/impl/PriceCalculationServiceImpl.java b/src/main/java/com/ycwl/basic/pricing/service/impl/PriceCalculationServiceImpl.java index b1783ce..1cf1490 100644 --- a/src/main/java/com/ycwl/basic/pricing/service/impl/PriceCalculationServiceImpl.java +++ b/src/main/java/com/ycwl/basic/pricing/service/impl/PriceCalculationServiceImpl.java @@ -140,7 +140,7 @@ public class PriceCalculationServiceImpl implements IPriceCalculationService { // 优先使用基于product_id的阶梯定价 PriceTierConfig tierConfig = productConfigService.getTierConfig( - productType.getCode(), productId, product.getProductSubType(), product.getQuantity()); + productType.getCode(), productId, product.getQuantity()); if (tierConfig != null) { log.debug("使用阶梯定价: productType={}, productId={}, quantity={}, price={}", @@ -186,7 +186,7 @@ public class PriceCalculationServiceImpl implements IPriceCalculationService { // 优先使用基于product_id的阶梯定价 PriceTierConfig tierConfig = productConfigService.getTierConfig( - productType.getCode(), productId, product.getProductSubType(), product.getQuantity()); + productType.getCode(), productId, product.getQuantity()); if (tierConfig != null) { actualPrice = tierConfig.getPrice(); diff --git a/src/main/java/com/ycwl/basic/pricing/service/impl/PricingManagementServiceImpl.java b/src/main/java/com/ycwl/basic/pricing/service/impl/PricingManagementServiceImpl.java index 948f908..0a70889 100644 --- a/src/main/java/com/ycwl/basic/pricing/service/impl/PricingManagementServiceImpl.java +++ b/src/main/java/com/ycwl/basic/pricing/service/impl/PricingManagementServiceImpl.java @@ -104,4 +104,50 @@ public class PricingManagementServiceImpl implements IPricingManagementService { config.setUpdatedTime(LocalDateTime.now()); return bundleConfigMapper.updateBundleConfig(config) > 0; } + + // ==================== 状态管理 ==================== + + @Override + @Transactional + public boolean updateProductConfigStatus(Long id, Boolean isActive) { + log.info("更新商品配置状态: id={}, isActive={}", id, isActive); + return productConfigMapper.updateProductConfigStatus(id, isActive) > 0; + } + + @Override + @Transactional + public boolean updateTierConfigStatus(Long id, Boolean isActive) { + log.info("更新阶梯配置状态: id={}, isActive={}", id, isActive); + return tierConfigMapper.updateTierConfigStatus(id, isActive) > 0; + } + + @Override + @Transactional + public boolean updateBundleConfigStatus(Long id, Boolean isActive) { + log.info("更新一口价配置状态: id={}, isActive={}", id, isActive); + return bundleConfigMapper.updateBundleConfigStatus(id, isActive) > 0; + } + + // ==================== 删除操作 ==================== + + @Override + @Transactional + public boolean deleteProductConfig(Long id) { + log.info("删除商品配置: id={}", id); + return productConfigMapper.deleteById(id) > 0; + } + + @Override + @Transactional + public boolean deleteTierConfig(Long id) { + log.info("删除阶梯配置: id={}", id); + return tierConfigMapper.deleteById(id) > 0; + } + + @Override + @Transactional + public boolean deleteBundleConfig(Long id) { + log.info("删除一口价配置: id={}", id); + return bundleConfigMapper.deleteById(id) > 0; + } } \ No newline at end of file diff --git a/src/main/java/com/ycwl/basic/pricing/service/impl/ProductConfigServiceImpl.java b/src/main/java/com/ycwl/basic/pricing/service/impl/ProductConfigServiceImpl.java index acf74ef..9103e2b 100644 --- a/src/main/java/com/ycwl/basic/pricing/service/impl/ProductConfigServiceImpl.java +++ b/src/main/java/com/ycwl/basic/pricing/service/impl/ProductConfigServiceImpl.java @@ -8,7 +8,7 @@ import com.ycwl.basic.pricing.mapper.PriceTierConfigMapper; import com.ycwl.basic.pricing.service.IProductConfigService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.cache.annotation.Cacheable; +//import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import java.util.List; @@ -25,13 +25,13 @@ public class ProductConfigServiceImpl implements IProductConfigService { private final PriceTierConfigMapper tierConfigMapper; @Override - @Cacheable(value = "product-config", key = "#productType") +// @Cacheable(value = "product-config", key = "#productType") public List getProductConfig(String productType) { return productConfigMapper.selectByProductType(productType); } @Override - @Cacheable(value = "product-config", key = "#productType + '_' + #productId") +// @Cacheable(value = "product-config", key = "#productType + '_' + #productId") public PriceProductConfig getProductConfig(String productType, String productId) { PriceProductConfig config = productConfigMapper.selectByProductTypeAndId(productType, productId); if (config == null) { @@ -41,38 +41,59 @@ public class ProductConfigServiceImpl implements IProductConfigService { } @Override - @Cacheable(value = "tier-config", key = "#productType + '_' + #productId + '_' + (#productSubType ?: 'default') + '_' + #quantity") - public PriceTierConfig getTierConfig(String productType, String productId, String productSubType, Integer quantity) { - PriceTierConfig config = tierConfigMapper.selectByProductTypeAndQuantity(productType, productId, productSubType, quantity); +// @Cacheable(value = "tier-config", key = "#productType + '_' + #productId + '_' + #quantity") + public PriceTierConfig getTierConfig(String productType, String productId, Integer quantity) { + PriceTierConfig config = tierConfigMapper.selectByProductTypeAndQuantity(productType, productId, quantity); if (config == null) { - log.warn("阶梯定价配置未找到: productType={}, productId={}, productSubType={}, quantity={}", - productType, productId, productSubType, quantity); + log.warn("阶梯定价配置未找到: productType={}, productId={}, quantity={}", + productType, productId, quantity); } return config; } @Override - @Deprecated - public PriceTierConfig getTierConfig(String productType, String productSubType, Integer quantity) { - // 兼容旧接口,使用默认productId - return getTierConfig(productType, "default", productSubType, quantity); - } - - @Override - @Cacheable(value = "active-product-configs") +// @Cacheable(value = "active-product-configs") public List getActiveProductConfigs() { return productConfigMapper.selectActiveConfigs(); } @Override - @Cacheable(value = "tier-configs", key = "#productType") +// @Cacheable(value = "tier-configs", key = "#productType") public List getTierConfigs(String productType) { return tierConfigMapper.selectByProductType(productType); } @Override - @Cacheable(value = "tier-configs", key = "#productType + '_' + #productId") +// @Cacheable(value = "tier-configs", key = "#productType + '_' + #productId") public List getTierConfigs(String productType, String productId) { return tierConfigMapper.selectByProductTypeAndId(productType, productId); } + + @Override +// @Cacheable(value = "all-tier-configs") + public List getAllTierConfigs() { + return tierConfigMapper.selectAllActiveConfigs(); + } + + // ==================== 管理端接口(包含禁用的配置) ==================== + + @Override + public List getAllProductConfigsForAdmin() { + return productConfigMapper.selectAllConfigsForAdmin(); + } + + @Override + public List getAllTierConfigsForAdmin() { + return tierConfigMapper.selectAllConfigsForAdmin(); + } + + @Override + public List getTierConfigsForAdmin(String productType) { + return tierConfigMapper.selectByProductTypeForAdmin(productType); + } + + @Override + public List getTierConfigsForAdmin(String productType, String productId) { + return tierConfigMapper.selectByProductTypeAndIdForAdmin(productType, productId); + } } \ No newline at end of file