<?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.zhongzheng.modules.inform.mapper.InformCourseMapper">

    <resultMap type="com.zhongzheng.modules.inform.domain.InformCourse" id="InformCourseResult">
        <result property="id" column="id"/>
        <result property="informId" column="inform_id"/>
        <result property="courseId" column="course_id"/>
        <result property="sectionId" column="section_id"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="moduleId" column="module_id"/>
        <result property="chapterId" column="chapter_id"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.inform.vo.InformCourseVo" id="InformCourseVo">
        <result property="id" column="id"/>
        <result property="informId" column="inform_id"/>
        <result property="courseId" column="course_id"/>
        <result property="sectionId" column="section_id"/>
        <result property="moduleId" column="module_id"/>
        <result property="chapterId" column="chapter_id"/>
        <result property="goodsName" column="goods_name"/>
        <result property="subjectName" column="subject_name"/>
        <result property="chapterName" column="chapter_name"/>
        <result property="moduleName" column="module_name"/>
        <result property="goodsId" column="goods_id"/>
        <result property="subjectId" column="subject_id"/>
        <result property="subjectName" column="subject_name"/>
        <result property="sectionName" column="section_name"/>
        <result property="recordingUrl" column="recording_url"/>
    </resultMap>

    <select id="queryCourse" parameterType="long" resultMap="InformCourseVo">
        SELECT
        ic.*,
        (SELECT g.goods_name FROM goods g where g.goods_id = ic.goods_id) as goods_name,
        (SELECT cs.subject_name FROM course_subject cs LEFT JOIN course c on c.subject_id = cs.id where c.course_id = ic.course_id) as subject_name,
        (SELECT cs.id FROM course_subject cs LEFT JOIN course c on c.subject_id = cs.id where c.course_id = ic.course_id) as subject_id,
        (SELECT cs.id FROM course_subject cs LEFT JOIN course c on c.subject_id = cs.id where c.course_id = ic.course_id) as subject_id,
        (SELECT recording_url FROM course_section cs  where ic.section_id = cs.section_id ) as recording_url
        FROM
        inform_course ic
        WHERE
        1=1
        <if test="informId != null and informId != ''">
            and ic.inform_id =  #{informId}
        </if>
    </select>
</mapper>
