商品服务查询

This commit is contained in:
xuelijun
2025-07-31 16:50:43 +08:00
parent 2f54798561
commit d92b69e1f1
34 changed files with 393 additions and 76 deletions

View File

@@ -8,7 +8,260 @@
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
<!-- 结果映射:将数据库查询结果映射到 ProdServiceVO -->
<resultMap id="ProdServiceResultMap" type="com.tashow.cloud.product.vo.prod.ProdServiceVO"> <!-- 确保这是 ProdServiceVO 的正确包名 -->
<!-- 商品基本信息映射 -->
<id property="prodId" column="prod_id"/>
<result property="regionSwitch" column="region_switch"/>
<result property="additionalSwitch" column="additional_switch"/>
<result property="additionalFeeSwitch" column="additional_fee_switch"/>
<result property="emergencySwitch" column="emergency_switch"/>
<result property="reservationSwitch" column="reservation_switch"/>
<result property="orderLimitSwitch" column="order_limit_switch"/>
<result property="weightSwitch" column="weight_switch"/>
<!-- 关联紧急响应配置 -->
<association property="prodEmergencyInfoVO" javaType="com.tashow.cloud.product.vo.prodemergencyresponse.ProdEmergencyInfoVO">
<id property="id" column="erc_record_id"/>
<result property="prodId" column="erc_prod_id"/>
<result property="responseTimeSlots" column="response_time_slots"/>
<result property="blacklistedDates" column="blacklisted_dates"/>
<result property="blackAppointDates" column="black_appoint_dates"/>
<result property="blackHappy" column="black_happy"/>
<result property="blackWeekend" column="black_weekend"/>
<!-- 嵌套集合:紧急响应时间区间 -->
<collection property="prodEmergencyResponseIntervalsList" ofType="com.tashow.cloud.product.dto.ProdEmergencyResponseIntervalsDO">
<id property="id" column="eri_record_id"/>
<result property="configId" column="eri_config_id"/>
<result property="modeName" column="mode_name"/>
<result property="responseHours" column="response_hours"/>
<result property="chargeMode" column="charge_mode"/>
<result property="floatingPercentage" column="floating_percentage"/>
<result property="price" column="price"/>
</collection>
</association>
<association property="prodReservationConfig" javaType="com.tashow.cloud.product.dto.ProdReservationConfigDO">
<id property="id" column="rc_record_id"/>
<result property="prodId" column="rc_prod_id"/>
<result property="reservationTimeSlots" column="rc_reservation_time_slots"/>
<result property="advanceHours" column="rc_advance_hours"/>
<result property="reservationDateRange" column="rc_reservation_date_range"/>
<result property="allowChange" column="rc_allow_change"/>
<result property="changeTimeRule" column="rc_change_time_rule"/>
<result property="maxChangeTimes" column="rc_max_change_times"/>
<result property="blacklistedDates" column="rc_blacklisted_dates"/>
<result property="isBlacklisted" column="rc_is_blacklisted"/>
<result property="blackAppointDates" column="rc_black_appoint_dates"/>
<result property="isBlackAppoint" column="rc_is_black_appoint"/>
<result property="blackHappy" column="rc_black_happy"/>
<result property="blackWeekend" column="rc_black_weekend"/>
</association>
<!-- 映射接单上限配置 (productOrderLimitVO) -->
<association property="productOrderLimitVO" javaType="com.tashow.cloud.product.dto.ProductOrderLimitDO">
<id property="id" column="ol_record_id"/>
<result property="prodId" column="ol_prod_id"/>
<result property="limitUnit" column="ol_limit_unit"/>
<result property="maxOrders" column="ol_max_orders"/>
</association>
<!-- 2. 所有 association 放在前面 -->
<!-- 映射服务区域配置 (prodServiceAreasInfo) -->
<association property="prodServiceAreasInfo" javaType="com.tashow.cloud.product.vo.prodserviceareas.ProdServiceAreasInfoVO">
<id property="id" column="sa_rule_id"/>
<result property="prodId" column="sa_prod_id"/>
<result property="ruleType" column="sa_rule_type"/>
<result property="fee" column="sa_fee"/>
</association>
<!-- 新增:映射体重区间价格配置列表 (prodWeightConfigList) -->
<collection property="prodWeightConfig" ofType="com.tashow.cloud.product.dto.ProdWeightRangePricesDO">
<id property="id" column="wrp_record_id"/>
<result property="prodId" column="wrp_prod_id"/>
<result property="weightRange" column="wrp_weight_range"/> <!-- 注意:数据库列是 weight_range -->
<result property="price" column="wrp_price"/>
<result property="isEnabled" column="wrp_is_enabled"/>
<!-- <result property="createTime" column="wrp_create_time"/> -->
<!-- <result property="updateTime" column="wrp_update_time"/> -->
<!-- <result property="creator" column="wrp_creator"/> -->
<!-- <result property="updater" column="wrp_updater"/> -->
</collection>
<!-- 新增:映射特殊日期规则配置列表 (prodAdditionalFeePeriodsList) -->
<collection property="prodAdditionalFeePeriodsList" ofType="com.tashow.cloud.product.dto.ProdAdditionalFeePeriodsDO">
<id property="id" column="afp_record_id"/>
<result property="prodId" column="afp_prod_id"/>
<result property="name" column="afp_name"/>
<result property="specialTimeSlots" column="afp_special_time_slots"/>
<result property="chargeMode" column="afp_charge_mode"/>
<result property="price" column="afp_price"/>
<result property="floatingPercentage" column="afp_floating_percentage"/>
</collection>
<!-- 新增:映射特殊时段规则配置列表 (ProdAdditionalFeeDatesList) -->
<collection property="prodAdditionalFeeDatesList" ofType="com.tashow.cloud.product.dto.ProdAdditionalFeeDatesDO">
<id property="id" column="afd_record_id"/>
<result property="prodId" column="afd_prod_id"/>
<result property="name" column="afd_name"/>
<result property="dateType" column="afd_date_type"/>
<result property="customTimeSlots" column="afd_custom_time_slots"/>
<result property="specificDates" column="afd_specific_dates"/>
<result property="chargeMode" column="afd_charge_mode"/>
<result property="price" column="afd_price"/>
<result property="isEnabled" column="afd_is_enabled"/>
</collection>
<!-- 映射服务区域地址名称 (areaNameList) -->
<collection property="prodServiceAreasInfo.areaNameList" ofType="string">
<result column="sa_area_name"/>
</collection>
</resultMap>
<select id="getProdPageList" resultType="com.tashow.cloud.product.dto.ProdDO" >
select * from tz_prod
</select>
<!-- 动态SQL查询商品列表及其服务配置 (返回 List<ProdServiceVO>) -->
<!-- 用于列表页,可根据开关动态决定是否关联紧急响应信息以优化性能 -->
<select id="selectProdService" parameterType="map" resultMap="ProdServiceResultMap">
SELECT
p.emergency_switch,
p.additional_switch,
p.additional_fee_switch,
p.reservation_switch,
p.order_limit_switch,
p.weight_switch,
<!-- 只有当 emergencySwitch 开启时,才查询紧急响应相关字段 -->
<if test="emergencySwitch != null and emergencySwitch == 1">
erc.id AS erc_record_id,
erc.prod_id AS erc_prod_id,
erc.response_time_slots,
erc.blacklisted_dates,
erc.black_appoint_dates,
erc.black_happy,
erc.black_weekend,
erc.create_time AS erc_create_time,
erc.update_time AS erc_update_time,
erc.creator AS erc_creator,
erc.updater AS erc_updater,
erc.deleted AS erc_deleted,
eri.id AS eri_record_id,
eri.config_id AS eri_config_id,
eri.mode_name,
eri.response_hours,
eri.charge_mode,
eri.floating_percentage,
eri.price,
eri.create_time AS eri_create_time,
eri.update_time AS eri_update_time,
eri.creator AS eri_creator,
eri.updater AS eri_updater,
eri.deleted AS eri_deleted,
</if>
<!-- 只有当 additionalFeeSwitch 开启时,才查询特殊日期规则相关字段 -->
<if test="additionalFeeSwitch != null and additionalFeeSwitch == 1">
afp.id AS afp_record_id,
afp.prod_id AS afp_prod_id,
afp.name AS afp_name,
afp.special_time_slots AS afp_special_time_slots,
afp.charge_mode AS afp_charge_mode,
afp.price AS afp_price,
afp.floating_percentage AS afp_floating_percentage,
</if>
<!-- 只有当 additionalSwitch 开启时,才查询特殊时段规则相关字段 -->
<if test="additionalSwitch != null and additionalSwitch == 1">
afd.id AS afd_record_id,
afd.prod_id AS afd_prod_id,
afd.name AS afd_name,
afd.date_type AS afd_date_type,
afd.custom_time_slots AS afd_custom_time_slots,
afd.specific_dates AS afd_specific_dates,
afd.charge_mode AS afd_charge_mode,
afd.price AS afd_price,
afd.is_enabled AS afd_is_enabled,
afd.create_time AS afd_create_time,
afd.update_time AS afd_update_time,
afd.creator AS afd_creator,
afd.updater AS afd_updater,
afd.deleted AS afd_deleted,
</if>
<!-- 只有当 reservationSwitch 开启时,才查询预约配置相关字段 -->
<if test="reservationSwitch != null and reservationSwitch == 1">
rc.id AS rc_record_id,
rc.prod_id AS rc_prod_id,
rc.reservation_time_slots AS rc_reservation_time_slots,
rc.advance_hours AS rc_advance_hours,
rc.reservation_date_range AS rc_reservation_date_range,
rc.allow_change AS rc_allow_change,
rc.change_time_rule AS rc_change_time_rule,
rc.max_change_times AS rc_max_change_times,
rc.blacklisted_dates AS rc_blacklisted_dates,
rc.is_blacklisted AS rc_is_blacklisted,
rc.black_appoint_dates AS rc_black_appoint_dates,
rc.is_black_appoint AS rc_is_black_appoint,
rc.black_happy AS rc_black_happy,
rc.black_weekend AS rc_black_weekend,
</if>
<!-- 只有当 orderLimitSwitch 开启时,才查询接单上限配置相关字段 -->
<if test="orderLimitSwitch != null and orderLimitSwitch == 1">
ol.id AS ol_record_id,
ol.prod_id AS ol_prod_id,
ol.limit_unit AS ol_limit_unit,
ol.max_orders AS ol_max_orders,
</if>
<!-- 只有当 weightSwitch 开启时,才查询体重区间价格相关字段 -->
<if test="weightSwitch != null and weightSwitch == 1">
wrp.id AS wrp_record_id,
wrp.prod_id AS wrp_prod_id,
wrp.weight_range AS wrp_weight_range,
wrp.price AS wrp_price,
wrp.is_enabled AS wrp_is_enabled,
</if>
<!-- 只有当 regionSwitch 开启时,才查询服务区域相关字段 -->
<if test="regionSwitch != null and regionSwitch == 1">
sa.id AS sa_rule_id,
sa.prod_id AS sa_prod_id,
sa.rule_type AS sa_rule_type,
sa.fee AS sa_fee,
saa.area_name AS sa_area_name,
</if>
p.prod_id
FROM
tz_prod p
<!-- 只有当 emergencySwitch 开启时才进行 LEFT JOIN -->
<if test="emergencySwitch != null and emergencySwitch == 1">
LEFT JOIN tz_prod_emergency_response erc ON p.prod_id = erc.prod_id AND erc.deleted = 0
LEFT JOIN tz_prod_emergency_response_intervals eri ON erc.id = eri.config_id AND eri.deleted = 0
</if>
<if test="additionalFeeSwitch != null and additionalFeeSwitch == 1">
LEFT JOIN tz_prod_additional_fee_periods afp ON p.prod_id = afp.prod_id AND afp.deleted = 0
</if>
<if test="additionalSwitch != null and additionalSwitch == 1">
LEFT JOIN tz_prod_additional_fee_dates afd ON p.prod_id = afd.prod_id AND afd.deleted = 0
</if>
<if test="reservationSwitch != null and reservationSwitch == 1">
LEFT JOIN tz_prod_reservation_config rc ON p.prod_id = rc.prod_id AND rc.deleted = 0
</if>
<if test="orderLimitSwitch != null and orderLimitSwitch == 1">
LEFT JOIN tz_product_order_limit ol ON p.prod_id = ol.prod_id AND ol.deleted = 0
</if>
<if test="weightSwitch != null and weightSwitch == 1">
LEFT JOIN tz_prod_weight_range_prices wrp ON p.prod_id = wrp.prod_id AND wrp.deleted = 0
</if>
<if test="regionSwitch != null and regionSwitch == 1">
LEFT JOIN tz_prod_service_over_area_rules sa ON p.prod_id = sa.prod_id AND sa.deleted = 0
LEFT JOIN tz_prod_service_area_relevance sar ON p.prod_id = sar.prod_id
LEFT JOIN tz_prod_service_areas saa ON sar.area_id = saa.id AND saa.deleted = 0
</if>
where p.deleted = 0
AND p.prod_id = #{prodId}
ORDER BY p.prod_id
</select>
</mapper>