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);