feat(pricing): 自定义处理 BundleProductItem 列表

- 使用自定义的 BundleProductListTypeHandler 替代 JacksonTypeHandler
- 在 PriceBundleConfigMapper 中添加 @Results 注解,指定自定义处理器
- 更新 insert 和 update 方法,使用新的 BundleProductListTypeHandler
This commit is contained in:
2025-08-15 15:28:43 +08:00
parent 688459d2da
commit 16e07ee9ef
2 changed files with 37 additions and 13 deletions

View File

@@ -1,11 +1,12 @@
package com.ycwl.basic.pricing.entity; package com.ycwl.basic.pricing.entity;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.ycwl.basic.pricing.dto.BundleProductItem; import com.ycwl.basic.pricing.dto.BundleProductItem;
import com.ycwl.basic.pricing.handler.BundleProductListTypeHandler;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import org.apache.ibatis.type.JdbcType;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List; 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<BundleProductItem> includedProducts; private List<BundleProductItem> includedProducts;
/** /**
* 排除商品 * 排除商品
*/ */
@TableField(typeHandler = JacksonTypeHandler.class) @TableField(typeHandler = BundleProductListTypeHandler.class, jdbcType = JdbcType.VARCHAR)
private List<BundleProductItem> excludedProducts; private List<BundleProductItem> excludedProducts;
/** /**

View File

@@ -2,11 +2,7 @@ package com.ycwl.basic.pricing.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ycwl.basic.pricing.entity.PriceBundleConfig; import com.ycwl.basic.pricing.entity.PriceBundleConfig;
import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.*;
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 java.util.List; import java.util.List;
@@ -19,13 +15,31 @@ public interface PriceBundleConfigMapper extends BaseMapper<PriceBundleConfig> {
/** /**
* 查询启用的一口价配置 * 查询启用的一口价配置
*/ */
@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<PriceBundleConfig> selectActiveBundles(); List<PriceBundleConfig> selectActiveBundles();
/** /**
* 根据ID查询启用的配置 * 根据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); PriceBundleConfig selectActiveBundleById(Long id);
// ==================== 管理端接口(包含禁用的配置) ==================== // ==================== 管理端接口(包含禁用的配置) ====================
@@ -33,7 +47,16 @@ public interface PriceBundleConfigMapper extends BaseMapper<PriceBundleConfig> {
/** /**
* 查询所有一口价配置(包含禁用的)- 管理端使用 * 查询所有一口价配置(包含禁用的)- 管理端使用
*/ */
@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<PriceBundleConfig> selectAllBundlesForAdmin(); List<PriceBundleConfig> selectAllBundlesForAdmin();
/** /**
@@ -41,7 +64,7 @@ public interface PriceBundleConfigMapper extends BaseMapper<PriceBundleConfig> {
*/ */
@Insert("INSERT INTO price_bundle_config (bundle_name, scenic_id, 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 " + "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())") "#{description}, #{isActive}, NOW(), NOW())")
int insertBundleConfig(PriceBundleConfig config); int insertBundleConfig(PriceBundleConfig config);
@@ -49,7 +72,7 @@ public interface PriceBundleConfigMapper extends BaseMapper<PriceBundleConfig> {
* 更新一口价配置 * 更新一口价配置
*/ */
@Update("UPDATE price_bundle_config SET bundle_name = #{bundleName}, scenic_id = #{scenicId}, bundle_price = #{bundlePrice}, " + @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}") "description = #{description}, is_active = #{isActive}, updated_time = NOW() WHERE id = #{id}")
int updateBundleConfig(PriceBundleConfig config); int updateBundleConfig(PriceBundleConfig config);