<?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.CoursePlanDao">
    <resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.CoursePlan">
        <id column="id_" jdbcType="INTEGER" property="id"/>
        <result column="course_group_id_" jdbcType="INTEGER" property="courseGroupId"/>
        <result column="class_num_" jdbcType="INTEGER" property="classNum"/>
        <result column="plan_" jdbcType="VARCHAR" property="plan"/>
        <result column="created_time_" jdbcType="TIMESTAMP" property="createdTime"/>
    </resultMap>

    <sql id="Base_Column_List">
        id_
        , course_group_id_, class_num_, plan_, created_time_
    </sql>

    <insert id="insertBatch" keyColumn="id_" keyProperty="id" useGeneratedKeys="true"
            parameterType="com.yonge.cooleshow.biz.dal.entity.CoursePlan">
        insert into course_plan(course_group_id_, class_num_, plan_, created_time_)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.courseGroupId}, #{entity.classNum}, #{entity.plan}, #{entity.createdTime})
        </foreach>
    </insert>

    <select id="queryCoursePlanByGroupId" resultType="com.yonge.cooleshow.biz.dal.vo.LiveCourseInfoVo$PlanVo">
        select
               a.id_  as planId,
               a.plan_ as plan,
               a.class_num_,
               b.id_ as courseId,
               b.start_time_,
               b.end_time_,
               c.room_uid_ as roomUid,
               IFNULL(c.live_state_,0) as liveState
        from course_plan as a
                 left join course_schedule as b on a.course_group_id_ = b.course_group_id_
                 AND a.class_num_ = b.class_num_
                 left join live_room as c on b.id_ = c.course_id_
        where a.course_group_id_ = #{groupId}
        order by b.start_time_
    </select>

</mapper>
