<?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.project.business.mapper.TtQuestionDatabaseMapper">

    <resultMap id="BaseResultMap" type="com.ruoyi.project.business.domain.train.TtQuestionDatabase">
        <id property="id" column="id" jdbcType="BIGINT"/>
        <result property="questionType" column="question_type" jdbcType="VARCHAR"/>
        <result property="questionContext" column="question_context" jdbcType="VARCHAR"/>
        <result property="score" column="score" jdbcType="INTEGER"/>
        <result property="correctAnswer" column="correct_answer" jdbcType="VARCHAR"/>
        <result property="option1" column="option1" jdbcType="VARCHAR"/>
        <result property="option2" column="option2" jdbcType="VARCHAR"/>
        <result property="option3" column="option3" jdbcType="VARCHAR"/>
        <result property="option4" column="option4" jdbcType="VARCHAR"/>
        <result property="option5" column="option5" jdbcType="VARCHAR"/>
        <result property="option6" column="option6" jdbcType="VARCHAR"/>
        <result property="option7" column="option7" jdbcType="VARCHAR"/>
        <result property="option8" column="option8" jdbcType="VARCHAR"/>
        <result property="option9" column="option9" jdbcType="VARCHAR"/>
        <result property="option10" column="option10" jdbcType="VARCHAR"/>
        <result property="directoryId" column="directory_id" jdbcType="BIGINT"/>
        <result property="status" column="status" jdbcType="CHAR"/>
        <result property="delFlag" column="del_flag" jdbcType="CHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="createBy" column="create_by" jdbcType="BIGINT"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
        <result property="updateBy" column="update_by" jdbcType="BIGINT"/>
        <result property="remark" column="remark" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,question_type,question_context,
        score,correct_answer,option1,
        option2,option3,option4,
        option5,option6,option7,
        option8,option9,option10,
        directory_id,status,del_flag,
        create_time,create_by,update_time,
        update_by,remark
    </sql>
    <insert id="batchInsertTcQuestion" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO tt_question_database
        (question_type,
        question_context,
        score,
        correct_answer,
        option1,
        option2,
        option3,
        option4,
        option5,
        option6,
        option7,
        option8,
        option9,
        option10,
        directory_id,
        del_flag,
        create_time,
        create_by,
        update_time,
        update_by,
        remark)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.questionType},
            #{item.questionContext},
            #{item.score},
            #{item.correctAnswer},
            #{item.option1},
            #{item.option2},
            #{item.option3},
            #{item.option4},
            #{item.option5},
            #{item.option6},
            #{item.option7},
            #{item.option8},
            #{item.option9},
            #{item.option10},
            #{item.directoryId},
            #{item.delFlag},
            #{item.createTime},
            #{item.createBy},
            #{item.updateTime},
            #{item.updateBy},
            #{item.remark})
        </foreach>
    </insert>
    <select id="selectRandomQuestionList" parameterType="Integer" resultType="ttQuestionDatabase">
        SELECT
            *
        FROM
            tt_question_database
        WHERE
            id >= (SELECT FLOOR(RAND() * (SELECT MAX(id) FROM tt_question_database)))
                   ORDER BY id
            LIMIT #{num}
    </select>
    <select id="selectRandomQuestionListByNum"
            resultType="com.ruoyi.project.business.domain.train.TtQuestionDatabase">
        SELECT * FROM tt_question_database
        WHERE status != '1' and del_flag = '0'
        and question_type = #{questionType}
        <if test="existIds != null">
            and id not in
            <foreach collection="existIds" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        ORDER BY RAND() LIMIT #{questionTypeNum};
    </select>
</mapper>
