<?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.ssj.service.mapper.KmtQualityQuestionsMapper">

    <!--查询搜索的题目-->
    <select id="findKmtQuestionsById" resultType="com.ssj.service.kmt.dto.ExerciseQuetionDto">
        select eq.id question_id, eq.course_name, eq.handle_user_id, eq.auditing_user_id, eq.analysis_user_id, eq.analysis_auditer_id, eq.book_course_id course_id,
        eq.big_question_index, eq.num small_question_index, eq.question,eq.question_text, eq.option_answer answer,
        eq.answer_json, eq.deal_status question_status, eq.create_time, eq.remark reason, eq.from_user_id, eq.to_user_id, eq.analysis question_analysis,
        eq.analysis_json, eq.question_type question_types, eq.difficulty_level difficulty_levels, eq.real_exam_type real_exam_types,
        eq.training_skill training_skills, parent_id, image question_image, eq.update_type, qqc.begin_year, qqc.end_year
        from kmt_quality_questions eq
        left join kmt_quality_question_comment qqc on eq.id=qqc.question_id
        where (eq.id=#{questionId} or eq.parent_id=#{questionId}) and eq.question_class_type in (0, 2) and eq.book_id is null
        <choose>
            <when test="dealType == 1">
                and eq.handle_user_id = #{userId} and eq.deal_status &lt; 2
            </when>
            <when test="dealType == 2">
                and eq.auditing_user_id = #{userId} and eq.deal_status in (3, 7)
            </when>
            <otherwise>
                and eq.deal_status != 6
            </otherwise>
        </choose>
        order by eq.num
    </select>

    <!--查询大题-->
    <select id="findBigQuestionById"  resultType="com.ssj.service.kmt.dto.ExerciseQuetionDto">
        select eq.id question_id, eq.course_name, eq.handle_user_id, eq.auditing_user_id, eq.analysis_user_id, eq.analysis_auditer_id, eq.book_course_id course_id,
        eq.big_question_index, eq.small_question_name small_question_index, eq.question,eq.question_text, eq.option_answer answer,
        eq.answer_json, eq.deal_status question_status, eq.create_time, eq.remark reason, eq.analysis question_analysis,
        eq.analysis_json, eq.question_type question_types, eq.difficulty_level difficulty_levels, eq.real_exam_type real_exam_types,
        eq.training_skill training_skills, eq.parent_id, image question_image,eq.update_type, qqc.begin_year, qqc.end_year
        from kmt_quality_questions eq
        left join kmt_quality_question_comment qqc on eq.id=qqc.question_id
        where eq.id = #{id}
    </select>

    <select id="findData2EsByQuestionList" resultType="java.util.Map">
        select k.id,
        k.question_id,
        k.how_details_id,
        k.how_details_kd_id,
        k.how_detail_sort_id,
        k.how_detail_kd_sort_id,
        k.version,
        date_format(k.create_time, '%Y-%m-%dT%H:%i:%s.000Z')        create_time,
        book_id,
        unit_id,
        book_course_id,
        question,
        question_type,
        option_answer,
        source,
        big_question_index,
        date_format(analysis_submit_time, '%Y-%m-%dT%H:%i:%s.000Z') analysis_submit_time,
        page_index,
        image,
        precision_percent,
        auditing_user_id,
        handle_user_id,
        deal_status,
        remark,
        analysis_submit_type,
        answer_image,
        t.num,
        small_question_name,
        question_text,
        option_answer_text,
        ifnull(parent_id, '') parent_id,
        big_name,
        analysis,
        question_json,
        answer_json,
        real_exam_type,
        date_format(publish_time, '%Y-%m-%dT%H:%i:%s.000Z')         publish_time,
        update_type,
        analysis_user_id,
        ifnull(difficulty_level, 0) difficulty_level,
        t.course_name,
        training_skill,
        analysis_json,
        concise_id,
        analysis_auditer_id,
        date_format(handler_submit_time, '%Y-%m-%dT%H:%i:%s.000Z')         handler_submit_time,
        date_format(analysis_handler_submit_time, '%Y-%m-%dT%H:%i:%s.000Z')         analysis_handler_submit_time,
        question_class_type,
        ifnull(khds.alias, '') knowledge_name,
        khds.course_name,
        khds.semester,
        khds.grade,
        date_format(t.repulse_time, '%Y-%m-%dT%H:%i:%s.000Z')        repulse_time,
        qqc.begin_year,
        qqc.end_year
        from (select *
        from kmt_quality_question_know
        where question_id in
        <foreach collection="questionIdList" open="(" item="questionId" separator="," close=")">
            #{questionId}
        </foreach>
        limit 1000) k join kmt_quality_questions t on k.question_id = t.id
        left join kmt_quality_question_comment qqc on t.id =  qqc.question_id
        left join zyb_know_how_details_sort khds on k.how_detail_sort_id = khds.id
    </select>

    <select id="findQuestionByParentId" resultType="com.ssj.bean.kmt.kmt.domain.KmtQualityQuestions">
        select * from kmt_quality_questions where (id in
        <foreach collection="parentIds" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>or parent_id in
        <foreach collection="parentIds" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
        ) and deal_status != 6
        order by num
        limit 2000
    </select>

    <select id="findQualityQuestionKnowByQuestionId" resultType="com.ssj.bean.kmt.kmt.domain.KmtQualityQuestionKnow">
        select * from kmt_quality_question_know where question_id=#{questionId}
    </select>

</mapper>