<?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.LiveBroadcastMapper">
    
    <resultMap type="LiveBroadcast" id="LiveBroadcastResult">
        <result property="id"    column="id"    />
        <result property="companyId"    column="company_id"    />
        <result property="title"    column="title"    />
        <result property="coverUrl"    column="cover_url"    />
        <result property="status"    column="status"    />
        <result property="doctorId"    column="doctor_id"    />
        <result property="tagIds"    column="tag_ids"    />
        <result property="doctorName"    column="doctor_name"    />
        <result property="doctorTitle"    column="doctor_title"    />
        <result property="doctorAvatar"    column="doctor_avatar"    />
        <result property="hospitalName"    column="hospital_name"    />
        <result property="department"    column="department"    />
        <result property="scheduledStartTime"    column="scheduled_start_time"    />
        <result property="scheduledEndTime"    column="scheduled_end_time"    />
        <result property="actualStartTime"    column="actual_start_time"    />
        <result property="actualEndTime"    column="actual_end_time"    />
        <result property="liveUrl"    column="live_url"    />
        <result property="playbackUrl"    column="playback_url"    />
        <result property="description"    column="description"    />
        <result property="viewCount"    column="view_count"    />
        <result property="likeCount"    column="like_count"    />
        <result property="favoriteCount"    column="favorite_count"    />
        <result property="needRegister"    column="need_register"    />
        <result property="shareQrcodeUrl"    column="share_qrcode_url"    />
        <result property="sort"    column="sort"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="deleted"    column="deleted"    />
    </resultMap>

    <sql id="selectLiveBroadcastVo">
        select id, company_id, title, cover_url, status, doctor_id, tag_ids,doctor_name, doctor_title, doctor_avatar, hospital_name, department, scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, live_url, playback_url, description, view_count, like_count, favorite_count, need_register, share_qrcode_url, sort, create_by, create_time, update_by, update_time, deleted from live_broadcast
    </sql>

    <select id="selectLiveBroadcastList" parameterType="LiveBroadcast" resultMap="LiveBroadcastResult">
        <include refid="selectLiveBroadcastVo"/>
        <where>  
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="title != null and title != ''">
                AND title LIKE CONCAT('%', #{title}, '%')
            </if>
            <if test="coverUrl != null  and coverUrl != ''"> and cover_url = #{coverUrl}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="doctorId != null "> and doctor_id = #{doctorId}</if>
            <if test="tagIds != null and tagIds != ''"> and t.tag_ids = #{tagIds}</if>
            <if test="doctorName != null  and doctorName != ''"> and doctor_name like concat('%', #{doctorName}, '%')</if>
            <if test="doctorTitle != null  and doctorTitle != ''"> and doctor_title = #{doctorTitle}</if>
            <if test="doctorAvatar != null  and doctorAvatar != ''"> and doctor_avatar = #{doctorAvatar}</if>
            <if test="hospitalName != null  and hospitalName != ''"> and hospital_name like concat('%', #{hospitalName}, '%')</if>
            <if test="department != null  and department != ''"> and department = #{department}</if>
            <if test="scheduledStartTime != null "> and scheduled_start_time = #{scheduledStartTime}</if>
            <if test="scheduledEndTime != null "> and scheduled_end_time = #{scheduledEndTime}</if>
            <if test="actualStartTime != null "> and actual_start_time = #{actualStartTime}</if>
            <if test="actualEndTime != null "> and actual_end_time = #{actualEndTime}</if>
            <if test="liveUrl != null  and liveUrl != ''"> and live_url = #{liveUrl}</if>
            <if test="playbackUrl != null  and playbackUrl != ''"> and playback_url = #{playbackUrl}</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
            <if test="viewCount != null "> and view_count = #{viewCount}</if>
            <if test="likeCount != null "> and like_count = #{likeCount}</if>
            <if test="favoriteCount != null "> and favorite_count = #{favoriteCount}</if>
            <if test="needRegister != null "> and need_register = #{needRegister}</if>
            <if test="shareQrcodeUrl != null  and shareQrcodeUrl != ''"> and share_qrcode_url = #{shareQrcodeUrl}</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="deleted != null "> and deleted = #{deleted}</if>
        </where>
    </select>
    
    <select id="selectLiveBroadcastById" parameterType="Long" resultMap="LiveBroadcastResult">
        <include refid="selectLiveBroadcastVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertLiveBroadcast" parameterType="LiveBroadcast" useGeneratedKeys="true" keyProperty="id">
        insert into live_broadcast
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="companyId != null">company_id,</if>
            <if test="title != null and title != ''">title,</if>
            <if test="coverUrl != null">cover_url,</if>
            <if test="status != null">status,</if>
            <if test="doctorId != null">doctor_id,</if>
            <if test="tagIds != null">tag_ids,</if>
            <if test="doctorName != null">doctor_name,</if>
            <if test="doctorTitle != null">doctor_title,</if>
            <if test="doctorAvatar != null">doctor_avatar,</if>
            <if test="hospitalName != null">hospital_name,</if>
            <if test="department != null">department,</if>
            <if test="scheduledStartTime != null">scheduled_start_time,</if>
            <if test="scheduledEndTime != null">scheduled_end_time,</if>
            <if test="actualStartTime != null">actual_start_time,</if>
            <if test="actualEndTime != null">actual_end_time,</if>
            <if test="liveUrl != null">live_url,</if>
            <if test="playbackUrl != null">playback_url,</if>
            <if test="description != null">description,</if>
            <if test="viewCount != null">view_count,</if>
            <if test="likeCount != null">like_count,</if>
            <if test="favoriteCount != null">favorite_count,</if>
            <if test="needRegister != null">need_register,</if>
            <if test="shareQrcodeUrl != null">share_qrcode_url,</if>
            <if test="sort != null">sort,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="deleted != null">deleted,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="companyId != null">#{companyId},</if>
            <if test="title != null and title != ''">#{title},</if>
            <if test="coverUrl != null">#{coverUrl},</if>
            <if test="status != null">#{status},</if>
            <if test="doctorId != null">#{doctorId},</if>
            <if test="tagIds != null">#{tagIds},</if>
            <if test="doctorName != null">#{doctorName},</if>
            <if test="doctorTitle != null">#{doctorTitle},</if>
            <if test="doctorAvatar != null">#{doctorAvatar},</if>
            <if test="hospitalName != null">#{hospitalName},</if>
            <if test="department != null">#{department},</if>
            <if test="scheduledStartTime != null">#{scheduledStartTime},</if>
            <if test="scheduledEndTime != null">#{scheduledEndTime},</if>
            <if test="actualStartTime != null">#{actualStartTime},</if>
            <if test="actualEndTime != null">#{actualEndTime},</if>
            <if test="liveUrl != null">#{liveUrl},</if>
            <if test="playbackUrl != null">#{playbackUrl},</if>
            <if test="description != null">#{description},</if>
            <if test="viewCount != null">#{viewCount},</if>
            <if test="likeCount != null">#{likeCount},</if>
            <if test="favoriteCount != null">#{favoriteCount},</if>
            <if test="needRegister != null">#{needRegister},</if>
            <if test="shareQrcodeUrl != null">#{shareQrcodeUrl},</if>
            <if test="sort != null">#{sort},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="deleted != null">#{deleted},</if>
         </trim>
    </insert>

    <update id="updateLiveBroadcast" parameterType="LiveBroadcast">
        update live_broadcast
        <trim prefix="SET" suffixOverrides=",">
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="title != null and title != ''">title = #{title},</if>
            <if test="coverUrl != null">cover_url = #{coverUrl},</if>
            <if test="status != null">status = #{status},</if>
            <if test="doctorId != null">doctor_id = #{doctorId},</if>
            <if test="tagIds != null">tag_ids = #{tagIds},</if>
            <if test="doctorName != null">doctor_name = #{doctorName},</if>
            <if test="doctorTitle != null">doctor_title = #{doctorTitle},</if>
            <if test="doctorAvatar != null">doctor_avatar = #{doctorAvatar},</if>
            <if test="hospitalName != null">hospital_name = #{hospitalName},</if>
            <if test="department != null">department = #{department},</if>
            <if test="scheduledStartTime != null">scheduled_start_time = #{scheduledStartTime},</if>
            <if test="scheduledEndTime != null">scheduled_end_time = #{scheduledEndTime},</if>
            <if test="actualStartTime != null">actual_start_time = #{actualStartTime},</if>
            <if test="actualEndTime != null">actual_end_time = #{actualEndTime},</if>
            <if test="liveUrl != null">live_url = #{liveUrl},</if>
            <if test="playbackUrl != null">playback_url = #{playbackUrl},</if>
            <if test="description != null">description = #{description},</if>
            <if test="viewCount != null">view_count = #{viewCount},</if>
            <if test="likeCount != null">like_count = #{likeCount},</if>
            <if test="favoriteCount != null">favorite_count = #{favoriteCount},</if>
            <if test="needRegister != null">need_register = #{needRegister},</if>
            <if test="shareQrcodeUrl != null">share_qrcode_url = #{shareQrcodeUrl},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="deleted != null">deleted = #{deleted},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteLiveBroadcastById" parameterType="Long">
        delete from live_broadcast where id = #{id}
    </delete>

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