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

    <resultMap type="com.zhongzheng.modules.bank.domain.QuestionChapterExam" id="QuestionChapterExamResult">
        <result property="examId" column="exam_id"/>
        <result property="chapterExamId" column="chapter_exam_id"/>
        <result property="sort" column="sort"/>
        <result property="id" column="id"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.bank.vo.ExamVo" id="QuestionChapterExamResultVo">
        <result property="examId" column="exam_id"/>
        <result property="status" column="status"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="prefixName" column="prefix_name"/>
        <result property="code" column="code"/>
        <result property="examName" column="exam_name"/>
        <result property="publishStatus" column="publish_status"/>
        <result property="year" column="year"/>
        <result property="cityId" column="city_id"/>
        <result property="provinceId" column="province_id"/>
        <result property="examPaperId" column="exam_paper_id"/>
        <result property="answerTime" column="answer_time"/>
        <result property="examPaperId" column="exam_paper_id"/>
        <result property="answerNum" column="answer_num"/>
        <result property="sort" column="exam_sort"/>
        <result property="type" column="type"/>
        <result property="questionNum" column="question_num"/>
    </resultMap>

    <select id="getList" parameterType="com.zhongzheng.modules.bank.bo.QuestionChapterExamQueryBo" resultMap="QuestionChapterExamResultVo">
        SELECT
            e.*,
            qce.sort AS exam_sort,
               3 as type
        FROM
            question_chapter_exam qce
                LEFT JOIN (
                SELECT
                    e.*,
                    count( eq.question_id ) question_num
                FROM
                    exam e
                        LEFT JOIN exam_question eq ON e.exam_id = eq.exam_id
                GROUP BY
                    e.exam_id
            ) e ON qce.exam_id = e.exam_id
        WHERE
            qce.chapter_exam_id =#{chapterExamId}
          AND e.status = 1
    </select>
</mapper>
