<?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.LiveCouponUserMapper">

    <resultMap type="LiveCouponUser" id="LiveCouponUserResult">
        <result property="id"    column="id"    />
        <result property="couponId"    column="coupon_id"    />
        <result property="userId"    column="user_id"    />
        <result property="couponTitle"    column="coupon_title"    />
        <result property="couponPrice"    column="coupon_price"    />
        <result property="useMinPrice"    column="use_min_price"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="limitTime"    column="limit_time"    />
        <result property="useTime"    column="use_time"    />
        <result property="type"    column="type"    />
        <result property="status"    column="status"    />
        <result property="isFail"    column="is_fail"    />
        <result property="isDel"    column="is_del"    />
        <result property="goodsId"    column="goods_id"    />
    </resultMap>

    <sql id="selectLiveCouponUserVo">
        select id, coupon_id, user_id, coupon_title, coupon_price, use_min_price, create_time, update_time, limit_time, use_time, type, status, is_fail, is_del,goods_id from live_coupon_user
    </sql>

    <select id="selectLiveCouponUserList" parameterType="LiveCouponUser" resultMap="LiveCouponUserResult">
        <include refid="selectLiveCouponUserVo"/>
        <where>
            <if test="couponId != null "> and coupon_id = #{couponId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="couponTitle != null  and couponTitle != ''"> and coupon_title = #{couponTitle}</if>
            <if test="couponPrice != null "> and coupon_price = #{couponPrice}</if>
            <if test="useMinPrice != null "> and use_min_price = #{useMinPrice}</if>
            <if test="limitTime != null "> and limit_time = #{limitTime}</if>
            <if test="useTime != null "> and use_time = #{useTime}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="isFail != null "> and is_fail = #{isFail}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
            <if test="goodsId != null "> and goods_id = #{goodsId}</if>
        </where>
    </select>

    <select id="selectLiveCouponUserById" parameterType="Long" resultMap="LiveCouponUserResult">
        <include refid="selectLiveCouponUserVo"/>
        where id = #{id}
    </select>

    <insert id="insertLiveCouponUser" parameterType="LiveCouponUser" useGeneratedKeys="true" keyProperty="id">
        insert into live_coupon_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="couponId != null">coupon_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="couponTitle != null and couponTitle != ''">coupon_title,</if>
            <if test="couponPrice != null">coupon_price,</if>
            <if test="useMinPrice != null">use_min_price,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="limitTime != null">limit_time,</if>
            <if test="useTime != null">use_time,</if>
            <if test="type != null and type != ''">type,</if>
            <if test="status != null">status,</if>
            <if test="isFail != null">is_fail,</if>
            <if test="isDel != null">is_del,</if>
            <if test="goodsId != null">goods_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="couponId != null">#{couponId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="couponTitle != null and couponTitle != ''">#{couponTitle},</if>
            <if test="couponPrice != null">#{couponPrice},</if>
            <if test="useMinPrice != null">#{useMinPrice},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="limitTime != null">#{limitTime},</if>
            <if test="useTime != null">#{useTime},</if>
            <if test="type != null and type != ''">#{type},</if>
            <if test="status != null">#{status},</if>
            <if test="isFail != null">#{isFail},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="goodsId != null">#{goodsId},</if>
         </trim>
    </insert>

    <update id="updateLiveCouponUser" parameterType="LiveCouponUser">
        update live_coupon_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="couponId != null">coupon_id = #{couponId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="couponTitle != null and couponTitle != ''">coupon_title = #{couponTitle},</if>
            <if test="couponPrice != null">coupon_price = #{couponPrice},</if>
            <if test="useMinPrice != null">use_min_price = #{useMinPrice},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="limitTime != null">limit_time = #{limitTime},</if>
            <if test="useTime != null">use_time = #{useTime},</if>
            <if test="type != null and type != ''">type = #{type},</if>
            <if test="status != null">status = #{status},</if>
            <if test="isFail != null">is_fail = #{isFail},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="goodsId != null">goods_id = #{goodsId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteLiveCouponUserById" parameterType="Long">
        delete from live_coupon_user where id = #{id}
    </delete>

    <delete id="deleteLiveCouponUserByIds" parameterType="String">
        delete from live_coupon_user where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>
