<?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.hc.business.mapper.QuestionMapper">

    <resultMap type="question" id="QuestionMap">
        <result property="questionId" column="question_id" jdbcType="INTEGER"/>
        <result property="questionDescription" column="question_description" jdbcType="VARCHAR"/>
        <result property="tagId" column="tag_id" jdbcType="INTEGER"/>
        <result property="questionType" column="question_type" jdbcType="INTEGER"/>
        <result property="questionScore" column="question_score" jdbcType="INTEGER"/>
        <result property="questionLevel" column="question_level" jdbcType="INTEGER"/>
        <result property="analysis" column="analysis" jdbcType="VARCHAR"/>
        <collection property="questionAnswerList"
                    column="question_id"
                    javaType="ArrayList"
                    ofType="questionAnswer"
                    select="com.hc.business.mapper.QuestionAnswerMapper.queryByQuestionId"
        />
    </resultMap>

    <sql id="Base_Column_List">
        question_id,
           question_description,
           tag_id,
           question_type,
           question_score,
           question_level,
           analysis
    </sql>

    <select id="queryById" resultMap="QuestionMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM question
        WHERE question_id = #{questionId}
    </select>

    <select id="queryQuestions" resultMap="QuestionMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM question
    </select>

    <select id="queryByTagId" resultType="java.lang.Integer">
        SELECT
        <include refid="Base_Column_List"/>
        FROM question
        WHERE question_type = #{questionType}
        AND question_level = #{questionLevel}
        AND tag_id = #{questionTagId}
    </select>

    <select id="queryTagId" resultMap="QuestionMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM question
        WHERE tag_id = #{questionTagId}
    </select>


</mapper>