<?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.yanzhu.exam.questions.mapper.ExamQuestionsListMapper">
    
    <resultMap type="com.yanzhu.exam.questions.domain.ExamQuestionsList" id="ExamQuestionsListResult">
        <result property="rownum"    column="rownum"    />
        <result property="bankCode"    column="bank_code"    />
        <result property="bankName"    column="bank_name"    />
        <result property="questionsId"    column="questions_id"    />
        <result property="questionsCode"    column="questions_code"    />
        <result property="questionsTitle"    column="questions_title"    />
        <result property="questionsType"    column="questions_type"    />
        <result property="questionsScore"    column="questions_score"    />
        <result property="rateNumber"    column="rate_number"    />
        <result property="rightAnswer"    column="right_answer"    />
        <result property="answerAnalyse"    column="answer_analyse"    />
        <result property="status"    column="status"    />
        <result property="createBy"    column="create_by"    />
        <result property="createDept"    column="create_dept"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectExamQuestionsListVo">
	 select @rownum := @rownum + 1 as rownum, bank_code, bank_name, questions_id, questions_code, questions_title, questions_type, questions_score, rate_number, right_answer, answer_analyse, status, create_by, create_dept, create_time from
	 (
		select a.bank_code, b.bank_name, a.questions_id, a.questions_code, substring(a.questions_title,1,50) as questions_title, a.questions_type, a.questions_score, a.rate_number, a.right_answer, a.answer_analyse, a.status, a.create_by, a.create_dept, a.create_time from exam_questions_property a
		left join exam_questions_bank b on b.bank_code = a.bank_code
		order by a.questions_type, a.bank_code, a.questions_id        
	 ) t, (select @rownum := 0) r
    </sql>

    <select id="selectExamQuestionsList" parameterType="String" resultMap="ExamQuestionsListResult">
        <include refid="selectExamQuestionsListVo"/>
        where bank_code in 
        <foreach item="bankCode" collection="array" open="(" separator="," close=")">
            #{bankCode}
        </foreach>  
    </select>
    
    <select id="selectChoiceExamQuestionsList" parameterType="String" resultMap="ExamQuestionsListResult">
        <include refid="selectExamQuestionsListVo"/>
        where questions_code in
		(
		select questions_code from exam_task_questions where exam_code = #{examCode}
		)  
    </select>
    
</mapper>