<?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.iamberry.wechat.service.mapper.SettlementGiftMapper">
    <resultMap  id="BaseResultMap" type="SettlementGift" >
        <result    column="sett_gift_id"    property="settGiftId" />
        <result    column="promotions_id"    property="promotionsId" />
        <result    column="sett_gift_status"    property="settGiftStatus" />
        <result    column="sett_gift_desc"    property="settGiftDesc" />
        <result    column="sett_gift_create_time"    property="settGiftCreateTime" />
    </resultMap>
    <sql    id="Base_List" >
        t.sett_gift_id,
        t.promotions_id,
        t.sett_gift_status,
        t.sett_gift_desc,
        t.sett_gift_sort,
        t.sett_gift_create_time
    </sql>
    <select id="getSettlementGiftList" resultMap="BaseResultMap" parameterType="SettlementGift" >
        select
        <include refid="Base_List" />
        from tb_iamberry_eo_settlement_gift t
        <where>
            <if test="settGiftId != null ">
                AND t.sett_gift_id = #{settGiftId}
            </if >
            <if test="promotionsId != null ">
                AND t.promotions_id = #{promotionsId}
            </if >
            <if test="settGiftStatus != null ">
                AND t.sett_gift_status = #{settGiftStatus}
            </if >
        </where>
    </select>

    <resultMap  id="BaseResultAllMap" type="SettlementGift" >
        <result    column="sett_gift_id"    property="settGiftId" />
        <result    column="promotions_id"    property="promotionsId" />
        <result    column="sett_gift_status"    property="settGiftStatus" />
        <result    column="sett_gift_desc"    property="settGiftDesc" />
        <result    column="sett_gift_sort"    property="settGiftSort" />
        <result    column="sett_gift_create_time"    property="settGiftCreateTime" />
        <collection property="giftConditionList" column="sett_gift_id" ofType="GiftCondition" select="listGiftCondition"/>
        <collection property="giftPoolList" column="sett_gift_id" ofType="GiftPool" select="listGiftPool"/>
    </resultMap>
    <select id="getSettlementGiftListAll" resultMap="BaseResultAllMap" parameterType="java.util.List" >
        select
        <include refid="Base_List" />
        from tb_iamberry_eo_settlement_gift t
        <where>
            AND t.promotions_id IN (
                <foreach collection="array" item="item" separator=",">
                    #{item}
                </foreach>
            )
            AND t.sett_gift_status = 1
        </where>
        ORDER BY t.sett_gift_sort
    </select>

    <select id="listGiftCondition" resultType="GiftCondition" parameterType="GiftCondition" >
        select
            t.gift_condition_id,
            t.sett_gift_id,
            t.gift_condition_fill_color_id,
            t.gift_condition_create_time
        from tb_iamberry_eo_gift_condition t
        WHERE t.sett_gift_id = #{settGiftId}
    </select>

    <select id="listGiftPool" resultType="GiftPool" parameterType="GiftPool" >
        select
            t.gift_pool_id,
            t.sett_gift_id,
            t.gift_pool_color_id,
            t.gift_pool_price,
            t.gift_pool_num,
            t.gift_pool_status,
            t.gift_pool_sort,
            t.gift_pool_stock,
            t.gift_pool_relation,
            t.gift_pool_relation_desc,
            t.gift_pool_create_time
        from tb_iamberry_eo_gift_pool t
        WHERE t.sett_gift_id = #{settGiftId}
        AND t.gift_pool_status = 1
        AND t.gift_pool_stock > 0
        ORDER BY t.gift_pool_sort
    </select>

    <select id="getSettlementGiftById" resultMap="BaseResultMap" parameterType="Integer" >
        select
        <include refid="Base_List" />
        from tb_iamberry_eo_settlement_gift t
        where t.sett_gift_id= #{settGiftId}
    </select>
</mapper>