<?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.yonge.cooleshow.biz.dal.dao.LiveRoomDao">
    <resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.LiveRoom">
        <id column="id_" jdbcType="INTEGER" property="id"/>
        <result column="course_group_id_" jdbcType="INTEGER" property="courseGroupId"/>
        <result column="course_id_" jdbcType="INTEGER" property="courseId"/>
        <result column="speaker_id_" jdbcType="INTEGER" property="speakerId"/>
        <result column="room_uid_" jdbcType="VARCHAR" property="roomUid"/>
        <result column="room_title_" jdbcType="VARCHAR" property="roomTitle"/>
        <result column="live_start_time_" jdbcType="TIMESTAMP" property="liveStartTime"/>
        <result column="live_end_time_" jdbcType="TIMESTAMP" property="liveEndTime"/>
        <result column="live_remark_" jdbcType="VARCHAR" property="liveRemark"/>
        <result column="live_state_" jdbcType="INTEGER" property="liveState"/>
        <result column="room_state_" jdbcType="INTEGER" property="roomState"/>
        <result column="type_" jdbcType="VARCHAR" property="type"/>
        <result column="created_by_" jdbcType="INTEGER" property="createdBy"/>
        <result column="created_time_" jdbcType="TIMESTAMP" property="createdTime"/>
        <result column="updated_by_" jdbcType="INTEGER" property="updatedBy"/>
        <result column="updated_time_" jdbcType="TIMESTAMP" property="updatedTime"/>
        <result column="cover_pic_" jdbcType="VARCHAR" property="coverPic"/>
    </resultMap>

    <sql id="Base_Column_List">
        id_
        , course_group_id_, course_id_, speaker_id_, room_uid_, room_title_, live_start_time_, live_end_time_, live_remark_, live_state_, room_state_, type_, cover_pic_, created_by_, created_time_, updated_by_, updated_time_
    </sql>

    <insert id="insertBatch" keyColumn="id_" keyProperty="id" useGeneratedKeys="true"
            parameterType="com.yonge.cooleshow.biz.dal.entity.LiveRoom">
        insert into live_room(course_group_id_, course_id_, speaker_id_, room_uid_, room_title_, live_start_time_,
        live_end_time_, live_remark_, live_state_, room_state_, type_, cover_pic_, created_by_, created_time_,
        updated_by_, updated_time_)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.courseGroupId}, #{entity.courseId}, #{entity.speakerId}, #{entity.roomUid}, #{entity.roomTitle},
            #{entity.liveStartTime}, #{entity.liveEndTime}, #{entity.liveRemark}, #{entity.liveState},
            #{entity.roomState}, #{entity.type}, #{entity.coverPic}, #{entity.createdBy}, #{entity.createdTime},
            #{entity.updatedBy}, #{entity.updatedTime})
        </foreach>
    </insert>

    <select id="getLiveInRoomBySpeakerId" resultType="com.yonge.cooleshow.biz.dal.entity.LiveRoom">
        select * from live_room
        where speaker_id_ = #{speakerId} and live_state_ = 1 and room_state_ = 0
        order by live_start_time_ desc limit 1
    </select>
    
    <select id="queryTeacherLivingList" resultType="com.yonge.cooleshow.biz.dal.vo.TeacherLivingInfoVo">
        select lr.room_uid_ roomUid, lr.room_title_ liveTitle, lr.speaker_id_ teacherId, lr.cover_pic_ liveCoverImg, u.avatar_ avatar, u.username_ username
        from live_room lr left join sys_user u on lr.speaker_id_ = u.id_
        where lr.live_state_ = 1 and lr.type_ = 'temp'
        order by lr.live_start_time_ desc
    </select>

</mapper>
