<?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.qmth.distributed.print.business.mapper.ObeCourseRequirementMatrixMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.qmth.distributed.print.business.entity.ObeCourseRequirementMatrix">
        <id column="id" property="id" />
        <result column="culture_program_id" property="cultureProgramId" />
        <result column="obe_course_id" property="obeCourseId" />
        <result column="obe_requirement_id" property="obeRequirementId" />
        <result column="obe_sub_requirement_id" property="obeSubRequirementId" />
        <result column="content" property="content" />
        <result column="intensity" property="intensity" />
        <result column="create_id" property="createId" />
        <result column="create_time" property="createTime" />
        <result column="update_id" property="updateId" />
        <result column="update_time" property="updateTime" />
    </resultMap>
    <select id="listMatrix" resultType="com.qmth.distributed.print.business.bean.dto.obe.CourseRequirementMatrixDto"
            parameterType="java.lang.Long">
        SELECT
            ocrm.*,
            ocpc.sort_num courseSortNum,
            ocpr.sort_num requirementSortNum,
            socpr.sort_num subRequirementSortNum,
            socpr.content requirementContent
        FROM
            obe_course_requirement_matrix ocrm
                LEFT JOIN
            obe_culture_program_course ocpc ON ocrm.obe_course_id = ocpc.id
                LEFT JOIN
            obe_culture_program_requirement ocpr ON ocrm.obe_requirement_id = ocpr.id
                LEFT JOIN
            obe_culture_program_requirement socpr ON ocrm.obe_sub_requirement_id = socpr.id
                LEFT JOIN
            basic_course bc ON ocpc.course_id = bc.id
        WHERE
            ocrm.culture_program_id = #{cultureProgramId}
            <if test="courseId != null">
                and ocpc.course_id = #{courseId}
            </if>
        ORDER BY ocpc.sort_num , ocpr.sort_num
    </select>

</mapper>
