<?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.CourseMapper">

    <resultMap type="course" id="CourseMap">
        <result property="courseId" column="course_id" jdbcType="INTEGER"/>
        <result property="courseName" column="course_name" jdbcType="VARCHAR"/>
        <result property="courseLogo" column="course_logo" jdbcType="VARCHAR"/>
        <result property="courseDesc" column="course_desc" jdbcType="VARCHAR"/>
        <result property="courseHours" column="course_hours" jdbcType="FLOAT"/>
        <result property="courseTeacher" column="course_teacher" jdbcType="VARCHAR"/>
        <result property="isValid" column="is_valid" jdbcType="INTEGER"/>
        <result property="gallery" column="gallery" jdbcType="VARCHAR"/>
        <result property="reserved1" column="reserved1" jdbcType="INTEGER"/>
        <result property="time" column="time" jdbcType="INTEGER"/>
    </resultMap>

    <sql id="Base_Column_List">
        course_id,
           course_name,
           course_logo,
           course_desc,
           course_hours,
           course_teacher,
           is_valid,
           gallery,
           reserved1,
           time
    </sql>

    <select id="queryByTypeId" resultType="com.hc.business.dto.TypeCourseDto">
        <!--SELECT-->
        <!--<include refid="Base_Column_List"/>-->
        <!--FROM course-->
        <!--WHERE course_id in (select course_id from course_type_relation where course_type_id=#{typeId})-->
        select a.course_type_re_id,a.course_id,b.course_name,b.course_logo,b.course_hours,b.course_teacher,b.time
        from (select * from course_type_relation where course_type_id=#{typeId}) as a left join course as b on
        a.course_id = b.course_id
        WHERE b.is_valid = 1
        ORDER BY a.course_id DESC
    </select>

    <select id="queryTeacherName" resultMap="CourseMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM course
        WHERE course_teacher LIKE "%"#{name}"%" AND is_valid = 1
        ORDER BY course_id DESC
    </select>

    <select id="queryCourseName" resultMap="CourseMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM course
        WHERE course_name LIKE "%"#{name}"%" AND is_valid = 1
        ORDER BY course_id DESC
    </select>

    <select id="queryAll" resultMap="CourseMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM course
        <where>
            <if test="valid != null and valid != '' or valid == 0">
                is_valid = #{valid}
            </if>
        </where>
        ORDER BY course_id DESC
    </select>


</mapper>