<?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.mapper.SmsFlashPromotionProductRelationMapper">
  <resultMap id="BaseResultMap" type="com.tuling.tulingmall.model.SmsFlashPromotionProductRelation">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="flash_promotion_id" jdbcType="BIGINT" property="flashPromotionId" />
    <result column="flash_promotion_session_id" jdbcType="BIGINT" property="flashPromotionSessionId" />
    <result column="product_id" jdbcType="BIGINT" property="productId" />
    <result column="flash_promotion_price" jdbcType="DECIMAL" property="flashPromotionPrice" />
    <result column="flash_promotion_count" jdbcType="INTEGER" property="flashPromotionCount" />
    <result column="flash_promotion_limit" jdbcType="INTEGER" property="flashPromotionLimit" />
    <result column="sort" jdbcType="INTEGER" property="sort" />
  </resultMap>
  <resultMap id="flashProductMap" type="com.tuling.tulingmall.dto.SmsFlashPromotionProduct" extends="com.tuling.tulingmall.mapper.SmsFlashPromotionProductRelationMapper.BaseResultMap">
    <association property="product" resultMap="com.tuling.tulingmall.mapper.PmsProductMapper.BaseResultMap" columnPrefix="p_"/>
  </resultMap>
  <select id="getList" resultMap="flashProductMap">
    SELECT
      r.id,
      r.flash_promotion_price,
      r.flash_promotion_count,
      r.flash_promotion_limit,
      r.flash_promotion_id,
      r.flash_promotion_session_id,
      r.product_id,
      r.sort,
      p.id p_id,
      p.`name` p_name,
      p.product_sn p_product_sn,
      p.price p_price,
      p.stock p_stock
    FROM
      sms_flash_promotion_product_relation r
        LEFT JOIN tl_mall_goods.pms_product p ON r.product_id = p.id
    WHERE
      r.flash_promotion_id = #{flashPromotionId}
      AND r.flash_promotion_session_id = #{flashPromotionSessionId}
    ORDER BY r.sort DESC
  </select>
</mapper>