<?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.ie.mapper.SubquestionsMapper">

    <resultMap type="Subquestions" id="SubquestionsResult">
        <result property="id"    column="id"    />
        <result property="title"    column="title"    />
        <result property="optionA"    column="option_a"    />
        <result property="optionB"    column="option_b"    />
        <result property="optionC"    column="option_c"    />
        <result property="optionD"    column="option_d"    />
        <result property="pid"    column="pid"    />
        <result property="answer1"    column="answer1"    />
        <result property="answer2"    column="answer2"    />
        <result property="parse"    column="parse"    />
        <result property="qtpye"    column="qtpye"    />
        <result property="diff"    column="diff"    />
        <result property="subjectid"    column="subjectId"    />
        <result property="gradeid"    column="gradeId"    />
        <result property="knowledges"    column="knowledges"    />
        <result property="source"    column="source"    />
        <result property="tiid"    column="tiid"    />
        <result property="ptiid"    column="ptiid"    />
        <result property="fromsite"    column="fromsite"    />
        <result property="answerJson"    column="answer_json"    />
    </resultMap>

    <sql id="selectSubquestionsVo">
        select id, title, option_a, option_b, option_c, option_d, pid, answer1, answer2, parse, qtpye, diff, subjectId, gradeId, knowledges, source, tiid, ptiid, fromsite, answer_json from subquestions
    </sql>

    <select id="selectSubquestionsByQuestionIds" parameterType="Long" resultMap="SubquestionsResult">
        <include refid="selectSubquestionsVo"/>
        where pid in <foreach item="id" collection="array" open="(" separator="," close=")">#{id}</foreach>
    </select>

    <select id="selectSubquestionsByQuestionId" parameterType="Long" resultMap="SubquestionsResult">
        <include refid="selectSubquestionsVo"/>
        where pid =#{questionId}
    </select>

    <select id="selectSubquestionsList" parameterType="Subquestions" resultMap="SubquestionsResult">
        <include refid="selectSubquestionsVo"/>
        where 1=1
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="optionA != null  and optionA != ''"> and option_a = #{optionA}</if>
            <if test="optionB != null  and optionB != ''"> and option_b = #{optionB}</if>
            <if test="optionC != null  and optionC != ''"> and option_c = #{optionC}</if>
            <if test="optionD != null  and optionD != ''"> and option_d = #{optionD}</if>
            <if test="pid != null "> and pid = #{pid}</if>
            <if test="answer1 != null  and answer1 != ''"> and answer1 = #{answer1}</if>
            <if test="answer2 != null  and answer2 != ''"> and answer2 = #{answer2}</if>
            <if test="parse != null  and parse != ''"> and parse = #{parse}</if>
            <if test="qtpye != null  and qtpye != ''"> and qtpye = #{qtpye}</if>
            <if test="diff != null "> and diff = #{diff}</if>
            <if test="subjectid != null "> and subjectId = #{subjectid}</if>
            <if test="gradeid != null "> and gradeId = #{gradeid}</if>
            <if test="knowledges != null  and knowledges != ''"> and knowledges = #{knowledges}</if>
            <if test="source != null  and source != ''"> and source = #{source}</if>
            <if test="tiid != null  and tiid != ''"> and tiid = #{tiid}</if>
            <if test="ptiid != null  and ptiid != ''"> and ptiid = #{ptiid}</if>
            <if test="fromsite != null "> and fromsite = #{fromsite}</if>
            <if test="answerJson != null  and answerJson != ''"> and answer_json = #{answerJson}</if>
    </select>

    <!--分页慢 https://github.com/pagehelper/Mybatis-PageHelper/blob/master/wikis/zh/Changelog.md  更新时间2017-08-01-->
    <select id="selectSubquestionsList_COUNT" resultType="Long">
        select count(*)
        from subquestions q
        where 1=1 and q.id &gt;=1 and q.id &lt;=999999999
        <if test="title != null  and title != ''"> and title = #{title}</if>
        <if test="optionA != null  and optionA != ''"> and option_a = #{optionA}</if>
        <if test="optionB != null  and optionB != ''"> and option_b = #{optionB}</if>
        <if test="optionC != null  and optionC != ''"> and option_c = #{optionC}</if>
        <if test="optionD != null  and optionD != ''"> and option_d = #{optionD}</if>
        <if test="pid != null "> and pid = #{pid}</if>
        <if test="answer1 != null  and answer1 != ''"> and answer1 = #{answer1}</if>
        <if test="answer2 != null  and answer2 != ''"> and answer2 = #{answer2}</if>
        <if test="parse != null  and parse != ''"> and parse = #{parse}</if>
        <if test="qtpye != null  and qtpye != ''"> and qtpye = #{qtpye}</if>
        <if test="diff != null "> and diff = #{diff}</if>
        <if test="subjectid != null "> and subjectId = #{subjectid}</if>
        <if test="gradeid != null "> and gradeId = #{gradeid}</if>
        <if test="knowledges != null  and knowledges != ''"> and knowledges = #{knowledges}</if>
        <if test="source != null  and source != ''"> and source = #{source}</if>
        <if test="tiid != null  and tiid != ''"> and tiid = #{tiid}</if>
        <if test="ptiid != null  and ptiid != ''"> and ptiid = #{ptiid}</if>
        <if test="fromsite != null "> and fromsite = #{fromsite}</if>
        <if test="answerJson != null  and answerJson != ''"> and answer_json = #{answerJson}</if>
    </select>

    <select id="selectSubquestionsById" parameterType="Integer" resultMap="SubquestionsResult">
        <include refid="selectSubquestionsVo"/>
        where id = #{id}
    </select>

    <insert id="insertSubquestions" parameterType="Subquestions" useGeneratedKeys="true" keyProperty="id">
        insert into subquestions
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="title != null">title,</if>
            <if test="optionA != null">option_a,</if>
            <if test="optionB != null">option_b,</if>
            <if test="optionC != null">option_c,</if>
            <if test="optionD != null">option_d,</if>
            <if test="pid != null">pid,</if>
            <if test="answer1 != null">answer1,</if>
            <if test="answer2 != null">answer2,</if>
            <if test="parse != null">parse,</if>
            <if test="qtpye != null">qtpye,</if>
            <if test="diff != null">diff,</if>
            <if test="subjectid != null">subjectId,</if>
            <if test="gradeid != null">gradeId,</if>
            <if test="knowledges != null">knowledges,</if>
            <if test="source != null">source,</if>
            <if test="tiid != null">tiid,</if>
            <if test="ptiid != null">ptiid,</if>
            <if test="fromsite != null">fromsite,</if>
            <if test="answerJson != null">answer_json,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="title != null">#{title},</if>
            <if test="optionA != null">#{optionA},</if>
            <if test="optionB != null">#{optionB},</if>
            <if test="optionC != null">#{optionC},</if>
            <if test="optionD != null">#{optionD},</if>
            <if test="pid != null">#{pid},</if>
            <if test="answer1 != null">#{answer1},</if>
            <if test="answer2 != null">#{answer2},</if>
            <if test="parse != null">#{parse},</if>
            <if test="qtpye != null">#{qtpye},</if>
            <if test="diff != null">#{diff},</if>
            <if test="subjectid != null">#{subjectid},</if>
            <if test="gradeid != null">#{gradeid},</if>
            <if test="knowledges != null">#{knowledges},</if>
            <if test="source != null">#{source},</if>
            <if test="tiid != null">#{tiid},</if>
            <if test="ptiid != null">#{ptiid},</if>
            <if test="fromsite != null">#{fromsite},</if>
            <if test="answerJson != null">#{answerJson},</if>
         </trim>
    </insert>

    <update id="updateSubquestions" parameterType="Subquestions">
        update subquestions
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null">title = #{title},</if>
            <if test="optionA != null">option_a = #{optionA},</if>
            <if test="optionB != null">option_b = #{optionB},</if>
            <if test="optionC != null">option_c = #{optionC},</if>
            <if test="optionD != null">option_d = #{optionD},</if>
            <if test="pid != null">pid = #{pid},</if>
            <if test="answer1 != null">answer1 = #{answer1},</if>
            <if test="answer2 != null">answer2 = #{answer2},</if>
            <if test="parse != null">parse = #{parse},</if>
            <if test="qtpye != null">qtpye = #{qtpye},</if>
            <if test="diff != null">diff = #{diff},</if>
            <if test="subjectid != null">subjectId = #{subjectid},</if>
            <if test="gradeid != null">gradeId = #{gradeid},</if>
            <if test="knowledges != null">knowledges = #{knowledges},</if>
            <if test="source != null">source = #{source},</if>
            <if test="tiid != null">tiid = #{tiid},</if>
            <if test="ptiid != null">ptiid = #{ptiid},</if>
            <if test="fromsite != null">fromsite = #{fromsite},</if>
            <if test="answerJson != null">answer_json = #{answerJson},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSubquestionsByQuestionId" parameterType="Integer">
        delete from subquestions where pid = #{questionId}
    </delete>

    <delete id="deleteSubquestionsById" parameterType="Integer">
        delete from subquestions where id = #{id}
    </delete>

    <delete id="deleteSubquestionsByIds" parameterType="String">
        delete from subquestions where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
