<?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.ItemGiftMapper">
    <resultMap  id="BaseResultMap" type="ItemGift" >
        <result    column="item_gift_id"    property="itemGiftId" />
        <result    column="item_id"    property="itemId" />
        <result    column="gift_pool_id"    property="giftPoolId" />
        <result    column="item_gift_num"    property="itemGiftNum" />
    </resultMap>
    <sql    id="Base_List" >
        t.item_gift_id,
        t.item_id,
        t.gift_pool_id,
        t.item_gift_num
    </sql>
    <select id="getItemGiftList" resultMap="BaseResultMap" parameterType="ItemGift" >
        select
        <include refid="Base_List" />
        from tb_iamberry_eo_item_gift t
        <where>
            <if test="itemGiftId != null ">
                AND t.item_gift_id = #{itemGiftId}
            </if >
            <if test="itemId != null ">
                AND t.item_id = #{itemId}
            </if >
            <if test="giftPoolId != null ">
                AND t.gift_pool_id = #{giftPoolId}
            </if >
            <if test="itemGiftNum != null ">
                AND t.item_gift_num = #{itemGiftNum}
            </if >
        </where>
    </select>
    <select id="getItemGiftById" resultMap="BaseResultMap" parameterType="Integer" >
        select
        <include refid="Base_List" />
        from tb_iamberry_eo_item_gift t
        where t.item_gift_id= #{itemGiftId}
    </select>
    <insert id="save" parameterType="ItemGift" >
        insert into
        tb_iamberry_eo_item_gift
        (
        item_id,
        gift_pool_id,
        item_gift_num
        )
        values
        (
        #{itemId},
        #{giftPoolId},
        #{itemGiftNum}
        )
    </insert>
    <update id="update" parameterType="ItemGift" >
        update
        tb_iamberry_eo_item_gift
        <set >
            <if test="itemId != null ">
                item_id = #{itemId},
            </if >
            <if test="giftPoolId != null ">
                gift_pool_id = #{giftPoolId},
            </if >
            <if test="itemGiftNum != null ">
                item_gift_num = #{itemGiftNum}
            </if >
        </set >
        where item_gift_id= #{itemGiftId}
    </update>

    <insert id="saveList" parameterType="java.util.List" >
        insert into
        tb_iamberry_eo_item_gift
        (
        item_id,
        gift_pool_id,
        item_gift_num
        )
        values
        <foreach collection="list" item="node" index="index" separator="," open="" close="">
            (
            #{node.itemId},
            #{node.giftPoolId},
            #{node.itemGiftNum}
            )
        </foreach >
    </insert>

</mapper>