<?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.course.mapper.CourseMenuMapper">

    <resultMap type="com.zhongzheng.modules.course.domain.CourseMenu" id="CourseMenuResult">
        <result property="id" column="id"/>
        <result property="courseId" column="course_id"/>
        <result property="menuId" column="menu_id"/>
        <result property="type" column="type"/>
        <result property="parentId" column="parent_id"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="status" column="status"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.course.vo.CourseMenuVo" id="CourseMenuResultVo">
        <result property="id" column="id"/>
        <result property="courseId" column="course_id"/>
        <result property="menuId" column="menu_id"/>
        <result property="type" column="type"/>
        <result property="parentId" column="parent_id"/>
        <result property="status" column="status"/>
        <result property="menuName" column="menu_name"/>
    </resultMap>

    <select id="selectList" parameterType="com.zhongzheng.modules.course.bo.CourseMenuQueryBo"  resultMap="CourseMenuResultVo">
        SELECT
            m.*,
            CASE

                WHEN m.type = 1 THEN
                    cm.module_name
                WHEN m.type = 2 THEN
                    cc.`name`
                WHEN m.type = 3 THEN
                    cs.`name`
                END menu_name
        FROM
            course_menu m
                LEFT JOIN course_module cm ON m.menu_id = cm.module_id
                AND m.type = 1
                LEFT JOIN course_chapter cc ON m.menu_id = cc.chapter_id
                AND m.type = 2
                LEFT JOIN course_section cs ON m.menu_id = cs.section_id
                AND m.type = 3
        WHERE
            m.course_id = #{courseId}
    </select>

</mapper>
