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

    <resultMap type="LiveLotteryRegistration" id="LiveLotteryRegistrationResult">
        <result property="registrationId"    column="registration_id"    />
        <result property="liveId"    column="live_id"    />
        <result property="userId"    column="user_id"    />
        <result property="lotteryId"    column="lottery_id"    />
        <result property="isWin"    column="is_win"    />
        <result property="rizeLevel"    column="rize_level"    />
        <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="selectLiveLotteryRegistrationVo">
        select registration_id, live_id, user_id, lottery_id, is_win, rize_level, create_time, update_time, create_by, update_by from live_lottery_registration
    </sql>

    <select id="selectLiveLotteryRegistrationList" parameterType="LiveLotteryRegistration" resultMap="LiveLotteryRegistrationResult">
        <include refid="selectLiveLotteryRegistrationVo"/>
        <where>
        </where>
    </select>

    <select id="selectLiveLotteryRegistrationByRegistrationId" parameterType="Long" resultMap="LiveLotteryRegistrationResult">
        <include refid="selectLiveLotteryRegistrationVo"/>
        where registration_id = #{registrationId}
    </select>

    <insert id="insertLiveLotteryRegistration" parameterType="LiveLotteryRegistration" useGeneratedKeys="true" keyProperty="registrationId">
        insert into live_lottery_registration
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="liveId != null">live_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="lotteryId != null">lottery_id,</if>
            <if test="isWin != null">is_win,</if>
            <if test="rizeLevel != null">rize_level,</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="liveId != null">#{liveId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="lotteryId != null">#{lotteryId},</if>
            <if test="isWin != null">#{isWin},</if>
            <if test="rizeLevel != null">#{rizeLevel},</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>


    <!-- 批量插入抽奖注册记录 -->
    <insert id="insertLiveLotteryRegistrationBatch" parameterType="java.util.List">
        INSERT INTO live_lottery_registration (
        live_id,
        user_id,
        lottery_id,
        is_win,
        rize_level,
        create_time,
        update_time,
        create_by,
        update_by
        ) VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.liveId},
            #{item.userId},
            #{item.lotteryId},
            #{item.isWin},
            #{item.rizeLevel},
            #{item.createTime},
            #{item.updateTime},
            #{item.createBy},
            #{item.updateBy}
            )
        </foreach>
    </insert>

    <update id="updateLiveLotteryRegistration" parameterType="LiveLotteryRegistration">
        update live_lottery_registration
        <trim prefix="SET" suffixOverrides=",">
            <if test="liveId != null">live_id = #{liveId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="lotteryId != null">lottery_id = #{lotteryId},</if>
            <if test="isWin != null">is_win = #{isWin},</if>
            <if test="rizeLevel != null">rize_level = #{rizeLevel},</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 registration_id = #{registrationId}
    </update>
    <update id="updateLiveLotteryRegistrationNoId" parameterType="LiveLotteryRegistration">
        update live_lottery_registration
        <trim prefix="SET" suffixOverrides=",">
            <if test="liveId != null">live_id = #{liveId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="lotteryId != null">lottery_id = #{lotteryId},</if>
            <if test="isWin != null">is_win = #{isWin},</if>
            <if test="rizeLevel != null">rize_level = #{rizeLevel},</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 live_id = #{liveId} and user_id = #{userId} and lottery_id = #{lotteryId}
    </update>

    <delete id="deleteLiveLotteryRegistrationByRegistrationId" parameterType="Long">
        delete from live_lottery_registration where registration_id = #{registrationId}
    </delete>

    <delete id="deleteLiveLotteryRegistrationByRegistrationIds" parameterType="String">
        delete from live_lottery_registration where registration_id in
        <foreach item="registrationId" collection="array" open="(" separator="," close=")">
            #{registrationId}
        </foreach>
    </delete>
</mapper>
