<?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.artfess.examine.dao.ExamQuestionsInfoDao">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.artfess.examine.model.ExamQuestionsInfo">
        <id column="id_" property="id" />
        <result column="type_" property="type" />
        <result column="question_" property="question" />
        <result column="group_flag_" property="groupFlag" />
        <result column="right_option_" property="rightOption" />
        <result column="difficulty_" property="difficulty" />
        <result column="sub_id_" property="subId" />
        <result column="parsing_" property="parsing" />
        <result column="mark_type_" property="markType" />
        <result column="memo_" property="memo" />
        <result column="sn_" property="sn" />
        <result column="is_dele_" property="isDele" />
        <result column="create_by_" property="createBy" />
        <result column="create_org_id_" property="createOrgId" />
        <result column="create_time_" property="createTime" />
        <result column="update_by_" property="updateBy" />
        <result column="update_time_" property="updateTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id_, type_, question_, group_flag_, right_option_, difficulty_, parsing_, mark_type_, memo_, sn_, is_dele_, create_by_, create_org_id_, create_time_, update_by_, update_time_
    </sql>
    <select id="randomQuestion" resultType="com.artfess.examine.model.ExamQuestionsInfo">
        SELECT
            q.*
        FROM
            exam_questions_info q
        WHERE
            q.type_ = #{questionType}
            and q.sub_id_ = #{subjectId}
            and q.is_dele_ ='0'
        ORDER BY
            random()
            LIMIT #{numuber}

    </select>
    <select id="findBySubjectId" resultType="com.artfess.examine.vo.SubjectQuestionTypeVo">
        SELECT
            y.*,
            s.id_,
            s.name_ AS subjectName
        FROM
            exam_subject_info s
            inner JOIN (
            SELECT
                q.sub_id_,
                q.type_,
                min(q.score_) as score,
                COUNT ( 0 ) AS COUNT
            FROM
                exam_questions_info q
            WHERE
                q.sub_id_ = #{subjectId}
                and q.is_dele_ ='0'
            GROUP BY
                q.type_,
                q.sub_id_
            ORDER BY q.type_ desc
            ) y ON y.sub_id_ = s.id_
    </select>
    <select id="findByPage" resultType="com.artfess.examine.model.ExamQuestionsInfo">
        SELECT DISTINCT q.*,s.name_ as subjectName FROM exam_questions_info q
        LEFT JOIN exam_subject_info s on s.id_ = q.sub_id_
        LEFT JOIN exam_subject_pos ps on ps.subject_id_ = s.id_
        <if test="ew.customSqlSegment!=null">
            ${ew.customSqlSegment}
        </if>
    </select>
    <select id="selectTypeCount" resultType="com.artfess.examine.vo.SubjectQuestionTypeVo">
        SELECT
            q.type_,
            COUNT ( 0 ) AS COUNT
        FROM
            exam_questions_info q
        WHERE
            q.is_dele_ = '0'
        GROUP BY
            q.type_
        ORDER BY
            q.type_ asc
    </select>
    <select id="selectDifficulty" resultType="com.alibaba.fastjson.JSONObject">
        SELECT
            q.difficulty_ as difficulty,
            COUNT ( 0 ) AS COUNT
        FROM
            exam_questions_info q
        WHERE
            q.is_dele_ = '0'
        GROUP BY
            q.difficulty_
        ORDER BY
            q.difficulty_ asc
    </select>

</mapper>
