<?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.LiveRoomVideoDao">
    <resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.LiveRoomVideo">
        <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="room_uid_" jdbcType="VARCHAR" property="roomUid"/>
        <result column="record_id_" jdbcType="VARCHAR" property="recordId"/>
        <result column="url_" jdbcType="VARCHAR" property="url"/>
        <result column="start_time_" jdbcType="TIMESTAMP" property="startTime"/>
        <result column="end_time_" jdbcType="TIMESTAMP" property="endTime"/>
        <result column="type" jdbcType="INTEGER" property="type"/>
        <result column="created_time_" jdbcType="TIMESTAMP" property="createdTime"/>
    </resultMap>

    <sql id="Base_Column_List">
        id_
        , course_group_id_, course_id_, room_uid_, record_id_, url_, start_time_, end_time_, type, created_time_
    </sql>

    <insert id="insertBatch" keyColumn="id_" keyProperty="id" useGeneratedKeys="true"
            parameterType="com.yonge.cooleshow.biz.dal.entity.LiveRoomVideo">
        insert into live_room_video(course_group_id_, course_id_, room_uid_, record_id_, url_, start_time_, end_time_,
        type, created_time_)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.courseGroupId}, #{entity.courseId}, #{entity.roomUid}, #{entity.recordId}, #{entity.url},
            #{entity.startTime}, #{entity.endTime}, #{entity.type}, #{entity.createdTime})
        </foreach>
    </insert>

    <select id="getLastRecord" resultMap="BaseResultMap">
        SELECT * FROM live_room_video WHERE room_uid_ = #{roomId} AND record_id_ = #{recordId} ORDER BY id_ DESC LIMIT 1
    </select>

</mapper>
