<?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.zhentao.system.mapper.CourseMapper">
    <resultMap id="CourseResult" type="course">
        <id property="courseId" column="course_id"/>
        <result property="courseName" column="course_name"/>
        <result property="courseDescription" column="course_description"/>
        <result property="courseCategory" column="course_category"/>
        <result property="instructorId" column="instructor_id"/>
        <result property="courseCover" column="course_cover"/>
        <result property="coursePrice" column="course_price"/>
        <result property="courseDuration" column="course_duration"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="courseStatus" column="course_status"/>
        <result property="studyNum" column="student_num"/>
        <result property="isFree" column="is_free"/>
        <result property="recommendIndex" column="recommend_index"/>
        <result property="courseOutline" column="course_outline"/>
        <association property="category" javaType="courseCategory" resultMap="categoryResult"/>
    </resultMap>
    <resultMap id="categoryResult" type="courseCategory">
        <id property="categoryId" column="category_id"/>
        <result property="categoryName" column="category_name"/>
        <result property="categoryDescription" column="category_description"/>
    </resultMap>
    <select id="selectCourseList" resultType="com.zhentao.system.domain.Course">
        select c.*, cc.category_name, i.instructor_name from course c left join course_category cc on c.course_category = cc.category_id
        left join instructor i on c.instructor_id = i.instructor_id
        where c.course_status = '上线'
        <if test="courseName != null and courseName != ''">
            and c.course_name like concat('%', #{courseName}, '%')
        </if>
        <if test="courseCategory != null">
            and c.course_category = #{courseCategory}
        </if>
    </select>
    <select id="findById" resultType="com.zhentao.system.domain.Course">
        select * from course where course_category = #{courseCategory}
    </select>
</mapper>
