<?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.bank.mapper.QuestionModuleChapterMapper">

    <resultMap type="com.zhongzheng.modules.bank.domain.QuestionModuleChapter" id="QuestionModuleChapterResult">
        <result property="id" column="id"/>
        <result property="moduleExamId" column="module_exam_id"/>
        <result property="chapterExamId" column="chapter_exam_id"/>
        <result property="sort" column="sort"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.bank.vo.QuestionChapterVo" id="QuestionModuleChapterResultVo">
        <result property="chapterExamId" column="chapter_exam_id"/>
        <result property="name" column="name"/>
        <result property="sort" column="sort"/>
        <result property="status" column="status"/>
        <result property="prefixName" column="prefix_name"/>
        <result property="publishStatus" column="publish_status"/>
        <result property="code" column="code"/>
        <result property="sort" column="chapter_sort"/>
    </resultMap>

    <select id="getList" parameterType="com.zhongzheng.modules.bank.bo.QuestionModuleChapterQueryBo" resultMap="QuestionModuleChapterResultVo">
        SELECT
            qc.*,
            mc.sort AS chapter_sort
        FROM
            question_module_chapter mc
                LEFT JOIN question_chapter qc ON mc.chapter_exam_id = qc.chapter_exam_id
        WHERE
            mc.module_exam_id = #{moduleExamId}

    </select>

    <select id="getDoList" parameterType="com.zhongzheng.modules.bank.bo.QuestionModuleChapterQueryBo" resultMap="QuestionModuleChapterResultVo">
        SELECT
            qc.*,
            mc.sort as chapter_sort
        FROM
            question_module qm
                LEFT JOIN question_module_chapter mc ON mc.module_exam_id = qm.module_exam_id
                LEFT JOIN question_chapter qc ON mc.chapter_exam_id = qc.chapter_exam_id
        WHERE
            qm.module_exam_id  =#{moduleExamId}
          AND mc.chapter_exam_id IN ( SELECT chapter_exam_id FROM user_exam_record WHERE user_id = #{userId} AND goods_id = #{goodsId} AND module_exam_id = 0 AND chapter_exam_id > 0 GROUP BY chapter_exam_id)

    </select>
</mapper>
