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

    <resultMap type="com.zhongzheng.modules.bank.domain.ExamQuestion" id="ExamQuestionResult">
        <result property="id" column="id"/>
        <result property="examId" column="exam_id"/>
        <result property="questionId" column="question_id"/>
        <result property="sort" column="sort"/>
        <result property="score" column="score"/>
        <result property="partScore" column="part_score"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.bank.vo.ExamQuestionVo" id="ExamQuestionResultVo">
        <result property="id" column="id"/>
        <result property="examId" column="exam_id"/>
        <result property="questionId" column="question_id"/>
        <result property="sort" column="sort"/>
        <result property="score" column="score"/>
        <result property="partScore" column="part_score"/>
        <result property="content" column="content"/>
        <result property="type" column="type"/>
        <result property="answerQuestion" column="answer_question"/>
        <result property="status" column="status"/>
        <result property="analysisContent" column="analysis_content"/>
        <result property="imgUrl" column="img_url"/>
        <result property="jsonStr" column="json_str"/>
        <result property="prefixName" column="prefix_name"/>
        <result property="knowledgeIds" column="knowledge_ids"/>
        <result property="publishStatus" column="publish_status"/>
        <result property="code" column="code"/>
        <result property="answerTime" column="answer_time"/>
        <result property="examPaperId" column="exam_paper_id"/>
        <result property="answerNum" column="answer_num"/>
        <collection property="businessList" javaType="java.util.List" resultMap="QuestionBusiness"/>
        <collection property="knowledgeList" javaType="java.util.List" resultMap="ExamKnowledge"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.bank.vo.ExamQuestionVo" id="ExamQuestionResultAppVo">
        <result property="id" column="id"/>
        <result property="examId" column="exam_id"/>
        <result property="questionId" column="question_id"/>
        <result property="sort" column="sort"/>
        <result property="score" column="score"/>
        <result property="partScore" column="part_score"/>
        <result property="content" column="content"/>
        <result property="type" column="type"/>
        <result property="answerQuestion" column="answer_question"/>
        <result property="status" column="status"/>
        <result property="analysisContent" column="analysis_content"/>
        <result property="imgUrl" column="img_url"/>
        <result property="jsonStr" column="json_str"/>
        <result property="prefixName" column="prefix_name"/>
        <result property="knowledgeIds" column="knowledge_ids"/>
        <result property="publishStatus" column="publish_status"/>
        <result property="code" column="code"/>
        <result property="answerTime" column="answer_time"/>
        <result property="examPaperId" column="exam_paper_id"/>
        <result property="answerNum" column="answer_num"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.bank.domain.QuestionBusiness" id="QuestionBusiness">
        <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"/>
        <result property="type" column="business_type"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.exam.domain.ExamKnowledge" id="ExamKnowledge">
        <result property="knowledgeId" column="knowledge_id"/>
        <result property="knowledgeName" column="knowledge_name"/>
    </resultMap>

    <select id="getList" parameterType="com.zhongzheng.modules.bank.bo.ExamQuestionQueryBo" resultMap="ExamQuestionResultVo">
        SELECT
        q.*,
        eq.part_score,
        eq.score,
        eq.sort,
        qb.education_type_id,
        qb.business_id,
        qb.project_id,
        qb.subject_id,
        qb.type as business_type,
        cet.education_name,
        cpt.project_name,
        cb.business_name,
        cs.subject_name,
        ek.knowledge_name,
        ek.knowledge_id,
        e.pass_score,
        e.answer_time,
        e.answer_num
        FROM
        exam_question eq
        LEFT JOIN question q ON eq.question_id = q.question_id
        LEFT JOIN question_business qb ON q.question_id = qb.major_id and qb.type = 1
        LEFT JOIN course_education_type cet ON qb.education_type_id = cet.id
        LEFT JOIN course_project_type cpt ON qb.project_id = cpt.id
        LEFT JOIN course_business cb ON qb.business_id = cb.id
        LEFT JOIN course_subject cs ON cs.id = qb.subject_id
        LEFT JOIN exam e ON e.exam_id = eq.exam_id
        LEFT JOIN exam_knowledge ek ON FIND_IN_SET( ek.knowledge_id, q.knowledge_ids ) and ek.status != -1
        WHERE
              eq.exam_id =#{examId}
        ORDER BY eq.sort,eq.id DESC


    </select>

    <select id="getAppList" parameterType="com.zhongzheng.modules.bank.bo.ExamQuestionQueryBo" resultMap="ExamQuestionResultAppVo">
        SELECT
            q.*,
            eq.part_score,
            eq.score,
            eq.sort,
            e.pass_score,
            e.answer_time,
            e.answer_num
        FROM
            exam_question eq
                LEFT JOIN question q ON eq.question_id = q.question_id
                LEFT JOIN exam e ON e.exam_id = eq.exam_id
        WHERE
            eq.exam_id =#{examId}
        ORDER BY
            eq.sort,
            eq.id DESC

    </select>


</mapper>
