<?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.fs.live.mapper.LiveGiftMapper">

    <resultMap type="LiveGift" id="LiveGiftResult">
        <result property="giftId"    column="gift_id"    />
        <result property="giftName"    column="gift_name"    />
        <result property="description"    column="description"    />
        <result property="iconUrl"    column="icon_url"    />
        <result property="price"    column="price"    />
        <result property="status"    column="status"    />
    </resultMap>

    <sql id="selectLiveGiftVo">
        select gift_id, gift_name, description, icon_url, price, status from live_gift
    </sql>

    <select id="selectLiveGiftList" parameterType="LiveGift" resultMap="LiveGiftResult">
        <include refid="selectLiveGiftVo"/>
        <where>
            <if test="giftName != null  and giftName != ''"> and gift_name like concat('%', #{giftName}, '%')</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
            <if test="iconUrl != null  and iconUrl != ''"> and icon_url = #{iconUrl}</if>
            <if test="price != null "> and price = #{price}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>

    <select id="selectLiveGiftByGiftId" parameterType="Long" resultMap="LiveGiftResult">
        <include refid="selectLiveGiftVo"/>
        where gift_id = #{giftId}
    </select>

    <insert id="insertLiveGift" parameterType="LiveGift" useGeneratedKeys="true" keyProperty="giftId">
        insert into live_gift
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="giftName != null and giftName != ''">gift_name,</if>
            <if test="description != null">description,</if>
            <if test="iconUrl != null">icon_url,</if>
            <if test="price != null">price,</if>
            <if test="status != null">status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="giftName != null and giftName != ''">#{giftName},</if>
            <if test="description != null">#{description},</if>
            <if test="iconUrl != null">#{iconUrl},</if>
            <if test="price != null">#{price},</if>
            <if test="status != null">#{status},</if>
         </trim>
    </insert>

    <update id="updateLiveGift" parameterType="LiveGift">
        update live_gift
        <trim prefix="SET" suffixOverrides=",">
            <if test="giftName != null and giftName != ''">gift_name = #{giftName},</if>
            <if test="description != null">description = #{description},</if>
            <if test="iconUrl != null">icon_url = #{iconUrl},</if>
            <if test="price != null">price = #{price},</if>
            <if test="status != null">status = #{status},</if>
        </trim>
        where gift_id = #{giftId}
    </update>

    <delete id="deleteLiveGiftByGiftId" parameterType="Long">
        delete from live_gift where gift_id = #{giftId}
    </delete>

    <delete id="deleteLiveGiftByGiftIds" parameterType="String">
        delete from live_gift where gift_id in
        <foreach item="giftId" collection="array" open="(" separator="," close=")">
            #{giftId}
        </foreach>
    </delete>
</mapper>
