From 16e07ee9ef3e2339e579527345808932f6d9a7d9 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Fri, 15 Aug 2025 15:28:43 +0800 Subject: [PATCH] =?UTF-8?q?feat(pricing):=20=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=A4=84=E7=90=86=20BundleProductItem=20=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 使用自定义的 BundleProductListTypeHandler 替代 JacksonTypeHandler - 在 PriceBundleConfigMapper 中添加 @Results 注解,指定自定义处理器 - 更新 insert 和 update 方法,使用新的 BundleProductListTypeHandler --- .../pricing/entity/PriceBundleConfig.java | 7 +-- .../mapper/PriceBundleConfigMapper.java | 43 ++++++++++++++----- 2 files changed, 37 insertions(+), 13 deletions(-) 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 9be8864..bd2e705 100644 --- a/src/main/java/com/ycwl/basic/pricing/entity/PriceBundleConfig.java +++ b/src/main/java/com/ycwl/basic/pricing/entity/PriceBundleConfig.java @@ -1,11 +1,12 @@ package com.ycwl.basic.pricing.entity; import com.baomidou.mybatisplus.annotation.TableName; -import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; import com.baomidou.mybatisplus.annotation.TableField; import com.ycwl.basic.pricing.dto.BundleProductItem; +import com.ycwl.basic.pricing.handler.BundleProductListTypeHandler; import lombok.Data; import lombok.EqualsAndHashCode; +import org.apache.ibatis.type.JdbcType; import java.math.BigDecimal; import java.util.List; @@ -36,13 +37,13 @@ public class PriceBundleConfig extends BaseEntity { /** * 包含商品 */ - @TableField(typeHandler = JacksonTypeHandler.class) + @TableField(typeHandler = BundleProductListTypeHandler.class, jdbcType = JdbcType.VARCHAR) private List includedProducts; /** * 排除商品 */ - @TableField(typeHandler = JacksonTypeHandler.class) + @TableField(typeHandler = BundleProductListTypeHandler.class, jdbcType = JdbcType.VARCHAR) private List excludedProducts; /** 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 a0dfaf8..0bc1ce3 100644 --- a/src/main/java/com/ycwl/basic/pricing/mapper/PriceBundleConfigMapper.java +++ b/src/main/java/com/ycwl/basic/pricing/mapper/PriceBundleConfigMapper.java @@ -2,11 +2,7 @@ package com.ycwl.basic.pricing.mapper; 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; +import org.apache.ibatis.annotations.*; import java.util.List; @@ -19,13 +15,31 @@ public interface PriceBundleConfigMapper extends BaseMapper { /** * 查询启用的一口价配置 */ - @Select("SELECT * FROM price_bundle_config WHERE is_active = 1") + @Select("SELECT id, bundle_name, scenic_id, bundle_price, " + + "included_products, excluded_products, " + + "description, is_active, created_time, updated_time " + + "FROM price_bundle_config WHERE is_active = 1") + @Results({ + @Result(column = "included_products", property = "includedProducts", + typeHandler = com.ycwl.basic.pricing.handler.BundleProductListTypeHandler.class), + @Result(column = "excluded_products", property = "excludedProducts", + typeHandler = com.ycwl.basic.pricing.handler.BundleProductListTypeHandler.class) + }) List selectActiveBundles(); /** * 根据ID查询启用的配置 */ - @Select("SELECT * FROM price_bundle_config WHERE id = #{id} AND is_active = 1") + @Select("SELECT id, bundle_name, scenic_id, bundle_price, " + + "included_products, excluded_products, " + + "description, is_active, created_time, updated_time " + + "FROM price_bundle_config WHERE id = #{id} AND is_active = 1") + @Results({ + @Result(column = "included_products", property = "includedProducts", + typeHandler = com.ycwl.basic.pricing.handler.BundleProductListTypeHandler.class), + @Result(column = "excluded_products", property = "excludedProducts", + typeHandler = com.ycwl.basic.pricing.handler.BundleProductListTypeHandler.class) + }) PriceBundleConfig selectActiveBundleById(Long id); // ==================== 管理端接口(包含禁用的配置) ==================== @@ -33,7 +47,16 @@ public interface PriceBundleConfigMapper extends BaseMapper { /** * 查询所有一口价配置(包含禁用的)- 管理端使用 */ - @Select("SELECT * FROM price_bundle_config ORDER BY is_active DESC, bundle_name ASC") + @Select("SELECT id, bundle_name, scenic_id, bundle_price, " + + "included_products, excluded_products, " + + "description, is_active, created_time, updated_time " + + "FROM price_bundle_config ORDER BY is_active DESC, bundle_name ASC") + @Results({ + @Result(column = "included_products", property = "includedProducts", + typeHandler = com.ycwl.basic.pricing.handler.BundleProductListTypeHandler.class), + @Result(column = "excluded_products", property = "excludedProducts", + typeHandler = com.ycwl.basic.pricing.handler.BundleProductListTypeHandler.class) + }) List selectAllBundlesForAdmin(); /** @@ -41,7 +64,7 @@ public interface PriceBundleConfigMapper extends BaseMapper { */ @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}, #{scenicId}, #{bundlePrice}, #{includedProducts,typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler}, #{excludedProducts,typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler}, " + + "(#{bundleName}, #{scenicId}, #{bundlePrice}, #{includedProducts,typeHandler=com.ycwl.basic.pricing.handler.BundleProductListTypeHandler}, #{excludedProducts,typeHandler=com.ycwl.basic.pricing.handler.BundleProductListTypeHandler}, " + "#{description}, #{isActive}, NOW(), NOW())") int insertBundleConfig(PriceBundleConfig config); @@ -49,7 +72,7 @@ public interface PriceBundleConfigMapper extends BaseMapper { * 更新一口价配置 */ @Update("UPDATE price_bundle_config SET bundle_name = #{bundleName}, scenic_id = #{scenicId}, bundle_price = #{bundlePrice}, " + - "included_products = #{includedProducts,typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler}, excluded_products = #{excludedProducts,typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler}, " + + "included_products = #{includedProducts,typeHandler=com.ycwl.basic.pricing.handler.BundleProductListTypeHandler}, excluded_products = #{excludedProducts,typeHandler=com.ycwl.basic.pricing.handler.BundleProductListTypeHandler}, " + "description = #{description}, is_active = #{isActive}, updated_time = NOW() WHERE id = #{id}") int updateBundleConfig(PriceBundleConfig config);