<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tuling.tulingmall.promotion.dao.FlashPromotionProductDao">
<!--    <resultMap id="flashPromotionProduct" type="com.tuling.tulingmall.promotion.domain.FlashPromotionProduct"
               extends="com.tuling.tulingmall.mapper.PmsProductMapper.BaseResultMap">
        <result column="flash_promotion_price" property="flashPromotionPrice"/>
        <result column="flash_promotion_count" property="flashPromotionCount"/>
        <result column="flash_promotion_limit" property="flashPromotionLimit"/>
    </resultMap>-->
    <resultMap id="flashPromotionParam" type="com.tuling.tulingmall.promotion.domain.FlashPromotionParam"
               extends="com.tuling.tulingmall.promotion.mapper.SmsFlashPromotionMapper.BaseResultMap">
        <collection property="relation" columnPrefix="r_" resultMap="com.tuling.tulingmall.promotion.mapper.SmsFlashPromotionProductRelationMapper.BaseResultMap">
        </collection>
    </resultMap>
<!--    <select id="getFlashProductList" resultMap="flashPromotionProduct">
        SELECT
            pr.flash_promotion_price,
            pr.flash_promotion_count,
            pr.flash_promotion_limit,
            p.*
        FROM
            sms_flash_promotion_product_relation pr
            LEFT JOIN pms_product p ON pr.product_id = p.id
        WHERE
            pr.flash_promotion_id = #{flashPromotionId}
            AND pr.flash_promotion_session_id = #{sessionId}
    </select>-->
    <select id="getFlashPromotion" resultMap="flashPromotionParam">
        SELECT
        sp.*,
        sfp.id r_id,
        sfp.flash_promotion_id r_flash_promotion_id,
        sfp.flash_promotion_session_id r_flash_promotion_session_id,
        sfp.product_id r_product_id,
        sfp.flash_promotion_price r_flash_promotion_price,
        sfp.flash_promotion_count r_flash_promotion_count,
        sfp.flash_promotion_limit r_flash_promotion_limit,
        sfp.sort r_sort
        FROM
        sms_flash_promotion sp
        LEFT JOIN sms_flash_promotion_product_relation sfp ON sfp.flash_promotion_id=sp.id
        WHERE NOW()>=sp.start_date AND sp.end_date>NOW() and status=#{status}
        <if test="spid != null">
            AND sp.id=#{spid}
        </if>
        ORDER BY sfp.sort DESC
    </select>

<!--    <select id="getHomePromotionProductList" resultMap="flashPromotionProduct">
        SELECT
        pr.flash_promotion_price,
        pr.flash_promotion_count,
        pr.flash_promotion_limit,
        p.*
        FROM
        sms_flash_promotion_product_relation pr
        LEFT JOIN pms_product p ON pr.product_id = p.id
        WHERE
        pr.id IN
        <foreach collection="promotionIds" item="listItem" open="(" close=")" separator=",">
            #{listItem}
        </foreach>
    </select>-->
</mapper>