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

    <resultMap type="LiveRedConf" id="LiveRedConfResult">
        <result property="redId"    column="red_id"    />
        <result property="redStatus"    column="red_status"    />
        <result property="duration"    column="duration"    />
        <result property="redType"    column="red_type"    />
        <result property="liveId"    column="live_id"    />
        <result property="redNum"    column="red_num"    />
        <result property="totalLots"    column="total_lots"    />
        <result property="totalSend"    column="total_send"    />
        <result property="desc"    column="desc"    />
        <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="selectLiveRedConfVo">
        select red_id, red_status, duration, red_type, live_id, red_num, total_lots, total_send, `desc`, create_time, update_time, create_by, update_by from live_red_conf
    </sql>

    <select id="selectLiveRedConfList" parameterType="LiveRedConf" resultMap="LiveRedConfResult">
        <include refid="selectLiveRedConfVo"/>
        <where>
            <if test="redStatus != null "> and red_status = #{redStatus}</if>
            <if test="redType != null "> and red_type = #{redType}</if>
            <if test="liveId != null "> and live_id = #{liveId}</if>
            <if test="desc != null  and desc != ''"> and `desc` = #{desc}</if>
            <if test="createTime != null "> and create_time = #{createTime}</if>
            <if test="updateTime != null "> and update_time = #{updateTime}</if>
        </where>
        order by create_time  desc
    </select>

    <select id="selectLiveRedConfByRedId" parameterType="Long" resultMap="LiveRedConfResult">
        <include refid="selectLiveRedConfVo"/>
        where red_id = #{redId}
    </select>

    <insert id="insertLiveRedConf" parameterType="LiveRedConf" useGeneratedKeys="true" keyProperty="redId">
        insert into live_red_conf
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="redStatus != null">red_status,</if>
            <if test="duration != null">duration,</if>
            <if test="redType != null">red_type,</if>
            <if test="liveId != null">live_id,</if>
            <if test="redNum != null">red_num,</if>
            <if test="totalLots != null">total_lots,</if>
            <if test="totalSend != null">total_send,</if>
            <if test="desc != null and desc != ''">`desc`,</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="redStatus != null">#{redStatus},</if>
            <if test="duration != null">#{duration},</if>
            <if test="redType != null">#{redType},</if>
            <if test="liveId != null">#{liveId},</if>
            <if test="redNum != null">#{redNum},</if>
            <if test="totalLots != null">#{totalLots},</if>
            <if test="totalSend != null">#{totalSend},</if>
            <if test="desc != null and desc != ''">#{desc},</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="updateLiveRedConf" parameterType="LiveRedConf">
        update live_red_conf
        <trim prefix="SET" suffixOverrides=",">
            <if test="redStatus != null">red_status = #{redStatus},</if>
            <if test="duration != null">duration = #{duration},</if>
            <if test="redType != null">red_type = #{redType},</if>
            <if test="liveId != null">live_id = #{liveId},</if>
            <if test="redNum != null">red_num = #{redNum},</if>
            <if test="totalLots != null">total_lots = #{totalLots},</if>
            <if test="totalSend != null">total_send = #{totalSend},</if>
            <if test="desc != null and desc != ''">`desc` = #{desc},</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 red_id = #{redId}
    </update>

    <delete id="deleteLiveRedConfByRedId" parameterType="Long">
        delete from live_red_conf where red_id = #{redId}
    </delete>

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

    <select id="selectById" parameterType="Long" resultMap="LiveRedConfResult">
        <include refid="selectLiveRedConfVo"/>
        where red_id = #{redId}
    </select>

    <update id="finishRedStatusBySetIds">
        update live_red_conf set red_status = 2  where red_id in
        <foreach item="redId" collection="ids" open="(" separator="," close=")">
            #{redId}
        </foreach>
    </update>
</mapper>
