<?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.hc.business.mapper.ClassCourseMapper">

    <resultMap type="classCourse" id="ClassCourseMap">
        <result property="classCourseId" column="class_course_id" jdbcType="INTEGER"/>
        <result property="classId" column="class_id" jdbcType="INTEGER"/>
        <result property="courseId" column="course_id" jdbcType="INTEGER"/>
        <result property="courseType" column="course_type" jdbcType="INTEGER"/>
        <result property="createTime" column="create_time" jdbcType="INTEGER"/>
    </resultMap>

    <sql id="Base_Column_List">
        class_course_id,
           class_id,
           course_id,
           course_type,
           create_time
    </sql>

    <select id="queryByClassId" resultType="com.hc.business.dto.ClassCourseDto">
        SELECT *
        FROM class_course as cc
        INNER JOIN course as c on cc.course_id = c.course_id
        <where>
            c.is_valid = 1
            AND
            class_id = #{classId}
            <if test="courseType!=null and courseType!=''">
                AND course_type = #{courseType}
            </if>
        </where>
        ORDER BY cc.class_course_id DESC
    </select>

    <select id="queryByClassIdWithCourseId" resultMap="ClassCourseMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM class_course
        WHERE class_id = #{classId} AND course_id = #{courseId}
        ORDER BY class_course_id DESC
    </select>


</mapper>