<?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.ruoyi.school.paper.mapper.DbQuestionBankMapper">

    <resultMap id="DbQuestionBankResult" type="com.ruoyi.school.paper.domain.DbQuestionBank">
        <result property="id" column="id"/>
        <result property="categoryId" column="category_id"/>
        <result property="species" column="species"/>
        <result property="phaseId" column="phase_id"/>
        <result property="type" column="type"/>
        <result property="intensity" column="intensity"/>
        <result property="topic" column="topic"/>
        <result property="rightAnswers" column="right_answers"/>
        <result property="rightAnswersPic" column="right_answers_pic"/>
        <result property="resolveCourse" column="resolve_course"/>
        <result property="resolveVideo" column="resolve_video"/>
        <result property="resolveVideoName" column="resolve_video_name"/>
        <result property="remark" column="remark"/>
        <result property="status" column="status"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateBy" column="update_by"/>
    </resultMap>

    <resultMap id="QuestionBankDetail" type="com.ruoyi.school.paper.domain.vo.DbQuestionBankAndAnswerVo">
        <id property="id" column="id"/>
        <result property="categoryId" column="category_id"/>
        <result property="species" column="species"/>
        <result property="phaseId" column="phase_id"/>
        <result property="type" column="type"/>
        <result property="intensity" column="intensity"/>
        <result property="topic" column="topic"/>
        <result property="rightAnswers" column="right_answers"/>
        <result property="rightAnswersPic" column="right_answers_pic"/>
        <result property="resolveCourse" column="resolve_course"/>
        <result property="resolveVideo" column="resolve_video"/>
        <result property="resolveVideoName" column="resolve_video_name"/>
        <result property="remark" column="remark"/>
        <result property="status" column="status"/>
        <collection property="options" ofType="com.ruoyi.school.paper.domain.vo.DbQuestionBankAnswerVo">
            <id property="id" column="a_id"/>
            <result property="questionBankId" column="question_bank_id"/>
            <result property="optionTag" column="option_tag"/>
            <result property="optionContent" column="option_content"/>
            <result property="remark" column="a_remark"/>
            <result property="status" column="a_status"/>
        </collection>
    </resultMap>

    <select id="selectDetailById" resultMap="QuestionBankDetail">
        select bank.id,
               bank.category_id,
               bank.species,
               bank.phase_id,
               bank.type,
               bank.intensity,
               bank.topic,
               bank.right_answers,
               bank.right_answers_pic,
               bank.resolve_course,
               bank.resolve_video,
               bank.resolve_video_name,
               bank.remark,
               bank.status,
               answer.id     as a_id,
               answer.question_bank_id,
               answer.option_tag,
               answer.option_content,
               answer.remark as a_remark,
               answer.status as a_status
        from db_question_bank as bank
                 left join db_question_bank_answer as answer on bank.species = 2 and answer.question_bank_id = bank.id
        where bank.id = #{id}
    </select>

    <resultMap id="MyErrorTopicListVo" type="com.ruoyi.school.paper.domain.vo.MyErrorTopicListVo">
        <result property="questionBankId" column="question_bank_id"/>
        <result property="topic" column="topic"/>
        <result property="resolveCourse" column="resolve_course"/>
        <result property="resolveVideo" column="resolve_video"/>
        <result property="resolveVideName" column="resolve_video_name"/>
        <collection property="options" javaType="java.util.List" column="question_bank_id" select="getOptionList" ofType="com.ruoyi.school.paper.domain.DbQuestionBankAnswer">
            <result property="id" column="id"/>
            <result property="questionBankId" column="question_bank_id"/>
            <result property="optionTag" column="option_tag"/>
            <result property="optionContent" column="option_content"/>
            <result property="remark" column="remark"/>
            <result property="status" column="status"/>
            <result property="createTime" column="create_time"/>
            <result property="createBy" column="create_by"/>
            <result property="updateTime" column="update_time"/>
            <result property="updateBy" column="update_by"/>
        </collection>
    </resultMap>
    <resultMap type="com.ruoyi.school.paper.domain.DbQuestionBankAnswer" id="DbQuestionBankAnswerResult">
        <result property="id" column="id"/>
        <result property="questionBankId" column="question_bank_id"/>
        <result property="optionTag" column="option_tag"/>
        <result property="optionContent" column="option_content"/>
        <result property="remark" column="remark"/>
        <result property="status" column="status"/>
        <result property="createTime" column="create_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="updateBy" column="update_by"/>
    </resultMap>

    <select id="getExampleList" resultMap="MyErrorTopicListVo">
        select qb.id as question_bank_id,
                qb.topic as topic,
                qb.resolve_course,
                qb.resolve_video,
                qb.resolve_video_name
        from db_question_bank qb
        where type = 1
        <if test="bo.categoryId != null">
            and qb.category_id = #{bo.categoryId}
        </if>
        <if test="bo.species != null">
            and qb.species = #{bo.species}
        </if>
    </select>

    <select id="getOptionList" resultMap="DbQuestionBankAnswerResult">
        select option_tag, option_content from db_question_bank_answer where question_bank_id = #{question_bank_id}
    </select>
</mapper>
