<?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.education.business.mapper.education.GoalInfoMapper">

    <resultMap id="BaseResultMap" type="com.education.model.dto.GoalInfoDto">
            <id property="id" column="id" />
            <result property="subjectId" column="subject_id" />
            <result property="schoolType" column="school_type" />
            <result property="courseSectionId" column="course_section_id" />
            <result property="courseId" column="course_id" />
            <result property="gradeId" column="grade_id" />
            <result property="courseName" column="course_name" />
            <result property="courseSectionName" column="course_section_name"/>
            <result property="content" column="content" />
            <result property="gOriented" column="g_oriented" />
            <result property="pScoreStd" column="p_score_std" />
            <result property="sScoreStd" column="s_score_std" />
            <result property="rScoreStd" column="r_score_std" />
            <result property="eScoreStd" column="e_score_std" />
            <result property="nScoreStd" column="n_score_std" />
            <result property="createUser" column="create_user" />
            <result property="createDate" column="create_date" />
            <result property="updateDate" column="update_date" />
            <result property="knowPoints" column="know_points" />
    </resultMap>

    <sql id="Base_Column_List">
        id,subject_id,school_type,course_section_id,course_id,content,
        g_oriented,p_score_std,s_score_std,r_score_std,e_score_std,
        n_score_std,create_user,create_date,update_date
    </sql>

    <select id="selectPageList" resultMap="BaseResultMap">
        select distinct goal_info.*,course_info.name as course_name,course_section.title AS  course_section_name
        from goal_info
        left join course_info
        on  goal_info.course_id = course_info.id
        left join course_section
        ON  goal_info.course_id = course_section.course_id AND     goal_info.course_section_id = course_section.id
        <where>
            <if test="goalInfo.gOriented != null and goalInfo.gOriented != ''">
                <bind name="gOriented" value="'%' + goalInfo.gOriented + '%'"/>
                and goal_info.g_oriented like #{gOriented}
            </if>

            <if test="goalInfo.subjectId != null">
                and goal_info.subject_id = #{goalInfo.subjectId}
            </if>

            <if test="goalInfo.courseSectionId != null">
                and goal_info.course_section_id = #{goalInfo.courseSectionId}
            </if>

            <if test="goalInfo.courseId != null">
                and goal_info.course_id = #{goalInfo.courseId}
            </if>
        </where>
    </select>
</mapper>
