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

    <resultMap type="com.zhongzheng.modules.course.domain.CourseChapterSection" id="CourseChapterSectionResult">
        <result property="sectionId" column="section_id"/>
        <result property="chapterId" column="chapter_id"/>
        <result property="sort" column="sort"/>
        <result property="id" column="id"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.course.vo.CourseChapterSectionVo" id="CourseChapterSectionResultVo">
        <result property="sectionId" column="section_id"/>
        <result property="chapterId" column="chapter_id"/>
        <result property="sort" column="c_sort"/>
        <result property="id" column="id"/>
        <result property="type" column="type"/>

        <result property="code" column="code"/>
        <result property="name" column="name"/>
        <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="durationTime" column="duration_time"/>
    </resultMap>


    <select id="getListById" parameterType="Long"  resultMap="CourseChapterSectionResultVo">
        SELECT
            cs.*,
            ccs.sort as c_sort,
            ccs.id,
            ccs.chapter_id,
            3 as type
        FROM
            course_chapter_section ccs
                LEFT JOIN course_section cs ON ccs.section_id = cs.section_id
        WHERE
            cs.`status` !=- 1
	        AND ccs.chapter_id = #{id}
        ORDER BY
            c_sort DESC
    </select>

    <select id="getListTotalTime" parameterType="Long"  resultType="java.lang.Long">
        SELECT
            IFNULL(sum( cs.duration_time ),0) AS duration_time
        FROM
            course_chapter_section ccs
                LEFT JOIN course_section cs ON ccs.section_id = cs.section_id
        WHERE
            cs.`status` !=- 1
	    AND ccs.chapter_id  =#{id}
    </select>


</mapper>
