<?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.CourseSectionMapper">

    <resultMap type="com.zhongzheng.modules.course.domain.CourseSection" id="CourseSectionResult">
        <result property="sectionId" column="section_id"/>
        <result property="name" column="name"/>
        <result property="sort" column="sort"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="prefixName" column="prefix_name"/>
        <result property="status" column="status"/>
        <result property="sectionType" column="section_type"/>
        <result property="publishStatus" column="publish_status"/>
        <result property="liveUrl" column="live_url"/>
        <result property="liveStartTime" column="live_start_time"/>
        <result property="liveEndTime" column="live_end_time"/>
        <result property="recordingUrl" column="recording_url"/>
        <result property="durationTime" column="duration_time"/>
        <result property="coverUrl" column="cover_url"/>
        <result property="code" column="code"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.course.vo.CourseSectionVo" id="CourseSectionResultVo">
        <result property="sectionId" column="section_id"/>
        <result property="name" column="name"/>
        <result property="sort" column="sort"/>

        <result property="prefixName" column="prefix_name"/>
        <result property="status" column="status"/>
        <result property="sectionType" column="section_type"/>
        <result property="publishStatus" column="publish_status"/>
        <result property="liveUrl" column="live_url"/>
        <result property="liveStartTime" column="live_start_time"/>
        <result property="liveEndTime" column="live_end_time"/>
        <result property="recordingUrl" column="recording_url"/>
        <result property="durationTime" column="duration_time"/>
        <result property="coverUrl" column="cover_url"/>
        <result property="code" column="code"/>
        <collection property="businessList" javaType="java.util.List" resultMap="CourseSectionBusiness"/>
        <collection property="chapterList" javaType="java.util.List" resultMap="CourseChapterSectionListResult"/>
        <collection property="moduleList" javaType="java.util.List" resultMap="CourseModuleChapterListResult"/>
        <collection property="courseList" javaType="java.util.List" resultMap="CourseSectionListResult"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.course.domain.CourseSectionBusiness" id="CourseSectionBusiness">
        <result property="id" column="id"/>
        <result property="subjectId" column="subject_id"/>
        <result property="educationTypeId" column="education_type_id"/>
        <result property="businessId" column="business_id"/>
        <result property="projectId" column="project_id"/>

        <result property="educationName" column="education_name"/>
        <result property="projectName" column="project_name"/>
        <result property="businessName" column="business_name"/>
        <result property="subjectName" column="subject_name"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.course.vo.CourseChapterSectionListVo" id="CourseChapterSectionListResult">
        <result property="chapterName" column="chapter_name"/>
        <result property="chapterId" column="chapter_id"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.course.vo.CourseModuleChapterListVo" id="CourseModuleChapterListResult">
        <result property="moduleId" column="module_id"/>
        <result property="moduleName" column="module_name"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.course.vo.CourseSectionListVo" id="CourseSectionListResult">
        <result property="courseId" column="course_id"/>
        <result property="courseName" column="course_name"/>
    </resultMap>

    <select id="selectSectionList" parameterType="com.zhongzheng.modules.course.bo.CourseSectionQueryBo" resultMap="CourseSectionResultVo">
        SELECT
        c.*,
        csb.education_type_id,
        csb.id,
        csb.business_id,
        csb.subject_id,
        csb.project_id,
        cet.education_name,
        cpt.project_name,
        cb.business_name,
        cs.subject_name,
        ccs.chapter_id,
        cc.NAME AS chapter_name
        FROM
        course_section c
        LEFT JOIN course_section_business csb ON c.section_id = csb.section_id
        LEFT JOIN course_education_type cet ON csb.education_type_id = cet.id
        LEFT JOIN course_project_type cpt ON csb.project_id = cpt.id
        LEFT JOIN course_business cb ON csb.business_id = cb.id
        LEFT JOIN course_subject cs ON csb.subject_id = cs.id
        LEFT JOIN course_chapter_section ccs ON csb.id = ccs.section_id
        LEFT JOIN course_chapter cc ON ccs.chapter_id = cc.chapter_id
        WHERE
        1 = 1
        <if test="name != null and name != ''">
            AND c.name like concat('%', #{name}, '%')
        </if>
        <if test="publishStatus != null and publishStatus != ''">
            AND c.publish_status = #{publishStatus}
        </if>
        <if test="educationTypeId != null and educationTypeId != ''">
            AND csb.education_type_id = #{educationTypeId}
        </if>
        <if test="subjectId != null and subjectId != ''">
            AND csb.subject_id = #{subjectId}
        </if>
        <if test="businessId != null and businessId != ''">
            AND csb.business_id = #{businessId}
        </if>
        <if test="sectionType != null and sectionType != ''">
            AND c.section_type = #{sectionType}
        </if>
        <if test="prefixName != null and prefixName != ''">
            AND c.prefix_name like concat('%', #{prefixName}, '%')
        </if>
        <if test="status != null and status.size()!=0 ">
            AND c.status in
            <foreach collection="status" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>

    </select>


    <select id="selectSectionList_COUNT" resultType="Long">
        SELECT
        count( DISTINCT c.section_id )
        FROM
        course_section c
        LEFT JOIN course_section_business csb ON c.section_id = csb.section_id
        WHERE
        1 = 1
        <if test="name != null and name != ''">
            AND c.name like concat('%', #{name}, '%')
        </if>
        <if test="publishStatus != null and publishStatus != ''">
            AND c.publish_status = #{publishStatus}
        </if>
        <if test="educationTypeId != null and educationTypeId != ''">
            AND csb.education_type_id = #{educationTypeId}
        </if>
        <if test="subjectId != null and subjectId != ''">
            AND csb.subject_id = #{subjectId}
        </if>
        <if test="businessId != null and businessId != ''">
            AND csb.business_id = #{businessId}
        </if>
        <if test="sectionType != null and sectionType != ''">
            AND c.section_type = #{sectionType}
        </if>
        <if test="prefixName != null and prefixName != ''">
            AND c.prefix_name like concat('%', #{prefixName}, '%')
        </if>
        <if test="status != null and status.size()!=0 ">
            AND c.status in
            <foreach collection="status" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
    </select>
</mapper>
