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

    <resultMap type="LiveUserRedRecord" id="LiveUserRedRecordResult">
        <result property="id"    column="id"    />
        <result property="redId"    column="red_id"    />
        <result property="liveId"    column="live_id"    />
        <result property="userId"    column="user_id"    />
        <result property="integral"    column="integral"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectLiveUserRedRecordVo">
        select id, red_id, live_id, user_id, integral, create_time, update_time, create_by, update_by from live_user_red_record
    </sql>

    <select id="selectLiveUserRedRecordList" parameterType="LiveUserRedRecord" resultMap="LiveUserRedRecordResult">
        <include refid="selectLiveUserRedRecordVo"/>
        <where>
            <if test="liveId != null "> and live_id = #{liveId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="createTime != null "> and create_time = #{createTime}</if>
        </where>
    </select>

    <select id="selectLiveUserRedRecordById" parameterType="Long" resultMap="LiveUserRedRecordResult">
        <include refid="selectLiveUserRedRecordVo"/>
        where id = #{id}
    </select>

    <insert id="insertLiveUserRedRecord" parameterType="LiveUserRedRecord" useGeneratedKeys="true" keyProperty="id">
        insert into live_user_red_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="redId != null">red_id,</if>
            <if test="liveId != null">live_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="integral != null">integral,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="redId != null">#{redId},</if>
            <if test="liveId != null">#{liveId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="integral != null">#{integral},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
         </trim>
    </insert>

    <update id="updateLiveUserRedRecord" parameterType="LiveUserRedRecord">
        update live_user_red_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="redId != null">red_id = #{redId},</if>
            <if test="liveId != null">live_id = #{liveId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="integral != null">integral = #{integral},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteLiveUserRedRecordById" parameterType="Long">
        delete from live_user_red_record where id = #{id}
    </delete>

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

    <!-- 批量插入用户红包记录 -->
    <insert id="insertLiveUserRedRecordBatch" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO live_user_red_record
        (red_id, live_id, user_id, integral, create_time, update_time, create_by, update_by)
        VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.redId},
            #{item.liveId},
            #{item.userId},
            #{item.integral},
            #{item.createTime},
            #{item.updateTime},
            #{item.createBy},
            #{item.updateBy}
            )
        </foreach>
    </insert>

</mapper>
