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

    <resultMap type="LiveEventConf" id="LiveEventConfResult">
        <result property="eventId"    column="event_id"    />
        <result property="liveId"    column="live_id"    />
        <result property="eventType"    column="event_type"    />
        <result property="triggerCount"    column="trigger_count"    />
        <result property="redId"    column="red_id"    />
        <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="selectLiveEventConfVo">
        select event_id, live_id, event_type, trigger_count, red_id, create_time, update_time, create_by, update_by from live_event_conf
    </sql>

    <select id="selectLiveEventConfList" parameterType="LiveEventConf" resultMap="LiveEventConfResult">
        <include refid="selectLiveEventConfVo"/>
        <where>
            <if test="liveId != null "> and live_id = #{liveId}</if>
            <if test="eventType != null "> and event_type = #{eventType}</if>
            <if test="triggerCount != null "> and trigger_count = #{triggerCount}</if>
        </where>
    </select>

    <select id="selectLiveEventConfByEventId" parameterType="Long" resultMap="LiveEventConfResult">
        <include refid="selectLiveEventConfVo"/>
        where event_id = #{eventId}
    </select>

    <insert id="insertLiveEventConf" parameterType="LiveEventConf" useGeneratedKeys="true" keyProperty="eventId">
        insert into live_event_conf
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="liveId != null">live_id,</if>
            <if test="eventType != null">event_type,</if>
            <if test="triggerCount != null">trigger_count,</if>
            <if test="redId != null">red_id,</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="eventType != null">#{eventType},</if>
            <if test="triggerCount != null">#{triggerCount},</if>
            <if test="redId != null">#{redId},</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="updateLiveEventConf" parameterType="LiveEventConf">
        update live_event_conf
        <trim prefix="SET" suffixOverrides=",">
            <if test="liveId != null">live_id = #{liveId},</if>
            <if test="eventType != null">event_type = #{eventType},</if>
            <if test="triggerCount != null">trigger_count = #{triggerCount},</if>
            <if test="redId != null">red_id = #{redId},</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 event_id = #{eventId}
    </update>

    <delete id="deleteLiveEventConfByEventId" parameterType="Long">
        delete from live_event_conf where event_id = #{eventId}
    </delete>

    <delete id="deleteLiveEventConfByEventIds" parameterType="String">
        delete from live_event_conf where event_id in
        <foreach item="eventId" collection="array" open="(" separator="," close=")">
            #{eventId}
        </foreach>
    </delete>
</mapper>
